From 312fcf2e0b3206d46b20c8621925590bec6536ec Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 9 Sep 2011 00:05:18 +0000 Subject: [PATCH] - Change remove file handler to only remove if you click the x, not the whole entry - Add hooks for js functions when upload starts and finishes --- etemplate/js/et2_widget_file.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/etemplate/js/et2_widget_file.js b/etemplate/js/et2_widget_file.js index 8daf7b5e99..1783e2b1b9 100644 --- a/etemplate/js/et2_widget_file.js +++ b/etemplate/js/et2_widget_file.js @@ -46,6 +46,18 @@ var et2_file = et2_inputWidget.extend({ "type": "string", "default": et2_no_init, "description": "The ID of an alternate node (div) to display progress and results." + }, + "onStart": { + "name": "Start event handler", + "type": "any", + "default": et2_no_init, + "description": "A (js) function called when an upload starts. Return true to continue with upload, false to cancel." + }, + "onFinish": { + "name": "Finish event handler", + "type": "any", + "default": et2_no_init, + "description": "A (js) function called when all files to be uploaded are finished." } }, @@ -142,6 +154,9 @@ var et2_file = et2_inputWidget.extend({ */ onStart: function(event, file_count) { this.disabled_buttons = $j("input[type='submit'], button").not("[disabled]").attr("disabled", true); + + event.data = this; + if(this.options.onStart && typeof this.options.onStart == 'function') return this.options.onStart(event,file_count); return true; }, @@ -150,6 +165,8 @@ var et2_file = et2_inputWidget.extend({ */ onFinish: function(event, file_count) { this.disabled_buttons.attr("disabled", false); + event.data = this; + if(this.options.onFinish && typeof this.options.onFinish == 'function') return this.options.onFinish(event,file_count); }, @@ -169,8 +186,8 @@ var et2_file = et2_inputWidget.extend({ { var status = $j("
  • "+file_name +"

  • ") - .appendTo(this.progress) - .click(this, this.cancel); + .appendTo(this.progress); + $j("div.remove",status).click(this, this.cancel); if(error != "") { status.addClass("message validation_error"); @@ -222,16 +239,18 @@ console.warn(event,name,error); cancel: function(e) { e.preventDefault(); // Look for file name in list - var target = $j(e.target); + var target = $j(e.target).parents("li.message"); +console.info(target); for(var key in e.data.options.value) { if(e.data.options.value[key].name == target.attr("file")) { delete e.data.options.value[key]; - $j(e.target).remove(); + target.remove(); return; } } // In case it didn't make it to the list (error) + target.remove(); $j(e.target).remove(); } });