BigW Consortium Gitlab

project_new.js 2.79 KB
Newer Older
1
/* eslint-disable */
Fatih Acet committed
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

Fatih Acet committed
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();
Fatih Acet committed
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);
      });
Fatih Acet committed
31 32 33
    };

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

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

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

47
    ProjectNew.prototype.toggleRepoVisibility = function () {
48 49 50
      var $repoAccessLevel = $('.js-repo-access-level select'),
          containerRegistry = document.querySelectorAll('.js-container-registry')[0],
          containerRegistryCheckbox = document.getElementById('project_container_registry_enabled');
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

      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');
75 76 77 78

            if (containerRegistry) {
              containerRegistry.style.display = '';
            }
79 80
          } else {
            this.$repoSelects.addClass('disabled');
81 82 83 84 85

            if (containerRegistry) {
              containerRegistry.style.display = 'none';
              containerRegistryCheckbox.checked = false;
            }
86 87 88 89
          }
        }.bind(this));
    };

Fatih Acet committed
90 91 92 93 94
    return ProjectNew;

  })();

}).call(this);