Changeset 859 for trunk/web-app
- Timestamp:
- Mar 13, 2011, 12:05:16 AM (14 years ago)
- Location:
- trunk/web-app/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web-app/js/application.js
r825 r859 19 19 } 20 20 21 function errorIndication( ) {22 return jQuery('#jQueryAjaxDefaultError').clone() ;21 function errorIndication(jqXHR, textStatus, errorThrown) { 22 return jQuery('#jQueryAjaxDefaultError').clone().append('Status:'+jqXHR.status+', '+textStatus+'.'); 23 23 } 24 25 // Apply updates to multiple page elements. 26 // @json JSON response object from an ajax request. 27 // @json.updates Array of element updates to apply. 28 // @element.mode The update mode: execute or replace, prepend, append. 29 // @element.script Script to execute, if execute mode. 30 // @element.target jQuery target selector, if update mode. 31 // @element.content Content to update target with, if update mode. 32 function applyElementUpdates(json) { 33 var updates; 34 var script; 35 36 if(json.updates) { 37 updates = json.updates; 38 var element; 39 var scripts = new Array(); 40 41 for(element in updates) { 42 element = updates[element]; 43 44 switch(element.mode) { 45 case 'execute': 46 scripts.push(element.script); 47 break; 48 case 'replace': 49 jQuery(element.target).html(element.content); 50 break; 51 case 'prepend': 52 jQuery(element.target).prepend(element.content); 53 break; 54 case 'append': 55 jQuery(element.target).append(element.content); 56 break; 57 } 58 } 59 60 // Run scripts. 61 for(script in scripts) { 62 script = scripts[script]; 63 eval(script); 64 } 65 66 } // if(json.updates) 67 } // applyElementUpdates 68 69 70 -
trunk/web-app/js/taskShow.js
r851 r859 1 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 }); 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 }); 8 } 9 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 27 32 } 28 33 … … 34 39 event.preventDefault(); 35 40 var listContainer = event.data.listContainer; 36 var createContainer = event.data.createContainer;41 var source = event.data.source; 37 42 var button = event.data.button; 38 var form = createContainer.find('form:first');43 var form = source.find('form:first'); 39 44 40 45 // 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 }); 46 function success(data, textStatus, jqXHR) { 47 source.hide(); 48 applyElementUpdates(data); 49 showButton(button); 49 50 } 50 51 51 52 // 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); 53 function error(jqXHR, textStatus, errorThrown) { 54 if(jqXHR.status == 403 && jqXHR.responseText) { 55 source.html(jqXHR.responseText); 56 createEntryFormInit(source, listContainer, button); 55 57 } 56 58 else { 57 createContainer.html(savedHtml);58 createContainer.prepend(errorIndication().show()).slideDown(600);59 source.html(savedHtml); 60 source.prepend(errorIndication(jqXHR, textStatus, errorThrown).show()).slideDown(600); 59 61 // Scroll the window. 60 jQuery('html,body').animate({scrollTop: createContainer.offset().top - 70}, 900, function() {61 createContainer.find(':input[name="comment"]').focus();62 jQuery('html,body').animate({scrollTop: source.offset().top - 70}, 900, function() { 63 source.find(':input[name="comment"]').focus(); 62 64 }); 63 65 } … … 65 67 66 68 // Start. 67 var savedHtml = createContainer.children().detach(); 68 createContainer.html(loadingIndication().show()).slideDown(600); 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); 69 73 70 74 jQuery.ajax({ 71 75 url: actionUrl, 72 data: form.serializeArray(), 76 data: params, 77 type: 'POST', 78 dataType: 'json', 73 79 success: success, 74 80 error: error … … 78 84 // Get a create Entry form via AJAX. 79 85 // @listContainer Container object to reload list into. 80 // @createContainer Container object to load response into.81 86 // @button Button object used to trigger this function. 82 87 // @params Params map to pass to actionUrl. 83 function getCreateEntryForm(listContainer, createContainer, button, params) { 88 // @params.target Selector indicating target to load response into. 89 function getCreateEntryForm(listContainer, button, params) { 84 90 85 91 var actionUrl = getContextPath()+"/entryDetailed/ajaxCreate/"; 92 var target = jQuery(params.target); 86 93 87 // On success load createContainer. 88 function success(data, textStatus, jqXHR){ 89 loadCreateContainer(data, createContainer, listContainer, button); 94 // On success load target. 95 function success(data, textStatus, jqXHR) { 96 applyElementUpdates(data); 97 createEntryFormInit(target, listContainer, button); 90 98 } 91 99 92 100 // 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);101 function error(jqXHR, textStatus, errorThrown) { 102 if(jqXHR.status == 403 && jqXHR.responseText) { 103 target.html(jqXHR.responseText); 96 104 } 97 105 else { 98 createContainer.html(errorIndication().show()).slideDown(600);106 target.html(errorIndication(jqXHR, textStatus, errorThrown).show()); 99 107 } 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 }); 108 showButton(button); 105 109 } 106 110 107 111 // Start. 108 112 button.hide(600); 109 createContainer.html(loadingIndication().show()).slideDown(600);113 target.html(loadingIndication().show()).slideDown(600); 110 114 111 115 jQuery.ajax({ 112 116 url: actionUrl, 113 117 data: params, 118 type: 'POST', 119 dataType: 'json', 114 120 success: success, 115 121 error: error
Note: See TracChangeset
for help on using the changeset viewer.