Changeset 833 for trunk/web-app/js


Ignore:
Timestamp:
Mar 3, 2011, 12:24:01 PM (14 years ago)
Author:
gav
Message:

AJAX Work Done and PM Entry, second draft.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/web-app/js/taskShow.js

    r831 r833  
    11
    2 // Load an Entry from via AJAX.
    3 // @container Container object to load response into.
     2// Load data into createContainer and register events.
     3function loadCreateContainer(data, createContainer, listContainer, button) {
     4        // Load the response data and show container.
     5        createContainer.html(data).slideDown(800);
     6        // Scroll the window.
     7        jQuery('html,body').animate({scrollTop: createContainer.offset().top}, 900, function() {
     8            createContainer.find(':input[name="comment"]').focus();
     9        });
     10        // Hijack form submit to use our function.
     11        var eventData = {listContainer:listContainer,createContainer:createContainer, button:button};
     12        createContainer.find('form:first').submit(eventData, submitCreateEntryForm);
     13        // Register the close img click handler.
     14        createContainer.find('.pane_close img').click(function(){
     15            createContainer.slideUp(600);
     16            button.show(600);
     17        });
     18}
     19
     20// Submit a create Entry form via AJAX.
     21function submitCreateEntryForm(event) {
     22
     23    var actionUrl = getContextPath()+"/entryDetailed/ajaxSave/";
     24
     25    event.preventDefault();
     26    var listContainer = event.data.listContainer;
     27    var createContainer = event.data.createContainer;
     28    var button = event.data.button;
     29    var form = createContainer.find('form:first');
     30
     31    // On success reload listContainer.
     32    function success(data, textStatus, jqXHR){
     33        createContainer.hide();
     34        listContainer.html(data);
     35        button.show(600);
     36    }
     37
     38    // On create failure controller sets 403 and returns the form template.
     39    function error(jqXHR, textStatus, errorThrown){
     40        if(jqXHR.status == 403 && jqXHR.responseText){
     41            loadCreateContainer(jqXHR.responseText, createContainer, listContainer, button);
     42        }
     43        else {
     44            createContainer.html(errorIndication().show()).slideDown(600);
     45        }
     46        button.show(600);
     47    }
     48
     49    // Start.
     50    createContainer.html(loadingIndication().show()).slideDown(600);
     51
     52    jQuery.ajax({
     53        url: actionUrl,
     54        data: form.serializeArray(),
     55        success: success,
     56        error: error
     57    });
     58}
     59
     60// Get a create Entry form via AJAX.
     61// @listContainer Container object to reload list into.
     62// @createContainer Container object to load response into.
    463// @button Button object used to trigger this function.
    5 // @args Params map to pass to actionUrl.
    6 function loadEntryForm(container, button, params) {
     64// @params Params map to pass to actionUrl.
     65function getCreateEntryForm(listContainer, createContainer, button, params) {
    766
    867    var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/";
    968
     69    // On success load createContainer.
    1070    function success(data, textStatus, jqXHR){
    11         container.html(data);
    12         jQuery('html,body').animate({scrollTop: container.offset().top}, 800, function() {
    13             container.css("border", "1px solid #006DBA");
    14             container.find(':input[name="comment"]').focus();
    15         });
     71        loadCreateContainer(data, createContainer, listContainer, button);
    1672    }
    1773
     74    // On error show controller responseText or show default error.
    1875    function error(jqXHR, textStatus, errorThrown){
    19         container.html(errorIndication().slideDown(600));
     76        if(jqXHR.status == 403 && jqXHR.responseText){
     77            loadCreateContainer(jqXHR.responseText, createContainer, listContainer, button);
     78        }
     79        else {
     80            createContainer.html(errorIndication().show()).slideDown(600);
     81        }
    2082        button.show(600);
    2183    }
     
    2385    // Start.
    2486    button.hide(600);
    25     container.html(loadingIndication().slideDown(600));
     87    createContainer.html(loadingIndication().show()).slideDown(600);
    2688
    2789    jQuery.ajax({
     
    3294    });
    3395}
     96
Note: See TracChangeset for help on using the changeset viewer.