All files / web/bundles/pimdatagrid/js/datagrid/cell action-cell.js

100% Statements 26/26
71.43% Branches 10/14
100% Functions 9/9
100% Lines 26/26

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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 1061123x                       1123x                             11364x 11364x   11364x                 11364x   11364x 11364x 11364x   44085x     44085x 44085x         11364x                   44085x                       11364x 44085x 44085x 7682x   44085x                   11250x 11250x 11250x 10253x 44085x     11250x   11250x          
define(
    ['jquery', 'underscore', 'backgrid'],
    function($, _, Backgrid) {
        'use strict';
 
        /**
         * Cell for grid actions
         *
         * @export  oro/datagrid/action-cell
         * @class   oro.datagrid.ActionCell
         * @extends Backgrid.Cell
         */
        return Backgrid.Cell.extend({
 
            /** @property */
            className: 'AknGrid-bodyCell AknGrid-bodyCell--actions action-cell',
 
            /** @property {Array} */
            actions: undefined,
 
            /** @property {Array} */
            launchers: undefined,
 
            /**
             * Initilize cell actions and launchers
             */
            initialize: function() {
                Backgrid.Cell.prototype.initialize.apply(this, arguments);
                this.actions = this.createActions();
 
                this.launchers = this.createLaunchers();
            },
 
            /**
             * Creates actions
             *
             * @return {Array}
             */
            createActions: function() {
                var result = [];
 
                var actions = this.column.get('actions');
                var actionConfiguration = this.model.get('action_configuration');
                _.each(actions, function(action, name) {
                    // filter available actions for current row
                    Eif (_.isUndefined(actionConfiguration) ||
                        _.isUndefined(actionConfiguration[name]) ||
                        actionConfiguration[name]) {
                        Eif (action.prototype.hidden !== true) {
                            result.push(this.createAction(action));
                        }
                    }
                }, this);
 
                return result;
            },
 
            /**
             * Creates action
             *
             * @param {Function} ActionPrototype
             * @protected
             */
            createAction: function(ActionPrototype) {
                return new ActionPrototype({
                    model: this.model,
                    datagrid: this.column.get('datagrid')
                });
            },
 
            /**
             * Creates actions launchers
             *
             * @protected
             */
            createLaunchers: function() {
                return _.map(this.actions, function(action) {
                    var launcherClass = action.launcherOptions.className;
                    if (_.isUndefined(launcherClass) || ('' === launcherClass) || ('no-hash' === launcherClass)) {
                        launcherClass = 'AknIconButton AknIconButton--small AknIconButton--grey';
                    }
                    return action.createLauncher({
                        className: launcherClass + ' AknButtonList-item'
                    });
                });
            },
 
            /**
             * Render cell with actions
             */
            render: function () {
                this.$el.empty();
                var iconsList = $('<div>').addClass('AknButtonList AknButtonList--right AknButtonList--expanded');
                if (!_.isEmpty(this.launchers)) {
                    _.each(this.launchers, function(launcher) {
                        iconsList.append(launcher.render().$el);
                    }, this);
                }
                this.$el.append(iconsList);
 
                return this;
            }
        });
    }
);