<commit_before>/**
 * The SubscribeView module.
 *
 * @return SubscribeView class (extends Backbone.View).
 */
define([
  'backbone',
  'underscore',
  'handlebars',
  'map/presenters/tabs/SubscribePresenter',
  'text!map/templates/tabs/subscribe.handlebars'
], function(Backbone, _, Handlebars, Presenter, tpl) {
  'use strict';

  var SubscribeModel = Backbone.Model.extend({
    defaults: {
      hidden: true
    }
  });


  var SubscribeView = Backbone.View.extend({

    el: '#analysis-subscribe',

    template: Handlebars.compile(tpl),

    /**
     * Map layer slugs with subscription url topics.
     */
    topics: {
      'forma': 'updates/forma'
    },

    events: {
      'click .close-icon' : 'hide',
      'click #subscribe': 'subscribeAlerts',
    },

    initialize: function(){
      this.presenter = new Presenter(this);
      this.render();
    },

    render: function(){
      this.$el.html(this.template());
      this.cacheVars();
    },

    cacheVars: function(){
      this.$content = this.$el.find('.analysis-subscribe-content');
      this.$steps = this.$el.find('.steps');
    },

    show: function(options){
      this.analysisResource = options.analysisResource;
      this.layer = options.layer;
      this.$el.addClass('active');
      this.$content.addClass('active');
    },

    hide: function(){
      this.$el.removeClass('active');
      this.$content.removeClass('active');
      this.nextStep(0);
    },


    subscribeAlerts: function() {
      var email = this.$el.find('#areaEmail').val();
      var topic = this.topics[this.layer.slug];

      var data = {
        topic: topic,
        email: email
      };

      ga('send', 'event', 'Map', 'Subscribe', 'Layer: ' + data.topic + ', Email: ' + data.email);

      if (this.analysisResource.iso) {
        data.iso = this.analysisResource.iso;
      } else if (this.analysisResource.geojson) {
        data.geom = JSON.parse(this.analysisResource.geojson);
      }
      if (this.validateEmail(email)) {
        $.ajax({
          type: 'POST',
          url: 'http://' + window.gfw.config.GFW_API_HOST + '/subscribe',
          crossDomain: true,
          data: JSON.stringify(data),
          dataType: 'json',
          success: _.bind(this._successSubscription, this),
          error: _.bind(function(responseData, textStatus, errorThrown) {
            this.remove();
          }, this)
        });
      }else{
        this.presenter.notificate('email-incorrect');
      }
    },
<commit_msg>Map: subscribe fix<commit_after>/**
 * The SubscribeView module.
 *
 * @return SubscribeView class (extends Backbone.View).
 */
define([
  'backbone',
  'underscore',
  'handlebars',
  'map/presenters/tabs/SubscribePresenter',
  'text!map/templates/tabs/subscribe.handlebars'
], function(Backbone, _, Handlebars, Presenter, tpl) {
  'use strict';

  var SubscribeModel = Backbone.Model.extend({
    defaults: {
      hidden: true
    }
  });


  var SubscribeView = Backbone.View.extend({

    el: '#analysis-subscribe',

    template: Handlebars.compile(tpl),

    /**
     * Map layer slugs with subscription url topics.
     */
    topics: {
      'forma': 'updates/forma'
    },

    events: {
      'click .close-icon' : 'hide',
      'click #subscribe': 'subscribeAlerts',
    },

    initialize: function(){
      this.presenter = new Presenter(this);
      this.render();
    },

    render: function(){
      this.$el.html(this.template());
      this.cacheVars();
    },

    cacheVars: function(){
      this.$content = this.$el.find('.analysis-subscribe-content');
      this.$steps = this.$el.find('.steps');
    },

    show: function(options){
      this.analysisResource = options.analysisResource;
      this.layer = options.layer;
      this.$el.addClass('active');
      this.$content.addClass('active');
    },

    hide: function(){
      this.$el.removeClass('active');
      this.$content.removeClass('active');
      this.nextStep(0);
    },


    subscribeAlerts: function() {
      var email = this.$el.find('#areaEmail').val();
      var topic = this.topics[this.layer.slug];

      var data = {
        topic: topic,
        email: email
      };

      ga('send', 'event', 'Map', 'Subscribe', 'Layer: ' + data.topic + ', Email: ' + data.email);

      if (this.analysisResource.iso) {
        data.iso = this.analysisResource.iso;
      } else if (this.analysisResource.geojson) {
        data.geom = JSON.parse(this.analysisResource.geojson);
      }
      if (this.validateEmail(email)) {
        $.ajax({
          type: 'POST',
          url: window.gfw.config.GFW_API_HOST + 'subscribe',
          crossDomain: true,
          data: JSON.stringify(data),
          dataType: 'json',
          success: _.bind(this._successSubscription, this),
          error: _.bind(function(responseData, textStatus, errorThrown) {
            this.remove();
          }, this)
        });
      }else{
        this.presenter.notificate('email-incorrect');
      }
    },

{'fraction_non_alphanumeric': 0.1591182364729459, 'fraction_numerical': 0.0004008016032064128, 'mean_word_length': 2.4231824417009604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3134833', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1502, 'n_words': 275}