All files / web/bundles/pimdatagrid/js/fetcher datagrid-view-fetcher.js

100% Statements 12/12
100% Branches 4/4
100% Functions 3/3
100% Lines 12/12

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              1162x                     1162x                 993x   993x 497x 497x     993x                     992x   992x 497x 497x     992x          
'use strict';
 
/**
 * Datagrid View Fetcher.
 * We override the default fetcher to add additional methods
 * to fetch default columns & default user datagrid view.
 */
define(
    [
        'jquery',
        'routing',
        'pim/base-fetcher'
    ],
    function (
        $,
        Routing,
        BaseFetcher
    ) {
        return BaseFetcher.extend({
            /**
             * Fetch default columns for grid with given alias
             *
             * @param {string} alias
             *
             * @return Promise
             */
            defaultColumns: function (alias) {
                let columns = this.entityPromises['columns']
 
                if (!columns) {
                    columns = $.getJSON(Routing.generate(this.options.urls.columns, { alias: alias }));
                    this.entityPromises['columns'] = columns;
                }
 
                return columns;
            },
 
            /**
             * Fetch default datagrid view for given alias of the current user
             *
             * @param {string} alias
             *
             * @return Promise
             */
            defaultUserView: function (alias) {
                let view = this.entityPromises['view']
 
                if (!view) {
                    view = $.getJSON(Routing.generate(this.options.urls.userDefaultView, { alias: alias }));
                    this.entityPromises['view'] = view
                }
 
                return view
            }
        });
    }
);