* Minor code cleanup + fixes, area change/list semi functional
This commit is contained in:
parent
aaac4e884b
commit
c9a24b7ec8
|
@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
}
|
|
@ -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) {
|
||||
|
|
Binary file not shown.
|
@ -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"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue