- this.element.modal({
- type: 'slide',
- modalClass: 'mage-new-category-dialog form-inline',
- title: $.mage.__('Create Category'),
-
- /** @inheritdoc */
- opened: function () {
- var enteredName = $('#category_ids-suggest').val();
-
- $('#new_category_name').val(enteredName);
-
- if (enteredName === '') {
- $('#new_category_name').focus();
- }
- $('#new_category_messages').html('');
- },
-
- /** @inheritdoc */
- closed: function () {
- var validationOptions = newCategoryForm.validation('option');
-
- $('#new_category_name, #new_category_parent-suggest').val('');
- validationOptions.unhighlight($('#new_category_parent-suggest').get(0),
- validationOptions.errorClass, validationOptions.validClass || '');
- newCategoryForm.validation('clearError');
- $('#category_ids-suggest').focus();
- },
- buttons: [{
- text: $.mage.__('Create Category'),
- class: 'action-primary',
-
- /** @inheritdoc */
- click: function (e) {
- var thisButton;
-
- if (!newCategoryForm.valid()) {
- return;
- }
- thisButton = $(e.currentTarget);
-
- thisButton.prop('disabled', true);
- $.ajax({
- type: 'POST',
- url: widget.options.saveCategoryUrl,
- data: {
- name: $('#new_category_name').val(),
- parent: $('#new_category_parent').val(),
- 'is_active': 1,
- 'include_in_menu': 1,
- 'use_config': ['available_sort_by', 'default_sort_by'],
- 'form_key': FORM_KEY,
- 'return_session_messages_only': 1
- },
- dataType: 'json',
- context: $('body')
- }).success(function (data) {
- var $suggest;
-
- if (!data.error) {
- $suggest = $('#category_ids-suggest');
-
- $suggest.trigger('selectItem', {
- id: data.category['entity_id'],
- label: data.category.name
- });
- $('#new_category_name, #new_category_parent-suggest').val('');
- $suggest.val('');
- clearParentCategory();
- $(widget.element).modal('closeModal');
- } else {
- $('#new_category_messages').html(data.messages);
- }
- }).complete(
- function () {
- thisButton.prop('disabled', false);
- }
- );
- }
- }]
- });