[826] | 1 | |
---|
[863] | 2 | var submit_confirmResult = true |
---|
| 3 | |
---|
[859] | 4 | function 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 | }); |
---|
[833] | 10 | } |
---|
| 11 | |
---|
[859] | 12 | function 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. |
---|
[863] | 21 | target.find('input[name^="submit_"]').click(function(e){ |
---|
[859] | 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 | |
---|
[833] | 36 | // Submit a create Entry form via AJAX. |
---|
| 37 | function submitCreateEntryForm(event) { |
---|
| 38 | |
---|
[863] | 39 | event.preventDefault(); |
---|
| 40 | |
---|
| 41 | if(submit_confirmResult == false) { |
---|
| 42 | submit_confirmResult = true |
---|
| 43 | return false; |
---|
| 44 | } |
---|
| 45 | |
---|
[833] | 46 | var actionUrl = getContextPath()+"/entryDetailed/ajaxSave/"; |
---|
| 47 | var listContainer = event.data.listContainer; |
---|
[859] | 48 | var source = event.data.source; |
---|
[833] | 49 | var button = event.data.button; |
---|
[859] | 50 | var form = source.find('form:first'); |
---|
[833] | 51 | |
---|
| 52 | // On success reload listContainer. |
---|
[859] | 53 | function success(data, textStatus, jqXHR) { |
---|
| 54 | source.hide(); |
---|
| 55 | applyElementUpdates(data); |
---|
| 56 | showButton(button); |
---|
[833] | 57 | } |
---|
| 58 | |
---|
| 59 | // On create failure controller sets 403 and returns the form template. |
---|
[859] | 60 | function error(jqXHR, textStatus, errorThrown) { |
---|
| 61 | if(jqXHR.status == 403 && jqXHR.responseText) { |
---|
| 62 | source.html(jqXHR.responseText); |
---|
| 63 | createEntryFormInit(source, listContainer, button); |
---|
[833] | 64 | } |
---|
| 65 | else { |
---|
[859] | 66 | source.html(savedHtml); |
---|
| 67 | source.prepend(errorIndication(jqXHR, textStatus, errorThrown).show()).slideDown(600); |
---|
[850] | 68 | // Scroll the window. |
---|
[859] | 69 | jQuery('html,body').animate({scrollTop: source.offset().top - 70}, 900, function() { |
---|
| 70 | source.find(':input[name="comment"]').focus(); |
---|
[844] | 71 | }); |
---|
[833] | 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | // Start. |
---|
[859] | 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); |
---|
[833] | 80 | |
---|
| 81 | jQuery.ajax({ |
---|
| 82 | url: actionUrl, |
---|
[859] | 83 | data: params, |
---|
| 84 | type: 'POST', |
---|
| 85 | dataType: 'json', |
---|
[833] | 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. |
---|
[831] | 93 | // @button Button object used to trigger this function. |
---|
[833] | 94 | // @params Params map to pass to actionUrl. |
---|
[859] | 95 | // @params.target Selector indicating target to load response into. |
---|
| 96 | function getCreateEntryForm(listContainer, button, params) { |
---|
[826] | 97 | |
---|
| 98 | var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/"; |
---|
[859] | 99 | var target = jQuery(params.target); |
---|
[826] | 100 | |
---|
[859] | 101 | // On success load target. |
---|
| 102 | function success(data, textStatus, jqXHR) { |
---|
| 103 | applyElementUpdates(data); |
---|
| 104 | createEntryFormInit(target, listContainer, button); |
---|
[826] | 105 | } |
---|
| 106 | |
---|
[833] | 107 | // On error show controller responseText or show default error. |
---|
[859] | 108 | function error(jqXHR, textStatus, errorThrown) { |
---|
| 109 | if(jqXHR.status == 403 && jqXHR.responseText) { |
---|
| 110 | target.html(jqXHR.responseText); |
---|
[833] | 111 | } |
---|
| 112 | else { |
---|
[859] | 113 | target.html(errorIndication(jqXHR, textStatus, errorThrown).show()); |
---|
[833] | 114 | } |
---|
[859] | 115 | showButton(button); |
---|
[826] | 116 | } |
---|
| 117 | |
---|
| 118 | // Start. |
---|
| 119 | button.hide(600); |
---|
[859] | 120 | target.html(loadingIndication().show()).slideDown(600); |
---|
[826] | 121 | |
---|
| 122 | jQuery.ajax({ |
---|
| 123 | url: actionUrl, |
---|
| 124 | data: params, |
---|
[859] | 125 | type: 'POST', |
---|
| 126 | dataType: 'json', |
---|
[826] | 127 | success: success, |
---|
| 128 | error: error |
---|
| 129 | }); |
---|
| 130 | } |
---|
[833] | 131 | |
---|