* New message_area.js for Message Area APIs, etc.

* msg_area_list.js module for listing/selecting message area (WIP; much to do)
This commit is contained in:
Bryan Ashby 2015-08-18 15:27:14 -06:00
parent 990dffe880
commit aa820ac0b5
5 changed files with 163 additions and 0 deletions

61
core/message_area.js Normal file
View File

@ -0,0 +1,61 @@
/* jslint node: true */
'use strict';
var msgDb = require('./database.js').dbs.message;
var async = require('async');
var _ = require('lodash');
var assert = require('assert');
exports.getAvailableMessageAreas = getAvailableMessageAreas;
function getAvailableMessageAreas(cb) {
var areas = []; // { areaId, name, groupIds[] }
async.series(
[
function getAreas(callback) {
msgDb.all(
'SELECT area_id, area_name ' +
'FROM message_area;',
function areaResults(err, areaRows) {
if(err) {
callback(err);
} else {
areaRows.forEach(function entry(ar) {
areas.push( {
areaId : ar.area_id,
name : ar.area_name,
});
});
callback(null);
}
}
);
},
function getAreaGroups(callback) {
var query = msgDb.prepare(
'SELECT group_id ' +
'FROM message_area_group ' +
'WHERE area_id=?;');
async.each(areas, function area(a, next) {
query.all( [ a.areaId ], function groupRows(err, groups) {
a.groupIds = groups;
next(err);
});
},
function complete(err) {
query.finalize(function finalized(err2) {
callback(err); // use orig err
});
});
}
],
function complete(err) {
cb(err, areas);
}
);
}

View File

@ -245,6 +245,7 @@ function ViewController(options) {
function complete(err) { function complete(err) {
// default to highest ID if no 'submit' entry present // default to highest ID if no 'submit' entry present
if(!submitId) { if(!submitId) {
// :TODO: fix bug here: If errornous MCI code sare used, we'll reference invalid views -- these should jsut be ignored
self.getView(highestId).submit = true; self.getView(highestId).submit = true;
} }

BIN
mods/art/msg_area_list.ans Normal file

Binary file not shown.

View File

@ -263,15 +263,37 @@
//"extraArgs" : { "messageAreaId" : 123 } //"extraArgs" : { "messageAreaId" : 123 }
}, },
{ {
"value" : { "command" : "C" },
"action" : "@menu:messageAreaChangeCurrentArea"
},
/*{
"value" : { "command" : "A" }, "value" : { "command" : "A" },
"action" : "@method:changeArea" "action" : "@method:changeArea"
}, },
*/
{ {
"value" : { "command" : "Q" }, "value" : { "command" : "Q" },
"action" : "@menu:mainMenu" "action" : "@menu:mainMenu"
} }
] ]
}, },
"messageAreaChangeCurrentArea" : {
"art" : "msg_area_list.ans",
"module" : "msg_area_list",
"options" : { "cls" : true },
"form" : {
"0" : {
"LVTL" : {
"mci" : {
"LV1" : {
"widht" : 30,
"height" : 10
}
}
}
}
}
},
// :TODO: messageAreaSelect (change msg areas -> call @systemMethod -> fallback to menu // :TODO: messageAreaSelect (change msg areas -> call @systemMethod -> fallback to menu
"messageAreaNewPost" : { "messageAreaNewPost" : {
"module" : "msg_area_post_fse", "module" : "msg_area_post_fse",

79
mods/msg_area_list.js Normal file
View File

@ -0,0 +1,79 @@
/* 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');
//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;
}
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) {
// :TODO: make this formattable/themable
areaList.push(msgArea.areaId + ' - ' + msgArea.name);
});
console.log(areaList)
areaListView.setItems(areaList);
areaListView.redraw();
}
],
function complete(err) {
}
);
};