From 6b294db3fcbc4fd491cddfc40eb371263eb33a17 Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 18 Apr 2017 09:34:22 -0600 Subject: [PATCH] File upload bugfixes: - Javascript error uploading files with ' in their name - uploading the same file twice to a customfield did not show the file uploaded properly --- api/js/etemplate/et2_widget_file.js | 12 ++++++------ api/js/etemplate/et2_widget_link.js | 2 +- api/js/etemplate/et2_widget_vfs.js | 20 ++++++++++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/api/js/etemplate/et2_widget_file.js b/api/js/etemplate/et2_widget_file.js index 210d731ef0..c7f480d441 100644 --- a/api/js/etemplate/et2_widget_file.js +++ b/api/js/etemplate/et2_widget_file.js @@ -551,7 +551,7 @@ var et2_file = (function(){ "use strict"; return et2_inputWidget.extend( if(this.progress) { var fileName = file.fileName || 'file'; - var status = jQuery("
  • "+fileName + var status = jQuery("
  • "+fileName +"

  • ") .appendTo(this.progress); jQuery("div.remove",status).on('click', file, jQuery.proxy(this.cancel,this)); @@ -568,7 +568,7 @@ var et2_file = (function(){ "use strict"; return et2_inputWidget.extend( _fileProgress: function(file) { if(this.progress) { - jQuery("li[data-file='"+file.fileName+"'] > span.progressBar > p").css("width", Math.ceil(file.progress()*100)+"%"); + jQuery("li[data-file='"+file.fileName.replace(/'/g, '"')+"'] > span.progressBar > p").css("width", Math.ceil(file.progress()*100)+"%"); } return true; @@ -594,7 +594,7 @@ var et2_file = (function(){ "use strict"; return et2_inputWidget.extend( if(typeof response.response[0].data[key] == "string") { // Message from server - probably error - jQuery("[data-file='"+name+"']",this.progress) + jQuery("[data-file='"+name.replace(/'/g, '"')+"']",this.progress) .addClass("error") .css("display", "block") .text(response.response[0].data[key]); @@ -609,14 +609,14 @@ var et2_file = (function(){ "use strict"; return et2_inputWidget.extend( } if(this.progress) { - jQuery("[data-file='"+name+"']",this.progress).addClass("message success"); + jQuery("[data-file='"+name.replace(/'/g, '"')+"']",this.progress).addClass("message success"); } } } } else if (this.progress) { - jQuery("[data-file='"+name+"']",this.progress) + jQuery("[data-file='"+name.replace(/'/g, '"')+"']",this.progress) .addClass("ui-state-error") .css("display", "block") .text(this.egw().lang("Server error")); @@ -650,7 +650,7 @@ var et2_file = (function(){ "use strict"; return et2_inputWidget.extend( if(this.options.value[key].name == file.fileName) { delete this.options.value[key]; - jQuery('[data-file="'+file.fileName+'"]',this.node).remove(); + jQuery('[data-file="'+file.fileName.replace(/'/g, '"')+'"]',this.node).remove(); return; } } diff --git a/api/js/etemplate/et2_widget_link.js b/api/js/etemplate/et2_widget_link.js index e34ba155a0..5f0f78d2ec 100644 --- a/api/js/etemplate/et2_widget_link.js +++ b/api/js/etemplate/et2_widget_link.js @@ -293,7 +293,7 @@ var et2_link_to = (function(){ "use strict"; return et2_inputWidget.extend( id: file, name: self.file_upload.options.value[file].name, type: self.file_upload.options.value[file].type, - remark: jQuery("li[file='"+self.file_upload.options.value[file].name+"'] > input", self.file_upload.progress) + remark: jQuery("li[file='"+self.file_upload.options.value[file].name.replace(/'/g, '"')+"'] > input", self.file_upload.progress) .filter(function() { return jQuery(this).attr("placeholder") != jQuery(this).val();}).val() }); } diff --git a/api/js/etemplate/et2_widget_vfs.js b/api/js/etemplate/et2_widget_vfs.js index 56efa833d8..73e87a2d0a 100644 --- a/api/js/etemplate/et2_widget_vfs.js +++ b/api/js/etemplate/et2_widget_vfs.js @@ -722,7 +722,7 @@ var et2_vfsUpload = (function(){ "use strict"; return et2_file.extend( if(sender !== this && sender._type.indexOf('vfs') >= 0 ) { var value = sender.getValue && sender.getValue() || sender.options.value || {}; - var row = jQuery('[data-path="'+(value.path)+'"]',this.list); + var row = jQuery("[data-path='"+(value.path.replace(/'/g, '"'))+"']",this.list); if(sender._type === 'vfs-mime') { return jQuery('.icon',row).get(0) || null; @@ -765,7 +765,7 @@ var et2_vfsUpload = (function(){ "use strict"; return et2_file.extend( if(value && value.path) { this._addFile(value); - jQuery("[data-file='"+file.fileName+"']",this.progress).hide(); + jQuery("[data-file='"+file.fileName.replace(/'/g, '"')+"']",this.progress).hide(); } } } @@ -773,8 +773,20 @@ var et2_vfsUpload = (function(){ "use strict"; return et2_file.extend( }, _addFile: function(file_data) { + if(jQuery("[data-path='"+file_data.path.replace(/'/g, '"')+"']").remove().length) + { + for(var child_index = this._children.length-1; child_index >= 0; child_index--) + { + var child = this._children[child_index]; + if(child.options.value.path === file_data.path) + { + this.removeChild(child); + child.free(); + } + } + } var row = jQuery(document.createElement("tr")) - .attr("data-path", file_data.path) + .attr("data-path", file_data.path.replace(/'/g, '"')) .attr("draggable", "true") .appendTo(this.list); var mime = jQuery(document.createElement("td")) @@ -813,7 +825,7 @@ var et2_vfsUpload = (function(){ "use strict"; return et2_file.extend( { egw.json("filemanager_ui::ajax_action", [ 'delete', - [row.attr('data-path')], + [row.attr('data-path').replace(/"/g, "'")], '' ], function(data) {