Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
19 kB
6
Indexable
Never
// on page load if customer is already signed in

Mobi2Go.onReady(function () {
  // if customer privacy flag is false then show the modal
  if (
    Mobi2Go.Customer.isLoggedIn() &&
    !Mobi2Go.Customer.getCustomerLoginPrivacyAcceptance()
  ) {
    console.log("why do i get here", Mobi2Go.Customer.isLoggedIn());
    Mobi2Go.UI.trigger("showPrivacyModal");
  }
});

// After signing in trigger the customer flag
Mobi2Go.Customer.bind("logIn", function () {
  // if customer privacy flag is false then show the modal
  if (!Mobi2Go.Customer.getCustomerLoginPrivacyAcceptance()) {
    console.log("in here");
    Mobi2Go.UI.trigger("showPrivacyModal");
  }
});

Mobi2Go.UI.bind("orderConfirmationViewRendered", function () {
  console.log(
    "do i reach this",
    $(".m2g-order-confirmation-footer-confirm-button")
  );
  $(".m2g-order-confirmation-footer-confirm-button").attr("disabled", false);
  $(".m2g-order-confirmation-footer-confirm-button").removeClass(
    "m2g-button--disabled"
  );
});

// Login Privacy modal
(function () {
  const that = this;
  const is_mobile = Mobi2Go.app.isMobileUI();
  const policy =
    Mobi2Go.app.language === "en"
      ? "https://mtygroup.com/en/privacy-policy/"
      : "https://mtygroup.com/politique-de-confidentialite/";
  const title = "Our policy has changed";
  const login_english =
    '<p class="m2g-privacy-policy">By creating an online ordering account, you agree to your personal information being collected and stored by MOBI HQ LTD. ("MOBI") and shared with MTY Franchising Inc. and/or its affiliates and/or its subsidiaries ("MTY"). The information you provide will allow for a seamless online ordering experience and faster future check-outs.<br/>You can deactivate or delete your account at any time. You also have a right to access your personal information or correct any inaccuracies, as necessary.<br/>Before you sign up to Bâton Rouge's online order account, we ask that you read and accept the terms of MTY's and MOBI's privacy policy, <a href="' +
    policy +
    '" target="_blank" style="text-decoration: underline" data-policy>here.</a></p>';
  const login_french =
    "<p class='m2g-privacy-policy'>En créant un compte de commande en ligne, vous acceptez que vos renseignements personnels soient recueillis et utilisés par MOBI HQ LTD. (« MOBI ») et partagés avec Franchise MTY inc. et/ou ses affiliés et/ou ses filiales (« MTY »). Les informations que vous fournissez vous permettront de commander en ligne sans heurts et de passer plus rapidement à la caisse à l'avenir.<br/>" +
    "Vous pouvez désactiver ou supprimer votre compte à tout moment. Vous avez aussi le droit d'accéder à vos renseignements personnels ou de corriger toute inexactitude, le cas échéant.<br/>" +
    'Avant de vous inscrire au compte de commande en ligne de Bâton Rouge, nous vous demandons de lire et d'accepter les termes de la politique de confidentialité de MTY et de MOBI, <a href="' +
    policy +
    '" target="_blank" style="text-decoration: underline" data-policy>ici.</a></p>';
  const subtext = Mobi2Go.app.language === "en" ? login_english : login_french;
  var UI = Mobi2Go.UI;
  is_mobile
    ? UI.full_screen_alert.show({
        id: "update-policy",
        text: title,
        subtext,
        primary_button: "Accept",
        secondary_button: "Decline",
        onPrimaryButtonClick() {
          Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
        },
        onSecondaryButtonClick() {
          Mobi2Go.Customer.logOut();
        },
        close_button: false,
        DOM_listeners: {
          "click [data-policy]": function (e) {
            console.log("clicked in this one here");
            Mobi2Go.UI.trigger("showPolicy", "privacy");
          },
        },
      })
    : UI.View({
        name: "privacy-modal",
        model: "Customer",
        el: jQuery("<div/>").insertAfter(
          '[data-view="customer-email-updater"]'
        ),
        template:
          '<div id="modal" data-toggle="modal" data-keyboard="false" data-backdrop="static"><h1 class="m2g-privacy-modal m2g-modal-title">' +
          title +
          "</h1>" +
          subtext +
          '<div class="m2g-privacy-buttons"><button class="m2g-button m2g-button--primary m2g-privacy-accept" data-accept>Accept</button>' +
          '<button class="m2g-button m2g-button--secondary m2g-privacy-decline" data-decline>Decline</button></div></div>',
        initialise() {
          var that = this;
          this.modal = new Mobi2Go.UI.Modal(this.$el);
          UI.bind("showPrivacyModal", function () {
            that.open();
          });
          if (!this.template) {
            console.warn("privacy template not found");
            return;
          }

          var html = this.template();
          this.$el.html(html);
        },
        open() {
          if (this.modal.is_open) {
            return;
          }
          this.modal.open();
          this.modal.freeze();
        },
        close() {
          this.modal.unfreeze();
          this.modal.close();
        },
        DOM_listeners: {
          "click [data-accept]": function (e) {
            Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
            // at this point we need to set the flag on customer
            this.modal.unfreeze();
            this.modal.close();
          },
          "click [data-decline]": function (e) {
            // at this point we need to log customer out as they havent given permission to continue
            Mobi2Go.Customer.logOut();
            this.modal.unfreeze();
            this.modal.close();
          },
          "click [data-policy]": function (e) {
            Mobi2Go.UI.trigger("showPolicy", "privacy");
          },
        },
      });
})();

