|
@@ -8,6 +8,8 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
defaultBindProperty: 'value',
|
|
|
|
|
|
isFormField:true,
|
|
|
+ submitValue: true,
|
|
|
+
|
|
|
|
|
|
columnWidth: 1,
|
|
|
cls: 'multi-file-field',
|
|
@@ -21,14 +23,9 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
initComponent: function() {
|
|
|
var me = this;
|
|
|
this.title = this.fieldLabel;
|
|
|
-
|
|
|
- if(this.value || this.defalutValue) {
|
|
|
- me.getFilesInfo(this.value || this.defalutValue).then(function(res) {
|
|
|
- var filesInfo = res.data;
|
|
|
- me.addFiles(filesInfo);
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
+ this.files.length = 0;
|
|
|
+
|
|
|
Ext.apply(me, {
|
|
|
items: [{
|
|
|
xtype: 'hidden',
|
|
@@ -81,18 +78,33 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
});
|
|
|
|
|
|
this.callParent(arguments);
|
|
|
+
|
|
|
+ if(this.value || this.defalutValue) {
|
|
|
+ me.initSetValue(this.value || this.defalutValue);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- setValue: function(v){
|
|
|
+ initSetValue: function(v) {
|
|
|
+ this.setValue(v, true);
|
|
|
+ },
|
|
|
+
|
|
|
+ setValue: function(v, init){
|
|
|
var me = this,
|
|
|
- items = me.items.items,
|
|
|
- files = me.files,
|
|
|
- newValue = '',
|
|
|
- filesInfo;
|
|
|
+ oldValue = me.getValue(),
|
|
|
+ filesInfo,
|
|
|
+ newValue;
|
|
|
|
|
|
+ me.clearAll();
|
|
|
me.getFilesInfo(v).then(function(res) {
|
|
|
- var filesInfo = res.data;
|
|
|
- me.addFiles(filesInfo);
|
|
|
+ filesInfo = res.data;
|
|
|
+ newValue = me.addFiles(filesInfo);
|
|
|
+
|
|
|
+ me.items.items[0].setValue(newValue);
|
|
|
+
|
|
|
+ if(!init) {
|
|
|
+ me.publishState('value', newValue);
|
|
|
+ me.fireEvent('change', this, newValue, oldValue);
|
|
|
+ }
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -134,7 +146,6 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
var me = this,
|
|
|
items = me.items.items,
|
|
|
value = me.getValue(),
|
|
|
- id,
|
|
|
oldValue = value,
|
|
|
newValue = value;
|
|
|
|
|
@@ -146,9 +157,8 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- items[0].setValue(newValue);
|
|
|
- this.publishState('value', newValue);
|
|
|
- this.fireEvent('change', this, newValue, oldValue);
|
|
|
+ return newValue;
|
|
|
+
|
|
|
},
|
|
|
|
|
|
addFile: function(fileInfo) {
|
|
@@ -174,7 +184,7 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
fileForm = me.getFileForm(),
|
|
|
id = fileInfo.id,
|
|
|
name = fileInfo.name,
|
|
|
- path = fileInfo.fullName,
|
|
|
+ path = fileInfo.path,
|
|
|
size = fileInfo.size,
|
|
|
fileText, fieldWidth, newFileTag;
|
|
|
|
|
@@ -190,9 +200,9 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
columnWidth: fieldWidth,
|
|
|
readOnly: false,
|
|
|
editable: false,
|
|
|
- filepath: path,
|
|
|
- filesize: size,
|
|
|
- _id: id,
|
|
|
+ filePath: path,
|
|
|
+ fileSize: size,
|
|
|
+ fileId: id,
|
|
|
fieldStyle: 'background:#E0EEEE;'
|
|
|
});
|
|
|
fileForm.add(newFileTag);
|
|
@@ -224,16 +234,15 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
me.setLoading(false);
|
|
|
var res = Ext.decode(response.responseText);
|
|
|
if(res.success){
|
|
|
- console.log('success');
|
|
|
var data = res.data;
|
|
|
me.addFile(data);
|
|
|
}else{
|
|
|
- console.error('failure');
|
|
|
+ console.error('failure', res);
|
|
|
}
|
|
|
},
|
|
|
failure: function (response, opts) {
|
|
|
me.setLoading(false);
|
|
|
- console.error('failure');
|
|
|
+ console.error('failure', response);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
@@ -254,10 +263,6 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
var res = Ext.decode(response.responseText);
|
|
|
if(res.success){
|
|
|
resolve(res);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}else{
|
|
|
reject(res);
|
|
|
}
|
|
@@ -280,9 +285,44 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
},
|
|
|
|
|
|
clearAll: function() {
|
|
|
+ var oldValue = this.getValue();
|
|
|
this.getFileForm().removeAll();
|
|
|
- this.setValue('');
|
|
|
+ this.items.items[0].value = '';
|
|
|
this.files.length = 0;
|
|
|
+
|
|
|
+ this.publishState('value', '');
|
|
|
+ this.fireEvent('change', this, '', oldValue);
|
|
|
+ },
|
|
|
+
|
|
|
+ remove: function(fileInfo) {
|
|
|
+ var value = this.getValue(),
|
|
|
+ fileTags,
|
|
|
+ foundFileTag,
|
|
|
+ idx,
|
|
|
+ newValue;
|
|
|
+ if(typeof fileInfo === 'string') {
|
|
|
+ fileInfo = { id: fileInfo };
|
|
|
+ }
|
|
|
+
|
|
|
+ fileTags = this.getFileForm().items.items;
|
|
|
+ foundFileTag = fileTags.find(function(ft) {
|
|
|
+ return ft.fileId === fileInfo.id;
|
|
|
+ });
|
|
|
+ idx = this.files.findIndex(function(f) {
|
|
|
+ return f.id === fileInfo.id;
|
|
|
+ });
|
|
|
+
|
|
|
+ if(foundFileTag && idx > -1) {
|
|
|
+
|
|
|
+ newValue = value.replace(fileInfo.id + ';', '');
|
|
|
+
|
|
|
+ this.getFileForm().remove(foundFileTag);
|
|
|
+ this.items.items[0].setValue(newValue);
|
|
|
+ this.files.splice(idx, 1);
|
|
|
+
|
|
|
+ this.publishState('value', newValue);
|
|
|
+ this.fireEvent('change', this, newValue, value);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
getStrLength: function(str) {
|
|
@@ -291,6 +331,37 @@ Ext.define('Ext.ux.form.field.MFileField', {
|
|
|
return c;
|
|
|
},
|
|
|
|
|
|
+ getModelData: function(includeEmptyText, isSubmitting) {
|
|
|
+ var me = this,
|
|
|
+ data = null;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!me.disabled && (me.submitValue || !isSubmitting)) {
|
|
|
+ data = {};
|
|
|
+ data[me.getFieldIdentifier()] = me.getValue();
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+
|
|
|
+ getSubmitData: function() {
|
|
|
+ var me = this,
|
|
|
+ data = null;
|
|
|
+ if (!me.disabled && me.submitValue) {
|
|
|
+ data = {};
|
|
|
+ data[me.getName()] = '' + me.getValue();
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+
|
|
|
+ getFieldIdentifier: function () {
|
|
|
+ return this.isEditorComponent ? this.dataIndex : this.name;
|
|
|
+ },
|
|
|
+
|
|
|
+ getName: function() {
|
|
|
+ return this.name;
|
|
|
+ },
|
|
|
+
|
|
|
|
|
|
|
|
|
|