diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-06 22:35:05 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-06 22:35:05 +0000 |
commit | e96e26a12f578d46183b60c3b2cfd69ffe52ed16 (patch) | |
tree | de06bf9dadffd36b1e2d18ea36250b03ec64fece /lib/gallery.dialog.js | |
parent | 8a6eb931ded561c4b4f96838bf4576b89a2e0dc8 (diff) |
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.
Diffstat (limited to 'lib/gallery.dialog.js')
-rw-r--r-- | lib/gallery.dialog.js | 84 |
1 files changed, 48 insertions, 36 deletions
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 = '<div id="gDialog"></div>'; // @todo Fix i18n for Cancel link - var eCancel = '<a href="javascript: closeDialog()" class="gCancel">Cancel</a>'; 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 = '<a href="javascript: closeDialog()" class="gCancel">Cancel</a>'; + 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 |