1function smartFormGenerator(options){ 2 this.client_form_options=options.client_form_options; 3 this.Extensions=[]; 4 RedNaoEventManager.Publish('GetClientExtension',{Generator:this,Extensions:this.Extensions}); 5 this.MultipleStepsManager=null; 6 this.RedirectUrl=''; 7 this.InitializeConditionalLogic(); 8 this.SetDefaultIfUndefined('InvalidInputMessage','*Please fill all the required fields'); 9 this.SubmittingThroughIframe=false; 10 11 this.JavascriptCodes=[]; 12 if(typeof this.client_form_options.JavascriptCode!='undefined') 13 { 14 if(typeof this.client_form_options.JavascriptCode=='string') 15 this.client_form_options.JavaScriptCode=[{ 16 JavascriptCode:this.client_form_options.JavascriptCode, 17 ActionType:'customjs' 18 }]; 19 } 20 21 if(typeof this.client_form_options.ToolTipPosition=='undefined') 22 this.client_form_options.ToolTipPosition='none'; 23 24 var i; 25 for(i=0;i<this.client_form_options.JavascriptCode.length;i++) 26 { 27 try{ 28 this.JavascriptCodes.push(eval(this.client_form_options.JavascriptCode[i].JavascriptCode)()); 29 30 }catch(exception) 31 { 32 33 } 34 } 35 36 if(typeof this.client_form_options.Theme!='undefined'&&this.client_form_options.Theme=='material'){ 37 this.Theme='material'; 38 rnJQuery.RNLoadLibrary([smartFormsPath+'js/bootstrap/material.min.js'],[smartFormsPath+'css/bootstrap/bootstrap-material-scoped.css'],function(){ 39 40 }); 41 }else 42 this.Theme='basic'; 43 44 45 this.form_id=options.form_id; 46 this.options=options; 47 this.RedNaoFormElements=[]; 48 this.FormElements=[]; 49 var elementOptions=options.elements; 50 this.client_form_options.DocumentWidth=rnJQuery(window).width(); 51 for(i=0;i<elementOptions.length;i++) 52 { 53 elementOptions[i].FormId=this.form_id; 54 var element=sfRedNaoCreateFormElementByName(elementOptions[i].ClassName,elementOptions[i]); 55 element.FormId=this.form_id; 56 element.Generator=this; 57 element.InvalidInputMessage=RedNaoEscapeHtml(this.client_form_options.InvalidInputMessage); 58 element.ClientOptions=this.client_form_options; 59 this.RedNaoFormElements.push(element); 60 this.FormElements.push(element); 61 } 62 63 for(i=0;i<this.FormElements.length;i++) 64 { 65 this.FormElements[i].InitializeFieldLinking(this.FormElements); 66 } 67 68 this.containerName=options.container; 69 if(typeof this.client_form_options.CSS!='undefined') 70 this.CreateCSS(); 71 if(this.client_form_options.redirect_to_cb=="y"&&typeof this.client_form_options.redirect_to=='string') 72 { 73 this.client_form_options.redirect_to={ 74 URL:this.client_form_options.redirect_to, 75 RCSettings:{ 76 Redirect:'always', 77 ConditionSettings:[] 78 } 79 } 80 } 81 this.CreateForm(); 82 83} 84 85smartFormGenerator.prototype.GetCurrentData=function() 86{ 87 return RedNaoFormulaManagerVar.Data; 88}; 89 90smartFormGenerator.prototype.GetFormId=function() 91{ 92 if(typeof this.FormId=='undefined') 93 return 0; 94 return this.FormId; 95}; 96 97smartFormGenerator.prototype.CreateCSS=function() 98{ 99 if(SmartFormsIsIE8OrEarlier()) 100 return; 101 102 var $style=rnJQuery("<style type='text/css'></style>"); 103 $style.append(this.client_form_options.CSS); 104 rnJQuery("head").append($style); 105}; 106 107smartFormGenerator.prototype.InitializeConditionalLogic=function() 108{ 109 if(typeof this.client_form_options.Conditions !='undefined') 110 { 111 for(var i=0;i<this.client_form_options.Conditions.length;i++) 112 { 113 var condition=this.client_form_options.Conditions[i]; 114 this.client_form_options.Conditions[i]=SmartFormsGetConditionalHandlerByType(condition.Type,condition); 115 } 116 }else 117 this.client_form_options.Conditions=[]; 118}; 119 120smartFormGenerator.prototype.SetDefaultIfUndefined=function(propertyName,defaultValue) 121{ 122 if(typeof this.client_form_options[propertyName]=='undefined') 123 this.client_form_options[propertyName]=defaultValue; 124 if(typeof this.client_form_options.CaptchaVersion=='undefined') 125 this.client_form_options.CaptchaVersion='1'; 126}; 127 128smartFormGenerator.prototype.CreateForm=function(){ 129 SmartFormsModules.ContainerManager.ClearContainer(this.options.form_id); 130 var container=this.GetRootContainer(); 131 container.empty(); 132 var themeStyle=this.Theme=='material'?'rnbsm':''; 133 this.JQueryForm=rnJQuery('<form id="sf'+this.form_id+'" class="form-horizontal '+themeStyle+'" ></form>'); 134 this.JQueryForm.css('visibility','hidden'); 135 container.append(this.JQueryForm); 136 137 this.JQueryForm.parent().removeClass('compact').removeClass('exptop').removeClass('expleft'); 138 var labelLayout='auto'; 139 if(typeof this.client_form_options.LabelLayout!='undefined') 140 labelLayout=this.client_form_options.LabelLayout; 141 if(this.JQueryForm.width()<=500) 142 this.JQueryForm.parent().addClass('compact'); 143 if(labelLayout=='top') 144 this.JQueryForm.parent().addClass('exptop'); 145 if(labelLayout=='left') 146 this.JQueryForm.parent().addClass('expleft'); 147 148 var i; 149 for(i=0;i<this.RedNaoFormElements.length;i++) 150 { 151 this.RedNaoFormElements[i].AppendElementToContainer(this.JQueryForm); 152 } 153 this.JQueryForm.append('<div class="sfClearFloat"></div>'); 154 155 156 157 158 159 var self=this; 160 //if(RedNaoGetValueOrNull(this.client_form_options.Campaign)) 161 // this.CreatePayPalHiddenFields(); 162 163 this.SubmittingRedNaoDonationForm='n'; 164 RedNaoEventManager.Publish('FormCreated',{Generator:this}); 165 this.JQueryForm.submit(function(e){ 166 if(self.SubmittingRedNaoDonationForm=='y') 167 { 168 self.SubmittingRedNaoDonationForm='n'; 169 return; 170 } 171 172 if(self.SubmittingThroughIframe==true) 173 { 174 self.SubmittingThroughIframe=false; 175 return; 176 } 177 178 e.preventDefault(); 179 e.stopPropagation(); 180 self.SaveForm(); 181 }); 182 183 184 185 if(typeof this.client_form_options.FormType!='undefined'&&this.client_form_options.FormType=='sec') 186 { 187 rnJQuery.RNLoadLibrary([smartFormsPath+'js/utilities/fuelux/wizard.js' ,smartFormsPath+'js/multiple_steps/multiple_steps_base.js'],[smartFormsPath+'js/utilities/fuelux/fuelux.css'],function(){ 188 self.InitializeMultipleSteps(); 189 self.FormLoaded(); 190 }); 191 }else 192 { 193 this.FormLoaded(); 194 } 195 196}; 197 198smartFormGenerator.prototype.FireExtensionMethod=function(methodName,args) 199{ 200 var result=undefined; 201 for(var i=0;i<this.Extensions.length;i++) 202 { 203 if(typeof this.Extensions[i][methodName]!='undefined') 204 { 205 var auxResult = this.Extensions[i][methodName](this, args); 206 if (typeof auxResult != 'undefined') 207 result = auxResult; 208 } 209 } 210 211 return result; 212}; 213 214smartFormGenerator.prototype.FormLoaded=function() 215{ 216 this.FireExtensionMethod('BeforeInitializingFieldData'); 217 var i; 218 for(i=0;i<this.RedNaoFormElements.length;i++) 219 { 220 if(this.RedNaoFormElements[i].StoresInformation()) 221 RedNaoFormulaManagerVar.SetFormulaValue(this.RedNaoFormElements[i],this.RedNaoFormElements[i].Id,this.RedNaoFormElements[i].GetValueString()) 222 } 223 224 RedNaoFormulaManagerVar.RefreshAllFormulas(); 225 if(RedNaoGetValueOrNull(this.client_form_options.Campaign)) 226 this.CreatePayPalHiddenFields(); 227 this.ExecuteConditionalLogicInAllFields(); 228 this.JQueryForm.css('visibility', 'visible'); 229 try{ 230 for(i=0;i<this.JavascriptCodes.length;i++) 231 this.JavascriptCodes[i].AfterFormLoaded(this); 232 }catch(exception) 233 { 234 235 } 236}; 237 238smartFormGenerator.prototype.ExecuteConditionalLogicInAllFields=function() 239{ 240 for(var i=0;i<this.client_form_options.Conditions.length;i++) 241 { 242 this.client_form_options.Conditions[i].Initialize(this,RedNaoFormulaManagerVar.Data); 243 } 244}; 245 246smartFormGenerator.prototype.InitializeMultipleSteps=function() 247{ 248 this.MultipleStepsManager=new SfMultipleStepsBase(this.client_form_options.SplitSteps,this.JQueryForm,this.FormElements,this); 249 this.MultipleStepsManager.Generate(); 250}; 251 252smartFormGenerator.prototype.CreatePayPalHiddenFields=function() 253{ 254 if(smartDonationsSandbox=='y') 255 this.JQueryForm.attr('action','https://www.sandbox.paypal.com/cgi-bin/webscr'); 256 else 257 this.JQueryForm.attr('action','https://www.paypal.com/cgi-bin/webscr'); 258 this.JQueryForm.attr('method','POST'); 259 this.JQueryForm.attr('target','_self'); 260 261 var target="_self"; 262 if(window.self !== window.top) 263 target="_parent"; 264 this.JQueryForm.attr('target',target); 265 266 var type="_donations"; 267 var options=this.client_form_options; 268 if(typeof options.PayPalType!='undefined'&&options.PayPalType=='payment') 269 type='_xclick'; 270 this.JQueryForm.append(' <input type="hidden" name="cmd" class="smartDonationsPaypalCommand" value="'+type+'">\ 271 <input type="hidden" name="item_name" value="'+options.PayPalDescription+'">\ 272 <input type="hidden" name="business" value="'+options.PayPalEmail+'">\ 273 <input type="hidden" name="lc" value="US"> \
274 <input type="hidden" name="no_note" value="0"> \ 275 <input type="hidden" name="currency_code" value="'+options.PayPalCurrency+'"> \ 276 <input type="hidden" name="bn" value="Rednao_SP">\ 277 <input type="hidden" name="custom" value=type=form&campaign_id='+options.Campaign+'&formId='+this.options.form_id+'>\ 278 <input type="hidden" name="amount" class="amountToDonate" value="0">\ 279 <input name="bn" value="Rednao_SP" type="hidden">\ 280 <input type="hidden" name="notify_url" value="'+smartDonationsRootPath+'ipn/rednao_paypal_ipn.php">' 281 ); 282 283 if(RedNaoGetValueOrEmpty(this.client_form_options.redirect_to_cb)=="y") 284 this.JQueryForm.append('<input type="hidden" name="return" value="">'); 285 286}; 287 288smartFormGenerator.prototype.GenerationCompleted=function() 289{ 290 var form=this.GetRootContainer().find('form'); 291 form.addClass('formelements').attr('id','redNaoElementlist'); 292 293 for(var i=0;i<this.FormElements.length;i++) 294 { 295 this.FormElements[i].AppendElementToContainer(form); 296 } 297 298 var self=this; 299 form.find('.redNaoDonationButton').click(function() 300 { 301 302 try{ 303 304 self.SaveForm(); 305 306 }catch(error) 307 { 308 309 310 }finally{ 311 //noinspection ReturnInsideFinallyBlockJS 312 return false; 313 } 314 } 315 ); 316 317}; 318 319smartFormGenerator.prototype.GenerateDefaultStyle=function() 320{ 321 this.styles.formelements="width:600px;padding:10px;margin:0px;"; 322}; 323 324 325smartFormGenerator.prototype.SaveForm=function() 326{ 327 var formValues={}; 328 var formIsValid=true; 329 var amount=0; 330 331 this.GetRootContainer().find('.redNaoValidationMessage').remove(); 332 this.GetRootContainer().find('.redNaoSubmitButton').removeClass('btn-danger'); 333 this.GetRootContainer().find('.redNaoInputText,.redNaoRealCheckBox,.redNaoInputRadio,.redNaoInputCheckBox,.redNaoSelect,.redNaoTextArea,.redNaoInvalid,.has-error').removeClass('redNaoInvalid').removeClass('has-error'); 334 var isUsingAFileUploader=false; 335 336 var self=this; 337 var afterValidation=function(){ 338 var firstInvalidField=null; 339 for(var i=0;i<self.FormElements.length;i++) 340 { 341 self.FormElements[i].ClearInvalidStyle(); 342 if(self.FormElements[i].Options.ClassName=="sfFileUpload"||self.FormElements[i].Options.ClassName=="rednaoimageupload") 343 isUsingAFileUploader=true; 344 345 if(self.FormElements[i].Options.ClassName=='rednaorepeater') 346 { 347 for(var t=0;t<self.FormElements[i].Fields.length;t++) 348 { 349 if(self.FormElements[i].Fields[t].Options.ClassName=='sfFileUpload'||self.FormElements[i].Fields[t].Options.ClassName=='rednaoimageupload') 350 isUsingAFileUploader=true; 351 } 352 } 353 354 if(!self.FormElements[i].IsIgnored()&&!self.FormElements[i].IsValid()) 355 { 356 formIsValid=false; 357 if(firstInvalidField==null) 358 firstInvalidField=self.FormElements[i]; 359 continue; 360 } 361 if(self.FormElements[i].StoresInformation()) 362 { 363 var value=self.FormElements[i].GetValueString(); 364 amount+=self.FormElements[i].amount; 365 formValues[self.FormElements[i].Id]=value; 366 } 367 } 368 if(!formIsValid) 369 { 370 //self.GetRootContainer().prepend('<p class="redNaoValidationMessage" style="margin:0;padding: 0; font-style: italic; color:red;font-family:Arial,serif;font-size:12px;">'+RedNaoEscapeHtml(self.client_form_options.InvalidInputMessage)+'</p>'); 371 self.GetRootContainer().find('.redNaoSubmitButton').addClass('btn-danger'); 372 self.ScrollTo(firstInvalidField.JQueryElement); 373 return; 374 } 375 376 377 if(formValues.length>0) 378 formValues=formValues.substr(1); 379 380 try{ 381 382 for(i=0;i<self.JavascriptCodes.length;i++) 383 { 384 if(typeof self.JavascriptCodes[i].BeforeFormSubmit!='undefined'&&(self.JavascriptCodes[i].BeforeFormSubmit(formValues,self.FormElements)==false)) 385 return; 386 } 387 388 }catch(exception) 389 { 390 391 } 392 393 self.ProcessRedirectUrl().then(function(result){ 394 395 self.RedirectUrl=result; 396 if(RedNaoGetValueOrNull(self.client_form_options.Campaign)){ 397 if(typeof self.client_form_options.PayPalCondition=='undefined'||typeof self.client_form_options.PayPalCondition.DonationSettings=='undefined'||self.client_form_options.PayPalCondition.DonationSettings.RequestPayment=='always') 398 { 399 self.SendToSmartDonations(formValues, isUsingAFileUploader); 400 } 401 else 402 { 403 var calculation = RedNaoEventManager.Publish('CalculateCondition', { 404 Condition: self.client_form_options.PayPalCondition.DonationSettings.ConditionSettings, 405 Values: self.GetCurrentData() 406 }); 407 calculation.then(function (result) { 408 if (result) 409 self.SendToSmartDonations(formValues, isUsingAFileUploader); 410 else 411 self.PreSendToSmartForms(formValues, isUsingAFileUploader); 412 }); 413 } 414 } 415 416 else 417 self.PreSendToSmartForms(formValues,isUsingAFileUploader); 418 419 try{ 420 rnJQuery('body, input[type="submit"]').addClass('redNaoWait'); 421 self.JQueryForm.find('input[type="submit"],.redNaoMSButton').attr('disabled','disabled'); 422 }catch(exception) 423 { 424 425 } 426 }); 427 428 429 }; 430 431 var args={Generator:this,Promises:[]}; 432 RedNaoEventManager.Publish('BeforeValidatingForm',args); 433 if(args.Promises.length>0) 434 Promise.all(args.Promises).then(afterValidation); 435 else 436 afterValidation(); 437}; 438 439smartFormGenerator.prototype.ScrollTo=function($elementToScrollTo) 440{ 441 var scroll = $elementToScrollTo.offset(); 442 if (window.pageYOffset>scroll.top) 443 rnJQuery('html, body').animate({scrollTop: scroll.top-50}, 200); 444}; 445 446smartFormGenerator.prototype.PreSendToSmartForms=function(formValues,isUsingAFileUploader) 447{ 448 var handled=this.FireExtensionMethod('BeforeSendingToSmartFormsForm',formValues); 449 var self=this; 450 if(typeof handled!='undefined'&&handled instanceof Promise) 451 { 452 RedNaoEventManager.Publish('FormSubmitted',{Generator:self}); 453 handled.then(function(result){ 454 if(result) 455 self.SendToSmartForms(formValues,isUsingAFileUploader); 456 else 457 RedNaoEventManager.Publish('FormSubmittedCompleted',{Generator:self}); 458 }); 459 }else{ 460 self.SendToSmartForms(formValues,isUsingAFileUploader); 461 } 462 463 464}; 465 466smartFormGenerator.prototype.SendToSmartForms=function(formValues,isUsingAFileUploader) 467{ 468 469 var data={ 470 form_id:this.form_id, 471 action:"rednao_smart_forms_save_form_values", 472 formString:JSON.stringify(formValues), 473 requestUrl:document.URL 474 }; 475 476 477 478 if(this.client_form_options.UsesCaptcha=='y') 479 { 480 if(this.client_form_options.CaptchaVersion=='1') 481 data.captcha={ 482 version:1, 483 challenge:this.JQueryForm.find('[name="recaptcha_challenge_field"]').val(), 484 response:this.JQueryForm.find('[name="recaptcha_response_field"]').val() 485 }; 486 else{ 487 var captchaId=""; 488 for(var i=0;i<this.FormElements.length;i++) 489 if(this.FormElements[i].Id=="captcha2") 490 captchaId=this.FormElements[i].captchaId; 491 data.captcha={ 492 version:2, 493 response:grecaptcha.getResponse(captchaId) 494 } 495 } 496 497 498 } 499 500 if(isUsingAFileUploader) 501 this.SendFilesWithForm(data,formValues); 502 else 503 { 504 var self=this; 505 //noinspection JSUnusedLocalSymbols 506 RedNaoEventManager.Publish('FormSubmitted',{Generator:this}); 507 rnJQuery.ajax({ 508 type:'POST', 509 url:ajaxurl, 510 dataType:"json", 511 data:data, 512 success:function(result){self.SaveCompleted(result,formValues)}, 513 error:function(result){ 514 rnJQuery('body, input[type="submit"]').removeClass('redNaoWait'); 515 self.JQueryForm.find('input[type="submit"],.redNaoMSButton').removeAttr('disabled'); 516 alert('An error occurred, please try again later');} 517 }); 518 } 519}; 520 521smartFormGenerator.prototype.SendFilesWithForm=function(data,formValues) 522{ 523 data=JSON.stringify(data); 524 rnJQuery('#sfTemporalIFrame').remove(); 525 rnJQuery('body').append('<iframe id="sfTemporalIFrame" name="sfTemporalIFrame"></iframe>'); 526 var self=this; 527 RedNaoEventManager.Publish('FormSubmitted',{Generator:this}); 528 rnJQuery('#sfTemporalIFrame').on('load',function() 529 { 530 var response; 531 if (this.contentDocument) { 532 response = this.contentDocument.body.innerText; 533 } else { 534 response = this.contentWindow.document.body.innerText; 535 } 536 537 var regex=/{.*}/g; 538 var match=regex.exec(response); 539 if(match!=null) 540 response=match[0]; 541 542 self.SaveCompleted(rnJQuery.parseJSON(response),formValues); 543 }); 544 this.JQueryForm.attr('method','post'); 545 this.JQueryForm.attr('enctype','multipart/form-data'); 546 this.JQueryForm.attr('target','sfTemporalIFrame'); 547 this.JQueryForm.attr('action',ajaxurl); 548 var dataField=rnJQuery('<input type="hidden" name="data"/> '); 549 dataField.val(data); 550 this.JQueryForm.append(dataField); 551 this.JQueryForm.append('<input type="hidden" name="action" value="rednao_smart_forms_send_files"/>'); 552 this.SubmittingThroughIframe=true; 553 this.JQueryForm.submit(); 554 555}; 556 557//noinspection JSUnusedLocalSymbols 558smartFormGenerator.prototype.SendToSmartDonations=function(formValues,isUsingAFileUploader) 559{ 560 this.JQueryForm.find('input[name="return"]').val(this.RedirectUrl); 561 if(RedNaoPathExists(this.client_form_options,'Formulas.DonationFormula')) 562 { 563 //noinspection JSUnresolvedVariable 564 var formula=new RedNaoFormula(null,this.client_form_options.Formulas.DonationFormula); 565 var donationAmount=formula.GetValueFromFormula(RedNaoFormulaManagerVar.Data); 566 var self=this; 567 if(donationAmount instanceof Promise) 568 donationAmount.then(function(result){self.ProcessDonation(formValues,isUsingAFileUploader,result)}); 569 else 570 self.ProcessDonation(formValues,isUsingAFileUploader,donationAmount); 571 572 573 574 } 575 576 577 578}; 579 580smartFormGenerator.prototype.ProcessDonation=function(formValues,isUsingAFileUploader,donationAmount){ 581 if(donationAmount<=0) 582 { 583 this.GetRootContainer().prepend('<p class="redNaoValidationMessage" style="margin:0;padding: 0; font-style: italic; color:red;font-family:Arial,serif;font-size:12px;">*The donation amount should be greater than zero</p>'); 584 return; 585 } 586 587 var self=this; 588 589 590 var data={ 591 action:"rednao_smart_donations_save_form_values", 592 emailToNotify:this.emailToNotify, 593 formString:JSON.stringify(formValues) 594 }; 595 596 var donationFormSaveComplete=function(data){ 597 if(data.status=="success") 598 { 599 self.JQueryForm.find('.amountToDonate').val(donationAmount); 600 self.JQueryForm.find('input[name=custom]').val(encodeURI('type=form&campaign_id='+self.client_form_options.Campaign+"&formId="+data.randomString+'&sformid='+self.form_id)); 601 if(self.JQueryForm.find('.redNaoRecurrence').length>0&&self.JQueryForm.find('.redNaoRecurrence').find(':selected').val()!='OT') 602 { 603 self.JQueryForm.find('.amountToDonate').attr('name','a3'); 604 self.JQueryForm.find('.smartDonationsPaypalCommand').val('_xclick-subscriptions'); 605 self.JQueryForm.append('<input type="hidden" class="redNaoRecurrenceField" name="src" value="1"><input type="hidden" class="redNaoRecurrenceField" name="p3" value="1"><input type="hidden" name="t3" value="'+self.JQueryForm.find('.redNaoRecurrence').find(':selected').val()+'">'); 606 } 607 608 609 self.SubmittingRedNaoDonationForm='y'; 610 self.JQueryForm.submit(); 611 612 613 }else 614 { 615 alert("An error occured, please try again"); 616 } 617 }; 618 619 RedNaoEventManager.Publish('FormSubmitted',{Generator:this}); 620 if(isUsingAFileUploader) 621 { 622 var previousAction=this.JQueryForm.attr('action'); 623 var previousEncoding= this.JQueryForm.attr('enctype'); 624 var previousTarget= this.JQueryForm.attr('target'); 625 this.JQueryForm.attr('method','post'); 626 this.JQueryForm.attr('enctype','multipart/form-data'); 627 this.JQueryForm.attr('target','sfTemporalIFrame'); 628 this.JQueryForm.attr('action',ajaxurl); 629 this.JQueryForm.append('<input type="hidden" name="action" value="rednao_smart_donations_save_form_values"/>'); 630 631 632 rnJQuery('#sfTemporalIFrame').remove(); 633 rnJQuery('body').append('<iframe id="sfTemporalIFrame" name="sfTemporalIFrame"></iframe>'); 634 rnJQuery('#sfTemporalIFrame').on('load',function() 635 { 636 self.JQueryForm.attr('action',previousAction); 637 self.JQueryForm.attr('enctype',previousEncoding); 638 self.JQueryForm.attr('target',previousTarget); 639 var response; 640 if (this.contentDocument) { 641 response = this.contentDocument.body.innerHTML; 642 } else { 643 response = this.contentWindow.document.body.innerHTML; 644 } 645 646 try{ 647 response=JSON.parse(response); 648 }catch(e){ 649 650 } 651 donationFormSaveComplete(response); 652 }); 653 var dataField=rnJQuery('<input type="hidden" name="formString"/> '); 654 dataField.val(data.formString); 655 this.JQueryForm.append(dataField); 656 657 this.SubmittingThroughIframe=true; 658 this.JQueryForm.submit(); 659 }else 660 rnJQuery.post(ajaxurl,data,donationFormSaveComplete,"json"); 661} 662 663smartFormGenerator.prototype.SaveCompleted=function(result,formValues){ 664 RedNaoEventManager.Publish('FormSubmittedCompleted',{Generator:this}); 665 rnJQuery('body, input[type="submit"]').removeClass('redNaoWait'); 666 this.JQueryForm.find('input[type="submit"],.redNaoMSButton').removeAttr('disabled'); 667 if(this.RedirectUrl.search('@@formid')>=0) 668 this.RedirectUrl=this.RedirectUrl.replace('@@formid',result.insertedValues._formid); 669 670 if(typeof result.AdditionalActions!='undefined') 671 { 672 for(var i=0;i<result.AdditionalActions.length;i++) 673 { 674 if(result.AdditionalActions[i].Action=="RedirectTo") 675 { 676 window.location=result.AdditionalActions[0].Value; 677 return; 678 } 679 680 if(result.AdditionalActions[i].Action=="ShowMessage") 681 { 682 alert(result.AdditionalActions[i].Value.Message); 683 return; 684 } 685 686 687 var result=RedNaoEventManager.Publish('SubmitAction',{'Action':result.AdditionalActions[i],Generator:this}); 688 if(result===false) 689 return; 690 691 692 } 693 } 694 695 if(typeof result.refreshCaptcha!='undefined'&&result.refreshCaptcha=='y') 696 { 697 alert(result.message); 698 Recaptcha.reload(); 699 return; 700 } 701 702 if(result.success=='y') 703 this.FireExtensionMethod('FormSubmissionCompleted'); 704 705 if((RedNaoGetValueOrEmpty(this.client_form_options.alert_message_cb)!='y'&&RedNaoGetValueOrEmpty(this.client_form_options.redirect_to_cb)!='y')||result.success=='n') 706 { 707 alert(result.message); 708 if(RedNaoGetValueOrEmpty(this.client_form_options.DontClearForm)!='y') 709 this.CreateForm(); 710 return; 711 } 712 713 if(RedNaoGetValueOrEmpty(this.client_form_options.alert_message_cb)=='y') 714 alert(this.client_form_options.alert_message); 715 716 if(RedNaoGetValueOrEmpty(this.client_form_options.Do
716ntClearForm)!='y') 717 this.CreateForm(); 718 719 if(RedNaoGetValueOrEmpty(this.client_form_options.redirect_to_cb)=="y") 720 { 721 window.location=this.RedirectUrl; 722 } 723 724 725}; 726 727smartFormGenerator.prototype.GetUrl=function(redirectOptions,index,formValues){ 728 var self=this; 729 return new Promise(function(resolve){ 730 if(index>=redirectOptions.length) 731 resolve(''); 732 733 734 735 if(redirectOptions[index].RCSettings.Redirect=='always') 736 { 737 resolve(redirectOptions[index].URL); 738 }else{ 739 740 var processCalculation=function(calculation){ 741 if(calculation) 742 { 743 resolve(redirectOptions[index].URL); 744 }else{ 745 self.GetUrl(redirectOptions,index+1,formValues).then(function(result){resolve(result)}); 746 } 747 }; 748 749 var calculation=RedNaoEventManager.Publish('CalculateCondition',{Condition:redirectOptions[index].RCSettings.ConditionSettings ,Values:formValues}); 750 if(calculation instanceof Promise) 751 { 752 calculation.then(function(result){ 753 processCalculation(result); 754 }); 755 }else 756 processCalculation(calculation); 757 758 } 759 760 761 762 }); 763 764}; 765 766smartFormGenerator.prototype.ProcessRedirectUrl=function() 767{ 768 var self=this; 769 return new Promise(function(resolve){ 770 if(self.client_form_options.redirect_to_cb=='n') 771 resolve(''); 772 var redirectOptions=self.client_form_options.redirect_to; 773 var formValues=self.GetCurrentData(); 774 var i; 775 var url=''; 776 var redirectToUse=null; 777 778 779 self.GetUrl(redirectOptions,0,formValues).then(function(url) { 780 781 var regEx = /{([^}]+)}/g; 782 var matches; 783 784 while (matches = regEx.exec(url)) 785 { 786 regEx.lastIndex = 0; 787 for (i = 0; i < matches.length; i++) 788 { 789 if (matches[i][0] == '{') 790 continue; 791 var value = ''; 792 if (typeof formValues[matches[i]] != 'undefined') 793 { 794 value = formValues[matches[i]].label; 795 for (var t = 0; t < self.RedNaoFormElements.length; t++) 796 if (matches[i] == self.RedNaoFormElements[t].Id) 797 switch(self.RedNaoFormElements[t].Options.ClassName){ 798 case 'rednaodatepicker': 799 value=formValues[matches[i]].value; 800 break; 801 case "rednaoaddress": 802 value=JSON.stringify(formValues[matches[i]].OriginalValues); 803 break; 804 } 805 806 } 807 if (matches[i] == '_formid') 808 url = url.replace('{' + matches[i] + '}', '@@formid'); 809 else 810 url = url.replace('{' + matches[i] + '}', encodeURIComponent(value)); 811 } 812 } 813 814 resolve(url); 815 }); 816 }); 817}; 818 819smartFormGenerator.prototype.GetRootContainer=function() 820{ 821 return rnJQuery('#'+this.containerName); 822}; 823 824rnJQuery(function(){ 825 if( window.smartFormsItemsToLoad) 826 for(var i=0;i< window.smartFormsItemsToLoad.length;i++) 827 smartFormsLoadForm(window.smartFormsItemsToLoad[i]); 828}); 829 830 831var smartFormsLoadedItems=[]; 832 833function smartFormsLoadForm(options) 834{ 835 var form=new smartFormGenerator(options); 836 smartFormsLoadedItems.push(form); 837 838 839}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.