| 1 | |
|---|
| 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. |
|---|
| 7 | jQuery('html,body').animate({scrollTop: createContainer.offset().top - 70}, 900, function() { |
|---|
| 8 | createContainer.find(':input[name="comment"]').focus(); |
|---|
| 9 | }); |
|---|
| 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 | }); |
|---|
| 15 | // Hijack form submit to use our function. |
|---|
| 16 | var eventData = {listContainer:listContainer, createContainer:createContainer, button:button}; |
|---|
| 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); |
|---|
| 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 | }); |
|---|
| 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); |
|---|
| 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 | }); |
|---|
| 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 { |
|---|
| 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(); |
|---|
| 62 | }); |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | // Start. |
|---|
| 67 | var savedHtml = createContainer.children().detach(); |
|---|
| 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. |
|---|
| 81 | // @button Button object used to trigger this function. |
|---|
| 82 | // @params Params map to pass to actionUrl. |
|---|
| 83 | function getCreateEntryForm(listContainer, createContainer, button, params) { |
|---|
| 84 | |
|---|
| 85 | var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/"; |
|---|
| 86 | |
|---|
| 87 | // On success load createContainer. |
|---|
| 88 | function success(data, textStatus, jqXHR){ |
|---|
| 89 | loadCreateContainer(data, createContainer, listContainer, button); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // On error show controller responseText or show default error. |
|---|
| 93 | function error(jqXHR, textStatus, errorThrown){ |
|---|
| 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 | } |
|---|
| 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 | }); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | // Start. |
|---|
| 108 | button.hide(600); |
|---|
| 109 | createContainer.html(loadingIndication().show()).slideDown(600); |
|---|
| 110 | |
|---|
| 111 | jQuery.ajax({ |
|---|
| 112 | url: actionUrl, |
|---|
| 113 | data: params, |
|---|
| 114 | success: success, |
|---|
| 115 | error: error |
|---|
| 116 | }); |
|---|
| 117 | } |
|---|
| 118 | |
|---|