HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: //proc/self/cwd/nueva/admin346k89tef/themes/default/js/bundle/product/default-category.js
/**
 * Default category management
 */
const defaultCategory = (function () {
  const defaultCategoryForm = $('#form_step1_id_category_default');

  return {
    init() {
      // Populate category tree with the default category
      const defaultCategoryId = defaultCategoryForm.find('input:checked').val();
      productCategoriesTags.checkDefaultCategory(defaultCategoryId);

      /** Hide the default form, if javascript disabled it will be visible and so we
       * still can select a default category using the form
       */
      defaultCategoryForm.hide();
    },

    /**
     * Check the radio bouton with the selected value
     */
    check(value) {
      defaultCategoryForm.find(`input[value="${value}"]`).prop('checked', true);
    },

    isChecked(value) {
      return defaultCategoryForm.find(`input[value="${value}"]`).is(':checked');
    },

    /**
     * When the category selected as a default is unselected
     * The default category MUST be a selected category
     */
    reset() {
      const firstInput = defaultCategoryForm.find('input:first-child');
      firstInput.prop('checked', true);
      const categoryId = firstInput.val();
      productCategoriesTags.checkDefaultCategory(categoryId);
    },
  };
}());

window.defaultCategory = defaultCategory;

BOEvent.on('Product Default category Management started', () => {
  defaultCategory.init();
}, 'Back office');