// Checkout Privacy modal
(function () {
  const that = this;
  const is_mobile = Mobi2Go.app.isMobileUI();
  const policy =
    Mobi2Go.app.language === "en"
      ? "https://mtygroup.com/en/privacy-policy/"
      : "https://mtygroup.com/politique-de-confidentialite/";
  const title = "Our policy has changed";
  const checkout_english =
    '<p class="m2g-privacy-policy">By creating an online ordering account, you agree to your personal information being collected and stored by MOBI HQ LTD. ("MOBI") and shared with MTY Franchising Inc. and/or its affiliates and/or its subsidiaries ("MTY"). The information you provide will allow for a seamless online ordering experience and faster future check-outs.<br/>You can deactivate or delete your account at any time. You also have a right to access your personal information or correct any inaccuracies, as necessary.<br/>Before you sign up to Bâton Rouge's online order account, we ask that you read and accept the terms of MTY's and MOBI's privacy policy, <a href="' +
    policy +
    '" target="_blank" style="text-decoration: underline" data-policy>here.</a></p>';
  const checkout_french =
    "<p class='m2g-privacy-policy'>En créant un compte de commande en ligne, vous acceptez que vos renseignements personnels soient recueillis et utilisés par MOBI HQ LTD. (« MOBI ») et partagés avec Franchise MTY inc. et/ou ses affiliés et/ou ses filiales (« MTY »). Les informations que vous fournissez vous permettront de commander en ligne sans heurts et de passer plus rapidement à la caisse à l'avenir.<br/>" +
    "Vous pouvez désactiver ou supprimer votre compte à tout moment. Vous avez aussi le droit d'accéder à vos renseignements personnels ou de corriger toute inexactitude, le cas échéant.<br/>" +
    'Avant de vous inscrire au compte de commande en ligne de Bâton Rouge, nous vous demandons de lire et d'accepter les termes de la politique de confidentialité de MTY et de MOBI, <a href="' +
    policy +
    '" target="_blank" style="text-decoration: underline" data-policy>ici.</a></p>';
  const subtext =
    Mobi2Go.app.language === "en" ? checkout_english : checkout_french;
  var UI = Mobi2Go.UI;
  is_mobile
    ? UI.full_screen_alert.show({
        id: "ckeckout-policy-mobile",
        text: title,
        subtext,
        primary_button: "Accept",
        secondary_button: "Decline",
        onPrimaryButtonClick() {
          Mobi2Go.Customer.setCustomerCheckoutPrivacyAcceptance(true);
        },
        onSecondaryButtonClick() {
          Mobi2Go.Customer.logOut();
        },
        close_button: false,
        DOM_listeners: {
          "click [data-policy]": function (e) {
            console.log("clicked in this one here");
            Mobi2Go.UI.trigger("showPolicy", "privacy");
          },
        },
      })
    : UI.View({
        name: "checkout-privacy-modal",
        model: "Customer",
        el: jQuery("<div/>").insertAfter(
          '[data-view="customer-email-updater"]'
        ),
        template:
          '<div id="modal" data-toggle="modal" data-keyboard="false" data-backdrop="static"><h1 class="m2g-privacy-modal m2g-modal-title">' +
          title +
          "</h1>" +
          subtext +
          '<div class="m2g-privacy-buttons"><button class="m2g-button m2g-button--primary m2g-privacy-accept" data-accept>Accept</button>' +
          '<button class="m2g-button m2g-button--secondary m2g-privacy-decline" data-decline>Decline</button></div></div>',
        initialise() {
          var that = this;
          this.modal = new Mobi2Go.UI.Modal(this.$el);
          UI.bind("showCheckoutPrivacyModal", function () {
            that.open();
          });
          if (!this.template) {
            console.warn("privacy template not found");
            return;
          }

          var html = this.template();
          this.$el.html(html);
        },
        open() {
          if (this.modal.is_open) {
            return;
          }
          this.modal.open();
          this.modal.freeze();
        },
        close() {
          this.modal.unfreeze();
          this.modal.close();
        },
        DOM_listeners: {
          "click [data-accept]": function (e) {
            Mobi2Go.Customer.setCustomerCheckoutPrivacyAcceptance(true);
            // at this point we need to set the flag on customer
            this.modal.unfreeze();
            this.modal.close();
          },
          "click [data-decline]": function (e) {
            // at this point we need to log customer out as they havent given permission to continue
            Mobi2Go.Customer.logOut();
            this.modal.unfreeze();
            this.modal.close();
          },
          "click [data-policy]": function (e) {
            Mobi2Go.UI.trigger("showPolicy", "privacy");
          },
        },
      });
})();

// Checkbox for privacy on checkout
Mobi2Go.onReady(function () {
  // if customer privacy flag is false then show the checkbox
  if (
    Mobi2Go.Customer.isLoggedIn &&
    !Mobi2Go.Customer.getCustomerCheckoutPrivacyAcceptance()
  ) {
    Mobi2Go.UI.trigger("showPrivacyCheckbox");
  }
});

// Mobile Privacy Checkout Box
(function () {
  if (!Mobi2Go.app.isMobileUI()) {
    return;
  }
  Mobi2Go.Order.onReady(function () {
    Mobi2Go.UI.View({
      name: "privacy-checkout",
      model: Mobi2Go.Customer,
      el: jQuery("<div/>").insertBefore(
        ".m2g-order-confirmation-footer-container"
      ),
      template:
        '<div class="m2g-kerbside" <%=(this.isChecked ? "data-checked" : "")%>>' +
        '<div class="m2g-privacy-checkbox">' +
        '<div class="m2g-privacy-checkbox__element m2g-icon m2g-icon--tick m2g-icon--checkbox" data-toggle></div>' +
        '<div class="m2g-privacy-checkbox__label">I agree to the <button class="m2g-privacy-button" data-policy>Privacy Policy</button></div>' +
        "</div>" +
        "</div>",
      initialise() {
        if (!Mobi2Go.Customer.getCustomerCheckoutPrivacyAcceptance()) {
          $(".m2g-order-confirmation-footer-confirm-button").attr(
            "disabled",
            false
          );
          $(".m2g-order-confirmation-footer-confirm-button").removeClass(
            "m2g-button--disabled"
          );
        }
        var that = this;
        Mobi2Go.UI.bind("showPrivacyCheckbox", function () {
          that.render();
        });
        if (!this.template) {
          console.warn("privacy template not found");
          return;
        }

        var html = this.template();
        this.$el.html(html);
        this.isChecked = false;
        this.render();
      },
      render() {
        const html = this.template({
          isChecked: this.isChecked,
        });
        this.$el.html(html);
      },
      placement: "bottom",
      /*model_listeners: {
                 
                  },
              },*/
      DOM_listeners: {
        "click [data-toggle]": function () {
          this.isChecked = !this.isChecked;
          if (this.isChecked) {
            console.log(
              "clicked",
              $(".m2g-order-confirmation-footer-confirm-button")
            );
            Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
            $(".m2g-order-confirmation-footer-confirm-button").attr(
              "disabled",
              false
            );
            $(".m2g-order-confirmation-footer-confirm-button").removeClass(
              "m2g-button--disabled"
            );
          }

          if (!this.isChecked) {
            Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
            $(".m2g-order-confirmation-footer-confirm-button").attr(
              "disabled",
              true
            );
            $(".m2g-order-confirmation-footer-confirm-button").addClass(
              "m2g-button--disabled"
            );
          }
          this.render();
        },
        "click [data-policy]": function (e) {
          console.log("data clicked");
          Mobi2Go.UI.trigger("showCheckoutPrivacyModal");
        },
      },
    });
  });
})();

// Desktop checkout checkbox
(function () {
  if (Mobi2Go.app.isMobileUI()) {
    return;
  }
  Mobi2Go.Order.onReady(function () {
    Mobi2Go.UI.View({
      name: "privacy-checkout",
      model: Mobi2Go.Customer,
      el: jQuery("<div/>").insertAfter(".m2g-order-confirmation-comment"),
      template:
        '<div class="m2g-privacy-checkbox" <%=(this.isChecked ? "data-checked" : "")%>>' +
        '<div class="m2g-privacy-checkbox" >' +
        '<div class="m2g-privacy-checkbox__element m2g-icon m2g-icon--tick m2g-icon--checkbox" data-toggle></div>' +
        '<div class="m2g-privacy-checkbox__label">I agree to the <button class="m2g-privacy-button" data-policy>Privacy Policy</button></div>' +
        "</div>" +
        "</div>",
      initialise() {
        if (!Mobi2Go.Customer.getCustomerCheckoutPrivacyAcceptance()) {
          $(".m2g-order-confirmation-confirm-button").attr("disabled", true);
          $(".m2g-order-confirmation-confirm-button").addClass(
            "m2g-button--disabled"
          );
        }
        var that = this;
        Mobi2Go.UI.bind("showPrivacyCheckbox", function () {
          that.render();
        });
        if (!this.template) {
          console.warn("privacy template not found");
          return;
        }

        var html = this.template();
        this.$el.html(html);
        this.isChecked = false;
        this.render();
      },
      render() {
        const html = this.template({
          isChecked: this.isChecked,
        });
        this.$el.html(html);
      },
      /*model_listeners: {
                 
                  },
              },*/
      DOM_listeners: {
        "click [data-toggle]": function () {
          this.isChecked = !this.isChecked;
          if (this.isChecked) {
            Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
            $(".m2g-order-confirmation-confirm-button").attr("disabled", false);
            $(".m2g-order-confirmation-confirm-button").removeClass(
              "m2g-button--disabled"
            );
          }

          if (!this.isChecked) {
            Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
            $(".m2g-order-confirmation-confirm-button").attr("disabled", true);
            $(".m2g-order-confirmation-confirm-button").addClass(
              "m2g-button--disabled"
            );
          }
          this.render();
        },
        "click [data-policy]": function (e) {
          //   Mobi2Go.UI.trigger("showPolicy", "privacy");
          Mobi2Go.UI.trigger("showCheckoutPrivacyModal");
        },
      },
    });
  });
})();

// Mobile New User Login Checkbox
(function () {
  if (Mobi2Go.app.isMobileUI()) {
    return;
  }
  Mobi2Go.Order.onReady(function () {
    Mobi2Go.UI.View({
      name: "new-user-login",
      model: Mobi2Go.Customer,
      el: jQuery("<div/>").insertAfter(
        ".m2g-customer-terms-and-conditions-message"
      ),
      template:
        '<div class="m2g-privacy-checkbox" <%=(this.isChecked ? "data-checked" : "")%>>' +
        '<div class="m2g-privacy-checkbox" data-toggle>' +
        '<div class="m2g-privacy-checkbox__element m2g-icon m2g-icon--tick m2g-icon--checkbox"></div>' +
        '<div class="m2g-privacy-checkbox__label">Yes, I have read and agree with the terms of MTY\'s and MOBI\'s privacy policy <button class="m2g-privacy-button" data-policy>Privacy Policy</button></div>' +
        "</div>" +
        "</div>",
      initialise() {
        if (!Mobi2Go.Customer.getCustomerCheckoutPrivacyAcceptance()) {
          $(".m2g-order-confirmation-confirm-button").attr("disabled", true);
          $(".m2g-order-confirmation-confirm-button").addClass(
            "m2g-button--disabled"
          );
        }
        var that = this;
        Mobi2Go.UI.bind("showPrivacyCheckbox", function () {
          that.render();
        });
        if (!this.template) {
          console.warn("privacy template not found");
          return;
        }

        var html = this.template();
        this.$el.html(html);
        this.isChecked = false;
        this.render();
      },
      render() {
        const html = this.template({
          isChecked: this.isChecked,
        });
        this.$el.html(html);
      },
      DOM_listeners: {
        "click [data-toggle]": function () {
          this.isChecked = !this.isChecked;
          if (this.isChecked) {
            Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
            $(".m2g-order-confirmation-confirm-button").attr("disabled", false);
            $(".m2g-order-confirmation-confirm-button").removeClass(
              "m2g-button--disabled"
            );
          }

          if (!this.isChecked) {
            Mobi2Go.Customer.setCustomerLoginPrivacyAcceptance(true);
            $(".m2g-order-confirmation-confirm-button").attr("disabled", true);
            $(".m2g-order-confirmation-confirm-button").addClass(
              "m2g-button--disabled"
            );
          }
          this.render();
        },
      },
    });
  });
})();