diff --git a/app/code/Magento/Ui/view/base/web/js/grid/columns/expandable.js b/app/code/Magento/Ui/view/base/web/js/grid/columns/expandable.js new file mode 100644 index 0000000000000..0874a9d32c8e9 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/js/grid/columns/expandable.js @@ -0,0 +1,102 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + './column' +], function (Column) { + 'use strict'; + + return Column.extend({ + defaults: { + bodyTmpl: 'ui/grid/cells/expandable', + tooltipTmpl: 'ui/grid/cells/expandable/content', + visibeItemsLimit: 5, + tooltipTitle: '' + }, + + /** + * Gets label from full options array. + * + * @param {Object} record - Record object. + * @returns {String} + */ + getFullLabel: function (record) { + return this.getLabelsArray(record).join(', '); + }, + + /** + * Gets label from options array limited by 'visibeItemsLimit'. + * + * @param {Object} record - Record object. + * @returns {String} + */ + getShortLabel: function (record) { + return this.getLabelsArray(record).slice(0, this.visibeItemsLimit).join(', '); + }, + + /** + * Extracts array of labels associated with provided values and sort it alphabetically. + * + * @param {Object} record - Record object. + * @returns {Array} + */ + getLabelsArray: function (record) { + var values = this.getLabel(record), + options = this.options || [], + labels = []; + + if (_.isString(values)) { + values = values.split(','); + } + + if (!Array.isArray(values)) { + values = [values]; + } + + values = values.map(function (value) { + return value + ''; + }); + + options = this.flatOptions(options); + + options.forEach(function (item) { + if (_.contains(values, item.value + '')) { + labels.push(item.label); + } + }); + + return labels.sort(); + }, + + /** + * Transformation tree options structure to liner array. + * + * @param {Array} options + * @returns {Array} + */ + flatOptions: function (options) { + var self = this; + + return options.reduce(function (options, option) { + if (_.isArray(option.value)) { + options = options.concat(self.flatOptions(option.value)); + } else { + options.push(option); + } + + return options; + }, []); + }, + + /** + * Checks if amount of options is more than limit value. + * + * @param {Object} record - Data to be preprocessed. + * @returns {Boolean} + */ + isExpandable: function (record) { + return this.getLabel(record).length > this.visibeItemsLimit; + } + }); +}); diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/tooltip.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/tooltip.js index 4600ec08a5392..cfd898b61e5e7 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/tooltip.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/tooltip.js @@ -43,10 +43,12 @@ define([ closeButton: false, showed: false, strict: true, - center: false + center: false, + closeOnScroll: true }; tooltipData = { + tooltipClasses: '', trigger: false, timeout: 0, element: false, @@ -578,9 +580,12 @@ define([ $('.' + config.closeButtonClass).on('click.closeButton', tooltip.destroy.bind(null, id)); } - document.addEventListener('scroll', tooltip.destroy, true); + if (config.closeOnScroll) { + document.addEventListener('scroll', tooltip.destroy, true); + $(window).on('scroll.tooltip', tooltip.outerClick.bind(null, id)); + } + $(window).on('keydown.tooltip', tooltip.keydownHandler); - $(window).on('scroll.tooltip', tooltip.outerClick.bind(null, id)); $(window).on('resize.outerClick', tooltip.outerClick.bind(null, id)); }, @@ -666,6 +671,7 @@ define([ $('.' + defaults.closeButtonClass).off('click.closeButton'); tooltipData.trigger.off('mousemove.track'); document.removeEventListener('scroll', tooltip.destroy, true); + $(window).off('scroll.tooltip'); $(window).off(CLICK_EVENT + '.outerClick'); $(window).off('keydown.tooltip'); $(window).off('resize.outerClick'); diff --git a/app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable.html b/app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable.html new file mode 100644 index 0000000000000..f4de78f71e238 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable.html @@ -0,0 +1,27 @@ + +
diff --git a/app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable/content.html b/app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable/content.html new file mode 100644 index 0000000000000..88731f412a7a9 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/templates/grid/cells/expandable/content.html @@ -0,0 +1,14 @@ + +