(function () {
  'use strict';

  moj.Modules.Properties = {
    init: function() {
      this.cacheEls();
      this.bindEvents();
    },

    bindEvents: function() {
      var self = this;

      $('#PropertiesForm').on('submit', function(e) {
        var activeEl = document.activeElement;

        if(activeEl.type === 'submit' && activeEl.value) {
          e.preventDefault();
          self.handleAddRemoveButton(activeEl);
        } else {
          $.post('', self._injectFormData({}));
        }
      });
    },

    _injectFormData: function(data) {
      return this.$form.serializeArray().concat(data);
    },

    _updateForm: function(res) {
      this.$form.replaceWith($(res).find('#PropertiesForm'));

      this.init();
    },

    handleAddRemoveButton: function(button) {
      $.post('', this._injectFormData({
        name: button.name,
        value: button.value
      })).success($.proxy(this._updateForm, this));
    },

    cacheEls: function() {
      this.$form = $('#PropertiesForm');
    }
  };
}());

(function () {
  'use strict';

  moj.Modules.Properties = {
    init: function() {
      this.cacheEls();
      this.bindEvents();
    },

    bindEvents: function() {
      var self = this;

      $('#PropertiesForm').on('submit', function(e) {
        var activeEl = document.activeElement;

        if(activeEl.type === 'submit' && activeEl.value) {
          e.preventDefault();
          self.handleAddRemoveButton(activeEl);
        } else {
          $.post('', self._injectFormData({}));
        }
      });
    },

    _injectFormData: function(data) {
      return this.$form.serializeArray().concat(data);
    },

    _updateForm: function(res) {
      this.$form.replaceWith($(res).find('#PropertiesForm'));

      this.init();
    },

    handleAddRemoveButton: function(button) {
      var self = this;

      $.post('', this._injectFormData({
        name: button.name,
        value: button.value
      })).success(function(res) {
        self._updateForm(res);

        var totalProperties = self.$form.find('.fieldset-group').length;

        window.ga('send', 'event', 'property', button.name + ' / total:' + totalProperties);
      });
    },

    cacheEls: function() {
      this.$form = $('#PropertiesForm');
    }
  };
}());

Add events for property actions (add/remove)
FE: Add events for property actions (add/remove)
