diff --git a/js/.eslintrc.yml b/js/.eslintrc.yml index 8362be8..395483b 100644 --- a/js/.eslintrc.yml +++ b/js/.eslintrc.yml @@ -7,18 +7,17 @@ plugins: - extjs rules: indent: [error, 2, SwitchCase: 1] - semi: [warn, never] + semi: [error, always] max-len: [error, code: 120] - max-lines: [error, 600] + max-lines: [warn, 600] linebreak-style: [error, unix] quotes: [error, single] strict: [error, global] quote-props: [error, as-needed] max-statements: [warn, 20] - array-bracket-newline: [warn, consistent] consistent-this: [error, me] padded-blocks: off - no-tabs: off + newline-per-chained-call: [error, ignoreChainWithDepth: 3] no-warning-comments: off func-names: off function-paren-newline: off diff --git a/js/app/views/UploadPanelUI.js b/js/app/views/UploadPanelUI.js index e84427c..c4d78c2 100644 --- a/js/app/views/UploadPanelUI.js +++ b/js/app/views/UploadPanelUI.js @@ -1,20 +1,27 @@ /** - * Project  : AMDA-NG - * Name : UploadUI.js - * @class amdaUI.UploadUI - * @extends Ext.form.Panel - * @brief Upload Panel UI definition (View) - * @author Elena - * @version $Id: UploadPanelUI.js 2831 2015-03-26 10:33:42Z elena $ + * Project: AMDA-NG + * Name: UploadUI.js + * @class amdaUI.UploadUI + * @extends Ext.form.panel + * @brief Upload Panel UI definition (View) + * @author Elena + * @version $Id: UploadPanelUI.js 2831 2015-03-26 10:33:42Z elena $ */ +/* global AmdaAction, myDesktopApp, amdaModel, loadMask */ + +/** + * @typedef {AmdaApp} myDesktopApp + * @typedef {Object} AmdaAction + * @typedef {Object} Ext + */ + +'use strict'; Ext.define('amdaUI.UploadPanelUI', { extend: 'Ext.form.Panel', alias: 'widget.panelUpload', - requires: [ - 'amdaUI.RemoteSearchPlugin' - ], + requires: ['amdaUI.RemoteSearchPlugin'], isFile: true, isTimeTable: false, @@ -22,36 +29,40 @@ Ext.define('amdaUI.UploadPanelUI', { constructor: function (config) { this.init(config); - this.callParent(arguments); + this.superclass.constructor.apply(this, arguments); }, /* - * create MyData linked node and edit in module MyData - * update myDataParams info if needed - */ + * Create MyData linked node and edit in module MyData + * Update myDataParams info if needed + */ getObjectCallback: function (result, remoteEvent) { - var t = remoteEvent.getTransaction(); + var linkedFile, me, paramObj, t; + + t = remoteEvent.getTransaction(); if (result && !result.error) { - // set parameter into node - var me = this; + // Set parameter into node + me = this; myDesktopApp.getLoadedModule(this.tmpNode.get('moduleId'), true, function (module) { - // myData - if (me.tmpNode.get('nodeType') == amdaModel.MyDataParamNode.nodeType) { - var linkedFile = Ext.create('amdaModel.MyDataNode', {leaf: true, text: me.tmpNode.get('text')}); - + // MyData + if (me.tmpNode.get('nodeType') === amdaModel.MyDataParamNode.nodeType) { + linkedFile = Ext.create('amdaModel.MyDataNode', { + leaf: true, + text: me.tmpNode.get('text') + }); linkedFile.create(result.mask, result.description, result.maskDesc); linkedFile.updateMyDataParam(result.mask, result.maskDesc); - if (!linkedFile.get('id')) + if (!linkedFile.get('id')) { linkedFile.set('id', me.tmpNode.get('text')); + } - var paramObj = Ext.create(linkedFile.get('objectDataModel'), result); + paramObj = Ext.create(linkedFile.get('objectDataModel'), result); linkedFile.set('object', paramObj); me.tmpNode.set('fileObject', paramObj); - } - else { + } else { // Time Table or Catalog - var paramObj = Ext.create(me.tmpNode.get('objectDataModel'), result); + paramObj = Ext.create(me.tmpNode.get('objectDataModel'), result); paramObj.set('fromPlugin', true); if (result.intervals) { @@ -65,121 +76,125 @@ Ext.define('amdaUI.UploadPanelUI', { module.linkedNode.editInModule(); } }); - } - else { + } else { // EXCEPTION : parameter not found ! - myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '" + this.tmpNode.get('text') + "' found!"); + myDesktopApp.errorMsg(t.action + '.' + t.method + ' : No parameter "' + this.tmpNode.get('text') + '" found!'); } loadMask.hide(); }, /* - * form validation - * TODO markInvalid()? - */ + * Form validation + * TODO markInvalid()? + */ validate: function () { - var values = this.getForm().getValues(); - - if (values['filesrc'] == 'LOCAL') { - if (this.isFile) var locFile = this.getForm().findField('localFileName').getValue(); - else if (this.isTimeTable) var locFile = this.getForm().findField('localTTName').getValue(); - else var locFile = this.getForm().findField('localCatName').getValue(); + var locFile, values; + values = this.getForm().getValues(); + + if (values.filesrc === 'LOCAL') { + if (this.isFile) { + locFile = this.getForm().findField('localFileName').getValue(); + } else if (this.isTimeTable) { + locFile = this.getForm().findField('localTTName').getValue(); + } else { + locFile = this.getForm().findField('localCatName').getValue(); + } if (!locFile) { - myDesktopApp.warningMsg("Select File to Upload"); - return false; - } - } - else { - if (!values['remoteFile'] && !values['remoteTT'] && !values['remoteCat']) { - myDesktopApp.warningMsg("Select File to Upload"); + myDesktopApp.warningMsg('Select File to Upload'); return false; } + } else if (!values.remoteFile && !values.remoteTT && !values.remoteCat) { + myDesktopApp.warningMsg('Select File to Upload'); + return false; } return true; }, - //TODO proper parsing + // TODO proper parsing updateFormat: function (value) { - var arrayOfStr = value.split('.'); - //TODO use down method? + var arrayOfStr, autoFormat, radios, suffix, userFormat, userFormatObj; + + arrayOfStr = value.split('.'); + // TODO use down method? if (this.isFile) { - var radios = Ext.getCmp('filefrmt'); - var user_format_obj = radios.getValue(); - var user_format = user_format_obj.filefrmt; - } - else if (this.isTimeTable) { - var radios = Ext.getCmp('ttfrmt'); - var user_format_obj = radios.getValue(); - var user_format = user_format_obj.ttfrmt; - } - else { - var radios = Ext.getCmp('catfrmt'); - var user_format_obj = radios.getValue(); - var user_format = user_format_obj.catfrmt; + radios = Ext.getCmp('filefrmt'); + userFormatObj = radios.getValue(); + userFormat = userFormatObj.filefrmt; + } else if (this.isTimeTable) { + radios = Ext.getCmp('ttfrmt'); + userFormatObj = radios.getValue(); + userFormat = userFormatObj.ttfrmt; + } else { + radios = Ext.getCmp('catfrmt'); + userFormatObj = radios.getValue(); + userFormat = userFormatObj.catfrmt; } - var auto_format = user_format; + autoFormat = userFormat; - // auto define format in some special cases - //TODO name without extention => ASCII? - if (arrayOfStr.length == 1) auto_format = 'ASCII'; - else { - var suffix = arrayOfStr[arrayOfStr.length - 1].toLowerCase(); - if (suffix == 'gz') + // Auto define format in some special cases TODO: name without extention => ASCII? + if (arrayOfStr.length === 1) { + autoFormat = 'ASCII'; + } else { + suffix = arrayOfStr[arrayOfStr.length - 1].toLowerCase(); + if (suffix === 'gz') { suffix = arrayOfStr[arrayOfStr.length - 2].toLowerCase() + '.gz'; + } switch (suffix) { - case 'cdf' : - auto_format = 'CDF'; + case 'cdf': + autoFormat = 'CDF'; break; - case 'cef.gz' : - case 'cef' : - auto_format = 'CEF'; + case 'cef.gz': + case 'cef': + autoFormat = 'CEF'; break; - case 'xml' : - auto_format = 'VOT'; - case 'vot' : - auto_format = 'VOT'; + case 'xml': + autoFormat = 'VOT'; break; - case 'nc' : - auto_format = 'NC'; + case 'vot': + autoFormat = 'VOT'; break; - case 'asc' : - case 'txt' : - default : - auto_format = 'ASCII'; + case 'nc': + autoFormat = 'NC'; + break; + case 'asc': + case 'txt': + default: + autoFormat = 'ASCII'; } } - // set auto format : case when format was not set by user before - if (this.isFile && user_format !== auto_format) { - user_format_obj.filefrmt = auto_format; - } else if (this.isTimeTable && user_format !== auto_format) { - user_format_obj.ttfrmt = auto_format; - } else if (!this.isFile && !this.isTimeTable && user_format !== auto_format) { - user_format_obj.catfrmt = auto_format; + // Set auto format : case when format was not set by user before + if (this.isFile && userFormat !== autoFormat) { + userFormatObj.filefrmt = autoFormat; + } else if (this.isTimeTable && userFormat !== autoFormat) { + userFormatObj.ttfrmt = autoFormat; + } else if (!this.isFile && !this.isTimeTable && userFormat !== autoFormat) { + userFormatObj.catfrmt = autoFormat; } - radios.setValue(user_format_obj); + radios.setValue(userFormatObj); }, /* - * - */ + * Force upload + */ forceUpload: function (url, format, onFinish) { - var me = this; - var re = /http:\/\/127.0.0.1:/; - var isRemoteUrl = !re.test(url); + var isRemoteUrl, me, onFinishAll, onLoad, re; + me = this; + re = /http:\/\/127.0.0.1:/; + isRemoteUrl = !re.test(url); switch (format) { - case 'votable' : + case 'votable': this.getForm().findField('filefrmt').setValue('VOT'); break; - case 'cdf' : + case 'cdf': this.getForm().findField('filefrmt').setValue('CDF'); break; - default : + default: myDesktopApp.errorMsg('Not supported data receive from SAMP'); return; } @@ -187,25 +202,28 @@ Ext.define('amdaUI.UploadPanelUI', { if (!isRemoteUrl) { myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) { var onError = function (error) { - if (error) + if (error) { myDesktopApp.errorMsg(error); - else - myDesktopApp.errorMsg("Cannot load data from this SAMP notification"); - if (onFinish) + } else { + myDesktopApp.errorMsg('Cannot load data from this SAMP notification'); + } + if (onFinish) { onFinish(); + } }; - var onLoad = function (data) { - //Fake value for validation + onLoad = function (data) { + // Fake value for validation Ext.form.field.File.superclass.setValue.call(me.getForm().findField('localFileName'), 'samp.vot'); me.getForm().findField('filesrc').setValue('LOCAL'); - //Add data related to the samp notification + // Add data related to the samp notification me.getForm().findField('sampFileName').setValue('samp.vot'); me.getForm().findField('sampData').setValue(data); - var onFinishAll = function () { + onFinishAll = function () { me.getForm().findField('sampFileName').reset(); me.getForm().findField('sampData').reset(); - if (onFinish) + if (onFinish) { onFinish(); + } }; me.postUpload(onFinishAll); }; @@ -220,29 +238,35 @@ Ext.define('amdaUI.UploadPanelUI', { }, /* - * - */ + * Post upload + */ postUpload: function (onFinish) { // 'global' form containing 'partial' forms var form = this.getForm(); - // special validation + // Special validation if (this.validate()) { loadMask.show(); form.submit({ scope: this, url: 'php/uploadFile.php', waitMsg: 'Uploading your file...', - success: function (form, o) { - if (onFinish) + success: function (onSuccessForm, o) { + if (onFinish) { onFinish(); - this.tmpNode = Ext.create(this.nodeType, {leaf: true, text: o.result.file}); - AmdaAction.getUploadedObject(o.result.file, o.result.format, this.tmpNode.get('nodeType'), this.getObjectCallback, this); + } + this.tmpNode = Ext.create(this.nodeType, { + leaf: true, + text: o.result.file + }); + AmdaAction.getUploadedObject(o.result.file, o.result.format, + this.tmpNode.get('nodeType'), this.getObjectCallback, this); loadMask.hide(); }, - failure: function (form, o) { - if (onFinish) + failure: function (onFailureForm, o) { + if (onFinish) { onFinish(); + } loadMask.hide(); myDesktopApp.errorMsg('Error ' + o.result.error); } @@ -251,98 +275,135 @@ Ext.define('amdaUI.UploadPanelUI', { }, /* - * panel config - */ + * Panel config + */ init: function (config) { - this.isFile = config.panelType == 'file' ? true : false; - this.isTimeTable = config.panelType == 'timetable' ? true : false; + var combo, dayStart, fieldcontainer, fileFormat, form, items, local, localFile, localUploadName, myConf, + nonStandardFormat, radioId, remote, remoteFile, remoteUploadName, sampling, site, store, timeFormat, timeFormatId, + title, uploadForm; + this.isFile = config.panelType === 'file'; + this.isTimeTable = config.panelType === 'timetable'; - // file / time table / catalog settings + // File / time table / catalog settings if (this.isFile) { - var title = 'File'; - var items = [ + title = 'File'; + items = [ { - boxLabel: 'ASCII', name: 'filefrmt', inputValue: 'ASCII', checked: true, - listeners: - { - change: function (cb, nv, ov) { - if (nv) Ext.getCmp('tf').show(); - else Ext.getCmp('tf').hide(); + boxLabel: 'ASCII', + name: 'filefrmt', + inputValue: 'ASCII', + checked: true, + listeners: { + change: function (cb, nv) { + if (nv) { + Ext.getCmp('tf').show(); + } else { + Ext.getCmp('tf').hide(); } } + } }, { - boxLabel: 'netCDF  0) { - this.nextSibling().show(); - } - if (this.getValue().indexOf('d') > 0) { - this.nextSibling().hide(); - } - } + sampling = { + xtype: 'radiogroup', + fieldLabel: 'Time Sampling', + labelWidth: 90, + cls: 'x-check-group-alt', + hidden: !this.isFile, + defaults: {name: 'timesmpl'}, + items: [ + { + boxLabel: 'constant', + inputValue: 'constant', + checked: true + }, + { + boxLabel: 'variable  0) { + this.nextSibling().show(); + } + if (this.getValue().indexOf('d') > 0) { + this.nextSibling().hide(); } - }, - dayStart, - { - fieldLabel: 'define max time length', - name: 'timelength', - value: 'auto' - }], - listeners: - { - hide: function () { - this.items.getAt(1).hide(); } } - }; + }, + dayStart, + { + fieldLabel: 'define max time length', + name: 'timelength', + value: 'auto' + } + ], + listeners: { + hide: function () { + this.items.getAt(1).hide(); + } + } + }; - var timeFormat = Ext.create('Ext.form.FieldSet', { + timeFormat = Ext.create('Ext.form.FieldSet', { id: timeFormatId, title: 'Time Settings', hidden: !this.isFile, @@ -471,30 +542,34 @@ Ext.define('amdaUI.UploadPanelUI', { defaults: {name: 'timefrmt'}, items: [ { - boxLabel: 'standard