All files / web/bundles/pimui/js/job/common/edit/content/data help.js

100% Statements 11/11
100% Branches 2/2
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                  45x               45x             55x   55x                   683x 683x   683x 222x     461x   461x   461x                
/**
 * Extension to add a help tooltip on filters.
 *
 * @author    Yohan Blain <yohan.blain@akeneo.com>
 * @copyright 2016 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 */
'use strict';
 
define([
    'jquery',
    'underscore',
    'oro/translator',
    'pim/form',
    'pim/template/export/product/edit/content/data/help'
 
], function ($, _, __, BaseForm, template) {
    return BaseForm.extend({
        template: _.template(template),
 
        /**
         * {@inheritdoc}
         */
        configure: function () {
            this.listenTo(this.getRoot(), 'pim_enrich:form:filter:extension:add', this.addFilterExtension.bind(this));
 
            return BaseForm.prototype.configure.apply(this, arguments);
        },
 
        /**
         * Adds the extension to filters.
         * If the translation is not here the tooltip won't be displayed at all.
         *
         * @param {Object} event
         */
        addFilterExtension: function (event) {
            var key  = 'pim_enrich.export.product.filter.' + event.filter.shortname + '.help';
            var text = __(key);
 
            if (key === text) {
                return;
            }
 
            var $content = $(this.template({text: text}));
 
            $content.find('[data-toggle="tooltip"]').tooltip();
 
            event.filter.addElement(
                'after-input',
                'help',
                $content
            );
        }
    });
});