diff --git a/js/app/views/UploadPanelUI.js b/js/app/views/UploadPanelUI.js index 11833c4..e84427c 100644 --- a/js/app/views/UploadPanelUI.js +++ b/js/app/views/UploadPanelUI.js @@ -2,634 +2,636 @@ * Project  : AMDA-NG * Name : UploadUI.js * @class amdaUI.UploadUI - * @extends Ext.form.Panel + * @extends Ext.form.Panel * @brief Upload Panel UI definition (View) - * @author Elena - * @version $Id: UploadPanelUI.js 2831 2015-03-26 10:33:42Z elena $ + * @author Elena + * @version $Id: UploadPanelUI.js 2831 2015-03-26 10:33:42Z elena $ */ Ext.define('amdaUI.UploadPanelUI', { - extend: 'Ext.form.Panel', - alias: 'widget.panelUpload', - - requires : [ - 'amdaUI.RemoteSearchPlugin' - ], - - isFile : true, - isTimeTable : false, - tmpNode : null, - - constructor: function(config) - { - this.init(config); - this.callParent(arguments); - }, - - /* - * create MyData linked node and edit in module MyData - * update myDataParams info if needed - */ - getObjectCallback : function(result,remoteEvent) - { - var t = remoteEvent.getTransaction(); - if (result && !result.error) - { - // set parameter into node - var 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')}); - - linkedFile.create(result.mask, result.description, result.maskDesc); - linkedFile.updateMyDataParam(result.mask,result.maskDesc); - - if (!linkedFile.get('id')) - linkedFile.set('id',me.tmpNode.get('text')); - - var paramObj = Ext.create(linkedFile.get('objectDataModel'), result); - linkedFile.set('object',paramObj); - me.tmpNode.set('fileObject',paramObj); - } - else - { - // Time Table or Catalog - var paramObj = Ext.create(me.tmpNode.get('objectDataModel'), result); - - paramObj.set('fromPlugin',true); - if (result.intervals) - { - paramObj.set('intervals',result.intervals); - paramObj.set('nbIntervals',result.intervals.length); - } - me.tmpNode.set('object',paramObj); - } - if (module) - { - module.setLinkedNode(me.tmpNode); - module.linkedNode.editInModule(); - } - }); - } - else - { - // EXCEPTION : parameter not found ! - myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"+this.tmpNode.get('text')+"' found!"); - } - loadMask.hide(); - }, - -/* -* 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(); - - if (!locFile) - { - 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 - updateFormat: function(value) - { - var 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; - } - - var auto_format = user_format; - - // 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') - suffix = arrayOfStr[arrayOfStr.length - 2].toLowerCase() + '.gz'; - - switch (suffix) - { - case 'cdf' : auto_format = 'CDF'; break; - case 'cef.gz' : - case 'cef' : auto_format = 'CEF'; break; - case 'xml' : auto_format = 'VOT'; - case 'vot' : auto_format = 'VOT'; break; - case 'nc' : auto_format = 'NC'; break; - case 'asc' : - case 'txt' : - default : auto_format = '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; - } - - radios.setValue(user_format_obj); - }, - - /* - * - */ - forceUpload : function (url,format,onFinish) - { - var me = this; - var re = /http:\/\/127.0.0.1:/; - var isRemoteUrl = !re.test(url); - - switch (format) - { - case 'votable' : - this.getForm().findField('filefrmt').setValue('VOT'); - break; - case 'cdf' : - this.getForm().findField('filefrmt').setValue('CDF'); - break; - default : - myDesktopApp.errorMsg('Not supported data receive from SAMP'); - return; - } - - if (!isRemoteUrl) { - myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) { - var onError = function(error) { - if (error) - myDesktopApp.errorMsg(error); - else - myDesktopApp.errorMsg("Cannot load data from this SAMP notification"); - if (onFinish) - onFinish(); - }; - var 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 - me.getForm().findField('sampFileName').setValue('samp.vot'); - me.getForm().findField('sampData').setValue(data); - var onFinishAll = function() { - me.getForm().findField('sampFileName').reset(); - me.getForm().findField('sampData').reset(); - if (onFinish) - onFinish(); - } - me.postUpload(onFinishAll); - }; - module.loadFile(url,onLoad,onError); - }); - return; - } - - this.getForm().findField('filesrc').setValue('URL'); - this.getForm().findField('remoteFile').setValue(url); - this.postUpload(onFinish); - }, - - /* - * - */ - postUpload : function(onFinish) - { - // 'global' form containing 'partial' forms - var form = this.getForm(); - - // 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) - 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); - loadMask.hide(); - }, - failure: function(form, o) - { - if (onFinish) - onFinish(); - loadMask.hide(); - myDesktopApp.errorMsg('Error '+o.result.error); - } - }); - } - }, - - /* - * panel config - */ - init : function(config) - { - this.isFile = config.panelType == 'file'? true : false; - this.isTimeTable = config.panelType == 'timetable'? true : false; - - // file / time table / catalog settings - if (this.isFile) - { - var title = 'File'; - var 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: 'netCDF  ASCII? + if (arrayOfStr.length == 1) auto_format = 'ASCII'; + else { + var suffix = arrayOfStr[arrayOfStr.length - 1].toLowerCase(); + if (suffix == 'gz') + suffix = arrayOfStr[arrayOfStr.length - 2].toLowerCase() + '.gz'; + + switch (suffix) { + case 'cdf' : + auto_format = 'CDF'; + break; + case 'cef.gz' : + case 'cef' : + auto_format = 'CEF'; + break; + case 'xml' : + auto_format = 'VOT'; + case 'vot' : + auto_format = 'VOT'; + break; + case 'nc' : + auto_format = 'NC'; + break; + case 'asc' : + case 'txt' : + default : + auto_format = '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; + } + + radios.setValue(user_format_obj); + }, + + /* + * + */ + forceUpload: function (url, format, onFinish) { + var me = this; + var re = /http:\/\/127.0.0.1:/; + var isRemoteUrl = !re.test(url); + + switch (format) { + case 'votable' : + this.getForm().findField('filefrmt').setValue('VOT'); + break; + case 'cdf' : + this.getForm().findField('filefrmt').setValue('CDF'); + break; + default : + myDesktopApp.errorMsg('Not supported data receive from SAMP'); + return; + } + + if (!isRemoteUrl) { + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) { + var onError = function (error) { + if (error) + myDesktopApp.errorMsg(error); + else + myDesktopApp.errorMsg("Cannot load data from this SAMP notification"); + if (onFinish) + onFinish(); + }; + var 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 + me.getForm().findField('sampFileName').setValue('samp.vot'); + me.getForm().findField('sampData').setValue(data); + var onFinishAll = function () { + me.getForm().findField('sampFileName').reset(); + me.getForm().findField('sampData').reset(); + if (onFinish) + onFinish(); + }; + me.postUpload(onFinishAll); + }; + module.loadFile(url, onLoad, onError); + }); + return; + } + + this.getForm().findField('filesrc').setValue('URL'); + this.getForm().findField('remoteFile').setValue(url); + this.postUpload(onFinish); + }, + + /* + * + */ + postUpload: function (onFinish) { + // 'global' form containing 'partial' forms + var form = this.getForm(); + + // 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) + 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); + loadMask.hide(); + }, + failure: function (form, o) { + if (onFinish) + onFinish(); + loadMask.hide(); + myDesktopApp.errorMsg('Error ' + o.result.error); + } + }); + } + }, + + /* + * panel config + */ + init: function (config) { + this.isFile = config.panelType == 'file' ? true : false; + this.isTimeTable = config.panelType == 'timetable' ? true : false; + + // file / time table / catalog settings + if (this.isFile) { + var title = 'File'; + var 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: 'netCDF  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(); - } - } - }; - - var timeFormat = Ext.create('Ext.form.FieldSet', { - id: timeFormatId, - title: 'Time Settings', - hidden : !this.isFile, - items : [ - { - xtype: 'radiogroup', - fieldLabel: 'Time Format', - labelWidth: 90, - cls: 'x-check-group-alt', - defaults : { name : 'timefrmt'}, - items: [ - { boxLabel: 'standard  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(); + } + } + }; + + var timeFormat = Ext.create('Ext.form.FieldSet', { + id: timeFormatId, + title: 'Time Settings', + hidden: !this.isFile, + items: [ + { + xtype: 'radiogroup', + fieldLabel: 'Time Format', + labelWidth: 90, + cls: 'x-check-group-alt', + defaults: {name: 'timefrmt'}, + items: [ + { + boxLabel: 'standard