1'use strict'; // 2 3// **************************************************** 4// Gestion du Formulaire de contact 5// **************************************************** 6angular.module('AboShopApp').factory('contactManager', ['vcRecaptchaService','$q','TbsWS','commonConfig', '$rootScope', 'Auth', 'cartManager', 'formulaireManager', 'dataManager', 'customerManager', 7function (vcRecaptchaService, $q, TbsWS, commonConfig, $rootScope, Auth, cartManager, formulaireManager, dataManager, customerManager) { 8 9 var factory = {}; 10 factory.MESSAGE_SEND = "send"; 11 12 factory.getAddressCompany = function getAddressCompany(){ 13 var deferred = $q.defer(); 14 TbsWS.call('getaddresscompany/' + $rootScope.preferredLanguage,'public').then( 15 function(result){ 16 if(result && result.key === "addresscompany"){ 17 deferred.resolve(result.value); 18 } else { 19 deferred.resolve(null); 20 } 21 } 22 ,function(error) { 23 deferred.resolve(null); 24 } 25 ); 26 return deferred.promise; 27 }; 28 29 factory.getContactMails = function getContactMails(){ 30 var deferred = $q.defer(); 31 TbsWS.call('getmailscontact','public').then( 32 function(mails){ 33 deferred.resolve(mails); 34 } 35 ,function(error) { 36 deferred.resolve(null); 37 } 38 ); 39 return deferred.promise; 40 }; 41 42 factory.getHasMailContact = function getHasMailContact(){ 43 var deferred = $q.defer(); 44 TbsWS.call('gethasmailcontact','public').then( 45 function(result){ 46 if(result && result.key === "hasmailcontact"){ 47 deferred.resolve(result.value); 48 } else { 49 deferred.resolve(null); 50 } 51 } 52 ,function(error) { 53 deferred.resolve(null); 54 } 55 ); 56 return deferred.promise; 57 }; 58 59 60 61 factory.getContactFormInit = function getContactFormInit(){ 62 var contactForm = {}; 63 contactForm.alert = {}; 64 contactForm.alert.message = []; 65 contactForm.success = {}; 66 contactForm.success.message = []; 67 contactForm.fields = []; 68 contactForm.others = {}; 69 70 return contactForm; 71 }; 72 73 factory.getContactForm = function getContactForm(contactForm){ 74 var deferred = $q.defer(); 75 76 let formulaireconf = commonConfig.formulaireconf["contact"]; 77 78 if(formulaireconf !== undefined && formulaireconf.length > 0){ 79 80 customerManager.getBuildUserForm().then( 81 function(formulaireCustomer){ 82 _tryEndFormulaireContact(deferred, contactForm, formulaireCustomer.fields, formulaireconf); 83 } 84 ,function(error) { 85 console.error(error); 86 _tryEndFormulaireContact(deferred, contactForm, undefined, []); 87 } 88 ); 89 } else { 90 _tryEndFormulaireContact(deferred, contactForm, undefined, []); 91 } 92 return deferred.promise; 93 }; 94 95 function _tryEndLoad(deferred, contactForm, allfields, formulaireconf, tabCs){ 96 let ob={}, field,selectCSValeurs=[]; 97 98 let contact = dataManager.getContactData(); 99 100 if(allfields !== undefined && allfields.length > 0) { 101 for(let i=0;i<formulaireconf.length;i++){ 102 let param = formulaireconf[i]; 103 if(param !== undefined && param.display){ 104 if(param.type == "CS" && tabCs !== undefined && tabCs.length > 0){ 105 field = _.findWhere(tabCs, {refCs: parseInt(param.id)}); 106 if(field !== undefined){ 107 ob={}; 108 if(field.paramCs2Collection !== undefined && field.paramCs2Collection.length > 0){ 109 selectCSValeurs=[]; 110 111 for(let j = 0;j<field.paramCs2Collection.length;j++){ 112 ob={}; 113 ob.value = field.paramCs2Collection[j].libelleCs; 114 ob.label = field.paramCs2Collection[j].libelleCs; 115 selectCSValeurs.push(ob); 116 } 117 ob={}; 118 ob.idfusion = param.idfusion; 119 formulaireManager.createSelect("cs"+field.refCs,ob,field.libelleCs,selectCSValeurs,param.required); 120 } else { 121 ob.idfusion = param.idfusion; 122 formulaireManager.createTextField("cs"+field.refCs,ob,"",field.libelleCs,param.required); 123 } 124 contactForm.fields.push(ob); 125 } 126 } else if(param.type == "INPUT"){ 127 field = _.findWhere(allfields, {name: param.entity}); 128 if(field !== undefined){ 129 if(_.contains(["codeclient", "company"], param.entity)){ 130 field.editable = false; 131 field.required = false; 132 } else { 133 if(param.readonly !== undefined){ 134 field.editable = !param.readonly; 135 } 136 if(param.required !== undefined){ 137 field.required = param.required; 138 } 139 } 140 field.idfusion = param.idfusion; 141 contactForm.fields.push(field); 142 } 143 } 144 } 145 } 146 } else { 147 console.log("Aucune surcharge de formulaire"); 148 ob={}; 149 formulaireManager.createTextField("name",ob,(contact.name!==undefined?contact.name:""),'DICO_CONTACT_VOTRE_NOM',true); 150 contactForm.fields.push(ob); 151 } 152 153 154 //FIN du formulaire obligatoire 155 ob={}; 156 formulaireManager.createEmail("email",ob,(contact.email!==undefined?contact.email:""),'DICO_CONTACT_VOTRE_EMAIL',true,"text", 0, customerManager.MAX_LENGTH_EMAIL); 157 contactForm.fields.push(ob); 158 159 ob={}; 160 formulaireManager.createTextArea("message",ob,(contact.message!==undefined?contact.message:""),'DICO_CONTACT_VOTRE_MESSAGE',true,5,"text",commonConfig.mincarcontact,1500); 161 contactForm.fields.push(ob); 162 163 formulaireManager.createCaptcha(contactForm,true,"contactForm"); 164 165 deferred.resolve(contactForm); 166 } 167 168 function _tryEndFormulaireContact(deferred, contactForm, allfields, formulaireconf){ 169 let tabCSId = [], 170 params = {}; 171 172 if(allfields !== undefined && allfields.length > 0) { 173 for(let i=0;i<formulaireconf.length;i++){ 174 let param = formulaireconf[i]; 175 if(param !== undefined && param.display && param.type == "CS"){ 176 tabCSId.push(param.id); 177 } 178 } 179 if(tabCSId.length > 0){ 180 params.array = tabCSId; 181 TbsWS.call('getcs/'+ $rootScope.preferredLanguage,'public',params).then( 182 function(data){ 183 _tryEndLoad(deferred, contactForm, allfields, formulaireconf, data); 184 } 185 ,function(error) { 186 _tryEndLoad(deferred, contactForm, allfields, formulaireconf, []); 187 } 188 ); 189 } else { 190 _tryEndLoad(deferred, contactForm, allfields, formulaireconf, []); 191 } 192 } else { 193 _tryEndLoad(deferred, contactForm, allfields, formulaireconf, []); 194 } 195 }; 196 197 factory.sendMessage = function sendMessage(contactForm){ 198 var deferred = $q.defer(); 199 contactForm.alert.message = []; 200 contactForm.success.message = []; 201 if(!formulaireManager.verifForm(contactForm)){ 202 deferred.resolve(false); 203 } else { 204 var ob = {}; 205 ob.name = formulaireManager.getDefaultValue(_.findWhere(contactForm.fields, {name: "name"}),""); 206 ob.mail = formulaireManager.getDefaultValue(_.findWhere(contactForm.fields, {name: "email"}),""); 207 ob.message = formulaireManager.getDefaultValue(_.findWhere(contactForm.fields, {name: "message"}),""); 208 ob.complement = ""; 209 210 for(let i = 0 ; i < contactForm.fields.length ; i++){ 211 if(contactForm.fields[i].idfusion !== undefined && contactForm.fields[i].value !== undefined && contactForm.fields[i].value != ""){ 212 console.log(contactForm.fields[i]); 213 ob.complement += contactForm.fields[i].idfusion+"#_#"+contactForm.fields[i].value+"#__#"; 214 } 215 } 216 217 var captcha = undefined; 218 if(contactForm.others.captcha != undefined && contactForm.others.captcha.required){ 219 captcha = vcRecaptchaService.getResponse(contactForm.others.captcha.widgetId); 220 } 221 222 console.log(ob); 223 224 TbsWS.call('sendmail/'+$rootScope.preferredLanguage,'public', ob, captcha).then( 225 function(result){ 226 if(result && result.key === "sendmail"){ 227 var status = result.value; 228 contactForm.alert.message = []; 229 if(!status || status === undefined){ 230 contactForm.alert.message.push('DICO_ERREUR_CONTACT_ENVOIE_MESSAGE'); 231 deferred.resolve(false); 232 } else { 233 status = status.replace(/"/g,''); 234 if(status == factory.MESSAGE_SEND){ 235 contactForm.success.message.push('DICO_CONTACT_MESSAGE_ENVOYE'); 236 formulaireManager.resetForm(contactForm); 237 deferred.resolve(true); 238 } else { 239 contactForm.alert.message.push("DICO_ERREUR_CONTACT_ENVOIE_MESSAGE"); 240 deferred.resolve(false); 241 } 242 } 243 } else { 244 deferred.resolve(false); 245 } 246 } 247 ,function(error) { 248 contactForm.alert.message.push("DICO_ERREUR_CONTACT_ENVOIE_MESSAGE"); 249 deferred.resolve(false); 250 } 251 ); 252 } 253 return deferred.promise; 254 }; 255 256 return factory; 257 }]);
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.