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 this.form_id=options.form_id; 37 this.options=options; 38 this.RedNaoFormElements=[]; 39 this.FormElements=[]; 40 var elementOptions=options.elements; 41 this.client_form_options.DocumentWidth=rnJQuery(window).width(); 42 for(i=0;i<elementOptions.length;i++) 43 { 44 var element=sfRedNaoCreateFormElementByName(elementOptions[i].ClassName,elementOptions[i]); 45 element.FormId=this.form_id; 46 element.InvalidInputMessage=RedNaoEscapeHtml(this.client_form_options.InvalidInputMessage); 47 element.ClientOptions=this.client_form_options; 48 this.RedNaoFormElements.push(element); 49 this.FormElements.push(element); 50 } 51 52 this.containerName=options.container; 53 if(typeof this.client_form_options.CSS!='undefined') 54 this.CreateCSS(); 55 if(this.client_form_options.redirect_to_cb=="y"&&typeof this.client_form_options.redirect_to=='string') 56 { 57 this.client_form_options.redirect_to={ 58 URL:this.client_form_options.redirect_to, 59 RCSettings:{ 60 Redirect:'always', 61 ConditionSettings:[] 62 } 63 } 64 } 65 this.CreateForm(); 66 67} 68 69smartFormGenerator.prototype.GetCurrentData=function() 70{ 71 return RedNaoFormulaManagerVar.Data; 72}; 73 74smartFormGenerator.prototype.CreateCSS=function() 75{ 76 if(SmartFormsIsIE8OrEarlier()) 77 return; 78 79 var $style=rnJQuery("<style type='text/css'></style>"); 80 $style.append(this.client_form_options.CSS); 81 rnJQuery("head").append($style); 82}; 83 84smartFormGenerator.prototype.InitializeConditionalLogic=function() 85{ 86 if(typeof this.client_form_options.Conditions !='undefined') 87 { 88 for(var i=0;i<this.client_form_options.Conditions.length;i++) 89 { 90 var condition=this.client_form_options.Conditions[i]; 91 this.client_form_options.Conditions[i]=SmartFormsGetConditionalHandlerByType(condition.Type,condition); 92 } 93 }else 94 this.client_form_options.Conditions=[]; 95}; 96 97smartFormGenerator.prototype.SetDefaultIfUndefined=function(propertyName,defaultValue) 98{ 99 if(typeof this.client_form_options[propertyName]=='undefined') 100 this.client_form_options[propertyName]=defaultValue; 101}; 102 103smartFormGenerator.prototype.CreateForm=function(){ 104 var container=this.GetRootContainer(); 105 container.empty(); 106 this.JQueryForm=rnJQuery('<form id="sf'+this.form_id+'" class="form-horizontal" ></form>'); 107 this.JQueryForm.css('visibility','hidden'); 108 container.append(this.JQueryForm); 109 110 var i; 111 for(i=0;i<this.RedNaoFormElements.length;i++) 112 { 113 this.RedNaoFormElements[i].AppendElementToContainer(this.JQueryForm); 114 } 115 this.JQueryForm.append('<div class="sfClearFloat"></div>'); 116 117 118 119 120 121 var self=this; 122 //if(RedNaoGetValueOrNull(this.client_form_options.Campaign)) 123 // this.CreatePayPalHiddenFields(); 124 125 this.SubmittingRedNaoDonationForm='n'; 126 this.JQueryForm.submit(function(e){ 127 if(self.SubmittingRedNaoDonationForm=='y') 128 { 129 self.SubmittingRedNaoDonationForm='n'; 130 return; 131 } 132 133 if(self.SubmittingThroughIframe==true) 134 { 135 self.SubmittingThroughIframe=false; 136 return; 137 } 138 139 e.preventDefault(); 140 e.stopPropagation(); 141 self.SaveForm(); 142 }); 143 144 145 146 if(typeof this.client_form_options.FormType!='undefined'&&this.client_form_options.FormType=='sec') 147 { 148 rnJQuery.RNLoadLibrary([smartFormsPath+'js/utilities/fuelux/wizard.js' ,smartFormsPath+'js/multiple_steps/multiple_steps_base.js'],[smartFormsPath+'js/utilities/fuelux/fuelux.css'],function(){ 149 self.InitializeMultipleSteps(); 150 self.FormLoaded(); 151 }); 152 }else 153 { 154 if(this.JQueryForm.width()<=500) 155 this.JQueryForm.parent().addClass('compact'); 156 this.FormLoaded(); 157 } 158 159}; 160 161smartFormGenerator.prototype.FireExtensionMethod=function(methodName) 162{ 163 for(var i=0;i<this.Extensions.length;i++) 164 this.Extensions[i][methodName](); 165}; 166 167smartFormGenerator.prototype.FormLoaded=function() 168{ 169 this.FireExtensionMethod('BeforeInitializingFieldData'); 170 var i; 171 for(i=0;i<this.RedNaoFormElements.length;i++) 172 { 173 if(this.RedNaoFormElements[i].StoresInformation()) 174 RedNaoFormulaManagerVar.SetFormulaValue(this.RedNaoFormElements[i].Id,this.RedNaoFormElements[i].GetValueString()) 175 } 176 177 RedNaoFormulaManagerVar.RefreshAllFormulas(); 178 if(RedNaoGetValueOrNull(this.client_form_options.Campaign)) 179 this.CreatePayPalHiddenFields(); 180 this.ExecuteConditionalLogicInAllFields(); 181 this.JQueryForm.css('visibility', 'visible'); 182 try{ 183 for(i=0;i<this.JavascriptCodes.length;i++) 184 this.JavascriptCodes[i].AfterFormLoaded(); 185 }catch(exception) 186 { 187 188 } 189}; 190 191smartFormGenerator.prototype.ExecuteConditionalLogicInAllFields=function() 192{ 193 for(i=0;i<this.client_form_options.Conditions.length;i++) 194 { 195 this.client_form_options.Conditions[i].Initialize(this,RedNaoFormulaManagerVar.Data); 196 } 197}; 198 199smartFormGenerator.prototype.InitializeMultipleSteps=function() 200{ 201 this.MultipleStepsManager=new SfMultipleStepsBase(this.client_form_options.SplitSteps,this.JQueryForm,this.FormElements,this); 202 this.MultipleStepsManager.Generate(); 203}; 204 205smartFormGenerator.prototype.CreatePayPalHiddenFields=function() 206{ 207 if(smartDonationsSandbox=='y') 208 this.JQueryForm.attr('action','https://www.sandbox.paypal.com/cgi-bin/webscr'); 209 else 210 this.JQueryForm.attr('action','https://www.paypal.com/cgi-bin/webscr'); 211 this.JQueryForm.attr('method','POST'); 212 this.JQueryForm.attr('target','_self'); 213 214 var options=this.client_form_options; 215 this.JQueryForm.append(' <input type="hidden" name="cmd" class="smartDonationsPaypalCommand" value="_donations">\ 216 <input type="hidden" name="item_name" value="'+options.PayPalDescription+'">\ 217 <input type="hidden" name="business" value="'+options.PayPalEmail+'">\ 218 <input type="hidden" name="lc" value="US"> \
219 <input type="hidden" name="no_note" value="0"> \ 220 <input type="hidden" name="currency_code" value="'+options.PayPalCurrency+'"> \ 221 <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHostedGuest">\ 222 <input type="hidden" name="custom" value=type=form&campaign_id='+options.Campaign+'&formId='+this.options.form_id+'>\ 223 <input type="hidden" name="amount" class="amountToDonate" value="0">\ 224 <input name="bn" value="Rednao_SP" type="hidden">\ 225 <input type="hidden" name="notify_url" value="'+smartDonationsRootPath+'ipn/rednao_paypal_ipn.php">' 226 ); 227 228 if(RedNaoGetValueOrEmpty(this.client_form_options.redirect_to_cb)=="y") 229 this.JQueryForm.append('<input type="hidden" name="return" value="">'); 230 231}; 232 233smartFormGenerator.prototype.GenerationCompleted=function() 234{ 235 var form=this.GetRootContainer().find('form'); 236 form.addClass('formelements').attr('id','redNaoElementlist'); 237 238 for(var i=0;i<this.FormElements.length;i++) 239 { 240 this.FormElements[i].AppendElementToContainer(form); 241 } 242 243 var self=this; 244 form.find('.redNaoDonationButton').click(function() 245 { 246 247 try{ 248 249 self.SaveForm(); 250 251 }catch(error) 252 { 253 254 255 }finally{ 256 //noinspection ReturnInsideFinallyBlockJS 257 return false; 258 } 259 } 260 ); 261 262}; 263 264smartFormGenerator.prototype.GenerateDefaultStyle=function() 265{ 266 this.styles.formelements="width:600px;padding:10px;margin:0px;"; 267}; 268 269 270smartFormGenerator.prototype.SaveForm=function() 271{ 272 var formValues={}; 273 var formIsValid=true; 274 var amount=0; 275 276 this.GetRootContainer().find('.redNaoValidationMessage').remove(); 277 this.GetRootContainer().find('.redNaoSubmitButton').removeClass('btn-danger'); 278 this.GetRootContainer().find('.redNaoInputText,.redNaoRealCheckBox,.redNaoInputRadio,.redNaoInputCheckBox,.redNaoSelect,.redNaoTextArea,.redNaoInvalid,.has-error').removeClass('redNaoInvalid').removeClass('has-error'); 279 var isUsingAFileUploader=false; 280 RedNaoEventManager.Publish('BeforeValidatingForm',{Generator:this}); 281 var firstInvalidField=null; 282 for(var i=0;i<this.FormElements.length;i++) 283 { 284 this.FormElements[i].ClearInvalidStyle(); 285 if(this.FormElements[i].Options.ClassName=="sfFileUpload") 286 isUsingAFileUploader=true; 287 if(!this.FormElements[i].IsIgnored()&&!this.FormElements[i].IsValid()) 288 { 289 formIsValid=false; 290 if(firstInvalidField==null) 291 firstInvalidField=this.FormElements[i]; 292 continue; 293 } 294 if(this.FormElements[i].StoresInformation()) 295 { 296 var value=this.FormElements[i].GetValueString(); 297 amount+=this.FormElements[i].amount; 298 formValues[this.FormElements[i].Id]=value; 299 } 300 } 301 if(!formIsValid) 302 { 303 //this.GetRootContainer().prepend('<p class="redNaoValidationMessage" style="margin:0;padding: 0; font-style: italic; color:red;font-family:Arial,serif;font-size:12px;">'+RedNaoEscapeHtml(this.client_form_options.InvalidInputMessage)+'</p>'); 304 this.GetRootContainer().find('.redNaoSubmitButton').addClass('btn-danger'); 305 this.ScrollTo(firstInvalidField.JQueryElement); 306 return; 307 } 308 309 310 if(formValues.length>0) 311 formValues=formValues.substr(1); 312 313 try{ 314 315 for(i=0;i<this.JavascriptCodes.length;i++) 316 { 317 if(typeof this.JavascriptCodes[i].BeforeFormSubmit!='undefined'&&(this.JavascriptCodes[i].BeforeFormSubmit(formValues,this.FormElements)==false)) 318 return; 319 } 320 321 }catch(exception) 322 { 323 324 } 325 326 this.RedirectUrl=this.ProcessRedirectUrl(); 327 if(RedNaoGetValueOrNull(this.client_form_options.Campaign)) 328 this.SendToSmartDonations(formValues,isUsingAFileUploader); 329 else 330 this.SendToSmartForms(formValues,isUsingAFileUploader); 331 332 try{ 333 rnJQuery('body, input[type="submit"]').addClass('redNaoWait'); 334 this.JQueryForm.find('input[type="submit"],.redNaoMSButton').attr('disabled','disabled'); 335 }catch(exception) 336 { 337 338 } 339 340 341}; 342 343smartFormGenerator.prototype.ScrollTo=function($elementToScrollTo) 344{ 345 var scroll = $elementToScrollTo.offset(); 346 if (window.pageYOffset>scroll.top) 347 rnJQuery('html, body').animate({scrollTop: scroll.top-50}, 200); 348}; 349 350smartFormGenerator.prototype.SendToSmartForms=function(formValues,isUsingAFileUploader) 351{ 352 var data={ 353 form_id:this.form_id, 354 action:"rednao_smart_forms_save_form_values", 355 formString:JSON.stringify(formValues), 356 requestUrl:document.URL 357 }; 358 359 360 if(this.client_form_options.UsesCaptcha=='y') 361 { 362 data.captcha={ 363 challenge:this.JQueryForm.find('[name="recaptcha_challenge_field"]').val(), 364 response:this.JQueryForm.find('[name="recaptcha_response_field"]').val() 365 } 366 367 } 368 369 if(isUsingAFileUploader) 370 this.SendFilesWithForm(data,formValues); 371 else 372 { 373 var self=this; 374 //noinspection JSUnusedLocalSymbols 375 RedNaoEventManager.Publish('FormSubmitted',{Generator:this}); 376 rnJQuery.ajax({ 377 type:'POST', 378 url:ajaxurl, 379 dataType:"json", 380 data:data, 381 success:function(result){self.SaveCompleted(result,formValues)}, 382 error:function(result){ 383 rnJQuery('body, input[type="submit"]').removeClass('redNaoWait'); 384 self.JQueryForm.find('input[type="submit"],.redNaoMSButton').removeAttr('disabled'); 385 alert('An error occurred, please try again later');} 386 }); 387 } 388}; 389 390smartFormGenerator.prototype.SendFilesWithForm=function(data,formValues) 391{ 392 data=JSON.stringify(data); 393 rnJQuery('#sfTemporalIFrame').remove(); 394 rnJQuery('body').append('<iframe id="sfTemporalIFrame" name="sfTemporalIFrame"></iframe>'); 395 var self=this; 396 RedNaoEventManager.Publish('FormSubmitted',{Generator:this}); 397 rnJQuery('#sfTemporalIFrame').on('load',function() 398 { 399 var response; 400 if (this.contentDocument) { 401 response = this.contentDocument.body.innerHTML; 402 } else { 403 response = this.contentWindow.document.body.innerHTML; 404 } 405 406 self.SaveCompleted(rnJQuery.parseJSON(response),formValues); 407 }); 408 this.JQueryForm.attr('method','post'); 409 this.JQueryForm.attr('enctype','multipart/form-data'); 410 this.JQueryForm.attr('target','sfTemporalIFrame'); 411 this.JQueryForm.attr('action',smartFormsPath+"smart_forms_uploader.php"); 412 var dataField=rnJQuery('<input type="hidden" name="data"/> '); 413 dataField.val(data); 414 this.JQueryForm.append(dataField); 415 this.SubmittingThroughIframe=true; 416 this.JQueryForm.submit(); 417 418}; 419 420//noinspection JSUnusedLocalSymbols 421smartFormGenerator.prototype.SendToSmartDonations=function(formValues,isUsingAFileUploader) 422{ 423 this.JQueryForm.find('input[name="return"]').val(this.RedirectUrl); 424 if(RedNaoPathExists(this.client_form_options,'Formulas.DonationFormula')) 425 { 426 //noinspection JSUnresolvedVariable 427 var formula=new RedNaoFormula(null,this.client_form_options.Formulas.DonationFormula); 428 var donationAmount=formula.GetValueFromFormula(RedNaoFormulaManagerVar.Data); 429 430 431 if(donationAmount<=0) 432 { 433 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>'); 434 return; 435 } 436 437 } 438 439 440 441 var self=this; 442 443 444 var data={ 445 action:"rednao_smart_donations_save_form_values", 446 emailToNotify:this.emailToNotify, 447 formString:JSON.stringify(formValues) 448 }; 449 450 RedNaoEventManager.Publish('FormSubmitted',{Generator:this}); 451 rnJQuery.post(ajaxurl,data,function(data){ 452 if(data.status=="success") 453 { 454 self.JQueryForm.find('.amountToDonate').val(donationAmount); 455 self.JQueryForm.find('input[name=custom]').val(encodeURI('type=form&campaign_id='+self.client_form_options.Campaign+"&formId="+data.randomString+'&sformid='+self.form_id)); 456 if(self.JQueryForm.find('.redNaoRecurrence').length>0&&self.JQueryForm.find('.redNaoRecurrence').find(':selected').val()!='OT') 457 { 458 self.JQueryForm.find('.amountToDonate').attr('name','a3'); 459 self.JQueryForm.find('.smartDonationsPaypalCommand').val('_xclick-subscriptions'); 460 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()+'">'); 461 } 462 self.SubmittingRedNaoDonationForm='y'; 463 self.JQueryForm.submit(); 464 465 466 }else 467 { 468 alert("An error occured, please try again"); 469 } 470 471 },"json"); 472 473}; 474 475smartFormGenerator.prototype.SaveCompleted=function(result,formValues){ 476 RedNaoEventManager.Publish('FormSubmittedCompleted',{Generator:this}); 477 rnJQuery('body, input[type="submit"]').removeClass('redNaoWait'); 478 this.JQueryForm.find('input[type="submit"],.redNaoMSButton').removeAttr('disabled'); 479 480 if(typeof result.AdditionalActions!='undefined') 481 { 482 for(var i=0;i<result.AdditionalActions.length;i++) 483 { 484 if(result.AdditionalActions[i].Action=="RedirectTo") 485 { 486 window.location=result.AdditionalActions[0].Value; 487 return; 488 } 489 490 if(result.AdditionalActions[i].Action=="ShowMessage") 491 { 492 alert(result.AdditionalActions[i].Value.Message); 493 return; 494 } 495 } 496 } 497 498 if(typeof result.refreshCaptcha!='undefined'&&result.refreshCaptcha=='y') 499 { 500 alert(result.message); 501 Recaptcha.reload(); 502 return; 503 } 504 505 if(result.success=='y') 506 this.FireExtensionMethod('FormSubmissionCompleted'); 507 508 if((RedNaoGetValueOrEmpty(this.client_form_options.alert_message_cb)!='y'&&RedNaoGetValueOrEmpty(this.client_form_options.redirect_to_cb)!='y')||result.success=='n') 509 { 510 alert(result.message); 511 this.CreateForm(); 512 return; 513 } 514 515 if(RedNaoGetValueOrEmpty(this.client_form_options.alert_message_cb)=='y') 516 alert(this.client_form_options.alert_message); 517 518 if(RedNaoGetValueOrEmpty(this.client_form_options.redirect_to_cb)=="y") 519 { 520 window.location=this.RedirectUrl; 521 } 522 523 this.CreateForm(); 524 525}; 526 527smartFormGenerator.prototype.ProcessRedirectUrl=function() 528{ 529 var redirectOptions=this.client_form_options.redirect_to; 530 var formValues=this.GetCurrentData(); 531 var i; 532 var url=''; 533 var redirectToUse=null; 534 for(i=0;i<redirectOptions.length;i++) 535 { 536 if(redirectOptions[i].RCSettings.Redirect=='always'||RedNaoEventManager.Publish('CalculateCondition',{Condition:redirectOptions[i].RCSettings.ConditionSettings ,Values:formValues})) 537 { 538 url=redirectOptions[i].URL; 539 } 540 } 541 542 var regEx=/{([^}]+)}/g; 543 var matches; 544 545 while(matches=regEx.exec(url)) 546 { 547 for(i=0;i<matches.length;i++) 548 { 549 if(matches[i][0]=='{') 550 continue; 551 var value=''; 552 if(typeof formValues[matches[i]]!='undefined') 553 { 554 value = formValues[matches[i]].label; 555 for(var t=0;t<this.RedNaoFormElements.length;t++) 556 if(matches[i]==this.RedNaoFormElements[t].Id&&this.RedNaoFormElements[t].Options.ClassName=="rednaodatepicker") 557 value=formValues[matches[i]].value; 558 } 559 url=url.replace('{'+matches[i]+'}',encodeURIComponent(value)); 560 } 561 } 562 563 return url; 564}; 565 566smartFormGenerator.prototype.GetRootContainer=function() 567{ 568 return rnJQuery('#'+this.containerName); 569}; 570 571rnJQuery(function(){ 572 if( window.smartFormsItemsToLoad) 573 for(var i=0;i< window.smartFormsItemsToLoad.length;i++) 574 smartFormsLoadForm(window.smartFormsItemsToLoad[i]); 575}); 576 577 578var smartFormsLoadedItems=[]; 579 580function smartFormsLoadForm(options) 581{ 582 var form=new smartFormGenerator(options); 583 smartFormsLoadedItems.push(form); 584 585 586}
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.