All files / web/bundles/pimdatagrid/js/datagrid/action sequential-edit-action.js

80% Statements 12/15
50% Branches 2/4
100% Functions 4/4
80% Lines 12/15

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  299x                                         299x         6x   6x 6x   6x       6x   6x             6x                 6x 6x         6x            
/* global define */
define([
        'jquery',
        'underscore',
        'oro/translator',
        'routing',
        'oro/datagrid/mass-action',
        'pim/router',
        'oro/messenger',
        'pim/provider/sequential-edit-provider',
        'oro/loading-mask'
    ],
    function($, _, __, Routing, MassAction, router, messenger, sequentialEditProvider, LoadingMask) {
        'use strict';
 
        /**
         * Sequential edit action
         *
         * @export  oro/datagrid/sequential-edit-action
         * @class   oro.datagrid.SequentialEditAction
         * @extends oro.datagrid.MassAction
         */
        return MassAction.extend({
            /**
             * Execute sequential edit
             */
            execute: function() {
                const params = Object.assign({}, this.getActionParameters(), {gridName: this.datagrid.name, actionName: 'sequential_edit'});
 
                const loadingMask = new LoadingMask();
                loadingMask.render().$el.appendTo($('.hash-loading-mask')).show();
 
                return $.ajax({
                    url: Routing.generate('pim_enrich_sequential_edit_rest_get_ids'),
                    data: params
                }).then((response) => {
                    sequentialEditProvider.set(response.entities);
 
                    Iif (1000 < response.total) {
                        messenger.notify(
                            'warning',
                            __('pim_enrich.entity.product.module.sequential_edit.item_limit', {'count': response.total})
                        );
                    }
 
                    Iif (0 === response.total) {
                        messenger.notify(
                            'error',
                            __('pim_enrich.entity.product.module.sequential_edit.empty')
                        );
 
                        return;
                    }
 
                    const entity = _.first(response.entities);
                    router.redirectToRoute(
                        'pim_enrich_' + entity.type + '_edit',
                        { id: entity.id }
                    );
                }).always(() => {
                    loadingMask.hide().$el.remove();
                });
            }
        });
    }
);