2014-10-23 05:41:00 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2014-10-31 22:25:11 +00:00
|
|
|
var TextView = require('./text_view.js').TextView;
|
|
|
|
var EditTextView = require('./edit_text_view.js').EditTextView;
|
|
|
|
var ButtonView = require('./button_view.js').ButtonView;
|
|
|
|
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
|
|
|
var Config = require('./config.js').config;
|
|
|
|
var packageJson = require('../package.json');
|
2015-04-16 04:46:45 +00:00
|
|
|
|
|
|
|
|
2014-10-31 22:25:11 +00:00
|
|
|
var assert = require('assert');
|
2015-04-16 04:46:45 +00:00
|
|
|
var os = require('os');
|
|
|
|
var _ = require('lodash');
|
2014-10-23 05:41:00 +00:00
|
|
|
|
|
|
|
exports.MCIViewFactory = MCIViewFactory;
|
|
|
|
|
|
|
|
function MCIViewFactory(client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
|
2014-10-28 03:58:34 +00:00
|
|
|
var label;
|
2015-04-16 04:46:45 +00:00
|
|
|
switch(code) {
|
|
|
|
// :TODO: Fix conflict with ButtonView (BN); chagne to BT
|
2015-04-19 08:13:13 +00:00
|
|
|
case 'BN' : label = Config.general.boardName; break;
|
2014-10-28 03:58:34 +00:00
|
|
|
case 'VL' : label = 'ENiGMA½ v' + packageJson.version; break;
|
2014-10-31 22:25:11 +00:00
|
|
|
case 'VN' : label = packageJson.version; break;
|
2015-04-16 04:46:45 +00:00
|
|
|
|
|
|
|
case 'UN' : label = this.client.user.username; break;
|
|
|
|
case 'UR' : label = this.client.user.properties.real_name; break;
|
|
|
|
case 'LO' : label = this.client.user.properties.location; break;
|
|
|
|
|
|
|
|
case 'OS' :
|
|
|
|
switch(os.platform()) {
|
|
|
|
case 'linux' : label = 'Linux'; break;
|
|
|
|
case 'darwin' : label = 'OS X'; break;
|
|
|
|
case 'win32' : label = 'Windows'; break;
|
|
|
|
case 'sunos' : label = 'SunOS'; break;
|
|
|
|
default : label = os.type(); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'OA' : label = os.arch(); break;
|
|
|
|
case 'SC' : label = os.cpus()[0].model; break;
|
2014-10-28 03:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
};
|
|
|
|
|
2014-10-23 05:41:00 +00:00
|
|
|
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
|
|
|
assert(mci.code);
|
|
|
|
assert(mci.id > 0);
|
|
|
|
assert(mci.position);
|
|
|
|
|
|
|
|
var view;
|
|
|
|
var options = {
|
2015-04-09 04:54:13 +00:00
|
|
|
client : this.client,
|
2014-10-23 05:41:00 +00:00
|
|
|
id : mci.id,
|
|
|
|
color : mci.color,
|
|
|
|
focusColor : mci.focusColor,
|
|
|
|
position : { x : mci.position[0], y : mci.position[1] },
|
|
|
|
};
|
|
|
|
|
2014-10-31 22:25:11 +00:00
|
|
|
function setOption(pos, name) {
|
|
|
|
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
|
|
|
options[name] = mci.args[pos];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
function setFocusOption(pos, name) {
|
|
|
|
if(mci.focusArgs && mci.focusArgs.length > pos && mci.focusArgs[pos].length > 0) {
|
|
|
|
options[name] = mci.focusArgs[pos];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-23 05:41:00 +00:00
|
|
|
switch(mci.code) {
|
2015-04-16 04:46:45 +00:00
|
|
|
// Text Label (Text View)
|
2014-10-28 03:58:34 +00:00
|
|
|
case 'TL' :
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(0, 'textStyle');
|
|
|
|
setOption(1, 'justify');
|
|
|
|
if(setOption(2, 'maxLength')) {
|
|
|
|
options.maxLength = parseInt(options.maxLength, 10);
|
2014-10-28 03:58:34 +00:00
|
|
|
options.dimens = { width : options.maxLength };
|
|
|
|
}
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new TextView(options);
|
2014-10-28 03:58:34 +00:00
|
|
|
break;
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Edit Text
|
2014-10-28 03:58:34 +00:00
|
|
|
case 'ET' :
|
2014-10-31 22:25:11 +00:00
|
|
|
if(setOption(0, 'maxLength')) {
|
2015-04-19 08:13:13 +00:00
|
|
|
options.maxLength = parseInt(options.maxLength, 10); // ensure number
|
2014-11-03 23:49:15 +00:00
|
|
|
options.dimens = { width : options.maxLength };
|
2014-10-23 05:41:00 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 22:25:11 +00:00
|
|
|
setOption(1, 'textStyle');
|
2014-10-23 05:41:00 +00:00
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
if(options.textStyle === 'P') {
|
2015-04-17 04:29:53 +00:00
|
|
|
// Assign the proper password character / text mask
|
|
|
|
assert(_.isObject(this.client.currentThemeInfo));
|
|
|
|
options.textMaskChar = this.client.currentThemeInfo.getPasswordChar();
|
2015-04-16 04:46:45 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
setFocusOption(0, 'focusTextStyle');
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new EditTextView(options);
|
2014-10-23 05:41:00 +00:00
|
|
|
break;
|
2014-10-24 04:18:38 +00:00
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Pre-defined Label (Text View)
|
2014-10-28 03:58:34 +00:00
|
|
|
case 'PL' :
|
|
|
|
if(mci.args.length > 0) {
|
|
|
|
options.text = this.getPredefinedViewLabel(mci.args[0]);
|
|
|
|
if(options.text) {
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setOption(2, 'justify');
|
2014-10-28 03:58:34 +00:00
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
if(setOption(3, 'maxLength')) {
|
|
|
|
options.maxLength = parseInt(options.maxLength, 10);
|
2014-10-28 03:58:34 +00:00
|
|
|
options.dimens = { width : options.maxLength };
|
|
|
|
}
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new TextView(options);
|
2014-10-28 03:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Button
|
|
|
|
case 'BT' :
|
2014-10-24 04:18:38 +00:00
|
|
|
if(mci.args.length > 0) {
|
2014-11-03 23:49:15 +00:00
|
|
|
options.dimens = { width : parseInt(mci.args[0], 10) };
|
2014-10-24 04:18:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(1, 'textStyle');
|
|
|
|
setOption(2, 'justify');
|
|
|
|
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new ButtonView(options);
|
2014-10-24 04:18:38 +00:00
|
|
|
break;
|
2014-10-31 22:25:11 +00:00
|
|
|
|
2015-04-16 04:46:45 +00:00
|
|
|
// Vertial Menu
|
2014-10-31 22:25:11 +00:00
|
|
|
case 'VM' :
|
2014-11-03 23:49:15 +00:00
|
|
|
setOption(0, 'itemSpacing');
|
|
|
|
setOption(1, 'justify');
|
|
|
|
setOption(2, 'textStyle');
|
|
|
|
|
|
|
|
setFocusOption(0, 'focusTextStyle');
|
2014-10-31 22:25:11 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
view = new VerticalMenuView(options);
|
2014-10-31 22:25:11 +00:00
|
|
|
break;
|
2015-04-16 04:46:45 +00:00
|
|
|
|
|
|
|
default :
|
|
|
|
options.text = this.getPredefinedViewLabel(mci.code);
|
|
|
|
if(options.text) {
|
|
|
|
view = new TextView(options);
|
|
|
|
}
|
|
|
|
break;
|
2014-10-23 05:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
};
|