[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 | }); |
---|
| 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. |
---|
| 25 | function 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 { |
---|
| 52 | createContainer.html(errorIndication().show()).slideDown(600); |
---|
[844] | 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 | }); |
---|
[833] | 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. |
---|
[831] | 75 | // @button Button object used to trigger this function. |
---|
[833] | 76 | // @params Params map to pass to actionUrl. |
---|
| 77 | function getCreateEntryForm(listContainer, createContainer, button, params) { |
---|
[826] | 78 | |
---|
| 79 | var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/"; |
---|
| 80 | |
---|
[833] | 81 | // On success load createContainer. |
---|
[826] | 82 | function success(data, textStatus, jqXHR){ |
---|
[833] | 83 | loadCreateContainer(data, createContainer, listContainer, button); |
---|
[826] | 84 | } |
---|
| 85 | |
---|
[833] | 86 | // On error show controller responseText or show default error. |
---|
[826] | 87 | function error(jqXHR, textStatus, errorThrown){ |
---|
[833] | 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 | } |
---|
[844] | 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 | }); |
---|
[826] | 99 | } |
---|
| 100 | |
---|
| 101 | // Start. |
---|
| 102 | button.hide(600); |
---|
[833] | 103 | createContainer.html(loadingIndication().show()).slideDown(600); |
---|
[826] | 104 | |
---|
| 105 | jQuery.ajax({ |
---|
| 106 | url: actionUrl, |
---|
| 107 | data: params, |
---|
| 108 | success: success, |
---|
| 109 | error: error |
---|
| 110 | }); |
---|
| 111 | } |
---|
[833] | 112 | |
---|