Changeset 859
- Timestamp:
- Mar 13, 2011, 12:05:16 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/EntryDetailedController.groovy
r838 r859 10 10 11 11 // the delete, save and update actions only accept POST requests 12 static allowedMethods = [delete:'POST', save:'POST', update:'POST' ]12 static allowedMethods = [delete:'POST', save:'POST', update:'POST', ajaxCreate:'POST', ajaxSave:'POST'] 13 13 14 14 def list = { … … 106 106 def ajaxCreate = { 107 107 if(!params.taskId || !params.entryTypeId) { 108 response.status = 403109 108 params.errorMessage = g.message(code: "entry.create.no.params.ajax") 110 render( template: "/shared/messages")109 render(contentType:"text/json", status: 403, template: "/shared/messages") 111 110 return 112 111 } … … 115 114 116 115 if(!taskInstance) { 117 response.status = 403118 116 params.errorMessage = g.message(code:"default.not.found", args:['Task',params.taskId]) 119 render( template: "/shared/messages")117 render(contentType:"text/json", status: 403, template: "/shared/messages") 120 118 return 121 119 } … … 123 121 // Check for Complete task. 124 122 if(taskInstance.taskStatus.id == 3) { 125 response.status = 403126 123 params.errorMessage = g.message(code:"task.operationNotPermittedOnCompleteTask") 127 render( template: "/shared/messages")124 render(contentType:"text/json", status: 403, template: "/shared/messages") 128 125 return 129 126 } … … 133 130 entryInstance.task = taskInstance 134 131 entryInstance.entryType = EntryType.read(params.entryTypeId) 135 render(template: "create", model: ['entryInstance': entryInstance]) 136 } 132 def model = ['entryInstance': entryInstance] 133 134 render(contentType:"text/json") { 135 updates = array { 136 element([ mode: 'replace', target:"$params.target", content: g.render(template: 'create', model:model) ]) 137 } 138 } 139 140 } // ajaxCreate 137 141 138 142 def ajaxSave = { … … 142 146 if(!result.error) { 143 147 def entryList = Entry.withCriteria { 144 eq("entryType", result.entryInstance.entryType) 145 task { 146 idEq(result.taskId) 147 } 148 } 149 render(template: "list", model: ['entryList': entryList]) 150 return 151 } 152 153 if(result.error.code != "default.create.failure") { 154 response.status = 403 148 eq("entryType", result.entryInstance.entryType) 149 task { 150 idEq(result.taskId) 151 } 152 } 153 154 def model = ['entryList': entryList] 155 156 render(contentType:"text/json") { 157 updates = array { 158 element([ mode: 'replace', target:"$params.target", content: g.render(template: 'list', model:model) ]) 159 } 160 } 161 return 162 } 163 164 if(result.error.code != "default.create.failure") 155 165 params.errorMessage = g.message(code: result.error.code) 156 render(template: "/shared/messages") 157 return 158 } 159 160 response.status = 403 161 render(template: "create", model: ['entryInstance': result.entryInstance]) 166 167 def model = ['entryInstance': result.entryInstance] 168 render(contentType:"text/json", status: 403, template: "create", model: model) 162 169 } // ajaxSave 163 170 -
trunk/grails-app/views/taskDetailed/_showProcedureTab.gsp
r833 r859 46 46 value="Add PM Entry" 47 47 onclick="getCreateEntryForm(jQuery('#pmEntryContainer'), 48 jQuery('#createPMEntryContainer'),49 48 jQuery('#pmEntryButton'), 50 {taskId: ${taskInstance?.id}, entryTypeId: 6})" /> 49 {target: '#createPMEntryContainer', 50 taskId: ${taskInstance?.id}, 51 entryTypeId: 6})" /> 51 52 </span> 52 53 </div> -
trunk/grails-app/views/taskDetailed/_showTaskTab.gsp
r846 r859 231 231 value="Add Fault" 232 232 onclick="getCreateEntryForm(jQuery('#entryFaultContainer'), 233 jQuery('#createEntryFaultContainer'),234 233 jQuery('#entryFaultButton'), 235 {taskId: ${taskInstance?.id}, entryTypeId: 1})" /> 234 {target: '#createEntryFaultContainer', 235 taskId: ${taskInstance?.id}, 236 entryTypeId: 1})" /> 236 237 </span> 237 238 </div> … … 260 261 value="Add Cause" 261 262 onclick="getCreateEntryForm(jQuery('#entryCauseContainer'), 262 jQuery('#createEntryCauseContainer'),263 263 jQuery('#entryCauseButton'), 264 {taskId: ${taskInstance?.id}, entryTypeId: 2})" /> 264 {target: '#createEntryCauseContainer', 265 taskId: ${taskInstance?.id}, 266 entryTypeId: 2})" /> 265 267 </span> 266 268 </div> … … 289 291 value="Add Work Done" 290 292 onclick="getCreateEntryForm(jQuery('#workDoneContainer'), 291 jQuery('#createWorkDoneContainer'),292 293 jQuery('#workDoneButton'), 293 {taskId: ${taskInstance?.id}, entryTypeId: 3})" /> 294 {target: '#createWorkDoneContainer', 295 taskId: ${taskInstance?.id}, 296 entryTypeId: 3})" /> 294 297 </span> 295 298 </div> -
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.