Changeset 240 for trunk/grails-app/taglib
- Timestamp:
- Mar 5, 2010, 5:26:05 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy
r238 r240 112 112 113 113 /** 114 * generate a ajax submit JavaScript 115 * @see WizardTagLib::ajaxFlowRedirect 116 * @see WizardTagLib::baseElement (ajaxSubmitOnChange) 117 */ 118 def ajaxSubmitJs = { attrs, body -> 119 // define AJAX provider 120 setProvider([library: ajaxProvider]) 121 122 // got a function name? 123 def functionName = attrs.remove('functionName') 124 if (functionName && !attrs.get('name')) { 125 attrs.name = functionName 126 } 127 128 // generate an ajax button 129 def button = this.ajaxButton(attrs, body) 130 131 // strip the button part to only leave the Ajax call 132 button = button.replaceFirst(/<[^\"]*\"jQuery.ajax/,'jQuery.ajax') 133 button = button.replaceFirst(/return false.*/,'') 134 135 // change form if a form attribute is present 136 if (attrs.get('form')) { 137 button = button.replaceFirst(/this\.form/, 138 "\\\$('" + attrs.get('form') + "')" 139 ) 140 } 141 142 out << button 143 } 144 145 /** 114 146 * generate ajax webflow redirect javascript 115 147 * … … 130 162 * update = the divs to update upon success or error 131 163 * 164 * OR: to generate a JavaScript function you can call yourself, use 'functionName' instead of 'name' 165 * 132 166 * Example initial webflow action to work with this javascript: 133 167 * ... … … 145 179 */ 146 180 def ajaxFlowRedirect = { attrs, body -> 147 // define AJAX provider148 setProvider([library: ajaxProvider])149 150 // generate an ajax button151 def button = this.ajaxButton(attrs, body)152 153 // strip the button part to only leave the Ajax call154 button = button.replaceFirst(/<[^\"]*\"jQuery.ajax/,'jQuery.ajax')155 button = button.replaceFirst(/return false.*/,'')156 157 // change form if a form attribute is present158 if (attrs.get('form')) {159 button = button.replaceFirst(/this\.form/,160 "\\\$('" + attrs.get('form') + "')"161 )162 }163 164 181 // generate javascript 165 out << '<script language="JavaScript">'182 out << '<script type="text/javascript">' 166 183 out << '$(document).ready(function() {' 167 out << button184 out << ajaxSubmitJs(attrs, body) 168 185 out << '});' 169 186 out << '</script>' … … 199 216 def addExampleElement = attrs.remove('addExampleElement') 200 217 def addExample2Element = attrs.remove('addExample2Element') 218 219 // got an ajax onchange action? 220 def ajaxOnChange = attrs.remove('ajaxOnChange') 221 if (ajaxOnChange) { 222 if (!attrs.onChange) attrs.onChange = '' 223 224 // add onChange AjaxSubmit javascript 225 attrs.onChange += ajaxSubmitJs( 226 [ 227 functionName: ajaxOnChange, 228 url: attrs.get('url'), 229 update: attrs.get('update'), 230 afterSuccess: attrs.get('afterSuccess') 231 ], 232 '' 233 ) 234 } 201 235 202 236 // execute inputElement call
Note: See TracChangeset
for help on using the changeset viewer.