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

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

Update taskShow.js to fix blur/fuzzy text in IE.
Also don't show button after validation error.

File size: 3.9 KB
Line 
1
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, function() {
17                if(jQuery.browser.msie) {
18                    jQuery(this).get(0).style.removeAttribute('filter'); // Remove blur/fuzzy text in IE.
19                }
20            });
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);
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        });
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 {
52            createContainer.html(errorIndication().show()).slideDown(600);
53            button.show(600, function() {
54                if(jQuery.browser.msie) {
55                    jQuery(this).get(0).style.removeAttribute('filter'); // Remove blur/fuzzy text in IE.
56                }
57            });
58        }
59    }
60
61    // Start.
62    createContainer.html(loadingIndication().show()).slideDown(600);
63
64    jQuery.ajax({
65        url: actionUrl,
66        data: form.serializeArray(),
67        success: success,
68        error: error
69    });
70}
71
72// Get a create Entry form via AJAX.
73// @listContainer Container object to reload list into.
74// @createContainer Container object to load response into.
75// @button Button object used to trigger this function.
76// @params Params map to pass to actionUrl.
77function getCreateEntryForm(listContainer, createContainer, button, params) {
78
79    var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/";
80
81    // On success load createContainer.
82    function success(data, textStatus, jqXHR){
83        loadCreateContainer(data, createContainer, listContainer, button);
84    }
85
86    // On error show controller responseText or show default error.
87    function error(jqXHR, textStatus, errorThrown){
88        if(jqXHR.status == 403 && jqXHR.responseText){
89            loadCreateContainer(jqXHR.responseText, createContainer, listContainer, button);
90        }
91        else {
92            createContainer.html(errorIndication().show()).slideDown(600);
93        }
94        button.show(600, function() {
95            if(jQuery.browser.msie) {
96                jQuery(this).get(0).style.removeAttribute('filter'); // Remove blur/fuzzy text in IE.
97            }
98        });
99    }
100
101    // Start.
102    button.hide(600);
103    createContainer.html(loadingIndication().show()).slideDown(600);
104
105    jQuery.ajax({
106        url: actionUrl,
107        data: params,
108        success: success,
109        error: error
110    });
111}
112
Note: See TracBrowser for help on using the repository browser.