project_new.js 1.4 KB
Newer Older
F
Fatih Acet 已提交
1 2 3 4 5 6
(function() {
  var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  this.ProjectNew = (function() {
    function ProjectNew() {
      this.toggleSettings = bind(this.toggleSettings, this);
7 8 9
      this.$selects = $('.features select').filter(function () {
        return $(this).data('field');
      });
10

F
Fatih Acet 已提交
11 12 13 14 15 16 17 18 19 20 21
      $('.project-edit-container').on('ajax:before', (function(_this) {
        return function() {
          $('.project-edit-container').hide();
          return $('.save-project-loader').show();
        };
      })(this));
      this.toggleSettings();
      this.toggleSettingsOnclick();
    }

    ProjectNew.prototype.toggleSettings = function() {
22 23 24 25 26 27 28 29
      var self = this;

      this.$selects.each(function () {
        var $select = $(this),
            className = $select.data('field').replace(/_/g, '-')
              .replace('access-level', 'feature');
        self._showOrHide($select, '.' + className);
      });
F
Fatih Acet 已提交
30 31 32
    };

    ProjectNew.prototype.toggleSettingsOnclick = function() {
33
      this.$selects.on('change', this.toggleSettings);
F
Fatih Acet 已提交
34 35 36
    };

    ProjectNew.prototype._showOrHide = function(checkElement, container) {
37 38
      var $container = $(container);

39
      if ($(checkElement).val() !== '0') {
F
Fatih Acet 已提交
40 41 42 43 44 45 46 47 48 49 50
        return $container.show();
      } else {
        return $container.hide();
      }
    };

    return ProjectNew;

  })();

}).call(this);