source: trunk/web-app/js/taskShow.js @ 850

Last change on this file since 850 was 850, checked in by gav, 13 years ago

Task show ajax improvement, save/restore form and data if no response from server.

File size: 4.1 KB
RevLine 
[826]1
[833]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.
[845]7        jQuery('html,body').animate({scrollTop: createContainer.offset().top - 70}, 900, function() {
[833]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);
[844]16            button.show(600, function() {
17                if(jQuery.browser.msie) {
18                    jQuery(this).get(0).style.removeAttribute('filter'); // Remove blur/fuzzy text in IE.
19                }
20            });
[833]21        });
22}
23
24// Submit a create Entry form via AJAX.
25function submitCreateEntryForm(event) {
26
27    var actionUrl = getContextPath()+"/entryDetailed/ajaxSave/";
28
29    event.preventDefault();
30    var listContainer = event.data.listContainer;
31    var createContainer = event.data.createContainer;
32    var button = event.data.button;
33    var form = createContainer.find('form:first');
34
35    // On success reload listContainer.
36    function success(data, textStatus, jqXHR){
37        createContainer.hide();
38        listContainer.html(data);
[844]39        button.show(600, function() {
40            if(jQuery.browser.msie) {
41                jQuery(this).get(0).style.removeAttribute('filter'); // Remove blur/fuzzy text in IE.
42            }
43        });
[833]44    }
45
46    // On create failure controller sets 403 and returns the form template.
47    function error(jqXHR, textStatus, errorThrown){
48        if(jqXHR.status == 403 && jqXHR.responseText){
49            loadCreateContainer(jqXHR.responseText, createContainer, listContainer, button);
50        }
51        else {
[850]52            createContainer.html(savedHtml);
53            createContainer.prepend(errorIndication().show()).slideDown(600);
54            // Scroll the window.
55            jQuery('html,body').animate({scrollTop: createContainer.offset().top - 70}, 900, function() {
56                createContainer.find(':input[name="comment"]').focus();
[844]57            });
[833]58        }
59    }
60
61    // Start.
[850]62    var savedHtml = createContainer.children().detach();
[833]63    createContainer.html(loadingIndication().show()).slideDown(600);
64
65    jQuery.ajax({
66        url: actionUrl,
67        data: form.serializeArray(),
68        success: success,
69        error: error
70    });
71}
72
73// Get a create Entry form via AJAX.
74// @listContainer Container object to reload list into.
75// @createContainer Container object to load response into.
[831]76// @button Button object used to trigger this function.
[833]77// @params Params map to pass to actionUrl.
78function getCreateEntryForm(listContainer, createContainer, button, params) {
[826]79
80    var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/";
81
[833]82    // On success load createContainer.
[826]83    function success(data, textStatus, jqXHR){
[833]84        loadCreateContainer(data, createContainer, listContainer, button);
[826]85    }
86
[833]87    // On error show controller responseText or show default error.
[826]88    function error(jqXHR, textStatus, errorThrown){
[833]89        if(jqXHR.status == 403 && jqXHR.responseText){
90            loadCreateContainer(jqXHR.responseText, createContainer, listContainer, button);
91        }
92        else {
93            createContainer.html(errorIndication().show()).slideDown(600);
94        }
[844]95        button.show(600, function() {
96            if(jQuery.browser.msie) {
97                jQuery(this).get(0).style.removeAttribute('filter'); // Remove blur/fuzzy text in IE.
98            }
99        });
[826]100    }
101
102    // Start.
103    button.hide(600);
[833]104    createContainer.html(loadingIndication().show()).slideDown(600);
[826]105
106    jQuery.ajax({
107        url: actionUrl,
108        data: params,
109        success: success,
110        error: error
111    });
112}
[833]113
Note: See TracBrowser for help on using the repository browser.