Use sane switch style :)

This commit is contained in:
Bryan Ashby 2016-08-03 22:43:06 -06:00
parent f024527db1
commit 33f0553ea9
11 changed files with 223 additions and 222 deletions

View File

@ -550,26 +550,26 @@ function FullScreenEditorModule(options) {
function setInitialData(callback) { function setInitialData(callback) {
switch(self.editorMode) { switch(self.editorMode) {
case 'view' : case 'view' :
if(self.message) { if(self.message) {
self.initHeaderViewMode(); self.initHeaderViewMode();
self.initFooterViewMode(); self.initFooterViewMode();
var bodyMessageView = self.viewControllers.body.getView(1); var bodyMessageView = self.viewControllers.body.getView(1);
if(bodyMessageView && _.has(self, 'message.message')) { if(bodyMessageView && _.has(self, 'message.message')) {
//self.setBodyMessageViewText(); //self.setBodyMessageViewText();
bodyMessageView.setText(cleanControlCodes(self.message.message)); bodyMessageView.setText(cleanControlCodes(self.message.message));
}
} }
} break;
break;
case 'edit' :
case 'edit' : self.viewControllers.header.getView(1).setText(self.client.user.username); // from
self.viewControllers.header.getView(1).setText(self.client.user.username); // from
if(self.replyToMessage) { if(self.replyToMessage) {
self.initHeaderReplyEditMode(); self.initHeaderReplyEditMode();
} }
break; break;
} }
callback(null); callback(null);
@ -577,14 +577,14 @@ function FullScreenEditorModule(options) {
function setInitialFocus(callback) { function setInitialFocus(callback) {
switch(self.editorMode) { switch(self.editorMode) {
case 'edit' : case 'edit' :
self.switchToHeader(); self.switchToHeader();
break; break;
case 'view' : case 'view' :
self.switchToFooter(); self.switchToFooter();
//self.observeViewPosition(); //self.observeViewPosition();
break; break;
} }
callback(null); callback(null);
@ -885,21 +885,21 @@ function FullScreenEditorModule(options) {
console.log(err) console.log(err)
} else { } else {
switch(self.footerMode) { switch(self.footerMode) {
case 'editor' : case 'editor' :
if(!_.isUndefined(self.viewControllers.footerEditorMenu)) { if(!_.isUndefined(self.viewControllers.footerEditorMenu)) {
//self.viewControllers.footerEditorMenu.setFocus(false); //self.viewControllers.footerEditorMenu.setFocus(false);
self.viewControllers.footerEditorMenu.detachClientEvents(); self.viewControllers.footerEditorMenu.detachClientEvents();
} }
self.viewControllers.body.switchFocus(1); self.viewControllers.body.switchFocus(1);
self.observeEditorEvents(); self.observeEditorEvents();
break; break;
case 'editorMenu' : case 'editorMenu' :
self.viewControllers.body.setFocus(false); self.viewControllers.body.setFocus(false);
self.viewControllers.footerEditorMenu.switchFocus(1); self.viewControllers.footerEditorMenu.switchFocus(1);
break; break;
default : throw new Error('Unexpected mode'); default : throw new Error('Unexpected mode');
} }
} }

View File

@ -43,17 +43,17 @@ module.exports = class KeyEntryView extends View {
setPropertyValue(propName, propValue) { setPropertyValue(propName, propValue) {
switch(propName) { switch(propName) {
case 'eatTabKey' : case 'eatTabKey' :
if(_.isBoolean(propValue)) { if(_.isBoolean(propValue)) {
this.eatTabKey = propValue; this.eatTabKey = propValue;
} }
break; break;
case 'caseInsensitive' : case 'caseInsensitive' :
if(_.isBoolean(propValue)) { if(_.isBoolean(propValue)) {
this.caseInsensitive = propValue; this.caseInsensitive = propValue;
} }
break; break;
} }
super.setPropertyValue(propName, propValue); super.setPropertyValue(propName, propValue);

View File

@ -175,40 +175,40 @@ function handleAction(client, formData, conf, cb) {
assert(_.isObject(actionAsset)); assert(_.isObject(actionAsset));
switch(actionAsset.type) { switch(actionAsset.type) {
case 'method' : case 'method' :
case 'systemMethod' : case 'systemMethod' :
if(_.isString(actionAsset.location)) { if(_.isString(actionAsset.location)) {
return callModuleMenuMethod( return callModuleMenuMethod(
client, client,
actionAsset, actionAsset,
paths.join(Config.paths.mods, actionAsset.location), paths.join(Config.paths.mods, actionAsset.location),
formData, formData,
conf.extraArgs, conf.extraArgs,
cb); cb);
} else if('systemMethod' === actionAsset.type) { } else if('systemMethod' === actionAsset.type) {
// :TODO: Need to pass optional args here -- conf.extraArgs and args between e.g. () // :TODO: Need to pass optional args here -- conf.extraArgs and args between e.g. ()
// :TODO: Probably better as system_method.js // :TODO: Probably better as system_method.js
return callModuleMenuMethod( return callModuleMenuMethod(
client, client,
actionAsset, actionAsset,
paths.join(__dirname, 'system_menu_method.js'), paths.join(__dirname, 'system_menu_method.js'),
formData, formData,
conf.extraArgs, conf.extraArgs,
cb); cb);
} else { } else {
// local to current module // local to current module
const currentModule = client.currentMenuModule; const currentModule = client.currentMenuModule;
if(_.isFunction(currentModule.menuMethods[actionAsset.asset])) { if(_.isFunction(currentModule.menuMethods[actionAsset.asset])) {
return currentModule.menuMethods[actionAsset.asset](formData, conf.extraArgs, cb); return currentModule.menuMethods[actionAsset.asset](formData, conf.extraArgs, cb);
}
const err = new Error('Method does not exist');
client.log.warn( { method : actionAsset.asset }, err.message);
return cb(err);
} }
const err = new Error('Method does not exist');
client.log.warn( { method : actionAsset.asset }, err.message);
return cb(err);
}
case 'menu' : case 'menu' :
return client.currentMenuModule.gotoMenu(actionAsset.asset, { formData : formData, extraArgs : conf.extraArgs }, cb ); return client.currentMenuModule.gotoMenu(actionAsset.asset, { formData : formData, extraArgs : conf.extraArgs }, cb );
} }
} }
@ -227,28 +227,28 @@ function handleNext(client, nextSpec, conf, cb) {
// :TODO: DRY this with handleAction() // :TODO: DRY this with handleAction()
switch(nextAsset.type) { switch(nextAsset.type) {
case 'method' : case 'method' :
case 'systemMethod' : case 'systemMethod' :
if(_.isString(nextAsset.location)) { if(_.isString(nextAsset.location)) {
return callModuleMenuMethod(client, nextAsset, paths.join(Config.paths.mods, nextAsset.location), {}, extraArgs, cb); return callModuleMenuMethod(client, nextAsset, paths.join(Config.paths.mods, nextAsset.location), {}, extraArgs, cb);
} else if('systemMethod' === nextAsset.type) { } else if('systemMethod' === nextAsset.type) {
// :TODO: see other notes about system_menu_method.js here // :TODO: see other notes about system_menu_method.js here
return callModuleMenuMethod(client, nextAsset, paths.join(__dirname, 'system_menu_method.js'), {}, extraArgs, cb); return callModuleMenuMethod(client, nextAsset, paths.join(__dirname, 'system_menu_method.js'), {}, extraArgs, cb);
} else { } else {
// local to current module // local to current module
const currentModule = client.currentMenuModule; const currentModule = client.currentMenuModule;
if(_.isFunction(currentModule.menuMethods[nextAsset.asset])) { if(_.isFunction(currentModule.menuMethods[nextAsset.asset])) {
const formData = {}; // we don't have any const formData = {}; // we don't have any
return currentModule.menuMethods[nextAsset.asset]( formData, extraArgs, cb ); return currentModule.menuMethods[nextAsset.asset]( formData, extraArgs, cb );
}
const err = new Error('Method does not exist');
client.log.warn( { method : nextAsset.asset }, err.message);
return cb(err);
} }
const err = new Error('Method does not exist'); case 'menu' :
client.log.warn( { method : nextAsset.asset }, err.message); return client.currentMenuModule.gotoMenu(nextAsset.asset, { extraArgs : extraArgs }, cb );
return cb(err);
}
case 'menu' :
return client.currentMenuModule.gotoMenu(nextAsset.asset, { extraArgs : extraArgs }, cb );
} }
const err = new Error('Invalid asset type for "next"'); const err = new Error('Invalid asset type for "next"');

View File

@ -128,11 +128,12 @@ MenuView.prototype.setItemSpacing = function(itemSpacing) {
MenuView.prototype.setPropertyValue = function(propName, value) { MenuView.prototype.setPropertyValue = function(propName, value) {
switch(propName) { switch(propName) {
case 'itemSpacing' : this.setItemSpacing(value); break; case 'itemSpacing' : this.setItemSpacing(value); break;
case 'items' : this.setItems(value); break; case 'items' : this.setItems(value); break;
case 'focusItems' : this.setFocusItems(value); break; case 'focusItems' : this.setFocusItems(value); break;
case 'hotKeys' : this.setHotKeys(value); break; case 'hotKeys' : this.setHotKeys(value); break;
case 'hotKeySubmit' : this.hotKeySubmit = value; break; case 'hotKeySubmit' : this.hotKeySubmit = value; break;
case 'justify' : this.justify = value; break;
} }
MenuView.super_.prototype.setPropertyValue.call(this, propName, value); MenuView.super_.prototype.setPropertyValue.call(this, propName, value);

View File

@ -564,7 +564,7 @@ function persistMessage(message, cb) {
}, },
function recordToMessageNetworks(callback) { function recordToMessageNetworks(callback) {
msgNetRecord(message, callback); msgNetRecord(message, callback);
} }
], ],
cb cb
); );

View File

@ -1024,8 +1024,8 @@ MultiLineEditTextView.prototype.getData = function() {
MultiLineEditTextView.prototype.setPropertyValue = function(propName, value) { MultiLineEditTextView.prototype.setPropertyValue = function(propName, value) {
switch(propName) { switch(propName) {
case 'mode' : this.mode = value; break; case 'mode' : this.mode = value; break;
case 'autoScroll' : this.autoScroll = value; break; case 'autoScroll' : this.autoScroll = value; break;
} }
MultiLineEditTextView.super_.prototype.setPropertyValue.call(this, propName, value); MultiLineEditTextView.super_.prototype.setPropertyValue.call(this, propName, value);

View File

@ -35,86 +35,86 @@ function stylizeString(s, style) {
var stylized = ''; var stylized = '';
switch(style) { switch(style) {
// None/normal // None/normal
case 'normal' : case 'normal' :
case 'N' : case 'N' :
return s; return s;
// UPPERCASE // UPPERCASE
case 'upper' : case 'upper' :
case 'U' : case 'U' :
return s.toUpperCase(); return s.toUpperCase();
// lowercase // lowercase
case 'lower' : case 'lower' :
case 'l' : case 'l' :
return s.toLowerCase(); return s.toLowerCase();
// Title Case // Title Case
case 'title' : case 'title' :
case 'T' : case 'T' :
return s.replace(/\w\S*/g, function onProperCaseChar(t) { return s.replace(/\w\S*/g, function onProperCaseChar(t) {
return t.charAt(0).toUpperCase() + t.substr(1).toLowerCase(); return t.charAt(0).toUpperCase() + t.substr(1).toLowerCase();
}); });
// fIRST lOWER // fIRST lOWER
case 'first lower' : case 'first lower' :
case 'f' : case 'f' :
return s.replace(/\w\S*/g, function onFirstLowerChar(t) { return s.replace(/\w\S*/g, function onFirstLowerChar(t) {
return t.charAt(0).toLowerCase() + t.substr(1).toUpperCase(); return t.charAt(0).toLowerCase() + t.substr(1).toUpperCase();
}); });
// SMaLL VoWeLS // SMaLL VoWeLS
case 'small vowels' : case 'small vowels' :
case 'v' : case 'v' :
for(i = 0; i < len; ++i) { for(i = 0; i < len; ++i) {
c = s[i]; c = s[i];
if(-1 !== VOWELS.indexOf(c)) { if(-1 !== VOWELS.indexOf(c)) {
stylized += c.toLowerCase(); stylized += c.toLowerCase();
} else { } else {
stylized += c.toUpperCase(); stylized += c.toUpperCase();
}
} }
} return stylized;
return stylized;
// bIg vOwELS // bIg vOwELS
case 'big vowels' : case 'big vowels' :
case 'V' : case 'V' :
for(i = 0; i < len; ++i) { for(i = 0; i < len; ++i) {
c = s[i]; c = s[i];
if(-1 !== VOWELS.indexOf(c)) { if(-1 !== VOWELS.indexOf(c)) {
stylized += c.toUpperCase(); stylized += c.toUpperCase();
} else { } else {
stylized += c.toLowerCase(); stylized += c.toLowerCase();
}
} }
} return stylized;
return stylized;
// Small i's: DEMENTiA // Small i's: DEMENTiA
case 'small i' : case 'small i' :
case 'i' : case 'i' :
return s.toUpperCase().replace(/I/g, 'i'); return s.toUpperCase().replace(/I/g, 'i');
// mIxeD CaSE (random upper/lower) // mIxeD CaSE (random upper/lower)
case 'mixed' : case 'mixed' :
case 'M' : case 'M' :
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
if(Math.random() < 0.5) { if(Math.random() < 0.5) {
stylized += s[i].toUpperCase(); stylized += s[i].toUpperCase();
} else { } else {
stylized += s[i].toLowerCase(); stylized += s[i].toLowerCase();
}
} }
} return stylized;
return stylized;
// l337 5p34k // l337 5p34k
case 'l33t' : case 'l33t' :
case '3' : case '3' :
for(i = 0; i < len; ++i) { for(i = 0; i < len; ++i) {
c = SIMPLE_ELITE_MAP[s[i].toLowerCase()]; c = SIMPLE_ELITE_MAP[s[i].toLowerCase()];
stylized += c || s[i]; stylized += c || s[i];
} }
return stylized; return stylized;
} }
return s; return s;
@ -134,27 +134,27 @@ function pad(s, len, padChar, dir, stringSGR, padSGR, useRenderLen) {
const padlen = len >= renderLen ? len - renderLen : 0; const padlen = len >= renderLen ? len - renderLen : 0;
switch(dir) { switch(dir) {
case 'L' : case 'L' :
case 'left' : case 'left' :
s = padSGR + new Array(padlen).join(padChar) + stringSGR + s; s = padSGR + new Array(padlen).join(padChar) + stringSGR + s;
break; break;
case 'C' : case 'C' :
case 'center' : case 'center' :
case 'both' : case 'both' :
{ {
const right = Math.ceil(padlen / 2); const right = Math.ceil(padlen / 2);
const left = padlen - right; const left = padlen - right;
s = padSGR + new Array(left + 1).join(padChar) + stringSGR + s + padSGR + new Array(right + 1).join(padChar); s = padSGR + new Array(left + 1).join(padChar) + stringSGR + s + padSGR + new Array(right + 1).join(padChar);
} }
break; break;
case 'R' : case 'R' :
case 'right' : case 'right' :
s = stringSGR + s + padSGR + new Array(padlen).join(padChar); s = stringSGR + s + padSGR + new Array(padlen).join(padChar);
break; break;
default : break; default : break;
} }
return stringSGR + s; return stringSGR + s;

View File

@ -238,14 +238,14 @@ TextView.prototype.clearText = function() {
TextView.prototype.setPropertyValue = function(propName, value) { TextView.prototype.setPropertyValue = function(propName, value) {
switch(propName) { switch(propName) {
case 'textMaskChar' : this.textMaskChar = value.substr(0, 1); break; case 'textMaskChar' : this.textMaskChar = value.substr(0, 1); break;
case 'textOverflow' : this.textOverflow = value; break; case 'textOverflow' : this.textOverflow = value; break;
case 'maxLength' : this.maxLength = parseInt(value, 10); break; case 'maxLength' : this.maxLength = parseInt(value, 10); break;
case 'password' : case 'password' :
if(true === value) { if(true === value) {
this.textMaskChar = this.client.currentTheme.helpers.getPasswordChar(); this.textMaskChar = this.client.currentTheme.helpers.getPasswordChar();
} }
break; break;
} }

View File

@ -599,23 +599,23 @@ function displayThemedAsset(assetSpec, client, options, cb) {
}; };
switch(artAsset.type) { switch(artAsset.type) {
case 'art' : case 'art' :
displayThemeArt(dispOpts, function displayed(err, artData) { displayThemeArt(dispOpts, function displayed(err, artData) {
return cb(err, err ? null : { mciMap : artData.mciMap, height : artData.extraInfo.height } ); return cb(err, err ? null : { mciMap : artData.mciMap, height : artData.extraInfo.height } );
}); });
break; break;
case 'method' : case 'method' :
// :TODO: fetch & render via method // :TODO: fetch & render via method
break; break;
case 'inline ' : case 'inline ' :
// :TODO: think about this more in relation to themes, etc. How can this come // :TODO: think about this more in relation to themes, etc. How can this come
// from a theme (with override from menu.json) ??? // from a theme (with override from menu.json) ???
// look @ client.currentTheme.inlineArt[name] -> menu/prompt[name] // look @ client.currentTheme.inlineArt[name] -> menu/prompt[name]
break; break;
default : default :
return cb(new Error('Unsupported art asset type: ' + artAsset.type)); return cb(new Error('Unsupported art asset type: ' + artAsset.type));
} }
} }

View File

@ -205,7 +205,7 @@ function wordWrapText(text, options) {
switch(m[0].charAt(0)) { switch(m[0].charAt(0)) {
case ' ' : case ' ' :
word += m[0]; word += m[0];
break; break;
case '\t' : case '\t' :
// //
@ -218,7 +218,7 @@ function wordWrapText(text, options) {
} else { } else {
word += m[0]; word += m[0];
} }
break; break;
} }
addWord(); addWord();

View File

@ -58,10 +58,10 @@ function AreaViewFSEModule(options) {
// :TODO: Create methods for up/down vs using keyPressXXXXX // :TODO: Create methods for up/down vs using keyPressXXXXX
switch(formData.key.name) { switch(formData.key.name) {
case 'down arrow' : bodyView.scrollDocumentUp(); break; case 'down arrow' : bodyView.scrollDocumentUp(); break;
case 'up arrow' : bodyView.scrollDocumentDown(); break; case 'up arrow' : bodyView.scrollDocumentDown(); break;
case 'page up' : bodyView.keyPressPageUp(); break; case 'page up' : bodyView.keyPressPageUp(); break;
case 'page down' : bodyView.keyPressPageDown(); break; case 'page down' : bodyView.keyPressPageDown(); break;
} }
// :TODO: need to stop down/page down if doing so would push the last // :TODO: need to stop down/page down if doing so would push the last