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');
|
|
|
|
var assert = require('assert');
|
2014-10-23 05:41:00 +00:00
|
|
|
|
|
|
|
exports.MCIViewFactory = MCIViewFactory;
|
|
|
|
|
|
|
|
function MCIViewFactory(client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
|
|
|
|
2014-10-28 03:58:34 +00:00
|
|
|
MCIViewFactory.prototype.getPredefinedViewLabel = function(name) {
|
|
|
|
var label;
|
|
|
|
switch(name) {
|
|
|
|
case 'BN' : label = Config.bbsName; break;
|
|
|
|
case 'VL' : label = 'ENiGMA½ v' + packageJson.version; break;
|
2014-10-31 22:25:11 +00:00
|
|
|
case 'VN' : label = packageJson.version; 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 = {
|
|
|
|
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) {
|
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 };
|
|
|
|
}
|
|
|
|
|
|
|
|
view = new TextView(this.client, options);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ET' :
|
2014-10-31 22:25:11 +00:00
|
|
|
if(setOption(0, 'maxLength')) {
|
2014-11-03 23:49:15 +00:00
|
|
|
options.maxLength = parseInt(options.maxLength, 10);
|
|
|
|
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
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
setFocusOption(0, 'focusTextStyle');
|
|
|
|
|
2014-10-23 05:41:00 +00:00
|
|
|
view = new EditTextView(this.client, options);
|
|
|
|
break;
|
2014-10-24 04:18:38 +00:00
|
|
|
|
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 };
|
|
|
|
}
|
|
|
|
|
|
|
|
view = new TextView(this.client, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
case 'BN' :
|
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');
|
|
|
|
|
2014-10-24 04:18:38 +00:00
|
|
|
view = new ButtonView(this.client, options);
|
|
|
|
break;
|
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
|
|
|
|
|
|
|
view = new VerticalMenuView(this.client, options);
|
|
|
|
break;
|
2014-10-23 05:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
};
|
|
|
|
|