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