yaroslavbr
11/18/2016 - 10:52 AM

attribute-group-collection-component.js

define(function(require) {
    'use strict';

    var AttributeGroupComponent;
    var $ = require('jquery');
    var mediator = require('oroui/js/mediator');
    var BaseComponent = require('oroui/js/app/components/base/component');

    AttributeGroupComponent = BaseComponent.extend({

        /**
         * @property {Object}
         */
        options: {
            delimiter: ';'
        },

        /**
         * @inheritDoc
         */
        initialize: function(options) {
            this.options = _.defaults(options || {}, this.options);

            mediator.on('attribute-select:find-selected-attributes', this.onGetSelectedAttributes, this);
            //Remove delete button for default group
            if ($(this.options._sourceElement).find('[data-is-default]').val()) {
                $(this.options._sourceElement).parent().find('.removeRow.btn-link').remove();
            }
            //$(this.options._sourceElement).parent().width('550'); //Width fix for added elements
        },
        
        onGetSelectedAttributes: function (eventData) {
            var groupLabel = $(this.options._sourceElement).find('[data-attribute-select-group]').val();

            var attributesSelect = $(this.options._sourceElement).find('[data-name="field__attributes"]');
            if ($(attributesSelect).data('ftid') === eventData.sourceFtid) {
                return;
            }

            $(attributesSelect).find("option:selected").each(function () {
                var val = $(this).val();
                eventData.selectedOptions[val] = groupLabel;
            });
        }
    });

    return AttributeGroupComponent;
});