/** * 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 $ */ Ext.define('amdaUI.UploadPanelUI', { extend: 'Ext.form.Panel', alias: 'widget.panelUpload', requires : [ 'amdaUI.RemoteSearchPlugin' ], tmpNode : null, specialItems : null, formats : null, localName : 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 ! if (result.error) { myDesktopApp.errorMsg(result.error); } else { myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"+this.tmpNode.get('text')+"' found!"); } } loadMask.hide(); }, /* * form validation */ validate : function() { var values = this.getForm().getValues(); if (values['filesrc'] == 'LOCAL') { var locFile = this.getForm().findField(this.localName).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; }, /* * Upadte format if user didn't do this himself */ updateFormat: function(value) { var arrayOfStr = value.split('.'); var radios = Ext.getCmp(this.radioId); var user_format_obj = radios.getValue(); var user_format = user_format_obj[this.radioId]; // 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 (user_format !== auto_format) { user_format_obj[this.radioId] = 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); } }); } }, initFileUpload : function() { this.formats = [ { 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(); Ext.getCmp('nfs').hide(); } } } }, { boxLabel: 'netCDF  0) { this.nextSibling().show(); } if (this.getValue().indexOf('d') > 0) { this.nextSibling().hide(); } } } },{ xtype: 'checkbox', name : 'doy', fieldLabel: 'DOY starts from 1', hidden : true, inputValue: '1' },{ fieldLabel : 'define max time length', name : 'timelength', value: 'auto' }], listeners : { hide : function() { this.items.getAt(1).hide(); }, show : function() { if (this.items.getAt(0).getValue().indexOf('z') > 0) this.items.getAt(1).show(); } } }; /* * TimeFormat Fieldset : Global form */ var timeFormat = Ext.create('Ext.form.FieldSet', { title: 'Time Settings', items : [{ id: 'tf', xtype: 'radiogroup', fieldLabel: 'Time Format', labelWidth: 90, cls: 'x-check-group-alt', defaults : { name : 'timefrmt'}, items: [ { boxLabel: 'standard