From b8d4741c181acdc5fe39720edec0f8466c90cac5 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 6 Aug 2015 23:08:10 -0600 Subject: [PATCH] * Work with prompts. Prompts now handle special menu "submit" block without form IDs/etc. --- core/client.js | 1 - core/mci_view_factory.js | 2 +- core/view_controller.js | 75 ++++++++++++++++++++++++++++++++++++--- mods/art/MAINMENU.ANS | Bin 398 -> 304 bytes mods/art/doortoomany.ans | Bin 0 -> 245 bytes mods/art/menu_prompt.ans | Bin 0 -> 230 bytes mods/menu.json | 22 +++++++++++- mods/prompt.json | 19 +++++++++- 8 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 mods/art/doortoomany.ans create mode 100644 mods/art/menu_prompt.ans diff --git a/core/client.js b/core/client.js index 5bc795ed..76c44b7a 100644 --- a/core/client.js +++ b/core/client.js @@ -107,7 +107,6 @@ function Client(input, output) { // // Every 1m, check for idle. // - console.log('idleLogoutSeconds=' + Config.misc.idleLogoutSeconds) this.idleCheck = setInterval(function checkForIdle() { var nowMs = Date.now(); diff --git a/core/mci_view_factory.js b/core/mci_view_factory.js index 2bc14631..4000ca83 100644 --- a/core/mci_view_factory.js +++ b/core/mci_view_factory.js @@ -47,7 +47,7 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(code) { UW : this.client.user.properties.web_address, UF : this.client.user.properties.affiliation, UT : this.client.user.properties.theme_id, - MS : moment(this.client.user.properties.timestamp).format(this.client.currentTheme.helpers.getDateFormat()), + MS : moment(this.client.user.properties.account_created).format(this.client.currentTheme.helpers.getDateFormat()), SH : this.client.term.termHeight.toString(), diff --git a/core/view_controller.js b/core/view_controller.js index f11aa869..a3163791 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -252,6 +252,42 @@ function ViewController(options) { }); }; + // method for comparing submitted form data to configuration entries + this.actionBlockValueComparator = function(formValue, actionValue) { + // + // For a match to occur, one of the following must be true: + // + // * actionValue is a Object: + // a) All key/values must exactly match + // b) value is null; The key (view ID or "argName") must be present + // in formValue. This is a wildcard/any match. + // * actionValue is a Number: This represents a view ID that + // must be present in formValue. + // * actionValue is a string: This represents a view with + // "argName" set that must be present in formValue. + // + if(_.isNumber(actionValue) || _.isString(actionValue)) { + if(_.isUndefined(formValue[actionValue])) { + return false; + } + } else { + var actionValueKeys = Object.keys(actionValue); + for(var i = 0; i < actionValueKeys.length; ++i) { + var viewId = actionValueKeys[i]; + if(!_.has(formValue, viewId)) { + return false; + } + + if(null !== actionValue[viewId] && actionValue[viewId] !== formValue[viewId]) { + return false; + } + } + } + + self.client.log.trace( { formValue : formValue, actionValue : actionValue }, 'Action match'); + return true; + }; + if(!options.detached) { this.attachClientEvents(); } @@ -334,7 +370,7 @@ ViewController.prototype.switchFocus = function(id) { } }; -ViewController.prototype.nextFocus = function() { +ViewController.prototype.nextFocus = function() { if(!this.focusedView) { this.switchFocus(this.views[this.firstId].id); } else { @@ -421,12 +457,41 @@ ViewController.prototype.loadFromPromptConfig = function(options, cb) { callback(null); } }, - function prepareFormSubmission(callback) { + function prepareFormSubmission(callback) { if(false === self.noInput) { self.on('submit', function promptSubmit(formData) { self.client.log.trace( { formData : self.getLogFriendlyFormData(formData) }, 'Prompt submit'); - menuUtil.handleAction(self.client, formData, self.client.currentMenuModule.menuConfig); + if(_.isString(self.client.currentMenuModule.menuConfig.action)) { + menuUtil.handleAction(self.client, formData, self.client.currentMenuModule.menuConfig); + } else { + // + // Menus that reference prompts can have a sepcial "submit" block without the + // hassle of by-form-id configurations, etc. + // + // "submit" : [ + // { ... } + // ] + // + var menuSubmit = self.client.currentMenuModule.menuConfig.submit; + if(!_.isArray(menuSubmit)) { + self.client.log.debug('No configuration to handle submit'); + return; + } + + // + // Locate matching action block + // + // :TODO: this is bacially the same as for menus -- DRY it up! + for(var c = 0; c < menuSubmit.length; ++c) { + var actionBlock = menuSubmit[c]; + + if(_.isEqual(formData.value, actionBlock.value, self.actionBlockValueComparator)) { + menuUtil.handleAction(self.client, formData, actionBlock); + break; // there an only be one... + } + } + } }); } @@ -461,6 +526,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) { // :TODO: honor options.withoutForm // method for comparing submitted form data to configuration entries + /* var actionBlockValueComparator = function(formValue, actionValue) { // // For a match to occur, one of the following must be true: @@ -495,6 +561,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) { self.client.log.trace( { formValue : formValue, actionValue : actionValue }, 'Action match'); return true; }; + */ async.waterfall( [ @@ -569,7 +636,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) { for(var c = 0; c < confForFormId.length; ++c) { var actionBlock = confForFormId[c]; - if(_.isEqual(formData.value, actionBlock.value, actionBlockValueComparator)) { + if(_.isEqual(formData.value, actionBlock.value, self.actionBlockValueComparator)) { menuUtil.handleAction(self.client, formData, actionBlock); break; // there an only be one... } diff --git a/mods/art/MAINMENU.ANS b/mods/art/MAINMENU.ANS index 968aea289ee5f5d5d3fcecd4612869e6470d297c..c26cd179a6e076f97c4019c12d9c8a5a978d9090 100644 GIT binary patch delta 89 zcmeBU-oP|LhFdz?*f>`KNE+l$)KXwnm>8;{sQ}~~<_1GVb%B(DHBeD-WpPPru7YP? gT0SoqM9IWGa+7%(qdC_zFfcGO1~BkWE@YGi0ROTU9{>OV literal 398 zcmb1+Hn27^ur@Z&<>kT!rK62aa}^Y%qYbT%jdR_B3}b^_T_6S2XPoPkpPrwV#>)j! z1tg7gK}vH&(bR<&rxq!A=B4Gsl!8=&3=&5Jz_$6O=9MZW=jY}o=A~ExZGt#f)iuPBmrE+xG1S@Bz(9d| kz{tSR)WF=>fR~YhfsrwQL7V{$ggu>n6~f#dAv`z<0J(Zi2><{9 diff --git a/mods/art/doortoomany.ans b/mods/art/doortoomany.ans new file mode 100644 index 0000000000000000000000000000000000000000..e3fa4a31c4012abb99d927635ab08f6f0fb8aa6e GIT binary patch literal 245 zcmb1+Hn27^ur@Z&<>f+#($Pjn&eG9_*2bo}A<{raKsrAkD3GfF<>e;kRVt+9=NBnt z<`tJD<|U^V>w)Eip$ZaH(h`$Xp;~|zSV>148|G^8a!Ca{hB~_%7${H=7#SFv8dw+@ cmoP9eFfs-(Z~$o_5cYKPRS0u;gz(@b05qU1r2qf` literal 0 HcmV?d00001 diff --git a/mods/art/menu_prompt.ans b/mods/art/menu_prompt.ans new file mode 100644 index 0000000000000000000000000000000000000000..e785578d24b127705000403355f5e230e2c5f339 GIT binary patch literal 230 zcmb1+Hn27^ur@Z&y?y^S5GhDU8|JDyhZyp5Nk<#x-oJBq)1CVuL2F~f+(@7hh|Vu9 zQb^9v%}vZp0m~TVT7eWplo{u$x`r4*v@6`bclRDImsGH0sI#kqfdch_k%6J9frWut cDgy%pBVzyqGmr)XVNWMtg)nzV2oFvI05