diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 07:30:14 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-12-23 07:30:14 +0000 |
commit | 76b1500209e5c5becef180eae2abed78d18d09db (patch) | |
tree | 19c929f1a8183bb48db5e09dbbd8081c22644430 /themes/default/js/ui.init.js | |
parent | 69daaffb054f20574cb59078ce205920f4678da6 (diff) |
Clean up the way that we upload via dialogs:
1) If the create request is Ajax, then return a 201 Created response code
2) If we receive back a 201 response, then switch to the new page.
3) Display a status message when we do an upload.
Diffstat (limited to 'themes/default/js/ui.init.js')
-rw-r--r-- | themes/default/js/ui.init.js | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/themes/default/js/ui.init.js b/themes/default/js/ui.init.js index 394c18b0..f4a7c49c 100644 --- a/themes/default/js/ui.init.js +++ b/themes/default/js/ui.init.js @@ -10,7 +10,7 @@ $("document").ready(function() { // Add Superfish menu class $("ul.gMenu").addClass("sf-menu"); $("ul#gViewMenu").addClass("sf-menu"); - + // Superfish menu options $('ul.sf-menu').superfish({ delay: 500, @@ -41,24 +41,24 @@ $("document").ready(function() { for (var i=0; i < dialogLinks.length; i++) { $(dialogLinks[i]).bind("click", {element: dialogLinks[i]}, handleDialogEvent); }; - + // Declare which forms are short forms $("#gHeader #gSearchForm").addClass("gShortForm"); $("#gSidebar #gAddTagForm").addClass("gShortForm"); - + // Get the short forms var shortForms = $(".gShortForm"); - + // Set up short form behavior for (var i=0; i < shortForms.length; i++) { // Set variables var shortFormID = "#" + $(shortForms[i]).attr("id"); var shortInputID = "#" + $(shortFormID + " input:first").attr("id"); var shortLabelValue = $(shortFormID + " label:first").html(); - + // Set default input value equal to label text $(shortInputID).val(shortLabelValue); - + // Attach event listeners to inputs $(shortInputID).bind("focus blur", function(e){ var eLabelVal = $(this).siblings("label").html(); @@ -72,12 +72,12 @@ $("document").ready(function() { } }); }; - + }); /** * Fire openDialog() and prevent links from opening - * + * * @see openDialog() */ function handleDialogEvent(event) { @@ -86,14 +86,14 @@ function handleDialogEvent(event) { } /** - * Display modal dialogs, populate dialog with trigger link's title and href - * + * Display modal dialogs, populate dialog with trigger link's title and href + * * @requires ui.core * @requires ui.draggable * @requires ui.resizable * @requires ui.dialog * @see handleDialogEvent() - * + * * @todo Set dialog attributes dynamically (width, height, drag, resize) * @todo Set ui-dialog-buttonpane button values equal to the original form button value * @todo Display loading animation on form submit @@ -105,19 +105,25 @@ function openDialog(element) { $("body").append(eDialog); var buttons = {}; - buttons["Submit"] = function() { - var form = $("#gDialog").find("form"); - var options = - $(form).ajaxSubmit({ - success: function(data, textStatus) { - if (data == "") { - window.location.reload(); - $("#gDialog").dialog("close"); - } - $("#gDialog").html(data); + var form = $("#gDialog").find("form"); + var ajaxify_dialog = function() { + $(form).ajaxForm({ + complete: function(xhr, statusText) { + if (xhr.status == 201) { + $("#gDialog").dialog("close"); + window.location = xhr.getResponseHeader("Location"); + } else { + $("#gDialog").replaceWith(data.responseText); + ajaxify_dialog(); + } } }); }; + ajaxify_dialog(); + buttons["Submit"] = function() { + var form = $("#gDialog").find("form"); + form[0].submit(); + }; buttons["Reset"] = function() { var form = $("#gDialog").find("form"); form[0].reset(); @@ -140,18 +146,18 @@ function openDialog(element) { $("#gDialog").dialog('destroy').remove(); } }); - loading("#gDialog") + loading("#gDialog"); $(".ui-dialog-content").height(400); $("#gDialog").html(sHref); $.get(sHref, function(data) { - loading("#gDialog"); + loading("#gDialog"); $("#gDialog").html(data).hide().fadeIn(); // Get dialog and it's contents' height - var contentHt = $(".ui-dialog-titlebar").height() - + $(".ui-dialog-content form").height() - + $(".ui-dialog-buttonpane").height() + var contentHt = $(".ui-dialog-titlebar").height() + + $(".ui-dialog-content form").height() + + $(".ui-dialog-buttonpane").height() + 60; - // Resize height if content's shorter than dialog + // Resize height if content's shorter than dialog if (contentHt < $("#gDialog").data("height.dialog")) { $(".ui-dialog").animate({height: contentHt}); } @@ -161,7 +167,7 @@ function openDialog(element) { /** * Toggle the processing indicator, both large and small - * + * * @param element ID to which to apply the loading class, including # * @param size Either Large or Small */ |