=== SlimBrowserApplet.lua ================================================================== --- SlimBrowserApplet.lua (revision 30520) +++ SlimBrowserApplet.lua (local) @@ -100,6 +100,7 @@ -- The last entered text local _lastInput = "" +local _inputParams = {} -- connectingToPlayer and _upgradingPlayer popup handlers local _connectingPopup = false @@ -581,9 +582,18 @@ playerid = _player:getId() end + -- look for multiple input keys in inputParamKeys + local newparams = {} + local inputParamKeys = jsonAction['inputParamKeys'] + if inputParamKeys then + newparams = {} + for k, v in pairs(inputParamKeys) do + table.insert( newparams, k .. ":" .. v) + end + end + -- look for __INPUT__ as a param value local params = jsonAction["params"] - local newparams if params then newparams = {} for k, v in pairs(params) do @@ -612,10 +622,8 @@ table.insert(request, from) table.insert(request, qty) - if newparams then - for i, v in ipairs(newparams) do - table.insert(request, v) - end + for i, v in ipairs(newparams) do + table.insert(request, v) end if step then @@ -2186,6 +2194,164 @@ end +-- _browseInput: method to render a textinput/keyboard for SlimBrowse input +-- self in this function is the input/keyboard window +local function _browseInput(self, inputSpec, last) + -- never allow screensavers in an input window + self:setAllowScreensaver(false) + if inputSpec.title then + self:setTitle(inputSpec.title) + end + + local nowPlayingButton + if inputSpec.setupWindow == 1 then + nowPlayingButton = nil + else + nowPlayingButton = _nowPlayingButton() + end + + if inputSpec.title then + titleText = inputSpec.title + end + + local newTitleWidget = Group('title', { + text = Label("text", titleText), + lbutton = _backButton(), + rbutton = nowPlayingButton, + }) + self:setTitleWidget(newTitleWidget) + + + -- make sure it's a number for the comparison below + -- Lua insists on checking type while Perl couldn't care less :( + inputSpec.len = tonumber(inputSpec.len) + + -- default allowedChars + if not inputSpec.allowedChars then + if inputSpec._kbType == 'qwertyLower' then + inputSpec.allowedChars = _string("ALLOWEDCHARS_WITHCAPS") + elseif inputSpec._kbType and string.match(inputSpec._kbType, 'email') then + inputSpec.allowedChars = _string("ALLOWEDCHARS_EMAIL") + else + inputSpec.allowedChars = _string("ALLOWEDCHARS_CAPS") + end + end + local v = "" + local initialText = inputSpec.initialText + local inputStyle = inputSpec._inputStyle + + if initialText then + v = tostring(initialText) + end + + if inputStyle == 'time' then + if not initialText then + initialText = '0' + end + local timeFormat = _getTimeFormat() + local _v = DateTime:timeFromSFM(v, timeFormat) + v = Textinput.timeValue(_v, timeFormat) + elseif inputStyle == 'ip' then + if not initialText then + initialText = '0.0.0.0' + end + v = Textinput.ipAddressValue(initialText) + end + + -- create a text input + local input = Textinput( + "textinput", + v, + function(_, value) + -- check for min number of chars + if #value < inputSpec.len then + self:playSound("BUMP") + return false + end + + + log:debug("Input: " , value) + _lastInput = value + --table.insert(_inputParams, value) + item['_inputDone'] = value + + -- popup time + local displayPopup = _safeDeref(item, 'input', 'processingPopup') + local displayPopupText = _safeDeref(item, 'input', 'processingPopup', 'text') + if displayPopup then + _inputInProgress(self, displayPopupText) + end + -- now we should perform the action ! + _actionHandler(nil, nil, db, nil, nil, 'go', item) + -- close the text input if this is a "do" + local doAction = _safeDeref(item, 'actions', 'do') + if doAction then + -- close the window + self:playSound("WINDOWHIDE") + self:hide() + else + self:playSound("WINDOWSHOW") + end + return true + end, + inputSpec.allowedChars + ) + + --[[ FIXME: removing help (all platforms) for purposes of Fab4. + -- fix up help + local helpText + if inputSpec.help then + local help = inputSpec.help + helpText = help.text + if not helpText then + if help.token then + helpText = _string(help.token) + end + end + end + + local softButtons = { inputSpec.softbutton1, inputSpec.softbutton2 } + local helpStyle = 'help' + + if softButtons[1] or softButtons[2] then + helpStyle = 'softHelp' + end + + if helpText then + local help = Textarea(helpStyle, helpText) + self:addWidget(help) + end + + if softButtons[1] then + self:addWidget(Label("softButton1", softButtons[1])) + end + if softButtons[2] then + self:addWidget(Label("softButton2", softButtons[2])) + end + --]] + + if inputSpec.help and inputSpec.help.text then + _addHelpButton(self, inputSpec.help.text, inputSpec.setupWindow) + end + + local kbType = inputSpec._kbType or 'qwerty' + local keyboard = Keyboard("keyboard", kbType) + local backspace = Button( + Icon('button_keyboard_back'), + function() + local e = Event:new(EVENT_CHAR_PRESS, string.byte("\b")) + Framework:dispatchEvent(nil, e) + return EVENT_CONSUME + end + ) + local group = Group('keyboard_textinput', { textinput = input, backspace = backspace } ) + + self:addWidget(group) + self:addWidget(keyboard) + self:focusWidget(group) + +end + -- _newDestination -- origin is the step we are coming from -- item is the source item @@ -2212,172 +2378,39 @@ -- if the item has an input field, we must ask for it if item and item['input'] and not item['_inputDone'] then - -- never allow screensavers in an input window - window:setAllowScreensaver(false) - if item.input.title then - window:setTitle(item.input.title) - end + local inputSpec = item['input'] + -- inspect inputSpec. if it's a multiple item table, then that's a multiple parameter input + debug.dump(inputSpec) +--[[ single param +{ + setupWindow = 1, + title = "Enter Email Address", + len = 3, + softbutton2 = "Delete", + _kbType = "email", + softbutton1 = "Insert", +} - local nowPlayingButton - if item.input.setupWindow == 1 then - nowPlayingButton = nil - else - nowPlayingButton = _nowPlayingButton() +multiple params +{ [[table: 0x16bad6f0 + ["HASH(0x3455c70)"] = function: 0x16b55ff0, + ["HASH(0x342cf88)"] = { [[table: 0x16bc45c0 + help = { [[table: 0x16bc4600 ... }, + len = 1, + allowedChars = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+{}|:\\\"'<>?-=,./~`[];0123456789", + initialText = "Office Boom!", + _kbType = "qwerty", + }, +} +--]] + if inputSpec[1] and type(inputSpec[1] == 'table') then + log:warn('yes') + elseif inputSpec[2] then + log:warn('no') end + local last + _browseInput(window, inputSpec, last) - if item.input.title then - titleText = item.input.title - end - - local newTitleWidget = Group('title', { - text = Label("text", titleText), - lbutton = _backButton(), - rbutton = nowPlayingButton, - }) - window:setTitleWidget(newTitleWidget) - - local inputSpec - - -- legacy SS compatibility - -- FIXME: remove SS compatibility with legacy JiveMLON generation - if type(item['input']) != "table" then - inputSpec = { - len = item['input'], - help = { - token = "SLIMBROWSER_SEARCH_HELP", - }, - } - else - inputSpec = item["input"] - end - - -- make sure it's a number for the comparison below - -- Lua insists on checking type while Perl couldn't care less :( - inputSpec.len = tonumber(inputSpec.len) - - -- default allowedChars - if not inputSpec.allowedChars then - if inputSpec._kbType == 'qwertyLower' then - inputSpec.allowedChars = _string("ALLOWEDCHARS_WITHCAPS") - elseif inputSpec._kbType and string.match(inputSpec._kbType, 'email') then - inputSpec.allowedChars = _string("ALLOWEDCHARS_EMAIL") - else - inputSpec.allowedChars = _string("ALLOWEDCHARS_CAPS") - end - end - local v = "" - local initialText = _safeDeref(item, 'input', 'initialText') - local inputStyle = _safeDeref(item, 'input', '_inputStyle') - - if initialText then - v = tostring(initialText) - end - - if inputStyle == 'time' then - if not initialText then - initialText = '0' - end - local timeFormat = _getTimeFormat() - local _v = DateTime:timeFromSFM(v, timeFormat) - v = Textinput.timeValue(_v, timeFormat) - elseif inputStyle == 'ip' then - if not initialText then - initialText = '0.0.0.0' - end - v = Textinput.ipAddressValue(initialText) - end - - -- create a text input - local input = Textinput( - "textinput", - v, - function(_, value) - -- check for min number of chars - if #value < inputSpec.len then - window:playSound("BUMP") - return false - end - - - log:debug("Input: " , value) - _lastInput = value - item['_inputDone'] = value - - -- popup time - local displayPopup = _safeDeref(item, 'input', 'processingPopup') - local displayPopupText = _safeDeref(item, 'input', 'processingPopup', 'text') - if displayPopup then - _inputInProgress(self, displayPopupText) - end - -- now we should perform the action ! - _actionHandler(nil, nil, db, nil, nil, 'go', item) - -- close the text input if this is a "do" - local doAction = _safeDeref(item, 'actions', 'do') - if doAction then - -- close the window - window:playSound("WINDOWHIDE") - window:hide() - else - window:playSound("WINDOWSHOW") - end - return true - end, - inputSpec.allowedChars - ) - - --[[ FIXME: removing help (all platforms) for purposes of Fab4. - -- fix up help - local helpText - if inputSpec.help then - local help = inputSpec.help - helpText = help.text - if not helpText then - if help.token then - helpText = _string(help.token) - end - end - end - - local softButtons = { inputSpec.softbutton1, inputSpec.softbutton2 } - local helpStyle = 'help' - - if softButtons[1] or softButtons[2] then - helpStyle = 'softHelp' - end - - if helpText then - local help = Textarea(helpStyle, helpText) - window:addWidget(help) - end - - if softButtons[1] then - window:addWidget(Label("softButton1", softButtons[1])) - end - if softButtons[2] then - window:addWidget(Label("softButton2", softButtons[2])) - end - --]] - - if inputSpec.help and inputSpec.help.text then - _addHelpButton(window, inputSpec.help.text, inputSpec.setupWindow) - end - - local kbType = inputSpec._kbType or 'qwerty' - local keyboard = Keyboard("keyboard", kbType) - local backspace = Button( - Icon('button_keyboard_back'), - function() - local e = Event:new(EVENT_CHAR_PRESS, string.byte("\b")) - Framework:dispatchEvent(nil, e) - return EVENT_CONSUME - end - ) - local group = Group('keyboard_textinput', { textinput = input, backspace = backspace } ) - - window:addWidget(group) - window:addWidget(keyboard) - window:focusWidget(group) - -- special case for sending over textArea elseif item and item['textArea'] then local textArea = Textarea("text", item['textArea']) @@ -2491,25 +2524,25 @@ local function _installActionListeners(self) if _actionListenerHandles then - return + return end _actionListenerHandles = {} for action, func in pairs( _globalActionsNEW ) do - local handle = Framework:addActionListener(action, self, func, false) - table.insert(_actionListenerHandles, handle) + local handle = Framework:addActionListener(action, self, func, false) + table.insert(_actionListenerHandles, handle) end end local function _removeActionListeners(self) if not _actionListenerHandles then - return + return end for i, handle in ipairs( _actionListenerHandles ) do - Framework:removeListener(handle) + Framework:removeListener(handle) end _actionListenerHandles = false @@ -2526,7 +2559,7 @@ local windowStack = Framework.windowStack Framework:playSound("JUMP") while #windowStack > 1 do - windowStack[#windowStack - 1]:hide(transition) + windowStack[#windowStack - 1]:hide(transition) end end