PageSourceSearch

https://www.efectoled.com/core/controllers/front/SocialLogin/SocialLoginController.js

js efectoled.com collected 2026-10-02 17:45:34 UTC 11,091 bytes, 294 lines download raw bytes

1class SocialLoginController{
2
3    /**
4     * Show CallBack Popup
5     * @param provider
6     * @returns {boolean}
7     */
8    static showAuthPopup(provider,isPro) {
9        if (ets_solo_callbackUrl != '' && provider != '')
10        {
11            RegisterController.setClientIdCookie();
12            let fixURL = ets_solo_callbackUrl;
13            if (ets_solo_callbackUrl.indexOf('?') !== -1) {
14                fixURL += '&provider='+ provider;
15            } else {
16                fixURL += '?provider='+ provider;
17            }
18            if(isPro == 1){
19              fixURL += '&isPro=1';
20            }
21            if (fixURL)
22                window.open(fixURL, 'authWindow', 'width=800,height=auto,scrollbars=yes');
23            return false;
24        }
25
26    }
27
28    /***
29     * Handle Social Login events
30     */
31    static  initSocialLogin(){
32      this.bindSaveCustomerExtra();
33      this.bindToggleIsProffesional();
34      this.bindShowPopup();
35
36      this.container = $('.js-social-content');
37      this.proWrapper = $('.js-isProwrapper');
38      this.customerWrapper = $('.js-isCustomerWrapper');
39      this.formFields = this.container.find('input:not([name="customer_type"]):not(#newsletter), select');
40      this.bindInputEvents();
41
42      $(document).on('click', '.js-social-login-btn', function () {
43            if(!$(this).hasClass('jsSocial-is-disabled')) {
44                if ($(this).attr('data-auth') !== '') {
45                    SocialLoginController.showAuthPopup($(this).attr('data-auth'),$(this).attr('data-is-pro'));
46                }
47            }
48        });
49       /// this.fnHandlePrivacyPolicy(); // use checkbox terms
50    }
51    static bindShowPopup() {
52      $(".js-external-alertCloseBtn").on("click", function(){
53        $('.js-external-ajax-msg').addClass("u-hidden");
54      });
55    }
56  static bindInputEvents() {
57    const that = this;
58    this.formFields.on('keyup change blur', function (event) {
59      if (event.type === 'keyup') {
60        $(this).parent().find('.js-error').addClass('u-hidden');
61        $(this).removeClass('o-form__input--danger');
62        return false;
63      }
64      const isValid = that.validateField($(this));
65      that.markInput($(this), isValid);
66    });
67  }
68
69    static bindSaveCustomerExtra() {
70        const that = this;
71        $(".js-saveSaveCustomerExtraBtn").off('click').on('click', function () {
72            const isValid = that.validateForm();
73            if (isValid){
74              that.isModal = $(this).data('address-modal');
75              let customerType = 1;
76              $(`#social_customer_extra_modal input[type="radio"].js-user-type`).each(function(){
77                if($(this).prop('checked')) customerType = $(this).val();
78              });
79              //var form = $("#social_customer_extra_modal form");
80              let google_id = "";
81
82              if (RegisterController.getGClientID() != "") {//existe de forma normal? por si acaso en algun momento quieren q el area cliente Si tenga analytics
83                google_id = RegisterController.getGClientID();
84              } else if (RegisterController.getClientIdCookie() != "" && CoreSettings.get_google_id_from_cookie == 1 ) {//podemos sacarlo de cookie?
85                google_id = RegisterController.getClientIdCookie();
86              }
87              let gclid_cookie_data="";
88              if ( $("[name='customer_type']:checked").val() == 2 ||  $("[name='customer_type']:checked").val() == 3 ) {
89                gclid_cookie_data = sessionStorage.getItem("gclid");
90              }
91
92              const data = {
93                    controller: 'SocialLogin',
94                    action: 'submitCustomerExtraAjax',
95                    customer_type: $("[name='customer_type']:checked").val(),
96                    professional_sector: $('[name=customer_extra_professional_sector]').find(":selected").val(),
97                    customer_extra_phone: $("[name=customer_extra_phone]").val(),
98                    customer_extra_phone_b2c: $("[name=customer_extra_phone_b2c]").val(),
99                    cif: $("[name=cif]").val(),
100                    company_cif: $("[name=company_cif]").val(),
101                    customer_extra_google_id: google_id,
102                    customer_extra_gclid: gclid_cookie_data,
103                    customer_extra_company_name: $("[name=customer_extra_company_name]").val(),
104                //form_data: form.serialize()
105              };
106              CoreAjax.Ajax(data, {
107                success: (data) => {
108                  console.log(data);
109                  if (data.errorMsg) {
110                    alert(data.errorMsg);
111                  } else {
112                    $(`#social_customer_extra_modal`).modal('hide');
113                    that.resetValuesInPopup();
114                    // window.location.reload();
115                  }
116                },
117                fail:(data) => {
118                  alert( "Error please try again later" );
119                },
120                done:(data) => {
121                  //alert( "done" );
122                }
123              },'body');
124
125            }
126        })
127    }
128  static validateForm() {
129    let isFormValid = true;
130    const that = this;
131    this.fields = {};
132    this.formData = new FormData();
133    this.formFields.each(function () {
134      if ($(this).is(':visible')) {
135        const isValid = that.validateField($(this), true);
136        that.markInput($(this), isValid);
137        isFormValid = isValid && isFormValid;
138      }
139    });
140    return isFormValid;
141  }
142  static markInput(element, isValid) {
143    if (!isValid) {
144      $(element).addClass('o-form__input--danger').removeClass('o-form__input--success');
145      $(element).parent().find('.js-error').removeClass('u-hidden');
146    }
147    else {
148      $(element).removeClass('o-form__input--danger').addClass('o-form__input--success');
149      $(element).parent().find('.js-error').addClass('u-hidden');
150    }
151  }
152  static validateField(field, store) {
153    this.validate = field.data('validate');
154    this.value = this.getFieldValue(field);
155    this.fieldName = field.attr("name");
156    if (store) this.fields[this.fieldName] = this.value;
157    if (store) this.formData.append(this.fieldName, this.value);
158    if ($(field).get(0).type === 'file') return $(field).get(0).files.length;
159    else if (field.prop("tagName") === 'SELECT') {
160      return this.value !== 'no-value';
161    } else if (this.validate === 'isChecked'){
162      return this.value;
163    }
164    else if (this.fieldName === 'customer_extra_company_name') {
165      return CoreValidation.isMoreThan(this.value, 0);
166    }
167    else if (this.fieldName === 'company_cif'){
168      const val = $("[name="+this.fieldName+"]").val();
169      const selector = $('.js-docTypeSelector');
170      const select_type = parseInt(selector[0].value);
171      return CoreValidation.isCif(this.value);
172    }
173    else if (this.fieldName === 'cif'){
174      const val = $("[name="+this.fieldName+"]").val();
175      const selector = $('.js-docTypeSelector');
176      const select_type = parseInt(selector[0].value);
177      if (select_type === 2) return CoreValidation.isDni(val)
178      else if (select_type === 3) return CoreValidation.isCif(val)
179      else if (select_type === 4) return CoreValidation.isNie(val)
180      else return CoreValidation.isNif(val)
181    }
182    else if (this.fieldName === 'customer_extra_phone'){
183        const val = $("[name="+this.fieldName+"]").val();
184        return CoreValidation.isPhone(val);
185    }
186    else if (this.fieldName === 'customer_extra_phone_b2c'){
187        const val = $("[name="+this.fieldName+"]").val();
188        if (val !== '') {
189            return CoreValidation.isPhone(val);
190        } else {
191            return true;
192        }
193    }
194    else if (this.validate) {
195      return CoreValidation[this.validate](this.value);
196    } else {
197      return false;
198    }
199  }
200
201    static getFieldValue(field) {
202        const type = field.attr('type');
203        if (type === 'checkbox') return field.is(':checked');
204        else if (type === 'file') return $(field).get(0).files[0];
205        return field.val().trim();
206    }
207
208    static resetValuesInPopup() {
209        $(`#social_customer_extra_modal input[type="text"]`).removeClass('o-form__input--success').val('');
210        $(`#social_customer_extra_modal input[type="radio"]:first`).click();
211    }
212
213    /**
214     * Handle Event PrivacyPolicy
215     */
216    static fnHandlePrivacyPolicy(){
217        SocialLoginController.fnDisableButtons()
218        $(".js-authTabsLogin").on("click",function(){
219            if($(this).hasClass("is-active")) {
220                SocialLoginController.fnEnableButtons()
221            };
222        });
223        $(".js-authTabsSignup").on("click",function(){
224            if($(this).hasClass("is-active")) {
225                SocialLoginController.fnDisableButtons()
226            };
227        });
228
229     /*   $("#privacy_policy").on("click",function () {privacy_policy
230
231             if(!$(this).is(":checked") && $(".js-authTabsSignup.is-active").length>0){
232                 SocialLoginController.fnDisableButtons();
233             }else  if($(this).is(":checked")) {
234                 SocialLoginController.fnEnableButtons()
235
236        }});*/
237
238
239    }
240
241    /***
242     * Disable Social Buttons
243     */
244    static fnDisableButtons(){
245        $(".block-social-login button").addClass("jsSocial-is-disabled");
246    }
247
248    /***
249     * Enable Social Buttons
250     */
251    static fnEnableButtons(){
252        $(".block-social-login button").removeClass("jsSocial-is-disabled");
253    }
254
255  static isPro() {
256    return  $("[name='customer_type']:checked").val() == 2 || $("[name='customer_type']:checked").val() == 3;
257  }
258
259  static bindToggleIsProffesional() {
260    const that = this;
261    const customerTypeSelector =  $("[name='customer_type']");
262    customerTypeSelector.on('change', function () {
263      customerTypeSelector.each(function () {
264        $(this).parent().removeClass('is-active');
265      });
266      $(this).parent().addClass('is-active');
267      if (that.isPro()) {
268        that.customerWrapper.addClass('u-hidden');
269        that.proWrapper.removeClass('u-hidden');
270        if($("[name='customer_type']:checked").val() == 2){
271          $(".js-freelance").removeClass('u-hidden');
272          $(".js-company").addClass('u-hidden');
273        } else if($("[name='customer_type']:checked").val() == 3) {
274          $(".js-freelance").addClass('u-hidden');
275          if($(".js-company").hasClass("u-hidden")){
276            $(".js-company").removeClass('u-hidden');
277          }
278        } else{
279          $(".js-company").addClass('u-hidden');
280          $(".js-freelance").addClass('u-hidden');
281        }
282      }
283      else {
284          that.proWrapper.addClass('u-hidden');
285          that.customerWrapper.removeClass('u-hidden');
286      }
287    })
288  }
289}
290
291contentLoader(function () {
292    SocialLoginController.initSocialLogin();
293});
294

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.