Etemplate: Fix VFS & file widgets were not properly handling files

This commit is contained in:
nathangray 2020-06-10 10:20:16 -06:00
parent 19f52cd1de
commit a993938134
5 changed files with 86 additions and 58 deletions

View File

@ -57,8 +57,8 @@ var et2_file = /** @class */ (function (_super) {
_this.span = null; _this.span = null;
// Contains all submit buttons need to be disabled during upload process // Contains all submit buttons need to be disabled during upload process
_this.disabled_buttons = jQuery("input[type='submit'], button"); _this.disabled_buttons = jQuery("input[type='submit'], button");
if (!_this.options.value) // Make sure it's an object, not an array, or values get lost when sent to server
_this.options.value = {}; _this.options.value = jQuery.extend({}, _this.options.value);
if (!_this.options.id) { if (!_this.options.id) {
console.warn("File widget needs an ID. Used 'file_widget'."); console.warn("File widget needs an ID. Used 'file_widget'.");
_this.options.id = "file_widget"; _this.options.id = "file_widget";
@ -75,26 +75,7 @@ var et2_file = /** @class */ (function (_super) {
// Set up the URL to have the request ID & the widget ID // Set up the URL to have the request ID & the widget ID
var instance = _this.getInstanceManager(); var instance = _this.getInstanceManager();
var self = _this; var self = _this;
_this.asyncOptions = jQuery.extend({ _this.asyncOptions = jQuery.extend({}, _this.getAsyncOptions(_this));
// Callbacks
onStart: function (event, file_count) {
return self.onStart(event, file_count);
},
onFinish: function (event, file_count) {
self.onFinish.apply(self, [event, file_count]);
},
onStartOne: function (event, file_name, index, file_count) {
},
onFinishOne: function (event, response, name, number, total) { return self.finishUpload(event, response, name, number, total); },
onProgress: function (event, progress, name, number, total) { return self.onProgress(event, progress, name, number, total); },
onError: function (event, name, error) { return self.onError(event, name, error); },
beforeSend: function (form) { return self.beforeSend(form); },
chunkSize: _this.options.chunk_size || 1024 * 1024,
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\File::ajax_upload"),
query: function (file) { return self.beforeSend(file); },
// Disable checking for already uploaded chunks
testChunks: false
}, _this.asyncOptions);
_this.asyncOptions.fieldName = _this.options.id; _this.asyncOptions.fieldName = _this.options.id;
_this.createInputWidget(); _this.createInputWidget();
_this.set_readonly(_this.options.readonly); _this.set_readonly(_this.options.readonly);
@ -166,6 +147,31 @@ var et2_file = /** @class */ (function (_super) {
} }
this.setDOMNode(this.node[0]); this.setDOMNode(this.node[0]);
}; };
/**
* Get any specific async upload options
*/
et2_file.prototype.getAsyncOptions = function (self) {
return {
// Callbacks
onStart: function (event, file_count) {
return self.onStart(event, file_count);
},
onFinish: function (event, file_count) {
self.onFinish.apply(self, [event, file_count]);
},
onStartOne: function (event, file_name, index, file_count) {
},
onFinishOne: function (event, response, name, number, total) { return self.finishUpload(event, response, name, number, total); },
onProgress: function (event, progress, name, number, total) { return self.onProgress(event, progress, name, number, total); },
onError: function (event, name, error) { return self.onError(event, name, error); },
beforeSend: function (form) { return self.beforeSend(form); },
chunkSize: this.options.chunk_size || 1024 * 1024,
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\File::ajax_upload"),
query: function (file) { return self.beforeSend(file); },
// Disable checking for already uploaded chunks
testChunks: false
};
};
/** /**
* Set a widget or DOM node as a HTML5 file drop target * Set a widget or DOM node as a HTML5 file drop target
* *

View File

@ -130,7 +130,9 @@ export class et2_file extends et2_inputWidget
this.span = null; this.span = null;
// Contains all submit buttons need to be disabled during upload process // Contains all submit buttons need to be disabled during upload process
this.disabled_buttons = jQuery("input[type='submit'], button"); this.disabled_buttons = jQuery("input[type='submit'], button");
if(!this.options.value) this.options.value = {};
// Make sure it's an object, not an array, or values get lost when sent to server
this.options.value = jQuery.extend({},this.options.value);
if(!this.options.id) { if(!this.options.id) {
console.warn("File widget needs an ID. Used 'file_widget'."); console.warn("File widget needs an ID. Used 'file_widget'.");
@ -155,28 +157,8 @@ export class et2_file extends et2_inputWidget
let self = this; let self = this;
this.asyncOptions = jQuery.extend({ this.asyncOptions = jQuery.extend({
// Callbacks
onStart: function(event, file_count) {
return self.onStart(event, file_count);
},
onFinish: function(event, file_count) {
self.onFinish.apply(self, [event, file_count])
},
onStartOne: function(event, file_name, index, file_count) {
}, },this.getAsyncOptions(this));
onFinishOne: function(event, response, name, number, total) { return self.finishUpload(event,response,name,number,total);},
onProgress: function(event, progress, name, number, total) { return self.onProgress(event,progress,name,number,total);},
onError: function(event, name, error) { return self.onError(event,name,error);},
beforeSend: function(form) { return self.beforeSend(form);},
chunkSize: this.options.chunk_size || 1024*1024,
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\File::ajax_upload"),
query: function(file) {return self.beforeSend(file);},
// Disable checking for already uploaded chunks
testChunks: false
},this.asyncOptions);
this.asyncOptions.fieldName = this.options.id; this.asyncOptions.fieldName = this.options.id;
this.createInputWidget(); this.createInputWidget();
this.set_readonly(this.options.readonly); this.set_readonly(this.options.readonly);
@ -257,6 +239,35 @@ export class et2_file extends et2_inputWidget
this.setDOMNode(this.node[0]); this.setDOMNode(this.node[0]);
} }
/**
* Get any specific async upload options
*/
getAsyncOptions(self: et2_file)
{
return {
// Callbacks
onStart: function(event, file_count) {
return self.onStart(event, file_count);
},
onFinish: function(event, file_count) {
self.onFinish.apply(self, [event, file_count])
},
onStartOne: function(event, file_name, index, file_count) {
},
onFinishOne: function(event, response, name, number, total) { return self.finishUpload(event,response,name,number,total);},
onProgress: function(event, progress, name, number, total) { return self.onProgress(event,progress,name,number,total);},
onError: function(event, name, error) { return self.onError(event,name,error);},
beforeSend: function(form) { return self.beforeSend(form);},
chunkSize: this.options.chunk_size || 1024*1024,
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\File::ajax_upload"),
query: function(file) {return self.beforeSend(file);},
// Disable checking for already uploaded chunks
testChunks: false
};
}
/** /**
* Set a widget or DOM node as a HTML5 file drop target * Set a widget or DOM node as a HTML5 file drop target
* *

View File

@ -828,9 +828,6 @@ var et2_vfsUpload = /** @class */ (function (_super) {
var _this = var _this =
// Call the inherited constructor // Call the inherited constructor
_super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_vfsUpload._attributes, _child || {})) || this; _super.call(this, _parent, _attrs, et2_core_inheritance_1.ClassWithAttributes.extendAttributes(et2_vfsUpload._attributes, _child || {})) || this;
_this.asyncOptions = {
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_upload")
};
_this.list = null; _this.list = null;
jQuery(_this.node).addClass("et2_vfs"); jQuery(_this.node).addClass("et2_vfs");
if (!_this.options.path) { if (!_this.options.path) {
@ -843,11 +840,19 @@ var et2_vfsUpload = /** @class */ (function (_super) {
_this.list = jQuery(document.createElement('table')).appendTo(_this.node); _this.list = jQuery(document.createElement('table')).appendTo(_this.node);
return _this; return _this;
} }
/**
* Get any specific async upload options
*/
et2_vfsUpload.prototype.getAsyncOptions = function (self) {
return jQuery.extend({}, _super.prototype.getAsyncOptions.call(this, self), {
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_upload")
});
};
/** /**
* If there is a file / files in the specified location, display them * If there is a file / files in the specified location, display them
* Value is the information for the file[s] in the specified location. * Value is the information for the file[s] in the specified location.
* *
* @param {Object[]} _value * @param {Object{}} _value
*/ */
et2_vfsUpload.prototype.set_value = function (_value) { et2_vfsUpload.prototype.set_value = function (_value) {
// Remove previous // Remove previous
@ -859,8 +864,8 @@ var et2_vfsUpload = /** @class */ (function (_super) {
this.progress.empty(); this.progress.empty();
this.list.empty(); this.list.empty();
// Set new // Set new
if (typeof _value == 'object' && _value && _value.length) { if (typeof _value == 'object' && _value && Object.keys(_value).length) {
for (var i = 0; i < _value.length; i++) { for (var i in _value) {
this._addFile(_value[i]); this._addFile(_value[i]);
} }
} }

View File

@ -934,10 +934,6 @@ class et2_vfsUpload extends et2_file
public static readonly legacyOptions : string[] = ["mime"]; public static readonly legacyOptions : string[] = ["mime"];
asyncOptions : {target : any} = {
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_upload")
};
list : JQuery = null; list : JQuery = null;
/** /**
@ -966,11 +962,21 @@ class et2_vfsUpload extends et2_file
this.list = jQuery(document.createElement('table')).appendTo(this.node); this.list = jQuery(document.createElement('table')).appendTo(this.node);
} }
/**
* Get any specific async upload options
*/
getAsyncOptions(self)
{
return jQuery.extend({},super.getAsyncOptions(self),{
target: egw.ajaxUrl("EGroupware\\Api\\Etemplate\\Widget\\Vfs::ajax_upload")
});
}
/** /**
* If there is a file / files in the specified location, display them * If there is a file / files in the specified location, display them
* Value is the information for the file[s] in the specified location. * Value is the information for the file[s] in the specified location.
* *
* @param {Object[]} _value * @param {Object{}} _value
*/ */
set_value(_value) { set_value(_value) {
// Remove previous // Remove previous
@ -984,9 +990,9 @@ class et2_vfsUpload extends et2_file
this.list.empty(); this.list.empty();
// Set new // Set new
if(typeof _value == 'object' && _value && _value.length) if(typeof _value == 'object' && _value && Object.keys(_value).length)
{ {
for(var i = 0; i < _value.length; i++) for(let i in _value)
{ {
this._addFile(_value[i]); this._addFile(_value[i]);
} }

View File

@ -346,7 +346,7 @@ class Vfs extends File
{ {
if(Api\Vfs::file_exists(self::get_vfs_path($id) . $relpath)) {} if(Api\Vfs::file_exists(self::get_vfs_path($id) . $relpath)) {}
}*/ }*/
parent::validate($cname, $content, $validated); parent::validate($cname, $expand, $content, $validated);
break; break;
} }
if (true) $valid = $value; if (true) $valid = $value;