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

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

Add check for submit_confirmResult in entry create ajax.

File size: 4.0 KB
Line 
1
2var submit_confirmResult = true
3
4function showButton(button) {
5    button.show(600, function() {
6        if(jQuery.browser.msie) {
7            jQuery(this).get(0).style.removeAttribute('filter'); // Remove blur/fuzzy text in IE.
8        }
9    });
10}
11
12function createEntryFormInit(target, listContainer, button) {
13
14    // Show.
15    target.slideDown(800);
16    // Scroll the window.
17    jQuery('html,body').animate({scrollTop: target.offset().top - 70}, 900, function() {
18        target.find(':input[name="comment"]').focus();
19    });
20    // Register 'submit_*' input button click handlers.
21    target.find('input[name^="submit_"]').click(function(e){
22        target.find(':input[name="submitAction"]').val(jQuery(this).attr('name'));
23        target.find('form:first').submit();
24    });
25    // Redirect form submit to use our function.
26    var eventData = {listContainer:listContainer, source:target, button:button};
27    target.find('form:first').submit(eventData, submitCreateEntryForm);
28    // Register the close img click handler.
29    target.find('.pane_close img').click(function(){
30        target.slideUp(600);
31        showButton(button);
32    });
33
34}
35
36// Submit a create Entry form via AJAX.
37function submitCreateEntryForm(event) {
38
39    event.preventDefault();
40
41    if(submit_confirmResult == false) {
42        submit_confirmResult = true
43        return false;
44    }
45
46    var actionUrl = getContextPath()+"/entryDetailed/ajaxSave/";
47    var listContainer = event.data.listContainer;
48    var source = event.data.source;
49    var button = event.data.button;
50    var form = source.find('form:first');
51
52    // On success reload listContainer.
53    function success(data, textStatus, jqXHR) {
54        source.hide();
55        applyElementUpdates(data);
56        showButton(button);
57    }
58
59    // On create failure controller sets 403 and returns the form template.
60    function error(jqXHR, textStatus, errorThrown) {
61        if(jqXHR.status == 403 && jqXHR.responseText) {
62            source.html(jqXHR.responseText);
63            createEntryFormInit(source, listContainer, button);
64        }
65        else {
66            source.html(savedHtml);
67            source.prepend(errorIndication(jqXHR, textStatus, errorThrown).show()).slideDown(600);
68            // Scroll the window.
69            jQuery('html,body').animate({scrollTop: source.offset().top - 70}, 900, function() {
70                source.find(':input[name="comment"]').focus();
71            });
72        }
73    }
74
75    // Start.
76    var savedHtml = source.children().detach();
77    var params = form.serializeArray();
78    params.push({name:'target', value:listContainer.selector});
79    source.html(loadingIndication().show()).slideDown(600);
80
81    jQuery.ajax({
82        url: actionUrl,
83        data: params,
84        type: 'POST',
85        dataType: 'json',
86        success: success,
87        error: error
88    });
89}
90
91// Get a create Entry form via AJAX.
92// @listContainer Container object to reload list into.
93// @button Button object used to trigger this function.
94// @params Params map to pass to actionUrl.
95// @params.target Selector indicating target to load response into.
96function getCreateEntryForm(listContainer, button, params) {
97
98    var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/";
99    var target = jQuery(params.target);
100
101    // On success load target.
102    function success(data, textStatus, jqXHR) {
103        applyElementUpdates(data);
104        createEntryFormInit(target, listContainer, button);
105    }
106
107    // On error show controller responseText or show default error.
108    function error(jqXHR, textStatus, errorThrown) {
109        if(jqXHR.status == 403 && jqXHR.responseText) {
110            target.html(jqXHR.responseText);
111        }
112        else {
113            target.html(errorIndication(jqXHR, textStatus, errorThrown).show());
114        }
115        showButton(button);
116    }
117
118    // Start.
119    button.hide(600);
120    target.html(loadingIndication().show()).slideDown(600);
121
122    jQuery.ajax({
123        url: actionUrl,
124        data: params,
125        type: 'POST',
126        dataType: 'json',
127        success: success,
128        error: error
129    });
130}
131
Note: See TracBrowser for help on using the repository browser.