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