All files / web/bundles/pimui/js/fetcher attribute-group-fetcher.js

88.89% Statements 8/9
87.5% Branches 7/8
100% Functions 3/3
88.89% Lines 8/9

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                  1162x                     1162x                   238x                 4325x   4325x 494x       494x                 4325x        
'use strict';
 
/**
 * Attribute group fetcher
 *
 * @author    Alexandr Jeliuc <alex@jeliuc.com>
 * @copyright 2017 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 */
define([
    'jquery',
    'underscore',
    'pim/base-fetcher',
    'routing'
], function (
    $,
    _,
    BaseFetcher,
    Routing
) {
    return BaseFetcher.extend({
        /**
         * Overrides base method, to send query using POST instead GET,
         * because the request URI can be too long.
         * TODO Should be deleted to set it back to GET.
         * SEE attribute fetcher
         *
         * {@inheritdoc}
         */
        getJSON: function (url, parameters) {
            return $.post(Routing.generate(url), parameters, null, 'json');
        },
 
        /**
         * Overrides bas method to remove the limit and fetch all the attribute groups.
         *
         * {@inheritdoc}
         */
        fetchAll: function (options) {
            options = options || {};
 
            if (null === this.entityListPromise || false === options.cached) {
                Iif (!_.has(this.options.urls, 'list')) {
                    return $.Deferred().reject().promise();
                }
 
                this.entityListPromise = $.getJSON(
                    Routing.generate(this.options.urls.list, {
                        options: {
                            limit: -1
                        }
                    })
                ).then(_.identity).promise();
            }
 
            return this.entityListPromise;
        }
    });
});