[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 /*+*********************************************************************************** 2 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 3 * ("License"); You may not use this file except in compliance with the License 4 * The Original Code is: vtiger CRM Open Source 5 * The Initial Developer of the Original Code is vtiger. 6 * Portions created by vtiger are Copyright (C) vtiger. 7 * All Rights Reserved. 8 *************************************************************************************/ 9 10 Settings_Vtiger_Detail_Js('Settings_Webforms_Detail_Js', { 11 12 /* 13 * function to trigger delete record action 14 * @params: delete record url. 15 */ 16 deleteRecord : function(deleteRecordActionUrl) { 17 var message = app.vtranslate('LBL_DELETE_CONFIRMATION'); 18 Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then(function(data) { 19 AppConnector.request(deleteRecordActionUrl).then( 20 function(data){ 21 if(data.success == true){ 22 window.location.href = data.result; 23 }else{ 24 Vtiger_Helper_Js.showPnotify(data.error.message); 25 } 26 }); 27 }, 28 function(error, err){ 29 } 30 ); 31 }, 32 33 /** 34 * Function to trigger show webform record action 35 * @params: show webform record url 36 */ 37 showForm : function(showFormRecordActionUrl){ 38 AppConnector.request(showFormRecordActionUrl).then( 39 function(data){ 40 var callback = function(container){ 41 //Form should be aas html without rendering 42 var showFormContents = container.find('pre').html(); 43 showFormContents = showFormContents + '<script type="text/javascript">'+ 44 'window.onload = function() { '+ 45 'var N=navigator.appName, ua=navigator.userAgent, tem;'+ 46 'var M=ua.match(/(opera|chrome|safari|firefox|msie)\\/?\\s*(\\.?\\d+(\\.\\d+)*)/i);'+ 47 'if(M && (tem= ua.match(/version\\/([\\.\\d]+)/i))!= null) M[2]= tem[1];'+ 48 'M=M? [M[1], M[2]]: [N, navigator.appVersion, "-?"];'+ 49 'var browserName = M[0];'+ 50 51 'var form = document.forms[0], '+ 52 'inputs = form.elements; '+ 53 'form.onsubmit = function() { '+ 54 'var required = [], att, val; '+ 55 'for (var i = 0; i < inputs.length; i++) { '+ 56 'att = inputs[i].getAttribute("required"); '+ 57 'val = inputs[i].value; '+ 58 'type = inputs[i].type; '+ 59 'if(type == "email") {'+ 60 'if(val != "") {'+ 61 'var elemLabel = inputs[i].getAttribute("label");'+ 62 'var emailFilter = /^[_/a-zA-Z0-9]+([!"#$%&()*+,./:;<=>?\\^_`{|}~-]?[a-zA-Z0-9/_/-])*@[a-zA-Z0-9]+([\\_\\-\\.]?[a-zA-Z0-9]+)*\\.([\\-\\_]?[a-zA-Z0-9])+(\\.?[a-zA-Z0-9]+)?$/;'+ 63 'var illegalChars= /[\\(\\)\\<\\>\\,\\;\\:\\\"\\[\\]]/ ;'+ 64 'if (!emailFilter.test(val)) {'+ 65 'alert("For "+ elemLabel +" field please enter valid email address"); return false;'+ 66 '} else if (val.match(illegalChars)) {'+ 67 'alert(elemLabel +" field contains illegal characters");return false;'+ 68 '}'+ 69 '}'+ 70 '}'+ 71 'if (att != null) { '+ 72 'if (val.replace(/^\\s+|\\s+$/g, "") == "") { '+ 73 'required.push(inputs[i].getAttribute("label")); '+ 74 '} '+ 75 '} '+ 76 '} '+ 77 'if (required.length > 0) { '+ 78 'alert("The following fields are required: " + required.join()); '+ 79 'return false; '+ 80 '} '+ 81 'var numberTypeInputs = document.querySelectorAll("input[type=number]");'+ 82 'for (var i = 0; i < numberTypeInputs.length; i++) { '+ 83 'val = numberTypeInputs[i].value;'+ 84 'var elemLabel = numberTypeInputs[i].getAttribute("label");'+ 85 'if(val != "") {'+ 86 'var intRegex = /^[+-]?\\d+$/;'+ 87 'if (!intRegex.test(val)) {'+ 88 'alert("For "+ elemLabel +" field please enter valid number"); return false;'+ 89 '}'+ 90 '}'+ 91 '}'; 92 if(container.find('[name=isCaptchaEnabled]').val() == true) { 93 captchaPublicKey = container.find('[name=VTIGER_RECAPTCHA_PUBLIC_KEY]').val(); 94 showFormContents = Settings_Webforms_Detail_Js.getCaptchaCode(showFormContents,captchaPublicKey); 95 } else { 96 showFormContents = showFormContents + 97 '}; '+ 98 '}'+ 99 '</script>'; 100 } 101 //Html contents should be placed inside textarea element 102 container.find('#showFormContent').text(showFormContents); 103 //Rendering content has been removed from container 104 container.find('pre').remove(); 105 container.find('code').remove(); 106 app.showScrollBar(container.find('#showFormContent'), {'height':'350px'}); 107 } 108 app.showModalWindow(data,callback); 109 }, 110 function(error){ 111 } 112 ) 113 }, 114 115 /** 116 * Function get Captcha Code 117 * @param <string> showFormContents 118 * @return <string> showFormContents 119 */ 120 getCaptchaCode : function(showFormContents,captchaPublicKey) { 121 122 var captchaContents = '<script type="text/javascript">'+ 123 'var RecaptchaOptions = { theme : "clean" };'+ 124 '</script>'+ 125 '<script type="text/javascript"'+ 126 'src="http://www.google.com/recaptcha/api/challenge?k='+captchaPublicKey+'">'+ 127 '</script>'+ 128 '<noscript>'+ 129 '<iframe src="http://www.google.com/recaptcha/api/noscript?k='+captchaPublicKey+'">'+ 130 'height="300" width="500" frameborder="0"></iframe><br>'+ 131 '<textarea name="recaptcha_challenge_field" rows="3" cols="40">'+ 132 '</textarea>'+ 133 '<input type="hidden" name="recaptcha_response_field" value="manual_challenge">'+ 134 '</noscript>'; 135 showFormContents = showFormContents.replace('<div id="captchaField"></div>',captchaContents); 136 showFormContents = showFormContents + 137 'var recaptchaValidationValue = document.getElementById("recaptcha_validation_value").value;'+ 138 'if (recaptchaValidationValue!= true){'+ 139 'var recaptchaResponseElement = document.getElementsByName("recaptcha_response_field")[0].value;'+ 140 'var recaptchaChallengeElement = document.getElementsByName("recaptcha_challenge_field")[0].value;'+ 141 'var captchaUrl = document.getElementById("captchaUrl").value;'+ 142 'var url = captchaUrl+"?recaptcha_response_field="+recaptchaResponseElement;'+ 143 'url = url + "&recaptcha_challenge_field="+recaptchaChallengeElement+"&callback=JSONPCallback";'+ 144 'jsonp.fetch(url);'+ 145 'return false;'+ 146 '}'+ 147 '}; '+ 148 '};'+ 149 'var jsonp = {' + 150 'callbackCounter: 0,'+ 151 152 'fetch: function(url) {'+ 153 'url = url +"&callId="+this.callbackCounter;'+ 154 'var scriptTag = document.createElement("SCRIPT");'+ 155 'scriptTag.src = url;'+ 156 'scriptTag.async = true;'+ 157 'scriptTag.id = "JSONPCallback_"+this.callbackCounter;'+ 158 'scriptTag.type = "text/javascript";'+ 159 'document.getElementsByTagName("HEAD")[0].appendChild(scriptTag);'+ 160 'this.callbackCounter++;'+ 161 '}'+ 162 '};'+ 163 'function JSONPCallback(data) {'+ 164 'if(data.result.success == true) {'+ 165 'document.getElementById("recaptcha_validation_value").value = true;'+ 166 'var form = document.forms[0];'+ 167 'form.submit();'+ 168 '} else {'+ 169 'document.getElementById("recaptcha_reload").click();'+ 170 'alert("you entered wrong captcha");'+ 171 '}'+ 172 'var element = document.getElementById("JSONPCallback_"+data.result.callId);'+ 173 'element.parentNode.removeChild(element);'+ 174 '}'+ 175 '</script>'; 176 177 return showFormContents; 178 } 179 }, { 180 /** 181 * Function which will handle the registrations for the elements 182 */ 183 registerEvents : function() { 184 this._super(); 185 Vtiger_Helper_Js.showHorizontalTopScrollBar(); 186 } 187 })
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |