Mini Kabibi Habibi

Current Path : C:/Program Files/McAfee/WebAdvisor/MFW/packages/webadvisor/aj_toasts/
Upload File :
Current File : C:/Program Files/McAfee/WebAdvisor/MFW/packages/webadvisor/aj_toasts/wa-aj-toast-checkbox.js

(function (wa, $) {
  var ui = wa.UI = wa.UI || {};
  var _window = wa.Core.Window;
  var _external = wa.Utils.External;
  var _instrument = wa.Utils.Instrument;
  var _settings = wa.Utils.Settings;
  const TOGGLE_COUNT = "toggle_count";

  ui.accept_extension = function () {
    var $el = {
      cardImage: $(".card__image"),
      cardContent: $(".card__content"),
      contentInfoTitle: $("#info-title"),
      contentInfoText: $("#info-text"),
      checkboxQuestion: $("#checkbox-question"),
      checkboxInput: $("#set-secure-search-checkbox"),
      doneButton: $("#done"),
      toast: $(".toast"),
      setSecureSearchLabel: $("#set-secure-search-label"),
    };

    function fillButtonText(btnText)
    {
      if (!btnText)
      {
        return;
      }

      if (btnText.length > 8)
      {
        $el.doneButton.attr("class", "button__unfixed__width");
      }
      else
      {
        $el.doneButton.attr("class", "button__fixed__width");
      }
      
      $el.doneButton.text(btnText);
    }

    function initComponents(lang) {
      if (!lang)
      {
        return;
      }
    }

    function fillText(lang) {
      $el.contentInfoTitle.append(lang("TOAST_VARIANT_40_TITLE"));
      $el.contentInfoText.append(lang("TOAST_VARIANT_40_INFO"));
      $el.checkboxQuestion.text(lang("TOAST_VARIANT_40_QUESTION"));
      $el.setSecureSearchLabel.text(lang("TOAST_VARIANT_40_CHECKLIST"));

      const btnText = lang("TOAST_VARIANT_BUTTON");
      fillButtonText(btnText);
    }

    show = function () {
      _window.ready(function () {
        var payload = JSON.parse(_external.getArgument("toast_data"));
        init(payload);

        _settings.increment_setting("toast_variation_phase_2_show_count", "0");
        _window.show();
      });
    }

    init = function (payload) {
      var lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SS_TOAST_VARIANTS).get;

      _window.setWidth("530");

      initComponents(lang);
      fillText(lang);

      let toast_elements = document.getElementsByClassName("toast");

      if (!toast_elements || toast_elements.length < 1)
      {
        return;
      }

      _window.setHeight((toast_elements[0].scrollHeight+12).toString());

      $el.doneButton.click(function () {
        var isChecked = $el.checkboxInput.is(":checked");
        var telemetryActionType = isChecked ? "Accepted" : "Declined";
        var nativeAction = isChecked ? wa.Core.SecureSearch.enable : wa.Core.SecureSearch.disable;
        // Set secure search
        nativeAction();
        // Action telemetry
        var tc = _settings.getSettingScopedWithDefault(-1, "0", TOGGLE_COUNT);
        let tc_str = tc.toString();
        var telemetryEvent = new Secure_Search_Toast().action_type(telemetryActionType).browser(_instrument.getBrowserTypeCode()).provider(_instrument.getSecureSearchProvider()).toastType("ClawBack").toggle_count(tc_str).Serialize();
        _instrument.sendTelemetryEvent(telemetryEvent);

        //Telemetry 3
        var analyticsEvent = {
            _event_name: "wa_secure_search_toast_interaction",
            action_type: telemetryActionType,
            browser: _instrument.getBrowserTypeCode(),
            provider: _instrument.getSecureSearchProvider(),
            toast_type: "ClawBack",
            toggle_count: tc_str
        };
        _instrument.sendAnalyticsEvent(analyticsEvent);

        _window.close();
      });

      // Impression telemetry
      var telemetryEvent = new Secure_Search_Toast().action_type("Impression").browser(_instrument.getBrowserTypeCode()).provider(_instrument.getSecureSearchProvider()).toastType("ClawBack").Serialize();
      _instrument.sendTelemetryEvent(telemetryEvent)

      // Telemetry 3
      var analyticsEvent = {
        _event_name: "wa_secure_search_toast_impression",
        action_type: "Impression",
        browser: _instrument.getBrowserTypeCode(),
        provider: _instrument.getSecureSearchProvider(),
        toast_type: "ClawBack"
      };
      _instrument.sendAnalyticsEvent(analyticsEvent);
    }

    return {
      show: show
    }
  };

}(window.WebAdvisor = window.WebAdvisor || {}, jQuery));

// Show SecureSearch upsell toast
$(function () {
  var toast = new WebAdvisor.UI.accept_extension();
  toast.show();
});

//CBCD1F5BE70A007EAE369E75507FDB430FA2726538BC7A674A95FA5AE8CA86A5556A335344E25C44B8B54260B912088803BB2C716B33E41A60FD8A47DF0D1F40++