All files / web/bundles/pimui/js/fetcher locale-fetcher.js

84.21% Statements 16/19
58.33% Branches 7/12
100% Functions 4/4
84.21% Lines 16/19

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    1162x 1162x                 1162x                   1602x 1602x   1602x 1602x       1602x 729x           729x                         729x     729x       1602x             848x 848x   848x        
'use strict';
 
define(['jquery', 'underscore', 'pim/base-fetcher', 'routing'], function($, _, BaseFetcher, Routing) {
  return BaseFetcher.extend({
 
    activatedLocalesListPromise: null,
    nonFilteredActivatedLocalesListPromise: null,
 
    /**
     * @param {Object} options
     */
    initialize: function(options) {
      this.options = options || {};
    },
 
    /**
     * Fetch all activated locales.
     *
     * @return {Promise}
     */
    fetchActivated: function(searchOptions) {
 
      searchOptions = _.extend({}, searchOptions);
      const nonFiltered = _.has(searchOptions, 'filter_locales') && false === searchOptions.filter_locales;
 
      let promise = this.activatedLocalesListPromise;
      Iif (true === nonFiltered) {
        promise = this.nonFilteredActivatedLocalesListPromise;
      }
 
      if (!promise) {
        Iif (!_.has(this.options.urls, 'list')) {
          return $.Deferred()
            .reject()
            .promise();
        }
 
        promise = $.getJSON(
          Routing.generate(this.options.urls.list),
          Object.assign(
            {},
            {
              activated: true,
            },
            searchOptions
          )
        )
          .then(_.identity)
          .promise();
 
        Iif (true === nonFiltered) {
          this.nonFilteredActivatedLocalesListPromise = promise;
        } else {
          this.activatedLocalesListPromise = promise;
        }
      }
 
      return promise;
    },
 
    /**
     * {inheritdoc}
     */
    clear: function() {
      this.activatedLocalesListPromise = null;
      this.nonFilteredActivatedLocalesListPromise = null;
 
      BaseFetcher.prototype.clear.apply(this, arguments);
    },
  });
});