<commit_before>import { Utils, SaveProject, Video } from './util';

const Ticketing = {
  init(tickets) {
    if (tickets.boxofficeUrl) {
      this.initBoxfficeWidget(tickets);
    }

    this.initTicketModal();
  },

  initBoxfficeWidget({
    boxofficeUrl,
    widgetElem,
    org,
    itemCollectionId,
    itemCollectionTitle,
  }) {
    let url;

    if (boxofficeUrl.slice(-1) === '/') {
      url = `${boxofficeUrl}boxoffice.js`;
    } else {
      url = `${boxofficeUrl}/boxoffice.js`;
    }

    $.get({
      url,
      crossDomain: true,
      timeout: window.Hasgeek.config.ajaxTimeout,
      retries: 5,
      retryInterval: window.Hasgeek.config.retryInterval,

      success(data) {
        const boxofficeScript = document.createElement('script');
        boxofficeScript.innerHTML = data.script;
        document.getElementsByTagName('body')[0].appendChild(boxofficeScript);
      },

      error(response) {
        const ajaxLoad = this;
        ajaxLoad.retries -= 1;
        let errorMsg;

        if (response.readyState === 4) {
          errorMsg = window.gettext(
            'The server is experiencing difficulties. Try again in a few minutes'
          );
          $(widgetElem).html(errorMsg);
        } else if (response.readyState === 0) {
          if (ajaxLoad.retries < 0) {
            if (!navigator.onLine) {
              errorMsg = window.gettext(
                'This device has no internet connection'
              );
            } else {
              errorMsg = window.gettext(
                'Unable to connect. If this device is behind a firewall or using any script blocking extension (like Privacy Badger), please ensure your browser can load boxoffice.hasgeek.com, api.razorpay.com and checkout.razorpay.com '
              );
            }

            $(widgetElem).html(errorMsg);
          } else {
            setTimeout(() => {
              $.get(ajaxLoad);
            }, ajaxLoad.retryInterval);
          }
        }
      },
    });
    window.addEventListener(
      'onBoxofficeInit',
      () => {
        window.Boxoffice.init({
          org,
          itemCollection: itemCollectionId,
          paymentDesc: itemCollectionTitle,
        });
      },
      false
    );
    $(document).on(
      'boxofficeTicketingEvents',
      (event, userAction, label, value) => {
        Utils.sendToGA('ticketing', userAction, label, value);
      }
    );
    $(document).on(
      'boxofficeShowPriceEvent',
      (event, prices, currency, quantityAvailable) => {
        let price, minPrice, maxPrice, isTicketAvailable;
        isTicketAvailable = Math.min(...quantityAvailable);
        if (!isTicketAvailable) {
          $('.js-tickets-available').addClass('mui--hide');
          $('.js-tickets-not-available').removeClass('mui--hide');
          $('.js-open-ticket-widget').addClass('register-block__txt--strike');
        } else {
          minPrice = Math.min(...prices);
          price = `${currency}${minPrice}`;
          if (prices.length > 1) {
            maxPrice = Math.max(...prices);
            price = `${currency}${minPrice} - ${currency}${maxPrice}`;
          }
          $('.js-ticket-price').text(price);
        }
      }
    );
  },

  initTicketModal() {
    if (window.location.hash.indexOf('#tickets') > -1) {
      this.openTicketModal();
    }

    $('.js-open-ticket-widget').click((event) => {
      event.preventDefault();
      this.openTicketModal();
    });

    $('body').on('click', '#close-ticket-widget', (event) => {
      event.preventDefault();
      this.hideTicketModal();
    });<commit_msg>In case of no tickets or price, show sales closed. (#1058)<commit_after>import { Utils, SaveProject, Video } from './util';

const Ticketing = {
  init(tickets) {
    if (tickets.boxofficeUrl) {
      this.initBoxfficeWidget(tickets);
    }

    this.initTicketModal();
  },

  initBoxfficeWidget({
    boxofficeUrl,
    widgetElem,
    org,
    itemCollectionId,
    itemCollectionTitle,
  }) {
    let url;

    if (boxofficeUrl.slice(-1) === '/') {
      url = `${boxofficeUrl}boxoffice.js`;
    } else {
      url = `${boxofficeUrl}/boxoffice.js`;
    }

    $.get({
      url,
      crossDomain: true,
      timeout: window.Hasgeek.config.ajaxTimeout,
      retries: 5,
      retryInterval: window.Hasgeek.config.retryInterval,

      success(data) {
        const boxofficeScript = document.createElement('script');
        boxofficeScript.innerHTML = data.script;
        document.getElementsByTagName('body')[0].appendChild(boxofficeScript);
      },

      error(response) {
        const ajaxLoad = this;
        ajaxLoad.retries -= 1;
        let errorMsg;

        if (response.readyState === 4) {
          errorMsg = window.gettext(
            'The server is experiencing difficulties. Try again in a few minutes'
          );
          $(widgetElem).html(errorMsg);
        } else if (response.readyState === 0) {
          if (ajaxLoad.retries < 0) {
            if (!navigator.onLine) {
              errorMsg = window.gettext(
                'This device has no internet connection'
              );
            } else {
              errorMsg = window.gettext(
                'Unable to connect. If this device is behind a firewall or using any script blocking extension (like Privacy Badger), please ensure your browser can load boxoffice.hasgeek.com, api.razorpay.com and checkout.razorpay.com '
              );
            }

            $(widgetElem).html(errorMsg);
          } else {
            setTimeout(() => {
              $.get(ajaxLoad);
            }, ajaxLoad.retryInterval);
          }
        }
      },
    });
    window.addEventListener(
      'onBoxofficeInit',
      () => {
        window.Boxoffice.init({
          org,
          itemCollection: itemCollectionId,
          paymentDesc: itemCollectionTitle,
        });
      },
      false
    );
    $(document).on(
      'boxofficeTicketingEvents',
      (event, userAction, label, value) => {
        Utils.sendToGA('ticketing', userAction, label, value);
      }
    );
    $(document).on(
      'boxofficeShowPriceEvent',
      (event, prices, currency, quantityAvailable) => {
        let price, minPrice, maxPrice, isTicketAvailable;
        isTicketAvailable =
          quantityAvailable.length > 0 ? Math.min(...quantityAvailable) : 0;
        minPrice = prices.length > 0 ? Math.min(...prices) : 0;
        if (!isTicketAvailable || !minPrice) {
          $('.js-tickets-available').addClass('mui--hide');
          $('.js-tickets-not-available').removeClass('mui--hide');
          $('.js-open-ticket-widget').addClass('register-block__txt--strike');
        } else {
          price = `${currency}${minPrice}`;
          if (prices.length > 1) {
            maxPrice = Math.max(...prices);
            price = `${currency}${minPrice} - ${currency}${maxPrice}`;
          }
          $('.js-ticket-price').text(price);
        }
      }
    );
  },

  initTicketModal() {
    if (window.location.hash.indexOf('#tickets') > -1) {
      this.openTicketModal();
    }

    $('.js-open-ticket-widget').click((event) => {
      event.preventDefault();
      this.openTicketModal();
    });

    $('body').on('click', '#close-ticket-widget', (event) => {
      event.preventDefault();
      this.hideTicketModal();
    });
{'fraction_non_alphanumeric': 0.1435002046105579, 'fraction_numerical': 0.00354658300368299, 'mean_word_length': 2.0372825186412595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4719623', 'n_tokens_mistral': 2192, 'n_tokens_neox': 2119, 'n_words': 393}