diff --git a/core/mci_view_factory.js b/core/mci_view_factory.js index 4000ca83..928212e6 100644 --- a/core/mci_view_factory.js +++ b/core/mci_view_factory.js @@ -74,6 +74,7 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(code) { IP : this.client.address().address, }[code]; } catch(e) { + this.client.log.warn( { code : code, exception : e.message }, 'Exception caught attempting to construct predefined label'); } }; diff --git a/core/message_area.js b/core/message_area.js index c35b33ac..f9612b14 100644 --- a/core/message_area.js +++ b/core/message_area.js @@ -8,6 +8,7 @@ var _ = require('lodash'); var assert = require('assert'); exports.getAvailableMessageAreas = getAvailableMessageAreas; +exports.changeCurrentArea = changeCurrentArea; function getAvailableMessageAreas(cb) { var areas = []; // { areaId, name, groupIds[] } @@ -58,4 +59,23 @@ function getAvailableMessageAreas(cb) { } ); +} + +function changeCurrentArea(client, areaId, cb) { + async.series( + [ + function validateAccess(callback) { + // :TODO: validate user has access to areaId -- must belong to group(s) specified + callback(null); + }, + function changeArea(callback) { + client.user.persistProperty('message_area_id', areaId, function persisted(err) { + callback(err); + }); + } + ], + function complete(err) { + cb(err); + } + ); } \ No newline at end of file diff --git a/core/view_controller.js b/core/view_controller.js index 81cb3862..79286754 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -267,6 +267,10 @@ function ViewController(options) { // * actionValue is a string: This represents a view with // "argName" set that must be present in formValue. // + if(_.isUndefined(actionValue)) { + return false; + } + if(_.isNumber(actionValue) || _.isString(actionValue)) { if(_.isUndefined(formValue[actionValue])) { return false; @@ -440,7 +444,7 @@ ViewController.prototype.loadFromPromptConfig = function(options, cb) { function applyThemeCustomization(callback) { if(_.isObject(promptConfig)) { menuUtil.applyThemeCustomization({ - name : promptName,//self.client.currentMenuModule.menuConfig.prompt, + name : promptName, type : "prompts", client : self.client, configMci : promptConfig.mci, @@ -526,44 +530,6 @@ 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: - // - // * 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; - }; - */ - async.waterfall( [ function findMatchingFormConfig(callback) { diff --git a/mods/art/msg_area_list.ans b/mods/art/msg_area_list.ans index 2f637e0d..0f48bc4d 100644 Binary files a/mods/art/msg_area_list.ans and b/mods/art/msg_area_list.ans differ diff --git a/mods/menu.json b/mods/menu.json index 1c1ad3ad..d0f6ded7 100644 --- a/mods/menu.json +++ b/mods/menu.json @@ -281,20 +281,23 @@ "art" : "msg_area_list.ans", "module" : "msg_area_list", "options" : { "cls" : true }, + "fallback" : "messageArea", "form" : { "0" : { - "LVTL" : { + "TLVM" : { "mci" : { - "LV1" : { + "VM1" : { "widht" : 30, "height" : 10, - "focus" : true + "focus" : true, + "submit" : true, + "argName" : "area" } }, "submit" : { "*" : [ { - "value" : null, + "value" : { "area" : null }, "action" : "@method:changeArea" } ] diff --git a/mods/msg_area_list.js b/mods/msg_area_list.js index cdf5dfd0..50d4fc33 100644 --- a/mods/msg_area_list.js +++ b/mods/msg_area_list.js @@ -34,7 +34,12 @@ function MessageAreaListModule(options) { this.menuMethods = { changeArea : function(formData, extraArgs) { - console.log(formData) + if(1 === formData.submitId) { + var areaId = self.messageAreas[formData.value.area].areaId; + messageArea.changeCurrentArea(self.client, areaId, function areaChanged(err) { + self.client.gotoMenuModule( { name : self.menuConfig.fallback } ); + }); + } } }; @@ -42,11 +47,21 @@ function MessageAreaListModule(options) { require('util').inherits(MessageAreaListModule, MenuModule); +MessageAreaListModule.prototype.enter = function(client) { + var self = this; + + messageArea.getAvailableMessageAreas(function fetched(err, areas) { + self.messageAreas = areas; + + MessageAreaListModule.super_.prototype.enter.call(self, client); + }); +}; + MessageAreaListModule.prototype.mciReady = function(mciData, cb) { var self = this; var vc = self.viewControllers.areaList = new ViewController( { client : self.client } ); - var messageAreas = []; + //var messageAreas = []; async.series( [ @@ -59,24 +74,28 @@ MessageAreaListModule.prototype.mciReady = function(mciData, cb) { var loadOpts = { callingMenu : self, mciMap : mciData.menu, - noInput : true, + formId : 0, }; vc.loadFromMenuConfig(loadOpts, function startingViewReady(err) { callback(err); }); }, + /* function fetchAreaData(callback) { messageArea.getAvailableMessageAreas(function fetched(err, areas) { messageAreas = areas; callback(err); }); }, + */ function populateAreaListView(callback) { var areaListView = vc.getView(1); var areaList = []; - messageAreas.forEach(function entry(msgArea) { + self.messageAreas.forEach(function entry(msgArea) { + // :TODO: depending on options, filter out private, local user to user, etc. area IDs + // :TODO: dep. on options, filter out areas that current user does not have access to areaList.push(strUtil.format(self.entryFormat, msgArea)); });