From 13d104c840c45e3ae2b63cafd0d2cc9a0b11d1d9 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 4 Jul 2015 12:02:37 -0600 Subject: [PATCH] * A lot of cleanup in ViewController * ViewController.getFormData() * Lots of WIP work on fse.js & multiple forms --- core/status_bar_view.js | 20 +++ core/view_controller.js | 236 +++++++-------------------- mods/art/demo_fse_netmail_body.ans | Bin 0 -> 145 bytes mods/art/demo_fse_netmail_header.ans | Bin 0 -> 566 bytes mods/fse.js | 65 ++++++++ mods/menu.json | 61 ++++++- 6 files changed, 200 insertions(+), 182 deletions(-) create mode 100644 mods/art/demo_fse_netmail_body.ans create mode 100644 mods/art/demo_fse_netmail_header.ans diff --git a/core/status_bar_view.js b/core/status_bar_view.js index 903fb5d4..ed47ca7d 100644 --- a/core/status_bar_view.js +++ b/core/status_bar_view.js @@ -40,5 +40,25 @@ StatusBarView.prototype.setPanels = function(panels) { |---------------------------------------------| | stuff | */ + assert(_.isArray(panels)); + + this.panels = []; + + var tvOpts = { + cursor : 'hide', + position : { row : this.position.row, col : 0 }, + }; + + panels.forEach(function panel(p) { + assert(_.isObject(p)); + assert(_.has(p, 'width')); + + if(p.text) { + this.panels.push( new TextView( { })) + } else { + this.panels.push( { width : p.width } ); + } + }); + }; diff --git a/core/view_controller.js b/core/view_controller.js index 2a61b6e2..e6d24305 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -74,46 +74,7 @@ function ViewController(options) { }; this.submitForm = function() { - /* - Generate a form resonse. Example: - - { - id : 0, - submitId : 1, - value : { - "1" : "hurp", - "2" : [ 'a', 'b', ... ], - "3" 2, - "pants" : "no way" - } - - } - */ - var formData = { - id : self.formId, - submitId : self.focusedView.id, - value : {}, - }; - - var viewData; - var view; - for(var id in self.views) { - try { - view = self.views[id]; - viewData = view.getData(); - if(!_.isUndefined(viewData)) { - if(_.isString(view.submitArgName)) { - formData.value[view.submitArgName] = viewData; - } else { - formData.value[id] = viewData; - } - } - } catch(e) { - Log.error(e); // :TODO: Log better ;) - } - } - - self.emit('submit', formData); + self.emit('submit', this.getFormData()); }; this.getLogFriendlyFormData = function(formData) { @@ -159,9 +120,6 @@ function ViewController(options) { // :TODO: move this elsewhere this.setViewPropertiesFromMCIConf = function(view, conf) { - // :TODO: This broke at least VerticalMenuView due to order of setting properties... really, - // shouldn't matter what the order is, so that should be fixed. - for(var propName in conf) { var propValue; var propAsset = asset.getViewPropertyAsset(conf[propName]); @@ -176,8 +134,6 @@ function ViewController(options) { default : propValue = propValue = conf[propName]; break; - - } } else { propValue = conf[propName]; @@ -186,141 +142,7 @@ function ViewController(options) { if(!_.isUndefined(propValue)) { view.setPropertyValue(propName, propValue); } - } - - // :TODO: Experimental.... - /* - function setViewProperty2(propName) { - if(!_.isUndefined(conf[propName])) { - var propValue; - var propAsset = asset.getViewPropertyAsset(conf[propName]); - if(propAsset) { - switch(propAsset.type) { - case 'config' : - propValue = asset.resolveConfigAsset(config[propName]); - break; - - // :TODO: handle @art (e.g. text : @art ...) - - default : - propValue = propValue = conf[propName]; - break; - - - } - } else { - propValue = conf[propName]; - } - - if(!_.isUndefined(propValue)) { - view.setPropertyValue(propName, propValue); - } - } - } - - function setViewProp(propName, setter) { - if(!_.isUndefined(conf[propName])) { - var propValue; - var propAsset = asset.getViewPropertyAsset(conf[propName]); - if(propAsset) { - switch(propAsset.type) { - case 'config' : - propValue = asset.resolveConfigAsset(config[propName]); - break; - - // :TODO: handle @art (e.g. text : @art ...) - - default : - propValue = propValue = conf[propName]; - break; - - - } - } else { - propValue = conf[propName]; - } - - if(!_.isUndefined(propValue)) { - if(setter) { - setter(propValue); - } else { - view[propName] = propValue; - } - } - } - } - */ - - //setViewProp('width', function(v) { view.setWidth(parseInt(v, 10)); }); - //setViewProp('height', function(v) { view.setHeight(parseInt(v, 10)); }); - //setViewProp('itemSpacing', function(v) { view.setItemSpacing(v); }); - //setViewProp('items', function(v) { view.setItems(v); }); - //setViewProp('text', function(v) { view.setText(v); }); - //setViewProp('textStyle'); - //setViewProp('focusTextStyle'); - //setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); }); - //setViewProp('justify'); - //setViewProp('textOverflow'); - //setViewProp('maskPattern', function(v) { view.setMaskPattern(v); }); - //setViewProp('maxLength'); - //setViewProp('hotKeys', function(v) { view.setHotKeys(v); }); - //setViewProp('argName', function(v) { view.submitArgName = v; }); - - // :TODO: better yet, just loop through properties directly from the JSON and - // call setPropertyValue(). View should be responsible for any conversions, e.g. - // boolean vs maskchar for 'password', etc. - - /* - [ - 'width', 'height', - 'itemSpacing', 'items', - 'text', 'textStyle', 'focusTextStyle', 'textMaskChar', - 'justify', 'textOverflow', - 'maskPattern', - 'maxLength', - 'fillChar', - 'password', - ].forEach(function pn(thePropName) { - setViewProperty2(thePropName); - }); - - // - // styleSGRx: 1..25 - // - for(var i = 1; i <= 25; i++) { - // :TODO: fix function in loop - setViewProp('styleSGR' + i, function(v) { - if(_.isObject(v)) { - view['styleSGR' + i] = ansi.getSGRFromGraphicRendition(v, true); - } else if(_.isString(v)) { - view['styleSGR' + i] = ansi.fromPipeCode(v); - } - }); - } - - setViewProp('fillChar', function(v) { - if(_.isNumber(v)) { - view.fillChar = String.fromCharCode(v); - } else if(_.isString(v)) { - view.fillChar = v.substr(0, 1); - } - }); - - setViewProp('password', function(v) { - if(true === v) { - view.textMaskChar = self.client.currentTheme.helpers.getPasswordChar(); - } - }); - - setViewProp('submit', function(v) { - if(_.isBoolean(v)) { - view.submit = v; - } else { - view.submit = _.isArray(v) && v.length > 0; - } - }); - */ - + } }; this.applyViewConfig = function(config, cb) { @@ -373,7 +195,9 @@ function ViewController(options) { }); }; - this.attachClientEvents(); + if(!options.detached) { + this.attachClientEvents(); + } } util.inherits(ViewController, events.EventEmitter); @@ -420,6 +244,14 @@ ViewController.prototype.getFocusedView = function() { return this.focusedView; }; +ViewController.prototype.removeFocus = function() { + var v = this.getFocusedView(); + if(v) { + v.setFocus(false); + this.focusedView = null; + } +}; + ViewController.prototype.switchFocus = function(id) { if(this.focusedView && this.focusedView.acceptsFocus) { this.switchFocusEvent('leave', this.focusedView); @@ -709,6 +541,48 @@ ViewController.prototype.formatMCIString = function(format) { }); }; +ViewController.prototype.getFormData = function() { + /* + Example form data: + { + id : 0, + submitId : 1, + value : { + "1" : "hurp", + "2" : [ 'a', 'b', ... ], + "3" 2, + "pants" : "no way" + } + + } + */ + var formData = { + id : this.formId, + submitId : this.focusedView.id, + value : {}, + }; + + var viewData; + var view; + for(var id in this.views) { + try { + view = this.views[id]; + viewData = view.getData(); + if(!_.isUndefined(viewData)) { + if(_.isString(view.submitArgName)) { + formData.value[view.submitArgName] = viewData; + } else { + formData.value[id] = viewData; + } + } + } catch(e) { + Log.error(e); // :TODO: Log better ;) + } + } + + return formData; +} + /* ViewController.prototype.formatMenuArgs = function(args) { var self = this; diff --git a/mods/art/demo_fse_netmail_body.ans b/mods/art/demo_fse_netmail_body.ans new file mode 100644 index 0000000000000000000000000000000000000000..1c5455734e597e8ee249e5c066ae1e2d6ce3415e GIT binary patch literal 145 zcmb1+Hn27^ur@Z&RrL)qDmHq8Z*=3o-Y28jV>!J>vBK?n!PK;i*8*2V@v#V~2O z08l@fhlWsnQwT7h}0t|5jXH$iBFT