<commit_before>var _ = require('underscore-cdb-v3');
var Backbone = require('backbone');
var CustomBaselayerModel = require('../../../../data/custom-baselayer-model');
var WMSServiceModel = require('../../../../data/wms-service-model');

/**
 * Model for an individual WMS/WMTS layer.
 */
module.exports = Backbone.Model.extend({

  defaults: {
    state: 'idle', //, saving, saveDone, saveFail
    layer: undefined // set after saveDone
  },

  SUPPORTED_MATRIX_SETS: [
    'EPSG:4326',
    'EPSG:4258'
  ],

  initialize: function (attrs, opts) {
    this.WMSServiceModel = WMSServiceModel;
  },

  canSave: function (customBaselayersCollection) {
    return !_.any(customBaselayersCollection.isCustomCategory(), function (customLayer) {
      return customLayer.get('name') === this.get('title');
    }, this);
  },

  createProxiedLayerOrCustomBaselayerModel: function () {
    this.set('state', 'saving');
    this._shouldBeProxied() ? this._createProxiedLayer() : this._newCustomBaselayerModel();
  },

  _supportedMatrixSets: function (matrixSets) {
    return _.intersection(matrixSets, this.SUPPORTED_MATRIX_SETS);
  },

  _shouldBeProxied: function () {
    if (this.get('type') === 'wmts') {
      var supportedMatrixSets = this._supportedMatrixSets(this.get('matrix_sets') || []);

      return supportedMatrixSets.length > 0;
    }

    return true;
  },

  _createProxiedLayer: function () {
    var self = this;

    this.wms = new this.WMSServiceModel({
      wms_url: this.url(),
      title: this.get('title'),
      name: this.get('name'),
      layer: this.get('name'),
      srs: this.get('srs'),
      bounding_boxes: this.get('llbbox'),
      type: this.get('type'), // wms/wmts
      matrix_sets: this.get('matrix_sets')
    });

    // Event tracking "WMS layer selected"
    // cdb.god.trigger('metrics', 'select_wms', {
    //   email: window.user_data.email
    // });

    this.wms.save({}, {
      success: function (mdl) {
        var customBaselayerModel;

        try {
          customBaselayerModel = mdl.newCustomBaselayerModel();
        } catch (e) {
        }

        if (customBaselayerModel) {
          self._setCustomBaselayerModel(customBaselayerModel);
        } else {<commit_msg>basemaps: wms, tests, remove event tracking<commit_after>var _ = require('underscore-cdb-v3');
var Backbone = require('backbone');
var CustomBaselayerModel = require('../../../../data/custom-baselayer-model');
var WMSServiceModel = require('../../../../data/wms-service-model');

/**
 * Model for an individual WMS/WMTS layer.
 */
module.exports = Backbone.Model.extend({

  defaults: {
    state: 'idle', //, saving, saveDone, saveFail
    layer: undefined // set after saveDone
  },

  SUPPORTED_MATRIX_SETS: [
    'EPSG:4326',
    'EPSG:4258'
  ],

  initialize: function (attrs, opts) {
    this.WMSServiceModel = WMSServiceModel;
  },

  canSave: function (customBaselayersCollection) {
    return !_.any(customBaselayersCollection.isCustomCategory(), function (customLayer) {
      return customLayer.get('name') === this.get('title');
    }, this);
  },

  createProxiedLayerOrCustomBaselayerModel: function () {
    this.set('state', 'saving');
    this._shouldBeProxied() ? this._createProxiedLayer() : this._newCustomBaselayerModel();
  },

  _supportedMatrixSets: function (matrixSets) {
    return _.intersection(matrixSets, this.SUPPORTED_MATRIX_SETS);
  },

  _shouldBeProxied: function () {
    if (this.get('type') === 'wmts') {
      var supportedMatrixSets = this._supportedMatrixSets(this.get('matrix_sets') || []);

      return supportedMatrixSets.length > 0;
    }

    return true;
  },

  _createProxiedLayer: function () {
    var self = this;

    this.wms = new this.WMSServiceModel({
      wms_url: this.url(),
      title: this.get('title'),
      name: this.get('name'),
      layer: this.get('name'),
      srs: this.get('srs'),
      bounding_boxes: this.get('llbbox'),
      type: this.get('type'), // wms/wmts
      matrix_sets: this.get('matrix_sets')
    });

    this.wms.save({}, {
      success: function (mdl) {
        var customBaselayerModel;

        try {
          customBaselayerModel = mdl.newCustomBaselayerModel();
        } catch (e) {
        }

        if (customBaselayerModel) {
          self._setCustomBaselayerModel(customBaselayerModel);
        } else {
{'fraction_non_alphanumeric': 0.15552995391705068, 'fraction_numerical': 0.004608294930875576, 'mean_word_length': 3.118595825426945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2657000', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1396, 'n_words': 246}