From c713e292e70d38649884ced6f115e2d61eff0888 Mon Sep 17 00:00:00 2001 From: Nathanaël Jourdane Date: Thu, 14 Jun 2018 16:04:27 +0200 Subject: [PATCH] fix eslint warnings --- js/.eslintrc.yml | 9 +++++++++ js/app/models/InteractiveNode.js | 642 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- js/app/views/ExplorerUI.js | 549 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 3 files changed, 676 insertions(+), 524 deletions(-) diff --git a/js/.eslintrc.yml b/js/.eslintrc.yml index 395483b..2f49518 100644 --- a/js/.eslintrc.yml +++ b/js/.eslintrc.yml @@ -10,6 +10,11 @@ rules: semi: [error, always] max-len: [error, code: 120] max-lines: [warn, 600] + max-params: [warn, 3] + complexity: [warn, 20] + no-ternary: off + no-plusplus: off + multiline-ternary: off linebreak-style: [error, unix] quotes: [error, single] strict: [error, global] @@ -26,6 +31,9 @@ rules: id-length: off no-magic-numbers: off no-invalid-this: off + no-extra-parens: [error, all, nestedBinaryExpressions: false] + camelcase: warn + max-depth: warn # ES3/5 compatibility: prefer-template: off @@ -33,3 +41,4 @@ rules: prefer-arrow-callback: off object-shorthand: off prefer-rest-params: off + prefer-destructuring: off diff --git a/js/app/models/InteractiveNode.js b/js/app/models/InteractiveNode.js index 9f5a161..03e8d24 100644 --- a/js/app/models/InteractiveNode.js +++ b/js/app/models/InteractiveNode.js @@ -8,36 +8,64 @@ * @version $Id: InteractiveNode.js 2683 2014-12-02 10:58:53Z elena $ */ +/* global amdaUI, AmdaAction, myDesktopApp, amdaPlotObj, amdaModel*/ + Ext.define('amdaModel.InteractiveNode', { extend: 'amdaModel.AmdaNode', - requires: [ - 'amdaPlotObj.PlotRequestObject' - ], + requires: ['amdaPlotObj.PlotRequestObject'], fields: [ - {name: 'contextNode', type: 'amdaModel.AmdaNode', persist: false}, - {name: 'objectDataModel', type: 'string', persist: false}, - {name: 'object', type: 'object', persist: false}, - {name: 'moduleId', type: 'string', persist: false}, - {name: 'filtered', type: 'boolean', defaultValue: false, persist: false}, - {name: 'disable', type: 'boolean', defaultValue: false, persist: false} + { + name: 'contextNode', + type: 'amdaModel.AmdaNode', + persist: false + }, + { + name: 'objectDataModel', + type: 'string', + persist: false + }, + { + name: 'object', + type: 'object', + persist: false + }, + { + name: 'moduleId', + type: 'string', + persist: false + }, + { + name: 'filtered', + type: 'boolean', + defaultValue: false, + persist: false + }, + { + name: 'disable', + type: 'boolean', + defaultValue: false, + persist: false + } ], statics: { preloadNodes: function (node, onready) { - var me = this; + var nodesToLoad; - var nodesToLoad = []; + nodesToLoad = []; nodesToLoad.push(node); - this.preloadTreeNode(node, nodesToLoad, function (node) { + this.preloadTreeNode(node, nodesToLoad, function () { var isFinish = true; - nodesToLoad.forEach(function (element, index, array) { - if (!element.isLoaded()) + nodesToLoad.forEach(function (element) { + if (!element.isLoaded()) { isFinish = false; + } }); - if (isFinish && onready) + if (isFinish && onready) { onready.call(); + } }); }, @@ -52,22 +80,24 @@ Ext.define('amdaModel.InteractiveNode', { } }); - if (onloaded) + if (onloaded) { onloaded.call(me, node); + } return; } node.store.load({ node: node, - callback: function (records, operation, successful) { + callback: function (records) { records.forEach(function (record) { if (!record.isLoaded() && !record.isLeaf()) { nodesToLoad.push(record); me.preloadTreeNode(record, nodesToLoad, onloaded); } }); - if (onloaded) + if (onloaded) { onloaded.call(me, node); + } } }); } @@ -76,49 +106,61 @@ Ext.define('amdaModel.InteractiveNode', { onReady: null, constructor: function (config) { + var suffix; this.callParent(arguments); this.set('nodeType', this.self.nodeType); this.set('ownerTreeId', amdaUI.ExplorerUI.RESRC_TAB.TREE_ID); - if (this.get('id')) { // TODO why sometimes (delete in remote interoper tree) this.get('id') = undefined ? - // if id of this node have root category suffix - if (Ext.util.Format.substr(this.get('id'), -(amdaUI.ExplorerUI.CAT_SUFFIX.length), this.get('id').length) === amdaUI.ExplorerUI.CAT_SUFFIX) { - // set the expanded property to true + // TODO why sometimes (delete in remote interoper tree) this.get('id') = undefined ? + if (this.get('id')) { + // If id of this node have root category suffix + suffix = amdaUI.ExplorerUI.CAT_SUFFIX; + if (Ext.util.Format.substr(this.get('id'), -suffix.length, this.get('id').length) === suffix) { + // Set the expanded property to true this.set('expanded', true); } } }, /** - * this method is overriden into ExecutableNode to return true + * This method is overriden into ExecutableNode to return true + * @returns {boolean} true if node is executable */ isExecutable: function () { return false; }, /** - * open Module with THIS NODE + * Open Module with THIS NODE + * @param {object} contextNode Context node + * @param {function} onReady onRady callback function + * @returns {void} */ editInModule: function (contextNode, onReady) { - // set the contextNode of this node - this.set('contextNode', contextNode); - // parameter module var me = this; + // Set the contextNode of this node + this.set('contextNode', contextNode); + // Parameter module myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) { // If the node to edit is not already linked to this module if (module.getLinkedNode() != me) { - // set relative node into parameter Module + // Set relative node into parameter Module module.setLinkedNode(me); if (contextNode == null) { - // set the root node as contextNode + // Set the root node as contextNode contextNode = me.getRootNode(); } module.setContextNode(contextNode); } else if (module.getLinkedNode() != null) { - //TODO the node to edit is already edited - // myDesktopApp.warningMsg('This object is being edited'); - //Sol1: msg alert: "warning this node is already edited! If you want to get the original, please press the 'reset' button"->'OK' - //Sol2: msg with user choice: "warning this node is already edited! Would you confirm this action and lost your modification?"->'Confirm','Cancel' + + /* + * TODO the node to edit is already edited + * myDesktopApp.warningMsg('This object is being edited'); + * Sol1: msg alert: "warning this node is already edited! If you want to get the original, + * please press the 'reset' button"->'OK' + * Sol2: msg with user choice: "warning this node is already edited! Would you confirm this action and lost your + * modification?"->'Confirm','Cancel' + */ } // Opening parameter window module.createWindow(onReady); @@ -127,6 +169,9 @@ Ext.define('amdaModel.InteractiveNode', { /** * Method to rename the workspace node + * @param {string} value The new name + * @param {function} callBackFn Callback function + * @returns {void} */ rename: function (value, callBackFn) { var dataToSend = { @@ -142,6 +187,9 @@ Ext.define('amdaModel.InteractiveNode', { /** * Method to rename the workspace node when D&D + * @param {string} parentId The parent ID + * @param {function} callBackFn callback function + * @returns {void} */ renameDD: function (parentId, callBackFn) { var dataToSend = { @@ -156,18 +204,24 @@ Ext.define('amdaModel.InteractiveNode', { }, /** - * validation method on name (used in module forms) - * @param name the name to validate - * @returns + * Validation method on name (used in module forms) + * @param {string} name the name to validate + * @param {function} callBackFn Callback function + * @returns {void} */ isValidName: function (name, callBackFn) { - var dataToSend = {name: name, nodeType: this.get('nodeType'), leaf: this.isLeaf()}; + var dataToSend = { + name: name, + nodeType: this.get('nodeType'), + leaf: this.isLeaf() + }; AmdaAction.validNameObject(dataToSend, callBackFn); }, /** - * Method to persist modifications of an AmdaObject by Server side and update the workspace - * node linked to a Module + * Method to persist modifications of an AmdaObject by Server side and update the workspace node linked to a Module + * @param {object} opt ... + * @returns {void} */ update: function (opt) { AmdaAction.modifyObject(this.get('object').getJsonValues(true), function (res, e) { @@ -175,20 +229,18 @@ Ext.define('amdaModel.InteractiveNode', { if (e.status) { if (res.id) { if (!this.get('contextNode')) { - // set the root node of 'Derived Parameters' tree as contextNode + // Set the root node of 'Derived Parameters' tree as contextNode this.set('contextNode', this.getRootNode()); } this.get('contextNode').expand(false, false); this.myGetOwnerTree().getSelectionModel().select(this); - if (opt) { - var scope = opt.scope ? opt.scope : this; - if (opt.callback) - opt.callback.call(scope, 'update'); + if (opt && opt.callback) { + opt.callback.call(opt.scope ? opt.scope : this, 'update'); } Ext.Msg.alert('Complete', 'Object ' + this.get('object').get('name') + ' has been modified'); - // fix the modifications for object + // Fix the modifications for object this.get('object').commit(); if (res.info) { @@ -198,33 +250,33 @@ Ext.define('amdaModel.InteractiveNode', { if (this.get('nodeType') == 'myDataParam') { if (res.isSpectra) { this.set('iconCls', 'icon-spectra'); - } - else { - if (res.size > 1) this.set('iconCls', 'icon-unknowntype'); + } else if (res.size > 1) { + this.set('iconCls', 'icon-unknowntype'); } } - // update my data on possibble mask change + // Update my data on possibble mask change if (res.updateMyData) { this.updateMyData(); this.updateMask(res.mask); } - // reload object into the view of corresponding Module + // Reload object into the view of corresponding Module var me = this; myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) { module.getUiContent().setObject(me.get('object')); }); - } - else { - //TODO proper error message handling - // error code from server; but e.status==true - // revert all modifications since last load or commit + } else { + + /* + *TODO proper error message handling + * error code from server; but e.status==true + * revert all modifications since last load or commit + */ this.get('object').reject(); myDesktopApp.errorMsg(res.error); } - } - else { - // revert all modifications since last load or commit + } else { + // Revert all modifications since last load or commit this.get('object').reject(); myDesktopApp.errorMsg(e.message); } @@ -232,114 +284,122 @@ Ext.define('amdaModel.InteractiveNode', { }, /** - * Method to create a new AmdaObject by server side and create the workspace node linked to a Module - * under its contextNode or the root node corresponding to this nodeType category + * Method to create a new AmdaObject by server side and create the workspace node linked to a Module under its + * contextNode or the root node corresponding to this nodeType category. + * @param {object} opt ... + * @returns {void} */ create: function (opt) { - if (!this.get('contextNode') || (this.get('contextNode').data.id == 'sharedtimeTable-treeRootNode') || (this.get('contextNode').data.id == 'sharedcatalog-treeRootNode')) { - // set the root node of 'Derived Parameters' tree as contextNode + var contextId; + if (!this.get('contextNode') || this.get('contextNode').data.id == 'sharedtimeTable-treeRootNode' || + this.get('contextNode').data.id == 'sharedcatalog-treeRootNode') { + // Set the root node of 'Derived Parameters' tree as contextNode this.set('contextNode', this.getRootNode()); } - // call the Ext.Direct method to create parameter - AmdaAction.createObject(this.get('object').getJsonValues(false), this.get('contextNode').get('id'), function (res, e) { - //success + // Call the Ext.Direct method to create parameter + contextId = this.get('contextNode').get('id'); + AmdaAction.createObject(this.get('object').getJsonValues(false), contextId, function (res, e) { + var myRoot, updateNode; + // Success if (e.status) { - // if correct response received - if (res.id) { //if (res.id || res.error == 'NAME_EXISTS') { - // 'save as' case ; delete old node if it exists + // If correct response received + if (res.id) { + // If (res.id || res.error == 'NAME_EXISTS') { if (this.toRename) { + // 'save as' case ; delete old node if it exists this.toRename = false; - var myRoot = this.getRootNode(); - // search the same named node to override - var updateNode = myRoot.findChild('text', this.get('object').get('name'), true); - // destroy the overrided node - updateNode.parentNode.removeChild(updateNode);//TODO ??if destroy==true => too many recursions.... + myRoot = this.getRootNode(); + // Search the same named node to override + updateNode = myRoot.findChild('text', this.get('object').get('name'), true); + // Destroy the overrided node + updateNode.parentNode.removeChild(updateNode); + // TODO ??if destroy==true => too many recursions.... updateNode.destroy(); } - // set text of this node + // Set text of this node this.set('text', this.get('object').get('name')); - //set id of this node + // Set id of this node this.set('id', res.id); this.internalId = res.id; - // set id of node's object + // Set id of node's object this.get('object').set('id', res.id); if (res.created) { - // set the created date + // Set the created date this.get('object').set('created', res.created); } if (res.info) { - // set the tooltip + // Set the tooltip this.set('info', res.info); - //set globalStart & global Stop to be used for time selection + // Set globalStart & global Stop to be used for time selection if (this.get('nodeType') == 'myDataParam') { - var startStop = res.info.split("
"); - var globalStart = startStop[1].substr(0, 19); - var globalStop = startStop[1].substr(20); + var startStop = res.info.split('
'); + this.set('globalStart', startStop[1].substr(0, 19)); + this.set('globalStop', startStop[1].substr(20)); - this.set('globalStart', globalStart); - this.set('globalStop', globalStop); - - if (res.mask) + if (res.mask) { this.set('linkedMask', res.mask); - if (res.size) + } + if (res.size) { this.set('size', res.size); + } if (res.isSpectra) { this.set('iconCls', 'icon-spectra'); - } - else { - if (res.size > 1) - this.set('iconCls', 'icon-unknowntype'); + } else if (res.size > 1) { + this.set('iconCls', 'icon-unknowntype'); } } } - //TODO do we need this commission ??? - // fix the modifications for object + + /* + *TODO do we need this commission ??? + * fix the modifications for object + */ this.get('object').commit(); - // if ownerTree panel is not active + // If ownerTree panel is not active if (this.myGetOwnerTree().ownerCt.getActiveTab() !== this.myGetOwnerTree()) { - // set ownerTree panel as the active tab - to enable selection of this node his ownerTree must have a view + // Set ownerTree panel as the active tab - to enable selection of this node his ownerTree must have a view this.myGetOwnerTree().ownerCt.setActiveTab(this.myGetOwnerTree()); } Ext.Msg.alert('Complete', 'New object ' + this.get('object').get('name') + ' has been created'); - // expand the contextNode + // Expand the contextNode this.get('contextNode').expand(false, function () { if (!this.get('contextNode').findChild('text', this.get('text'))) { - // create node in tree as child of contextNode + // Create node in tree as child of contextNode this.get('contextNode').appendChild(this); } - // select the new node + // Select the new node this.myGetOwnerTree().getSelectionModel().select(this); - if (opt) { - var scope = opt.scope ? opt.scope : this; - if (opt.callback) - opt.callback.call(scope, 'create'); + if (opt && opt.callback) { + opt.callback.call(opt.scope ? opt.scope : this, 'create'); } }, this); - // myDataParamNode - update MyData subtree - //TODO put this in mydataparamnode + /* + * MyDataParamNode - update MyData subtree + *TODO put this in mydataparamnode + */ if (res.updateMyData) { this.updateMyData(); this.updateMask(res.mask); } } - // error code from server; but e.status==true + // Error code from server; but e.status==true else { myDesktopApp.errorMsg(res.error); - // revert all modifications since last load or commit + // Revert all modifications since last load or commit this.get('object').reject(); } } - // failure: e.status == false + // Failure: e.status == false else { - // revert all modifications since last load or commit + // Revert all modifications since last load or commit this.get('object').reject(); - //TODO: this.destroy(); + // TODO: this.destroy(); myDesktopApp.errorMsg(e.message); } }, this); @@ -347,36 +407,46 @@ Ext.define('amdaModel.InteractiveNode', { /** * Generic part of Context Menu - * + * @returns {*[]|*} Menu items */ allMenuItems: function () { - var src = this.self.objectName; - var menuItems = [ + var menuItems, src; + + src = this.self.objectName; + menuItems = [ { fnId: 'root-createLeaf', text: 'Create ' + src - }, { + }, + { fnId: 'root-createDir', text: 'Create Folder' - }, { + }, + { fnId: 'dire-createLeaf', text: 'Create ' + src - }, { + }, + { fnId: 'dire-createDir', text: 'Create Folder' - }, { + }, + { fnId: 'dire-renameNode', text: 'Rename Folder' - }, { + }, + { fnId: 'dire-deleteNode', text: 'Delete Folder' - }, { + }, + { fnId: 'leaf-editLeaf', text: 'Edit ' + src - }, { + }, + { fnId: 'leaf-renameNode', text: 'Rename ' + src - }, { + }, + { fnId: 'leaf-deleteNode', text: 'Delete ' + src } @@ -385,13 +455,12 @@ Ext.define('amdaModel.InteractiveNode', { }, allMenuMultiItems: function () { - var menuMulti = [ + return [ { fnId: 'mult-deleteMulti', text: 'Delete selected ' + this.self.objectName + 's' } ]; - return menuMulti; }, getAllContextMenuItems: function () { @@ -402,20 +471,24 @@ Ext.define('amdaModel.InteractiveNode', { return this.allMenuMultiItems(); }, + // FIXME: duplicate declaration ↓ ↑ + /** - * default implementation - * no menu display if there's no override of this function + * Default implementation: no menu display if there's no override of this function + * @returns {null} Items */ getMultiContextMenuItems: function () { return null; }, /** - * Context Menu Actions - * + * Context Menu Actions + * @param {object} menu The menu + * @param {object} item the item + * @returns {void} */ - onMenuItemClick: function (menu, item, event) { - // fnId parsing : + onMenuItemClick: function (menu, item) { + // FnId parsing : var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length); switch (fnId) { @@ -445,36 +518,41 @@ Ext.define('amdaModel.InteractiveNode', { break; default: break; - } // switch end + } }, getTimeFromNode: function (node) { - var startString = String(node.get('globalStart')); - var stopString = String(node.get('globalStop')); - - var startDate = new Date(startString.replace(/\-/g, '\/').replace(/[T|Z]/g, ' ')); - var stopDate = new Date(stopString.replace(/\-/g, '\/').replace(/[T|Z]/g, ' ')); + var startDate, stopDate, timeObj; + startDate = new Date(String(node.get('globalStart')).replace(/-/g, '/').replace(/[T|Z]/g, ' ')); + stopDate = new Date(String(node.get('globalStop')).replace(/-/g, '/').replace(/[T|Z]/g, ' ')); if (stopDate - startDate > 86400000) { - var startTime = Ext.Date.add(stopDate, Ext.Date.DAY, -1); - // var timeObj = {start: Ext.Date.format(startTime, 'Y/m/d H:i:s'), stop: Ext.Date.format(stopDate, 'Y/m/d H:i:s')}; - var timeObj = {start: Ext.Date.format(startTime, 'Y/m/d'), stop: Ext.Date.format(stopDate, 'Y/m/d')}; - } - else { - var timeObj = {start: node.get('globalStart'), stop: node.get('globalStop')}; + // 'timeObj = {start: Ext.Date.format(startTime, 'Y/m/d H:i:s'), stop: Ext.Date.format(stopDate, 'Y/m/d H:i:s')}; + timeObj = { + start: Ext.Date.format(Ext.Date.add(stopDate, Ext.Date.DAY, -1), 'Y/m/d'), + stop: Ext.Date.format(stopDate, 'Y/m/d') + }; + } else { + timeObj = { + start: node.get('globalStart'), + stop: node.get('globalStop') + }; } return timeObj; }, createPlot: function (node) { - if (node.get('disable')) return; + if (node.get('disable')) { + return; + } myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id, true, function (module) { if (!myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.plot.id)) { var request = Ext.create(amdaPlotObj.PlotRequestObject.$className); var newNode = Ext.create(amdaModel.PlotNode.$className, {object: request}); - // edit newNode into Plot Module with node as contextNode + // Edit newNode into Plot Module with node as contextNode newNode.editInModule(); - if ((node.get('globalStart') != null) && (node.get('globalStop') != null) && node.get('globalStart') != 'depending on mission' && node.get('isParameter')) { + if (node.get('globalStart') != null && node.get('globalStop') != null && + node.get('globalStart') != 'depending on mission' && node.get('isParameter')) { module.getUiContent().setTimeFromData(node.getTimeFromNode(node)); } } @@ -483,7 +561,9 @@ Ext.define('amdaModel.InteractiveNode', { }, createDownload: function (node) { - if (node.get('disable')) return; + if (node.get('disable')) { + return; + } if (node.get('notyet')) { myDesktopApp.warningMsg('Sorry! access to this parameter is restricted.'); @@ -491,143 +571,163 @@ Ext.define('amdaModel.InteractiveNode', { } myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id, true, function (module) { + var paramName, request; if (!myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.download.id)) { - var request = Ext.create(amdaModel.Download.$className); + request = Ext.create(amdaModel.Download.$className); amdaModel.DownloadNode.set('object', request); - // singleton! + // Singleton! amdaModel.DownloadNode.editInModule(); - if ((node.get('globalStart') != null) && (node.get('globalStop') != null) && node.get('globalStart') != 'depending on mission' && node.get('isParameter')) { + if (node.get('globalStart') != null && node.get('globalStop') != null && + node.get('globalStart') != 'depending on mission' && node.get('isParameter')) { module.getUiContent().setTimeFromData(node.getTimeFromNode(node)); } } - var paramName; - var components = null; switch (node.$className) { - case 'amdaModel.AliasNode' : - paramName = "#" + node.get('text'); + case 'amdaModel.AliasNode': + paramName = '#' + node.get('text'); break; - case 'amdaModel.DerivedParamNode' : - paramName = "ws_" + node.get('text'); + case 'amdaModel.DerivedParamNode': + paramName = 'ws_' + node.get('text'); break; - case 'amdaModel.MyDataParamNode' : + case 'amdaModel.MyDataParamNode': paramName = 'wsd_' + node.get('text'); break; - default : - if (node.get('alias') != "") - paramName = "#" + node.get('alias'); - else + default: + if (node.get('alias') != '') { + paramName = '#' + node.get('alias'); + } else { paramName = node.get('id'); + } } -// var component_info = node.get('component_info'); -// if (component_info && component_info.parentId) { -// //It's a component -// paramName = component_info.parentId; -// components = []; -// if (component_info.index1) -// components['index1'] = component_info.index1; -// if (component_info.index2) -// components['index2'] = component_info.index2; -// } - module.addParam(paramName, true, node.get('needsArgs'), components); + + /* + * Var component_info = node.get('component_info'); + * If (component_info && component_info.parentId) { + * // It's a component + * ParamName = component_info.parentId; + * Components = []; + * If (component_info.index1) + * Components['index1'] = component_info.index1; + * If (component_info.index2) + * Components['index2'] = component_info.index2; + * } + */ + module.addParam(paramName, true, node.get('needsArgs'), null); }); }, deleteNode: function () { - // if the target is a directory - if (!this.isLeaf()) { - // determine if this directory is empty before launching the delete confirmation method - this.isNotEmptyDir(this.confirmDirectoryDeletion); - // else (the target is a leaf) - } else { - // no confirmation prompt for leaves + // If the target is a directory + if (this.isLeaf()) { + // No confirmation prompt for leaves this.confirmDirectoryDeletion(false); + } else { + // Determine if this directory is empty before launching the delete confirmation method + this.isNotEmptyDir(this.confirmDirectoryDeletion); + // Else (the target is a leaf) } }, /** - * this method return if node has Childs even if it was not already loaded + * This method return if node has Childs even if it was not already loaded + * @param {function} callbackFn Callback function + * @returns {void} */ isNotEmptyDir: function (callbackFn) { - var hasChilds; - // if node not already loaded - if (!this.isLoaded()) { - // call directFunction to load this node - AmdaAction.getTree({node: this.get('id'), nodeType: this.get('nodeType')}, function (res, e) { - callbackFn.call(this, res.length > 0 ? true : false); - }, this); - } - else { + // If node not already loaded + if (this.isLoaded()) { callbackFn.call(this, this.hasChildNodes()); + } else { + // Call directFunction to load this node + AmdaAction.getTree({ + node: this.get('id'), + nodeType: this.get('nodeType') + }, function (res) { + callbackFn.call(this, res.length > 0); + }, this); } }, /** - * this method is used to display a confirmation message + * This method is used to display a confirmation message + * @param {boolean} isNotEmptyDir true if the directory is not empty. + * @returns {void} */ confirmDirectoryDeletion: function (isNotEmptyDir) { - // if this is a non-empty directory + var ConfirmMsg = 'The target is a non-empty directory!
Do you want to continue and also delete its content?'; + // If this is a non-empty directory if (isNotEmptyDir) { // Prompt to the user if he also wants to delete its content - Ext.Msg.confirm('non-empty directory', 'The target is a non-empty directory!
Do you want to continue and also delete its content?', function (btn, text) { + Ext.Msg.confirm('non-empty directory', ConfirmMsg, function (btn, text) { if (btn == 'yes') { - // do delete + // Do delete this.realDelete(); } }, this); - } - else { + } else { this.realDelete(); } }, /* - * Call the extDirect method to delete parameter - * Callback method needed to execute node deletion in tree if id in result or to show error msg - */ + * Call the extDirect method to delete parameter + * Callback method needed to execute node deletion in tree if id in result or to show error msg + */ realDelete: function () { AmdaAction.deleteObject({ id: this.get('id'), leaf: this.isLeaf(), nodeType: this.get('nodeType') }, function (res, e) { - //TODO proper errors handling - // node deletion in tree - if (res) { // if success + var me, moduleId; + me = this; + + // Node deletion in tree - TODO proper errors handling + + // If success + if (res) { if (res.id) { - //Ext.Msg.show({title:'Warning', msg: 'Requests with parameter '+node.data.text+' are deleted', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK}); + + /* + * Ext.Msg.show({ + * title:'Warning', + * msg: 'Requests with parameter '+node.data.text+' are deleted', + * icon: Ext.MessageBox.ERROR, + * buttons: Ext.Msg.OK + * }); + */ if (this.parentNode) { if (this.isLeaf()) { - var moduleId = this.get('moduleId'); - // if really interactive node + moduleId = this.get('moduleId'); + // If really interactive node if (moduleId) { - var me = this; myDesktopApp.getLoadedModule(moduleId, true, function (module) { - var editedNode = module.getLinkedNode(); - // file node is not linked directly to the module - var isThisFile = false; + var editedNode, isThisFile, linkedNodes, newNode, tabPanel; + editedNode = module.getLinkedNode(); + // File node is not linked directly to the module + isThisFile = false; - if (editedNode && editedNode.$className == 'amdaModel.MyDataParamNode') - if (editedNode.get('fileObject').get('fileName') == me.get('text')) + if (editedNode && editedNode.$className == 'amdaModel.MyDataParamNode') { + if (editedNode.get('fileObject').get('fileName') == me.get('text')) { isThisFile = true; + } + } if (me.$className == 'amdaModel.DerivedParamNode') { - var obj = { - paramId: 'ws_' + me.get('text') - }; - AmdaAction.compilParamDelete(obj); + AmdaAction.compilParamDelete({paramId: 'ws_' + me.get('text')}); } if (editedNode === me || isThisFile) { - var newNode = Ext.ModelManager.create({leaf: true}, me.$className); - // several tabs could be connected to one node + newNode = Ext.ModelManager.create({leaf: true}, me.$className); + // Several tabs could be connected to one node if (moduleId === myDesktopApp.dynamicModules.plot.id) { - var linkedNodes = module.linkedNodes; + linkedNodes = module.linkedNodes; if (linkedNodes) { linkedNodes.each(function (key, value) { if (value === me) { linkedNodes.replace(key, newNode); - var tabPanel = module.getUiContent().tabPanel.items.getByKey(key); + tabPanel = module.getUiContent().tabPanel.items.getByKey(key); tabPanel.setObject(Ext.create(amdaModel.Plot.$className, {})); } }, me); @@ -638,141 +738,151 @@ Ext.define('amdaModel.InteractiveNode', { }); } } - //update mask info in myData + // Update mask info in myData if (res.maskDesc && !res.maskDeleted) { this.parentNode.set('info', res.maskDesc); this.updateMyDataParam(res.mask, res.maskDesc); } this.remove(); } - //TODO Several special node-dependent actions - to move to node functions.. - // nodes of another nodeType to be deleted as they depend on deleted node + + /* + *TODO Several special node-dependent actions - to move to node functions.. + * nodes of another nodeType to be deleted as they depend on deleted node + */ if (res.params) { this.deleteDependence(res.params); - //TODO reset + // TODO reset } - // mask was deleted or updated - to update mydata tree + // Mask was deleted or updated - to update mydata tree if (res.maskDeleted) { this.updateMyData(); } - } - else { + } else { myDesktopApp.warningMsg(res.error); } - } - else { + } else { myDesktopApp.errorMsg(e.message); } }, this); }, - /* - * Delete musti selection - */ + /** + * Delete multi selection + * @returns {void} + */ deleteMulti: function () { var selection = this.myGetOwnerTree().getSelectionModel().selected.items; - alert(selection.length + ' to delete!'); + Ext.alert(selection.length + ' to delete!'); Ext.Array.each(selection, function (item, index, allItems) { item.deleteNode(); - }) + }); }, - /* - * Create Folder - */ + /** + * Create Folder + * @returns {void} + */ createDir: function () { var me = this; amdaModel.InteractiveNode.preloadNodes(this.getRootNode(), function () { var newNode = Ext.create(me.$className, { - leaf: false, nodeType: me.get('nodeType'), + leaf: false, + nodeType: me.get('nodeType'), text: amdaModel.AmdaNode.NEW_DIR_NAME, children: [], parentId: me.get('id') }); - // insert the new node as a child of node + // Insert the new node as a child of node me.insertChild(0, newNode); - // start text edition on this new directory node + // Start text edition on this new directory node me.expand(false); newNode.expand(false); - // select the new node + // Select the new node me.myGetOwnerTree().getSelectionModel().select(newNode); - // call the renameNode method for this new node + // Call the renameNode method for this new node newNode.renameNode(true); }); }, /* - * - */ + * + */ createLeaf: function (contextNode) { - // create new node with the same type than the contextNode + // Create new node with the same type than the contextNode var newNode = Ext.create(contextNode.$className, {leaf: true}); - // load the rootNode and recursively all its child nodes + // Load the rootNode and recursively all its child nodes amdaModel.InteractiveNode.preloadNodes(contextNode.getRootNode(), function () { - // edit newNode into Parameter Module with node as contextNode + // Edit newNode into Parameter Module with node as contextNode newNode.editInModule(contextNode); }); }, renameNode: function (deleteOnFailure) { + var item, me; + me = this; if (this.myGetOwnerTree()) { - // load the rootNode and recursively all its child nodes if not already loaded - var me = this; + // Load the rootNode and recursively all its child nodes if not already loaded amdaModel.InteractiveNode.preloadNodes(this.getRootNode(), function () { - // fire the edition event on tree - var item = me.myGetOwnerTree().getSelectionModel().selected.items[0]; + // Fire the edition event on tree + item = me.myGetOwnerTree().getSelectionModel().selected.items[0]; item.deleteOnFailure = deleteOnFailure; me.myGetOwnerTree().fireEvent('edition', me.myGetOwnerTree().view, item); }); - } - else { + } else { myDesktopApp.errorMsg('tree is undefined'); } }, - /* - * load the rootNode and recursively all its child nodes - * to know all names of DerivedParameters - */ + /** + * Load the rootNode and recursively all its child nodes to know all names of DerivedParameters + * @param {function} onReady On ready callback function + * @returns {void} + */ editLeaf: function (onReady) { var me = this; amdaModel.InteractiveNode.preloadNodes(this.getRootNode(), function () { if (me.get('object')) { - // launch edition of parameter into parameter module + // Launch edition of parameter into parameter module me.editInModule(null, onReady); - } - else { - // call the ext method to get the details of parameter - // the edition of real parameter is done into callback method getObjectCallback - if (onReady) + } else { + + /* + * Call the ext method to get the details of parameter + * the edition of real parameter is done into callback method getObjectCallback + */ + if (onReady) { me.onReady = onReady; + } AmdaAction.getObject(me.get('id'), me.get('nodeType'), me.getObjectCallback, me); } }); }, - /* - * - */ + /** + * Get object callback + * @param {object} result The result + * @param {object} remoteEvent ... + * @returns {void} + */ getObjectCallback: function (result, remoteEvent) { var t = remoteEvent.getTransaction(); if (result) { var paramObj = Ext.create(this.get('objectDataModel'), result); - // set parameter into node + // Set parameter into node this.set('object', paramObj); // Edition of parameter into parameter Module this.editInModule(null, this.onReady); - } - else { + } else { // EXCEPTION : parameter not found !? - myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '" - + this.get('name') + "' found!"); + myDesktopApp.errorMsg(t.action + '.' + t.method + ' : No parameter \'' + + this.get('name') + '\' found!'); } } }); diff --git a/js/app/views/ExplorerUI.js b/js/app/views/ExplorerUI.js index 4765120..fbd1720 100644 --- a/js/app/views/ExplorerUI.js +++ b/js/app/views/ExplorerUI.js @@ -11,6 +11,8 @@ * @author CDA */ +/* global AmdaAction, amdaModel, myDesktopApp, amdaUI, MyTreeEditor */ + Ext.define('amdaUI.TreeToolColumn', { extend: 'Ext.tree.Column', alias: 'widget.treetoolcolumn', @@ -18,52 +20,57 @@ Ext.define('amdaUI.TreeToolColumn', { /** * Add more tools here. These will be on the prototype for all TreeToolColumns */ - tools: { - 'info': 'js/resources/images/16x16/info_mini.png' - }, + tools: {info: 'js/resources/images/16x16/info_mini.png'}, initComponent: function () { var me = this; + me.addEvents('toolclick'); me.callParent(); me.on('toolclick', me.toolHandler, me); }, renderer: function (value, metaData, record, rowIdx, colIdx, store, view) { - var toolCol = view.getHeaderAtIndex(colIdx); - - if (!toolCol.toolIsVisible(record)) return value; - - var toolId = 'tool-' + rowIdx + '-' + colIdx, - toolImg = toolCol.tools[toolCol.tool], - imgHtml = Ext.DomHelper.markup({ - id: toolId, - tag: 'img', - tooltype: toolCol.tool, - src: toolImg, - style: 'cursor:hand;' - }); + var imgHtml, + toolCol = view.getHeaderAtIndex(colIdx); + + if (!toolCol.toolIsVisible(record)) { + return value; + } + + imgHtml = Ext.DomHelper.markup({ + id: 'tool-' + rowIdx + '-' + colIdx, + tag: 'img', + tooltype: toolCol.tool, + src: toolCol.tools[toolCol.tool], + style: 'cursor:hand;' + }); return value + ' ' + imgHtml; }, processEvent: function (type, view, cell, recordIndex, cellIndex, e) { - if (type === "click" && e.target.tagName === "IMG") { - var tooltype = e.target.getAttribute("tooltype"); - if (tooltype) - return this.fireEvent("toolclick", view, cell, recordIndex, cellIndex, e); + var toolType; + + if (type === 'click' && e.target.tagName === 'IMG') { + toolType = e.target.getAttribute('tooltype'); + if (toolType) { + return this.fireEvent('toolclick', view, cell, recordIndex, cellIndex, e); + } } return this.fireEvent.apply(this, arguments); }, /** - * Override this when you add columns to the tree... see example below + * Override this when you add columns to the tree... see example below: + * + * ToolHandler: function() { + * Alert("override this"); + * } + * + * @returns {boolean} False */ -// toolHandler: function() { -// alert("override this"); -// }, - - toolIsVisible: function (record) { + toolIsVisible: function () { return false; } }); @@ -101,9 +108,10 @@ Ext.define('amdaUI.ExplorerUI', { }, initComponent: function (config) { - var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); + var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id), + myConf; - var myConf = { + myConf = { split: true, width: '100%', height: '100%', @@ -111,16 +119,14 @@ Ext.define('amdaUI.ExplorerUI', { border: true, header: false, defaults: { - // applied to each contained panel + // Applied to each contained panel containerScroll: true }, stateful: true, - //stateId: 'tp1', + // StateId: 'tp1', stateEvents: ['tabchange'], getState: function () { - return { - activeTab: this.items.findIndex('id', this.getActiveTab().id) - }; + return {activeTab: this.items.findIndex('id', this.getActiveTab().id)}; }, applyState: function (s) { this.setActiveTab(s.activeTab); @@ -144,14 +150,10 @@ Ext.define('amdaUI.ExplorerUI', { scope: this, select: function (combo, records) { AmdaAction.setCrtFilterId({id: records[0].get('id')}, function (result, e) { - var t = e.getTransaction(); if (e.status) { - if (result) { - var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); - if (explorerModule) - explorerModule.setCrtFilter(); - } - else + if (result && explorerModule) { + explorerModule.setCrtFilter(); + } else { Ext.Msg.show({ title: 'Filter', msg: 'Cannot apply filter', @@ -159,8 +161,8 @@ Ext.define('amdaUI.ExplorerUI', { icon: Ext.Msg.ERROR, buttons: Ext.Msg.OK }); - } - else { + } + } else { // FAILURE Ext.Msg.show({ title: 'Error System', @@ -176,8 +178,11 @@ Ext.define('amdaUI.ExplorerUI', { { text: '', iconCls: 'icon-parameters', - tooltip: {text: 'Edit Filter', align: 'bl-tl'}, - handler: function (t) { + tooltip: { + text: 'Edit Filter', + align: 'bl-tl' + }, + handler: function () { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.filters.id, true, function (module) { module.createWindow(); }); @@ -186,12 +191,15 @@ Ext.define('amdaUI.ExplorerUI', { { text: '', iconCls: 'icon-remover', - tooltip: {text: 'Reset Filter', align: 'bl-tl'}, - handler: function (t) { - var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); + tooltip: { + text: 'Reset Filter', + align: 'bl-tl' + }, + handler: function () { explorerModule.resetFilter(); } - }, '-', + }, + '-', { xtype: 'displayfield', fieldLabel: 'SortBy', @@ -200,7 +208,10 @@ Ext.define('amdaUI.ExplorerUI', { { text: 'Name', scope: this, - tooltip: {text: 'Sort out AMDA DataBase Data by Mission Name', align: 'bl-tl'}, + tooltip: { + text: 'Sort out AMDA DataBase Data by Mission Name', + align: 'bl-tl' + }, pressed: true, enableToggle: true, toggleGroup: 'sorting', @@ -209,8 +220,9 @@ Ext.define('amdaUI.ExplorerUI', { tree.getStore().sort([ { sorterFn: function (o1, o2) { - if (o1.get('nodeType') !== 'localParam') + if (o1.get('nodeType') !== 'localParam') { return; + } return o1.get('text').toUpperCase() < o2.get('text').toUpperCase() ? -1 : 1; } @@ -222,7 +234,10 @@ Ext.define('amdaUI.ExplorerUI', { { text: 'Target', scope: this, - tooltip: {text: 'Sort out AMDA DataBase Data by Mission Main Target', align: 'bl-tl'}, + tooltip: { + text: 'Sort out AMDA DataBase Data by Mission Main Target', + align: 'bl-tl' + }, enableToggle: true, toggleGroup: 'sorting', handler: function () { @@ -238,6 +253,7 @@ Ext.define('amdaUI.ExplorerUI', { }, initTree: function (treeType) { + var menu, store, tree, treeId; switch (treeType) { case amdaUI.ExplorerUI.RESRC_TAB.TREE_TYPE: treeId = amdaUI.ExplorerUI.RESRC_TAB.TREE_ID; @@ -253,7 +269,7 @@ Ext.define('amdaUI.ExplorerUI', { break; } - var store = Ext.create('Ext.data.TreeStore', { + store = Ext.create('Ext.data.TreeStore', { root: { expanded: true, nodeType: treeType @@ -263,25 +279,24 @@ Ext.define('amdaUI.ExplorerUI', { { direction: 'ASC', sorterFn: function (o1, o2) { - if (o1.get('nodeType') !== 'localParam') + if (o1.get('nodeType') !== 'localParam') { return; + } return o1.get('text').toUpperCase() < o2.get('text').toUpperCase() ? -1 : 1; } } ], listeners: { - beforeload: function (store, operation) { - store.proxy.extraParams = { - nodeType: operation.node.get('nodeType') - }; + beforeload: function (_store, operation) { + _store.proxy.extraParams = {nodeType: operation.node.get('nodeType')}; } } }); - var menu = new Ext.menu.Menu(); + menu = new Ext.menu.Menu(); - var tree = Ext.create('Ext.tree.Panel', { + tree = Ext.create('Ext.tree.Panel', { id: treeId, title: treeType, store: store, @@ -289,7 +304,7 @@ Ext.define('amdaUI.ExplorerUI', { animate: false, hideHeaders: true, selModel: Ext.create('Ext.selection.TreeModel', { - // ignoreRightMouseSelection: true, + // IgnoreRightMouseSelection: true, mode: 'MULTI' }), viewConfig: { @@ -297,7 +312,7 @@ Ext.define('amdaUI.ExplorerUI', { ptype: 'treeviewdragdrop', enableDrag: true, enableDrop: true, - //TODO - BRE - Wait a fix for drag&drop issue + // TODO - BRE - Wait a fix for drag&drop issue ddGroup: 'explorerTree', pluginId: 'ddplugin', @@ -326,8 +341,7 @@ Ext.define('amdaUI.ExplorerUI', { // Respect the allowDrop field on Tree nodes if (position === 'append' && targetNode.get('allowDrop') === false) { return false; - } - else if (position != 'append' && targetNode.parentNode.get('allowDrop') === false) { + } else if (position != 'append' && targetNode.parentNode.get('allowDrop') === false) { return false; } // If the target record is in the dragged dataset, then invalid drop @@ -335,54 +349,61 @@ Ext.define('amdaUI.ExplorerUI', { return false; } // - if (dataLength > 1) + if (dataLength > 1) { return false; + } var draggedRecord = draggedRecords[0]; // switch (targetNode.data.nodeType) { - case 'localParam' : - case 'remoteParam' : - case 'remoteSimuParam' : - case 'myData' : + case 'localParam': + case 'remoteParam': + case 'remoteSimuParam': + case 'myData': return false; - default : - if (draggedRecord.data.id == targetNode.data.nodeType + '-treeRootNode') + default: + if (draggedRecord.data.id == targetNode.data.nodeType + '-treeRootNode') { return false; - if ((position == 'before') && (targetNode.data.id == targetNode.data.nodeType + '-treeRootNode')) + } + if (position == 'before' && targetNode.data.id == targetNode.data.nodeType + '-treeRootNode') { return false; - return (draggedRecord.data.nodeType == targetNode.data.nodeType); + } + return draggedRecord.data.nodeType == targetNode.data.nodeType; } return false; }, onViewRender: function (view) { var me = this; - view.on('itemupdate', function (record, index, node, opts) { - var forceHide = false; - var crtRec = record.parentNode; + view.on('itemupdate', function (record) { + var forceHide = false, + crtRec = record.parentNode; + while (crtRec && !forceHide) { - if (crtRec.get('filtered')) + if (crtRec.get('filtered')) { forceHide = crtRec.get('filtered'); + } crtRec = crtRec.parentNode; } tree.setNodesVisibility(record, forceHide); tree.applyDisableToNode(record); }); - view.on('itemadd', function (records, index, node, opts) { + view.on('itemadd', function (records) { Ext.each(records, function (rec) { tree.applyFilterToNode(rec); tree.applyDisableToNode(rec); }); }); - view.on('afteritemexpand', function (record, index, node, opts) { - var forceHide = false; - var crtRec = record.parentNode; + view.on('afteritemexpand', function (record) { + var crtRec, forceHide; + forceHide = false; + crtRec = record.parentNode; while (crtRec && !forceHide) { - if (crtRec.get('filtered')) + if (crtRec.get('filtered')) { forceHide = crtRec.get('filtered'); + } crtRec = crtRec.parentNode; } @@ -419,21 +440,24 @@ Ext.define('amdaUI.ExplorerUI', { beforedrop: function (node, data, overModel, dropPosition) { var parentId; switch (dropPosition) { - case 'append' : - if (overModel.isLeaf()) + case 'append': + if (overModel.isLeaf()) { parentId = overModel.parentNode.get('id'); - else + } else { parentId = overModel.get('id'); + } if (!overModel.isExpanded() && overModel.isExpandable()) { myDesktopApp.warningMsg('Please open the folder before node adding'); return false; } break; - case 'before' : - case 'after' : + case 'before': + case 'after': parentId = overModel.parentNode.get('id'); break; + default: + break; } Ext.each(data.records, function (rec) { @@ -449,8 +473,7 @@ Ext.define('amdaUI.ExplorerUI', { return false; } - } - else { + } else { Ext.Msg.show({ title: 'Drop is impossible', msg: 'Cannot connect to the server', @@ -469,66 +492,60 @@ Ext.define('amdaUI.ExplorerUI', { }, listeners: { itemmouseenter: function (view, record, item) { - if (record.get('isParameter')) { - var el = Ext.get(item), - td = el.down('td > div'); - td.setStyle('cursor', 'crosshair'); - } - else { - var el = Ext.get(item), - td = el.down('td > div'); - td.setStyle('cursor', 'pointer'); - } + Ext.get(item).down('td > div').setStyle('cursor', record.get('isParameter') ? 'pointer' : 'crosshair'); }, itemcontextmenu: function (view, rec, item, index, e) { + var menuItems; + // Add record to selection model view.ownerCt.getSelectionModel().select(rec); - // block other events + // Block other events e.stopEvent(); - // clear menu items + // Clear menu items menu.removeAll(); - var menuItems; - // if it's a single selection + // If it's a single selection if (view.ownerCt.getSelectionModel().selected.length === 1) { - // get items menu corresponding to right clicked record + // Get items menu corresponding to right clicked record menuItems = rec.getContextMenuItems(this); } else if (view.ownerCt.getSelectionModel().selected.length > 1) { - // get items menu corresponding to right clicked record + // Get items menu corresponding to right clicked record menuItems = rec.getContextMenuMultiItems(this); } - // if there's at least one item menu + // If there's at least one item menu if (menuItems && menuItems.length) { - // add the items + // Add the items menu.add(menuItems); - // add listener on right clicked record - var onRecordClick = function (menu, item, e, eOpts) { + + // Add listener on right clicked record + var onRecordClick = function (menu, item, e) { if (this.myGetOwnerTree().getSelectionModel().isSelected(this)) { - //Dispatch click event to the record + // Dispatch click event to the record this.onMenuItemClick(menu, item, e); } - //Remove old click listener + // Remove old click listener menu.removeListener('click', onRecordClick, this); }; menu.addListener('click', onRecordClick, rec); - // then show menu + // Then show menu menu.showAt(e.getXY()); } }, itemdblclick: function (view, record, item, index, event) { + var zmgr, winId; + event.stopEvent(); - // first check if it is for SAVE-START-STOP plugin... + // First check if it is for SAVE-START-STOP plugin... if (Ext.PluginManager.getCount() > 0 && record.get('nodeType') == amdaModel.TimeTableNode.nodeType && record.isLeaf()) { - var zmgr = myDesktopApp.desktop.getDesktopZIndexManager(); - var winActive = zmgr.getActive(); - var winId = winActive.getId(); + zmgr = myDesktopApp.desktop.getDesktopZIndexManager(); + winId = zmgr.getActive().getId(); if (winId == 'explorer-win') { zmgr.eachTopDown(function (win) { var id = win.getId(); @@ -540,58 +557,56 @@ Ext.define('amdaUI.ExplorerUI', { } } - if (record.get('nodeType') == 'remoteParam' && !record.isLeaf() - && !record.get('isParameter')) { + if (record.get('nodeType') == 'remoteParam' && !record.isLeaf() && + !record.get('isParameter')) { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) { module.createWindow(record.getBaseId()); }); } - if (record.isLeaf() || record.data.isParameter) + if (record.isLeaf() || record.data.isParameter) { switch (record.get('nodeType')) { - case 'myData' : - case 'myDataParam' : - case 'derivedParam' : - case 'timeTable' : - case 'sharedtimeTable' : - case 'sharedcatalog' : - case 'catalog' : - case 'request' : - case 'condition' : + case 'myData': + case 'myDataParam': + case 'derivedParam': + case 'timeTable': + case 'sharedtimeTable': + case 'sharedcatalog': + case 'catalog': + case 'request': + case 'condition': record.editLeaf(); break; - case 'localParam' : + case 'localParam': case 'remoteParam': case 'remoteSimuParam': record.createAlias(record); break; - case 'bkgWorks' : + case 'bkgWorks': if (!record.get('object')) { AmdaAction.getObject(record.get('id'), record.get('nodeType'), record.getObjectCallback, record); + } else if (record.get('status') == 'done') { + // IsInteractive = true, isNewTab = false + record.editNode(true, false); + } else { + myDesktopApp.infoMsg('Job Status: ' + record.get('status')); } - else { - if (record.get('status') == 'done') { - var isInteractive = false; - var isNewTab = true; - record.editNode(isNewTab, isInteractive); - } - else { - myDesktopApp.infoMsg('Job Status: ' + record.get('status')); - } - } + break; + default: break; } + } }, - beforeselect: function (view, node, index, options) { - // if there's at least one node already selected - if (view.selected.length - //AND (the node which is beeing selected has a different nodeType than the first selected node OR the first selected node isn't a leaf - && (node.get('nodeType') !== view.selected.items[0].get('nodeType') || !view.selected.items[0].isLeaf()) + beforeselect: function (view, node) { + // If there's at least one node already selected + if (view.selected.length && + // AND (the node which is beeing selected has a different nodeType than the first selected node OR the first selected node isn't a leaf + (node.get('nodeType') !== view.selected.items[0].get('nodeType') || !view.selected.items[0].isLeaf()) || // OR the node which is beeing selected has no nodeType OR it isn't a leaf OR - || !node.get('nodeType') || !node.isLeaf() + !node.get('nodeType') || !node.isLeaf() ) { - // clear old selection + // Clear old selection view.deselectAll(); } }, @@ -604,20 +619,23 @@ Ext.define('amdaUI.ExplorerUI', { // Each grid row causes its own seperate show and hide. delegate: view.itemSelector, dismissDelay: 0, - // showDelay: 100, - // anchor: 'left', - // Moving within the row should not hide the tip. + + /* + * ShowDelay: 100, + * anchor: 'left', + * Moving within the row should not hide the tip. + */ trackMouse: true, autoRender: true, listeners: { // Change content dynamically depending on which element triggered the show. - beforeshow: function updateTipBody(tip) { + beforeshow: function updateTipBody (tip) { + var info; if (view.getRecord(tip.triggerElement)) { - var info = view.getRecord(tip.triggerElement).get('info'); + info = view.getRecord(tip.triggerElement).get('info'); if (!info || info == '') { tip.addCls('hide'); - } - else { + } else { tip.removeCls('hide'); tip.update(info); } @@ -626,61 +644,63 @@ Ext.define('amdaUI.ExplorerUI', { } }); }, - // if remote base is empty - open interoperability module + // If remote base is empty - open interoperability module itemexpand: function (node) { - if (node.get('nodeType') == amdaModel.RemoteParamNode.nodeType - && node.getDepth() == 3 && !node.hasChildNodes()) { + if (node.get('nodeType') == amdaModel.RemoteParamNode.nodeType && + node.getDepth() == 3 && !node.hasChildNodes()) { node.addData(); } }, scope: this }, - hideHeaders: true, - // must define a column with a field to enable editor + // Must define a column with a field to enable editor columns: [ { xtype: 'treetoolcolumn', text: 'Name', flex: 1, dataIndex: 'text', - tool: 'info', // this references the "tools" object on the prototype + // This references the "tools" object on the prototype + tool: 'info', toolHandler: function (view, cell, recordIndex, cellIndex, e) { - var tooltype = e.target.getAttribute("tooltype"); var record = view.store.getAt(recordIndex); - switch (tooltype) { - case 'info' : + switch (e.target.getAttribute('tooltype')) { + case 'info': myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function (module) { module.createWindow(record.get('help'), record.get('text')); }); break; + default: + break; } }, toolIsVisible: function (record) { switch (record.get('nodeType')) { - case 'localParam' : - case 'remoteParam' : - case 'remoteSimuParam' : - + case 'localParam': + case 'remoteParam': + case 'remoteSimuParam': return record.get('help') != ''; + default: + break; } return false; }, field: { validFlag: true, listeners: { - change: function (field, newValue, oldValue, eOpts) { - var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); - var explUI = explModule.getUiContent(); - var activeTreePanel = explUI.getActiveTab(); + change: function (field, newValue) { + var editedNode, explModule; + + explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); + editedNode = explModule.getUiContent().getActiveTab().getSelectionModel().selected.items[0]; - var editedNode = activeTreePanel.getSelectionModel().selected.items[0]; if (editedNode) { editedNode.isValidName(newValue, function (res) { var validFlag = true; if (newValue === amdaModel.AmdaNode.NEW_DIR_NAME) { - validFlag = 'Field is not modified' + validFlag = 'Field is not modified'; } else if (!res) { validFlag = 'Error during object validation'; } else if (!res.valid) { @@ -728,8 +748,9 @@ Ext.define('amdaUI.ExplorerUI', { setNodesVisibility: function (node, forceHide) { var isFiltered = node.get('filtered'); - for (var i = 0; i < node.childNodes.length; i++) + for (var i = 0; i < node.childNodes.length; i++) { this.setNodesVisibility(node.childNodes[i], forceHide || isFiltered); + } this.setNodeVisibility(node, !(forceHide || isFiltered)); }, @@ -742,34 +763,37 @@ Ext.define('amdaUI.ExplorerUI', { if (isVisible) { viewNode.show(); this.applyDisableToNode(record); - } - else + } else { viewNode.hide(); + } } }, applyFilterToNode: function (node) { - if (!node) + var filter, isFiltered, pos; + + if (!node) { return; + } - var filter = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).filter; + filter = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).filter; switch (node.get('nodeType')) { - case 'localParam' : - if (!filter || !filter['param']) { - //no filter applied + case 'localParam': + if (!filter || !filter.param) { + // No filter applied node.set('filtered', false); return; } - var pos = node.get('depth') - 3; //depth from local param root node + // Depth from local param root node + pos = node.get('depth') - 3; if (pos < 0 || pos > 2) { node.set('filtered', false); return; } - var isFiltered = true; - for (var i = 0; i < filter['param'].length; i++) { - s = filter['param'][i].split(';'); - if (node.get('id') == s[pos]) { + isFiltered = true; + for (var i = 0; i < filter.param.length; i++) { + if (node.get('id') == filter.param[i].split(';')[pos]) { isFiltered = false; break; } @@ -777,53 +801,52 @@ Ext.define('amdaUI.ExplorerUI', { node.set('filtered', isFiltered); break; - case 'remoteSimuParam' : - if (!filter || !filter['simu']) { - //no filter applied + case 'remoteSimuParam': + if (!filter || !filter.simu) { + // No filter applied node.set('filtered', false); return; } - var pos = node.get('depth') - 3; //depth from remote param root node - + // Depth from remote param root node + pos = node.get('depth') - 3; if (pos < 0 || pos > 5) { node.set('filtered', false); return; } - var isFiltered = true; - - for (var i = 0; i < filter['simu'].length; i++) { - s = filter['simu'][i].split(';'); - - if (node.get('id') == s[pos]) { + isFiltered = true; + for (var i = 0; i < filter.simu.length; i++) { + if (node.get('id') == filter.simu[i].split(';')[pos]) { isFiltered = false; break; } } node.set('filtered', isFiltered); break; - /*case 'alias' : - if (!this.localParamFilter.result || this.localParamFilter.id == "" || - !node.isLeaf()) { - //no filter applied - node.set('filtered',false); - return; - } - var crtParam = node.get('id'); - crtParam = crtParam.replace('alias_',''); - crtParam = crtParam.replace(/_/g,':'); - var isFiltered = true; - for (var i = 0; i < this.localParamFilter.result.length; i++) { - s = this.localParamFilter.result[i].split(';'); - console.log(s[2]); - if (crtParam == s[2]) { - isFiltered = false; - break; - } - } - node.set('filtered',isFiltered); - break;*/ - default : - return; + + /* + * Case 'alias': + * if (!this.localParamFilter.result || this.localParamFilter.id == "" || !node.isLeaf()) { + * // No filter applied + * node.set('filtered',false); + * return; + * } + * var crtParam = node.get('id'); + * crtParam = crtParam.replace('alias_',''); + * crtParam = crtParam.replace(/_/g,':'); + * var isFiltered = true; + * for (var i = 0; i < this.localParamFilter.result.length; i++) { + * s = this.localParamFilter.result[i].split(';'); + * console.log(s[2]); + * if (crtParam == s[2]) { + * isFiltered = false; + * break; + * } + * } + * node.set('filtered',isFiltered); + * break; + */ + default: + } }, @@ -835,8 +858,10 @@ Ext.define('amdaUI.ExplorerUI', { }, applyDisableToNode: function (node) { - var crtNode = node; - var disable = false; + var crtNode, disable, viewNode; + + crtNode = node; + disable = false; do { if (crtNode.get('disable')) { @@ -847,7 +872,7 @@ Ext.define('amdaUI.ExplorerUI', { } while (crtNode); - var viewNode = Ext.fly(tree.getView().getNode(node)); + viewNode = Ext.fly(tree.getView().getNode(node)); if (disable) { node.set('disable', true); viewNode.setStyle('opacity', 0.5); @@ -861,47 +886,53 @@ Ext.define('amdaUI.ExplorerUI', { }, updateFilter: function () { - var filter = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).filter; + var aliasNode, filter, keys, localNode, remoteNode, tree; - var keys = []; + filter = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).filter; + + keys = []; for (var f in filter) { - if (hasOwnProperty.call(filter, f)) + if (hasOwnProperty.call(filter, f)) { keys.push(f); + } } - var tree = this.query('#' + amdaUI.ExplorerUI.RESRC_TAB.TREE_ID)[0]; + tree = this.query('#' + amdaUI.ExplorerUI.RESRC_TAB.TREE_ID)[0]; tree.getView().refresh(); for (var i = 0; i < keys.length; i++) { - if (keys[i] == "_empty_") + if (keys[i] == '_empty_') { continue; + } switch (keys[i]) { - case 'param' : - //apply filter to local datasets - var localNode = tree.getRootNode().findChild('id', 'myLocalData-treeRootNode', true); + case 'param': + // Apply filter to local datasets + localNode = tree.getRootNode().findChild('id', 'myLocalData-treeRootNode', true); tree.applyFilterToNodes(localNode); tree.setNodesVisibility(localNode, false); tree.applyDisableToNode(localNode); - //apply filter to aliases - var aliasNode = tree.getRootNode().findChild('id', 'alias-treeRootNode', true); + // Apply filter to aliases + aliasNode = tree.getRootNode().findChild('id', 'alias-treeRootNode', true); tree.applyFilterToNodes(aliasNode); tree.setNodesVisibility(aliasNode, false); tree.applyDisableToNode(aliasNode); break; - case 'simu' : - //apply filter to simulation datasets (in remote data) - var remoteNode = tree.getRootNode().findChild('id', 'myRemoteSimuData-treeRootNode', true); + case 'simu': + // Apply filter to simulation datasets (in remote data) + remoteNode = tree.getRootNode().findChild('id', 'myRemoteSimuData-treeRootNode', true); tree.applyFilterToNodes(remoteNode); tree.setNodesVisibility(remoteNode, false); tree.applyDisableToNode(remoteNode); break; + default: + break; } } - this.dockedItems.getAt(1).items.items[0].select(filter['name']); + this.dockedItems.getAt(1).items.items[0].select(filter.name); } }); @@ -910,18 +941,21 @@ Ext.define('MyTreeEditor', { extend: 'Ext.grid.plugin.CellEditing', alias: 'editing.treeeditor', - // initialization method of plugin + // Initialization method of plugin init: function (cmp) { var me = this; me.hostCmp = cmp; - // on parent event + // On parent event me.hostCmp.on({ - // on edition event + // On edition event edition: { delay: 50, fn: function (view, record, item, index, e) { - // view.getHeaderAtIndex(0).field.validFlag = 'Not modified'; - // call the start edition method + + /* + * View.getHeaderAtIndex(0).field.validFlag = 'Not modified'; + * call the start edition method + */ me.startEdit(record, view.getHeaderAtIndex(0)); }, scope: me @@ -932,6 +966,7 @@ Ext.define('MyTreeEditor', { /** * Cancel any active editing. + * @returns {void} */ cancelEdit: function () { var me = this, @@ -949,8 +984,8 @@ Ext.define('MyTreeEditor', { }, /** - * overwrite the initEditTriggers to disable edition on click/dblclick - * and to add custom + * Overwrite the initEditTriggers to disable edition on click/dblclick and to add custom + * @returns {void} */ initEditTriggers: function () { var me = this, @@ -958,22 +993,22 @@ Ext.define('MyTreeEditor', { me.on({ edit: function (editor, event) { - // if there is a modification + // If there is a modification if (event.originalValue !== event.value) { - // delegate rename action on model + // Delegate rename action on model event.record.rename(event.value, function (result) { - // if a result has been returned : success + // If a result has been returned : success if (result) { - // delegate commit action to delete modification flag + // Delegate commit action to delete modification flag event.record.commit(); var rec = event.record.data; - // in case of directory + // In case of directory if (!rec.leaf) { - // set folder's ID returned by server + // Set folder's ID returned by server rec.id = result.id; } - } else { // in case of transaction error - // reset originalValue + } else { + // In case of transaction error, reset originalValue event.record.value = event.originalValue; event.record.set('text', event.originalValue); event.record.commit(); @@ -983,7 +1018,7 @@ Ext.define('MyTreeEditor', { } }); - // enable Enter key and Esc Key + // Enable Enter key and Esc Key view.on('render', function () { me.keyNav = Ext.create('Ext.util.KeyNav', view.el, { enter: me.onEnterKey, @@ -992,26 +1027,24 @@ Ext.define('MyTreeEditor', { }); }, me, {single: true}); }, - //overwrite the getEditing context because we do not need the rowId + // Overwrite the getEditing context because we do not need the rowId getEditingContext: function (record, columnHeader) { var me = this, grid = me.grid, - store = grid.store, colIdx, - view = grid.getView(), value; - // getting colIdx and real columnHeader + // Getting colIdx and real columnHeader if (Ext.isNumber(columnHeader)) { colIdx = columnHeader; columnHeader = grid.headerCt.getHeaderAtIndex(colIdx); } else { colIdx = columnHeader.getIndex(); } - // getting current value + // Getting current value value = record.get(columnHeader.dataIndex); - // return editing context + // Return editing context return { grid: grid, record: record, -- libgit2 0.21.2