Skip to content

Commit

Permalink
Fixes #1209 attribute edit options panel (1/2)
Browse files Browse the repository at this point in the history
w/ Swatches
  • Loading branch information
rbayet committed Nov 30, 2018
1 parent 3d750fc commit 06f37a2
Showing 1 changed file with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ define([
'use strict';

return function (optionConfig) {
var swatchProductAttributes = {
var activePanelClass = 'selected-type-options',
swatchProductAttributes = {
frontendInput: $('#frontend_input'),
isFilterable: $('#is_filterable'),
isFilterableInSearch: $('#is_filterable_in_search'),
Expand Down Expand Up @@ -218,6 +219,7 @@ define([
break;

case 'textarea':
case 'texteditor':
defaultValueTextareaVisibility = true;
break;

Expand Down Expand Up @@ -348,6 +350,7 @@ define([
*/
_showPanel: function (el) {
el.closest('.fieldset').show();
el.addClass(activePanelClass);
this._render(el.attr('id'));
},

Expand All @@ -357,6 +360,7 @@ define([
*/
_hidePanel: function (el) {
el.closest('.fieldset').hide();
el.removeClass(activePanelClass);
},

/**
Expand Down Expand Up @@ -424,6 +428,12 @@ define([
};

$(function () {
var editForm = $('#edit_form'),
swatchVisualPanel = $('#swatch-visual-options-panel'),
swatchTextPanel = $('#swatch-text-options-panel'),
tableBody = $(),
activePanel = $();

$('#frontend_input').bind('change', function () {
swatchProductAttributes.bindAttributeInputType();
});
Expand All @@ -437,6 +447,38 @@ define([
$('.attribute-popup .collapse, [data-role="advanced_fieldset-content"]')
.collapsable()
.collapse('hide');

editForm.on('beforeSubmit', function () {
var optionContainer, optionsValues;

activePanel = swatchTextPanel.hasClass(activePanelClass) ? swatchTextPanel : swatchVisualPanel;
optionContainer = activePanel.find('table tbody');

if (activePanel.hasClass(activePanelClass)) {
optionsValues = $.map(
optionContainer.find('tr'),
function (row) {
return $(row).find('input, select, textarea').serialize();
}
);
$('<input>')
.attr({
type: 'hidden',
name: 'serialized_options'
})
.val(JSON.stringify(optionsValues))
.prependTo(editForm);
}

tableBody = optionContainer.detach();
});

editForm.on('afterValidate.error highlight.validate', function () {
if (activePanel.hasClass(activePanelClass)) {
activePanel.find('table').append(tableBody);
$('input[name="serialized_options"]').remove();
}
});
});

window.saveAttributeInNewSet = swatchProductAttributes.saveAttributeInNewSet;
Expand Down

0 comments on commit 06f37a2

Please sign in to comment.