Changeset 1974934
- Timestamp:
- 11/15/2018 01:56:51 PM (7 years ago)
- File:
-
- 1 edited
-
ecampaign/branches/maintenance/public.js (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ecampaign/branches/maintenance/public.js
r1700887 r1974934 29 29 30 30 31 ecam.onClickSubmit = function (buttonElement, phpClass, phpMethod) 32 { 33 // check that we know where we are 34 if (buttonElement == null) 35 { 36 alert('onClickSubmit(): clickable element not declared'); 31 ecam.onClickSubmit = function (buttonElement, phpMethod) 32 { 33 var button = jQuery(buttonElement); 34 return ecam.submit(button, [], phpMethod); 35 }; 36 37 38 ecam.submit = function(trigger, postData, phpMethod) 39 { 40 // find the root of the form 41 var formRoot = trigger.parents('form, .ecform'); 42 if (formRoot.length == 0) 43 { 44 alert('submit(): unable to find form wrapper'); 37 45 return false; 38 46 } 39 var button = jQuery(buttonElement);40 // find the root of the form41 var formRoot = button.parents('form, .ecform');42 if (formRoot.length == 0)43 {44 alert('onClickSubmit(): no form wrapper');45 return false;46 }47 48 47 // find the closest element used to hold status messages 49 var status = ecam.findClosestRelative(button,'.ecstatus');48 var status = jQuery(trigger).closestRelative('.ecstatus'); 50 49 if (status.length == 0) 51 50 { 52 alert(' onClickSubmit(): status element not declared');51 alert('submit(): status element not declared'); 53 52 return false; 54 53 } … … 92 91 // visitorName, visitorEmail, may have to be picked up from fields in adjacent form. 93 92 94 var controlData = new Array(); 95 96 var recipient = formRoot.find('#recipients-email'); 97 98 controlData.push( // and add fields wrapped in DIV tags 93 var controlData = [ // and add fields wrapped in DIV tags 99 94 { name : 'action', value : 'ecampaign' }, 100 95 { name : 'formID', value : formRoot.attr('id')}, 101 { name : 'class', value : phpClass }, 102 { name : 'method', value : phpMethod }, 103 { name : 'recipientsEmail', value : ecam.removeAntiSpam(recipient) } 104 ); 96 { name : 'method', value : phpMethod } 97 ]; 105 98 106 99 var primaryFormFields = formRoot.find("input, textarea").serializeArray(); 107 var secondaryFormFields = formRoot.siblings().find("input, textarea").serializeArray(); 108 109 var postData = ecam.mergeArraysSkippingDuplicateKeys(new Array(controlData, primaryFormFields, secondaryFormFields)); 110 111 // about to post to server... 112 100 101 var postData = ecam.mergeArraysSkippingDuplicateKeys(new Array(postData, controlData, primaryFormFields)); 102 113 103 ecam.updateStatus(status,true,"waiting..."); 114 104 … … 153 143 switch(response.callbackJS) 154 144 { // cannot work how to use JS introspection 155 case 'update MessageFields' : ecam.updateMessageFields(response, button, formRoot); break;156 case 'reveal VerificationField' : ecam.revealVerificationField(response, button, formRoot); break;157 case ' revealForm' : ecam.revealForm(response, button, formRoot); break;145 case 'updateDOM' : ecam.updateDOM(response, formRoot); break; 146 case 'revealForm' : ecam.showElement(response, formRoot, true); break; 147 case 'hideForm' : ecam.showElement(response, formRoot, false); break; 158 148 } 159 149 } 160 150 if (response.regexp != undefined) 161 ecam.updateMessageBody(response.regexp, button,formRoot);151 ecam.updateMessageBody(response.regexp, formRoot); 162 152 } 163 153 } … … 165 155 }); 166 156 return false; // suppress any other action 167 };168 169 170 ecam.removeAntiSpam = function(selection)171 {172 var string = "";173 if (selection.length > 0)174 string = ecam.getNodeText(selection[0], string);175 return string ;176 157 }; 177 158 … … 231 212 */ 232 213 233 ecam.updateMessageBody = function (regexp, button,formRoot)214 ecam.updateMessageBody = function (regexp, formRoot) 234 215 { 235 216 var body = formRoot.find("textarea[name='body']").first(); 236 217 var currentText = body.val() ; // may NOT be actually what has been keyed in 237 238 var updatedText = currentText.replace( regexp.pattern, regexp.replacement);218 var pattern = (regexp.pattern) ? new RegExp(regexp.pattern) : regexp.search ; 219 var updatedText = currentText.replace(pattern, regexp.replacement); 239 220 240 221 if (updatedText != currentText) // successful update … … 253 234 if (ecam.lastUpdatedText != undefined && currentText == ecam.lastUpdatedText) 254 235 { 255 updatedText = ecam.lastOriginalText.replace( regexp.pattern, regexp.replacement);236 updatedText = ecam.lastOriginalText.replace(pattern, regexp.replacement); 256 237 if (updatedText != ecam.lastOriginalText) 257 238 { … … 260 241 else 261 242 { 262 alert("Unable to substitute " + regexp.pattern + " with " + regexp.replacement);243 alert("Unable to substitute " + pattern + " with " + regexp.replacement); 263 244 return ; 264 245 } … … 267 248 { 268 249 alert("Message text may have been edited; " + 269 " unable to substitute " + regexp.pattern + " with " + regexp.replacement +250 " unable to substitute " + pattern + " with " + regexp.replacement + 270 251 ". Please check the message text before sending."); 271 252 return ; … … 291 272 292 273 293 ecam.update MessageFields = function (response, button, formRoot)274 ecam.updateDOM = function (response, formRoot) 294 275 { 276 /* 295 277 var names="", emails="", num=0 ; 296 278 … … 308 290 formRoot.find("#recipients-email").html(names); 309 291 } 310 292 */ 293 if (response.updates != undefined && response.updates instanceof Object) 294 { 295 for (x in response.updates) 296 { 297 var update = response.updates[x]; 298 var root = update.selector != undefined ? jQuery(formRoot) : jQuery(); 299 var target = root.closestRelative(update.selector) ; 300 301 if (target.length == 0) 302 { 303 alert("Target has no matching elements"); return ; 304 } 305 if (update.val != undefined) 306 target.val(update.val); // input fields 307 if (update.text != undefined) 308 target.text(update.text); // (encoded) div and textarea 309 if (update.html != undefined) 310 target.html(update.html); 311 if (update.checked != undefined) 312 { 313 if (target.attr('type') != 'checkbox') 314 alert('Cannot (un)set checkbox'); 315 target.prop('checked', update.checked); 316 } 317 } 318 } 319 /* 320 if (response.targetEmail != undefined) 321 formRoot.find("#recipients-email").html(response.targetEmail) 322 311 323 if (response.targetSubject != undefined) 312 324 formRoot.find("input[name='subject']").attr('value',response.targetSubject); … … 314 326 if (response.targetBody != undefined) 315 327 formRoot.find("textarea[name='body']").html(response.targetBody); 328 */ 316 329 317 330 submitButton = formRoot.find(".ecsend input"); … … 319 332 }; 320 333 321 322 ecam.findClosestRelative = function (elements, select) 323 { 324 var parents = elements.parents(); 325 for (var i=0 ; i < parents.length ; i++) 326 { 327 var cousins = jQuery(parents[i]).find(select); 328 if (cousins.length > 0) 329 return cousins.first(); 330 } 331 return jQuery(); // returns an empty set 332 }; 333 334 335 /** 336 * called back when email send to target 337 * @param button (jQuery) clicked by user 338 */ 339 340 ecam.revealVerificationField = function (response, button, formRoot) 341 { 342 if (response.success) 343 { 344 formRoot.find('.eccode').show('slow'); 345 } 346 }; 347 348 349 ecam.revealForm = function (response, button, formRoot) 350 { 351 var nextForm ; 352 if (response.success) 353 { 354 button.attr("disabled","disabled"); // prevent user from trying to sending two messages 355 if (response.selector == undefined) 356 nextForm = formRoot.siblings(); // default is to reveal all forms 357 else 358 nextForm = jQuery(response.selector); 359 // nextForm.show('slow'); // the friends form is enabled, now show it 360 nextForm.removeClass('hidden'); // ja 23-nov-2015 361 } 362 }; 363 364 /** 365 * merge all the arrays of name, value pair objects contained in array s 334 335 ecam.showElement = function (response, item, display) 336 { 337 if (response.success && response.selector != undefined) 338 display ? jQuery(response.selector).slideDown(1000) : jQuery(response.selector).slideUp(1000); 339 } 340 341 /** 342 * merge all the arrays of jQuery type name, value pair objects contained in array s 366 343 * into single array. Ignore objects with duplicate keys. 367 344 */ … … 463 440 464 441 465 442 jQuery.fn.extend({ 443 closestRelative : function(select) { return this.genealogy(select).relative }, 444 commonAncestor : function(select) { return this.genealogy(select).ancestor }, 445 genealogy : function(select) 446 { 447 for (var parent = this.get(0); parent ; parent = parent.parentNode) 448 { 449 var jqParent = jQuery(parent); 450 var cousins = jqParent.find(select); 451 if (cousins.length > 0) 452 return { relative : cousins.first(), ancestor : jqParent.first()}; 453 } 454 return { relative : jQuery(), ancestor : jQuery() }; // returns an empty set 455 }, 456 serializeToObject : function(query) 457 { 458 var ar = this.serializeArray(); 459 for (var i in ar) 460 query[ar[i].name] = ar[i].value ; 461 return query ; 462 } 463 }); 466 464 467 465 jQuery(document).ready(function() { 466 468 467 469 468 jQuery(".ecinputwrap input[type='text']").each(function(index, element) … … 479 478 return true ; 480 479 } 481 ); 480 ); 481 var form0 = jQuery('.ec-target'); 482 var form = jQuery('.ec-target').has("input[name='autoSubmit']"); 483 var item = form.find('.autoSubmit'); 484 if (item.length && item.get(0).value.length) 485 // trigger an auto submit of form with supplied verification code. 486 ecam.submit(item, [], "verify"); 487 482 488 /** 483 * when the use updates an input field, copy it to any other input fields489 * when the user updates an input field, copy it to any other input fields 484 490 * of the same name to reduce rekeying. 485 491 */ 486 492 /* 487 493 jQuery(".ecinputwrap input[type='text']").change( 488 494 … … 500 506 } 501 507 ); 508 */ 502 509 }); 510 511
Note: See TracChangeset
for help on using the changeset viewer.