- importContainer.modal({
- title: $.mage.__('Select Product'),
- type: 'slide',
-
- /** @inheritdoc */
- opened: function () {
- $(document).off().on('click', '#productGrid_massaction-form button', function () {
- $('.import-custom-options-apply-button').trigger('click', 'massActionTrigger');
- });
- },
- buttons: [{
- text: $.mage.__('Import'),
- attr: {
- id: 'import-custom-options-apply-button'
- },
- 'class': 'action-primary action-import import-custom-options-apply-button',
-
- /** @inheritdoc */
- click: function (event, massActionTrigger) {
- var request = [];
-
- $(this.element).find('input[name=product]:checked').map(function () {
- request.push(this.value);
- });
-
- if (request.length === 0) {
- if (!massActionTrigger) {
- alert({
- content: $.mage.__('Please select items.')
- });
- }
-
- return;
- }
-
- $.post(widget.options.customOptionsUrl, {
- 'products[]': request,
- 'form_key': widget.options.formKey
- }, function ($data) {
- $.parseJSON($data).each(function (el) {
- var i;
-
- el.id = widget.getFreeOptionId(el.id);
- el['option_id'] = el.id;
-
- if (typeof el.optionValues !== 'undefined') {
- for (i = 0; i < el.optionValues.length; i++) {
- el.optionValues[i]['option_id'] = el.id;
- }
- }
- //Adding option
- widget.addOption(el);
- //Will save new option on server side
- $('#product_option_' + el.id + '_option_id').val(0);
- $('#option_' + el.id + ' input[name$="option_type_id]"]').val(-1);
- });
- importContainer.modal('closeModal');
- });
- }
- }]
- });