From 0f0e674f974ab17aa78825cddd42448e0a321926 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sat, 25 Jun 2016 22:43:12 -0600 Subject: [PATCH] Add nextMenu() @systemMethod, code cleanup, ES6, etc. --- core/system_menu_method.js | 49 ++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/core/system_menu_method.js b/core/system_menu_method.js index 0299c00e..72621122 100644 --- a/core/system_menu_method.js +++ b/core/system_menu_method.js @@ -1,25 +1,23 @@ /* jslint node: true */ 'use strict'; -var theme = require('./theme.js'); -var removeClient = require('./client_connections.js').removeClient; -var ansi = require('./ansi_term.js'); -var userDb = require('./database.js').dbs.user; -var sysProp = require('./system_property.js'); -var userLogin = require('./user_login.js').userLogin; +// ENiGMA½ +const removeClient = require('./client_connections.js').removeClient; +const ansiNormal = require('./ansi_term.js').normal; +const userLogin = require('./user_login.js').userLogin; -var async = require('async'); -var _ = require('lodash'); -var iconv = require('iconv-lite'); +// deps +const _ = require('lodash'); +const iconv = require('iconv-lite'); exports.login = login; exports.logoff = logoff; exports.prevMenu = prevMenu; +exports.nextMenu = nextMenu; -function login(callingMenu, formData, extraArgs) { - var client = callingMenu.client; +function login(callingMenu, formData) { - userLogin(callingMenu.client, formData.value.username, formData.value.password, function authResult(err) { + userLogin(callingMenu.client, formData.value.username, formData.value.password, err => { if(err) { // login failure if(err.existingConn && _.has(callingMenu, 'menuConfig.config.tooNodeMenu')) { @@ -36,32 +34,41 @@ function login(callingMenu, formData, extraArgs) { }); } -function logoff(callingMenu, formData, extraArgs) { +function logoff(callingMenu) { // // Simple logoff. Note that recording of @ logoff properties/stats // occurs elsewhere! // - var client = callingMenu.client; + const client = callingMenu.client; - setTimeout(function timeout() { + setTimeout( () => { // // For giggles... // client.term.write( - ansi.normal() + '\n' + + ansiNormal() + '\n' + iconv.decode(require('crypto').randomBytes(Math.floor(Math.random() * 65) + 20), client.term.outputEncoding) + - 'NO CARRIER', null, function written() { + 'NO CARRIER', null, () => { // after data is written, disconnect & remove the client - removeClient(client); - }); + return removeClient(client); + } + ); }, 500); } -function prevMenu(callingMenu, formData, extraArgs) { - callingMenu.prevMenu(function result(err) { +function prevMenu(callingMenu) { + callingMenu.prevMenu( err => { if(err) { callingMenu.client.log.error( { error : err.toString() }, 'Error attempting to fallback!'); } }); } + +function nextMenu(callingMenu) { + callingMenu.nextMenu( err => { + if(err) { + callingMenu.client.log.error( { error : err.toString() }, 'Error attempting to go to next menu!'); + } + }); +}