From e96e26a12f578d46183b60c3b2cfd69ffe52ed16 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 6 Mar 2009 22:35:05 +0000 Subject: Fix for ticket #130 1) Shuffled code around to create a on_form_loaded function 2) Check for a data.reset string in the json return. If it exists and is a function then call. The idea being that if there is an error we might have to reset some jquery widget initialization. --- lib/gallery.dialog.js | 84 +++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 36 deletions(-) (limited to 'lib/gallery.dialog.js') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index a11d3c3a..de8db0d5 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -11,6 +11,32 @@ function handleDialogEvent(event) { event.preventDefault(); } +function ajaxify_dialog() { + $("#gDialog form").ajaxForm({ + dataType: "json", + success: function(data) { + if (data.form) { + $("#gDialog form").replaceWith(data.form); + ajaxify_dialog(); + on_form_loaded(); + if (typeof data.reset == 'function') { + eval(data.reset + '()'); + } + } + if (data.result == "success") { + $("#gDialog").dialog("close"); + if (on_success) { + on_success(); + } else if (data.location) { + window.location = data.location; + } else { + window.location.reload(); + } + } + } + }); +}; + /** * Display modal dialogs, populate dialog with trigger link's href * @requires ui.core @@ -25,7 +51,6 @@ function openDialog(element, on_success) { var sTitle = $(element).attr("title"); var eDialog = '
'; // @todo Fix i18n for Cancel link - var eCancel = 'Cancel'; var dialogWidth; $("body").append(eDialog); @@ -52,21 +77,12 @@ function openDialog(element, on_success) { $("#gDialog iframe").width("100%"); $("#gDialog iframe").height($(window).height() - 100); } else if (childWidth == "" || childWidth > 300) { - dialogWidth = 500; - } - $("#gDialog").dialog('option', 'width', dialogWidth); - if ($("#gDialog .submit").length) { - $("#gDialog .submit").addClass("ui-state-default ui-corner-all"); - $("#gDialog .submit").parent().append(eCancel); + dialogWidth = 500; } - $("#gDialog .ui-state-default").hover( - function(){ - $(this).addClass("ui-state-hover"); - }, - function(){ - $(this).removeClass("ui-state-hover"); - } - ); + $("#gDialog").dialog('option', 'width', dialogWidth); + + on_form_loaded(); + $("#gDialog").dialog("open"); // Remove titlebar for progress dialogs or set title if ($("#gDialog #gProgress").length) { @@ -77,35 +93,31 @@ function openDialog(element, on_success) { $("#gDialog").dialog('option', 'title', $("#gDialog fieldset legend:eq(0)").html()); } - ajaxify_dialog = function() { - $("#gDialog form").ajaxForm({ - dataType: "json", - success: function(data) { - if (data.form) { - $("#gDialog form").replaceWith(data.form); - ajaxify_dialog(); - } - if (data.result == "success") { - $("#gDialog").dialog("close"); - if (on_success) { - on_success(); - } else if (data.location) { - window.location = data.location; - } else { - window.location.reload(); - } - } - } - }); - }; ajaxify_dialog(); }); return false; } +function on_form_loaded() { + var eCancel = 'Cancel'; + if ($("#gDialog .submit").length) { + $("#gDialog .submit").addClass("ui-state-default ui-corner-all"); + $("#gDialog .submit").parent().append(eCancel); + } + $("#gDialog .ui-state-default").hover( + function(){ + $(this).addClass("ui-state-hover"); + }, + function(){ + $(this).removeClass("ui-state-hover"); + } + ); +} + function closeDialog() { $("#gDialog").dialog("destroy").remove(); } + /** * Toggle the processing indicator, both large and small * @param elementID Target ID, including #, to apply .gLoadingSize -- cgit v1.2.3