2015-08-18 21:27:14 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
var ViewController = require('../core/view_controller.js').ViewController;
|
|
|
|
var messageArea = require('../core/message_area.js');
|
2015-08-18 23:00:18 +00:00
|
|
|
var strUtil = require('../core/string_util.js');
|
2015-08-18 21:27:14 +00:00
|
|
|
//var msgDb = require('./database.js').dbs.message;
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
var assert = require('assert');
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
exports.getModule = MessageAreaListModule;
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Message Area List',
|
|
|
|
desc : 'Module for listing / choosing message areas',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
|
|
|
function MessageAreaListModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
2015-08-18 23:00:18 +00:00
|
|
|
if(_.isObject(this.menuConfig.config)) {
|
|
|
|
if(_.isString(this.menuConfig.config.entryFormat)) {
|
|
|
|
this.entryFormat = this.menuConfig.config.entryFormat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.entryFormat = this.entryFormat || '( {areaId} ) - {name}';
|
|
|
|
|
|
|
|
this.menuMethods = {
|
|
|
|
changeArea : function(formData, extraArgs) {
|
|
|
|
console.log(formData)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-18 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(MessageAreaListModule, MenuModule);
|
|
|
|
|
|
|
|
MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
|
|
|
var self = this;
|
|
|
|
var vc = self.viewControllers.areaList = new ViewController( { client : self.client } );
|
|
|
|
|
|
|
|
var messageAreas = [];
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function callParentMciReady(callback) {
|
|
|
|
MessageAreaListModule.super_.prototype.mciReady.call(this, mciData, function parentMciReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
var loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
noInput : true,
|
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2015-08-18 23:00:18 +00:00
|
|
|
areaList.push(strUtil.format(self.entryFormat, msgArea));
|
2015-08-18 21:27:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
console.log(areaList)
|
|
|
|
|
|
|
|
areaListView.setItems(areaList);
|
|
|
|
areaListView.redraw();
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|