/** * Project  : AMDA-NG * Name : UploadUI.js * @class amdaUI.UploadUI * @extends Ext.panel.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' ], isFile : true, 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 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') { var locFile = this.isFile ? this.getForm().findField('localFileName').getValue() : this.getForm().findField('localTTName').getValue(); if (!locFile) { myDesktopApp.warningMsg("Select File to Upload"); return false; } } else { if (!values['remoteFile'] && !values['remoteTT']) { 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 { var radios = Ext.getCmp('ttfrmt'); var user_format_obj = radios.getValue(); var user_format = user_format_obj.ttfrmt; } 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.isFile && user_format !== auto_format) { user_format_obj.ttfrmt = auto_format; } radios.setValue(user_format_obj); }, /* * */ forceUpload : function (url,format) { this.getForm().findField('filesrc').setValue('URL'); switch (format) { case 'votable' : this.getForm().findField('filefrmt').setValue('VOT'); break; case 'cdf' : this.getForm().findField('filefrmt').setValue('CDF'); break; default : //ToDo Error - unknown format return; } this.getForm().findField('remoteFile').setValue(url); this.postUpload(); }, /* * */ postUpload : function() { // 'global' form containing 'partial' forms var form = this.getForm(); // special validation if(this.validate()){ form.submit({ scope: this, url: 'php/uploadFile.php', waitMsg: 'Uploading your file...', success: function(form, o){ this.tmpNode = Ext.create(this.nodeType,{leaf : true, text : o.result.file}); loadMask.show(); AmdaAction.getUploadedObject(o.result.file, o.result.format, this.tmpNode.get('nodeType'), this.getObjectCallback, this); }, failure: function(form, o) { loadMask.hide(); myDesktopApp.errorMsg('Error '+o.result.error); } }); } }, /* * panel config */ init : function(config) { this.isFile = config.panelType == 'file'? true : false; // file/time table settings if (this.isFile) { var title = 'Upload 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', items : [{ xtype: 'radiogroup', fieldLabel: 'Time Format', labelWidth: 90, cls: 'x-check-group-alt', defaults : { name : 'timefrmt'}, items: [ {boxLabel: 'standard