BigW Consortium Gitlab

dispatcher.js.es6 9.62 KB
Newer Older
1
/* eslint-disable */
Fatih Acet committed
2 3 4 5 6 7 8 9 10 11
(function() {
  var Dispatcher;

  $(function() {
    return new Dispatcher();
  });

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
12
      this.initFieldErrors();
Fatih Acet committed
13 14 15 16 17 18 19 20 21 22 23 24
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
      var page, path, shortcut_handler;
      page = $('body').attr('data-page');
      if (!page) {
        return false;
      }
      path = page.split(':');
      shortcut_handler = null;
      switch (page) {
25 26 27
        case 'sessions:new':
          new UsernameValidator();
          break;
28
        case 'projects:boards:show':
29
        case 'projects:boards:index':
30 31
          shortcut_handler = new ShortcutsNavigation();
          break;
32 33 34
        case 'projects:builds:show':
          new Build();
          break;
35
        case 'projects:merge_requests:index':
Fatih Acet committed
36 37
        case 'projects:issues:index':
          Issuable.init();
38
          new gl.IssuableBulkActions();
Fatih Acet committed
39 40 41 42 43 44 45 46 47 48 49 50 51
          shortcut_handler = new ShortcutsNavigation();
          break;
        case 'projects:issues:show':
          new Issue();
          shortcut_handler = new ShortcutsIssuable();
          new ZenMode();
          break;
        case 'projects:milestones:show':
        case 'groups:milestones:show':
        case 'dashboard:milestones:show':
          new Milestone();
          break;
        case 'dashboard:todos:index':
Bryce Johnson committed
52
          new gl.Todos();
Fatih Acet committed
53 54 55 56
          break;
        case 'projects:milestones:new':
        case 'projects:milestones:edit':
          new ZenMode();
57
          new gl.DueDateSelectors();
Fatih Acet committed
58 59 60 61 62 63 64 65 66 67 68 69 70
          new GLForm($('.milestone-form'));
          break;
        case 'groups:milestones:new':
          new ZenMode();
          break;
        case 'projects:compare:show':
          new Diff();
          break;
        case 'projects:issues:new':
        case 'projects:issues:edit':
          shortcut_handler = new ShortcutsNavigation();
          new GLForm($('.issue-form'));
          new IssuableForm($('.issue-form'));
71 72
          new LabelsSelect();
          new MilestoneSelect();
73
          new gl.IssuableTemplateSelectors();
Fatih Acet committed
74 75 76 77 78 79 80
          break;
        case 'projects:merge_requests:new':
        case 'projects:merge_requests:edit':
          new Diff();
          shortcut_handler = new ShortcutsNavigation();
          new GLForm($('.merge-request-form'));
          new IssuableForm($('.merge-request-form'));
81 82
          new LabelsSelect();
          new MilestoneSelect();
83
          new gl.IssuableTemplateSelectors();
Fatih Acet committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
          break;
        case 'projects:tags:new':
          new ZenMode();
          new GLForm($('.tag-form'));
          break;
        case 'projects:releases:edit':
          new ZenMode();
          new GLForm($('.release-form'));
          break;
        case 'projects:merge_requests:show':
          new Diff();
          shortcut_handler = new ShortcutsIssuable(true);
          new ZenMode();
          new MergedButtons();
          break;
        case 'projects:merge_requests:commits':
        case 'projects:merge_requests:builds':
          new MergedButtons();
          break;
        case "projects:merge_requests:diffs":
          new Diff();
          new ZenMode();
          new MergedButtons();
          break;
        case 'projects:merge_requests:index':
          shortcut_handler = new ShortcutsNavigation();
          Issuable.init();
          break;
        case 'dashboard:activity':
113
          new gl.Activities();
Fatih Acet committed
114 115
          break;
        case 'dashboard:projects:starred':
116
          new gl.Activities();
Fatih Acet committed
117 118 119 120 121 122 123
          break;
        case 'projects:commit:show':
          new Commit();
          new Diff();
          new ZenMode();
          shortcut_handler = new ShortcutsNavigation();
          break;
124 125 126
        case 'projects:commit:builds':
          new gl.Pipelines();
          break;
Fatih Acet committed
127 128 129 130 131 132 133 134 135 136 137
        case 'projects:commits:show':
        case 'projects:activity':
          shortcut_handler = new ShortcutsNavigation();
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
          if ($('#tree-slider').length) {
            new TreeView();
          }
          break;
Filipa Lacerda committed
138
        case 'projects:pipelines:builds':
139
        case 'projects:pipelines:show':
Filipa Lacerda committed
140 141 142 143 144 145 146 147 148 149
          const controllerAction = document.querySelector('.js-pipeline-container').dataset.controllerAction;

          new gl.Pipelines({
            initTabs: true,
            tabsOptions: {
              action: controllerAction,
              defaultAction: 'pipelines',
              parentEl: '.pipelines-tabs',
            },
          });
150
          break;
Fatih Acet committed
151
        case 'groups:activity':
152
          new gl.Activities();
Fatih Acet committed
153 154 155 156 157 158 159
          break;
        case 'groups:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
          new NotificationsDropdown();
          break;
        case 'groups:group_members:index':
160
          new gl.MemberExpirationDate();
161
          new gl.Members();
Fatih Acet committed
162 163 164
          new UsersSelect();
          break;
        case 'projects:project_members:index':
165
          new gl.MemberExpirationDate();
166
          new gl.Members();
Fatih Acet committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
          new UsersSelect();
          break;
        case 'groups:new':
        case 'groups:edit':
        case 'admin:groups:edit':
        case 'admin:groups:new':
          new GroupAvatar();
          break;
        case 'projects:tree:show':
          shortcut_handler = new ShortcutsNavigation();
          new TreeView();
          break;
        case 'projects:find_file:show':
          shortcut_handler = true;
          break;
        case 'projects:blob:show':
        case 'projects:blame:show':
          new LineHighlighter();
          shortcut_handler = new ShortcutsNavigation();
          new ShortcutsBlob(true);
          break;
188 189
        case 'groups:labels:new':
        case 'groups:labels:edit':
Fatih Acet committed
190 191 192 193 194 195
        case 'projects:labels:new':
        case 'projects:labels:edit':
          new Labels();
          break;
        case 'projects:labels:index':
          if ($('.prioritized-labels').length) {
196
            new gl.LabelManager();
Fatih Acet committed
197 198 199
          }
          break;
        case 'projects:network:show':
200 201
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
Fatih Acet committed
202 203 204 205 206 207 208 209 210
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
          new ProjectFork();
          break;
        case 'projects:artifacts:browse':
          new BuildArtifacts();
          break;
        case 'projects:group_links:index':
211
          new gl.MemberExpirationDate();
Fatih Acet committed
212 213 214 215
          new GroupsSelect();
          break;
        case 'search:show':
          new Search();
216 217
          break;
        case 'projects:protected_branches:index':
218 219
          new gl.ProtectedBranchCreate();
          new gl.ProtectedBranchEditList();
220
          break;
221 222 223
        case 'projects:variables:index':
          new gl.ProjectVariables();
          break;
Fatih Acet committed
224 225 226 227 228 229 230 231 232 233
      }
      switch (path.first()) {
        case 'admin':
          new Admin();
          switch (path[1]) {
            case 'groups':
              new UsersSelect();
              break;
            case 'projects':
              new NamespaceSelects();
234 235
              break;
            case 'labels':
236
              switch (path[2]) {
237
                case 'new':
238 239 240
                case 'edit':
                  new Labels();
              }
241
            case 'abuse_reports':
242
              new gl.AbuseReports();
243
              break;
Fatih Acet committed
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
          }
          break;
        case 'dashboard':
        case 'root':
          shortcut_handler = new ShortcutsDashboardNavigation();
          break;
        case 'profiles':
          new NotificationsForm();
          new NotificationsDropdown();
          break;
        case 'projects':
          new Project();
          new ProjectAvatar();
          switch (path[1]) {
            case 'compare':
              new CompareAutocomplete();
              break;
            case 'edit':
              shortcut_handler = new ShortcutsNavigation();
              new ProjectNew();
              break;
            case 'new':
              new ProjectNew();
              break;
            case 'show':
269
              new Star();
Fatih Acet committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
              new ProjectNew();
              new ProjectShow();
              new NotificationsDropdown();
              break;
            case 'wikis':
              new Wikis();
              shortcut_handler = new ShortcutsNavigation();
              new ZenMode();
              new GLForm($('.wiki-form'));
              break;
            case 'snippets':
              shortcut_handler = new ShortcutsNavigation();
              if (path[2] === 'show') {
                new ZenMode();
              }
              break;
            case 'labels':
            case 'graphs':
            case 'compare':
            case 'pipelines':
            case 'forks':
            case 'milestones':
            case 'project_members':
            case 'deploy_keys':
            case 'builds':
            case 'hooks':
            case 'services':
            case 'protected_branches':
              shortcut_handler = new ShortcutsNavigation();
          }
      }
301
      // If we haven't installed a custom shortcut handler, install the default one
Fatih Acet committed
302 303 304 305 306 307
      if (!shortcut_handler) {
        return new Shortcuts();
      }
    };

    Dispatcher.prototype.initSearch = function() {
308
      // Only when search form is present
Fatih Acet committed
309
      if ($('.search').length) {
310
        return new gl.SearchAutocomplete();
Fatih Acet committed
311 312 313
      }
    };

314
    Dispatcher.prototype.initFieldErrors = function() {
315
      $('.gl-show-field-errors').each((i, form) => {
316 317
        new gl.GlFieldErrors(form);
      });
318 319
    };

Fatih Acet committed
320 321 322 323 324
    return Dispatcher;

  })();

}).call(this);