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

  this.ProjectNew = (function() {
    function ProjectNew() {
      this.toggleSettings = bind(this.toggleSettings, this);
8 9
      this.$selects = $('.features select');
      this.$repoSelects = this.$selects.filter('.js-repo-select');
10

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

    ProjectNew.prototype.toggleSettings = function() {
23 24 25 26 27 28 29 30
      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 已提交
31 32 33
    };

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

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

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

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 73 74 75 76 77 78
    ProjectNew.prototype.toggleRepoVisibility = function () {
      var $repoAccessLevel = $('.js-repo-access-level select');

      this.$repoSelects.find("option[value='" + $repoAccessLevel.val() + "']")
        .nextAll()
        .hide();

      $repoAccessLevel.off('change')
        .on('change', function () {
          var selectedVal = parseInt($repoAccessLevel.val());

          this.$repoSelects.each(function () {
            var $this = $(this),
                repoSelectVal = parseInt($this.val());

            $this.find('option').show();

            if (selectedVal < repoSelectVal) {
              $this.val(selectedVal);
            }

            $this.find("option[value='" + selectedVal + "']").nextAll().hide();
          });

          if (selectedVal) {
            this.$repoSelects.removeClass('disabled');
          } else {
            this.$repoSelects.addClass('disabled');
          }
        }.bind(this));
    };

F
Fatih Acet 已提交
79 80 81 82 83
    return ProjectNew;

  })();

}).call(this);