dispatcher.js 23.2 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */
2
import projectSelect from './project_select';
F
Filipa Lacerda 已提交
3
import Milestone from './milestone';
4
import IssuableForm from './issuable_form';
5
import LabelsSelect from './labels_select';
C
Constance Okoghenun 已提交
6
import MilestoneSelect from './milestone_select';
P
Phil Hughes 已提交
7 8
import NotificationsForm from './notifications_form';
import notificationsDropdown from './notifications_dropdown';
9 10
import groupAvatar from './group_avatar';
import GroupLabelSubscription from './group_label_subscription';
P
Phil Hughes 已提交
11 12
import LineHighlighter from './line_highlighter';
import MergeRequest from './merge_request';
13
import Compare from './compare';
14 15
import Labels from './labels';
import LabelManager from './label_manager';
P
Phil Hughes 已提交
16
import Sidebar from './right_sidebar';
17
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
18
import Flash from './flash';
Z
Z.J. van de Weg 已提交
19
import BindInOut from './behaviors/bind_in_out';
20
import SecretValues from './behaviors/secret_values';
21
import Group from './group';
22
import ProjectsList from './projects_list';
M
Mike Greiling 已提交
23
import UserCallout from './user_callout';
D
Douwe Maan 已提交
24
import BlobViewer from './blob/viewer/index';
25
import UsersSelect from './users_select';
26
import GfmAutoComplete from './gfm_auto_complete';
27
import Star from './star';
28
import ZenMode from './zen_mode';
29
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
30 31
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
32
import NewGroupChild from './groups/new_group_child';
C
Clement Ho 已提交
33
import { convertPermissionToBoolean } from './lib/utils/common_utils';
34 35
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
36 37 38
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
39
import U2FAuthenticate from './u2f/authenticate';
40 41
import Members from './members';
import memberExpirationDate from './member_expiration_date';
42
import Diff from './diff';
43
import ProjectLabelSubscription from './project_label_subscription';
F
Filipa Lacerda 已提交
44
import SearchAutocomplete from './search_autocomplete';
45
import Activities from './activities';
46

F
Fatih Acet 已提交
47 48 49 50 51 52
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
53
      this.initFieldErrors();
F
Fatih Acet 已提交
54 55 56 57
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
58
      var path, shortcut_handler;
59
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
60 61 62
      if (!page) {
        return false;
      }
63

64
      const fail = () => Flash('Error loading dynamic module');
65
      const callDefault = m => m.default();
66

F
Fatih Acet 已提交
67 68
      path = page.split(':');
      shortcut_handler = null;
69

F
Filipa Lacerda 已提交
70
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
71
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
72
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
73 74 75 76 77 78 79 80 81
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
82

83 84
      const filteredSearchEnabled = gl.FilteredSearchManager && document.querySelector('.filtered-search');

F
Fatih Acet 已提交
85
      switch (page) {
86
        case 'sessions:new':
C
Clement Ho 已提交
87 88 89
          import('./pages/sessions/new')
            .then(callDefault)
            .catch(fail);
90
          break;
91
        case 'projects:boards:show':
92
        case 'projects:boards:index':
93 94 95 96
          import('./pages/projects/boards/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
97
          break;
98
        case 'projects:merge_requests:index':
99 100 101 102
          import('./pages/projects/merge_requests/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
103
          break;
S
Simon Knox 已提交
104 105 106 107 108 109
        case 'projects:issues:index':
          import('./pages/projects/issues/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
110
        case 'projects:issues:show':
S
Simon Knox 已提交
111 112 113 114
          import('./pages/projects/issues/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
115
          break;
P
Phil Hughes 已提交
116
        case 'dashboard:milestones:index':
117 118 119
          import('./pages/dashboard/milestones/index')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
120
          break;
F
Fatih Acet 已提交
121 122 123
        case 'projects:milestones:show':
        case 'groups:milestones:show':
          new Milestone();
124
          new Sidebar();
F
Fatih Acet 已提交
125
          break;
126 127 128 129 130
        case 'dashboard:milestones:show':
          import('./pages/dashboard/milestones/show')
            .then(callDefault)
            .catch(fail);
          break;
131
        case 'dashboard:issues':
C
Clement Ho 已提交
132 133 134
          import('./pages/dashboard/issues')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
135
          break;
136
        case 'dashboard:merge_requests':
137 138 139
          import('./pages/dashboard/merge_requests')
            .then(callDefault)
            .catch(fail);
140
          break;
141
        case 'groups:issues':
142
        case 'groups:merge_requests':
143
          if (filteredSearchEnabled) {
144
            const filteredSearchManager = new gl.FilteredSearchManager(page === 'groups:issues' ? 'issues' : 'merge_requests');
145 146
            filteredSearchManager.setup();
          }
147
          projectSelect();
148
          break;
F
Fatih Acet 已提交
149
        case 'dashboard:todos:index':
150
          import('./pages/dashboard/todos/index').then(callDefault).catch(fail);
F
Fatih Acet 已提交
151
          break;
152 153 154 155 156
        case 'admin:jobs:index':
          import('./pages/admin/jobs/index')
            .then(callDefault)
            .catch(fail);
          break;
157 158
        case 'dashboard:projects:index':
        case 'dashboard:projects:starred':
C
Clement Ho 已提交
159 160 161
          import('./pages/dashboard/projects')
            .then(callDefault)
            .catch(fail);
162
          break;
163 164 165
        case 'explore:projects:index':
        case 'explore:projects:trending':
        case 'explore:projects:starred':
166
          import('./pages/explore/projects')
J
Jacob Schatz 已提交
167
            .then(callDefault)
J
Jacob Schatz 已提交
168 169
            .catch(fail);
          break;
F
Filipa Lacerda 已提交
170
        case 'explore:groups:index':
171
          import('./pages/explore/groups')
J
Jacob Schatz 已提交
172
            .then(callDefault)
J
Jacob Schatz 已提交
173
            .catch(fail);
F
Filipa Lacerda 已提交
174
          break;
F
Fatih Acet 已提交
175
        case 'projects:milestones:new':
176 177 178 179 180
        case 'projects:milestones:create':
          import('./pages/projects/milestones/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
181
        case 'projects:milestones:edit':
182
        case 'projects:milestones:update':
183 184 185
          import('./pages/projects/milestones/edit')
            .then(callDefault)
            .catch(fail);
186
          break;
187
        case 'groups:milestones:new':
188 189 190 191 192
        case 'groups:milestones:create':
          import('./pages/groups/milestones/new')
            .then(callDefault)
            .catch(fail);
          break;
193 194
        case 'groups:milestones:edit':
        case 'groups:milestones:update':
195 196 197
          import('./pages/groups/milestones/edit')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
198 199
          break;
        case 'projects:compare:show':
200 201 202
          import('./pages/projects/compare/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
203
          break;
204
        case 'projects:branches:new':
205 206 207 208
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
          break;
209
        case 'projects:branches:create':
210 211 212
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
213
          break;
214
        case 'projects:branches:index':
215 216 217
          import('./pages/projects/branches/index')
            .then(callDefault)
            .catch(fail);
218
          break;
F
Fatih Acet 已提交
219
        case 'projects:issues:new':
S
Simon Knox 已提交
220 221 222 223 224
          import('./pages/projects/issues/new')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
225
        case 'projects:issues:edit':
S
Simon Knox 已提交
226 227 228 229
          import('./pages/projects/issues/edit')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
230
          break;
D
Douwe Maan 已提交
231
        case 'projects:merge_requests:creations:new':
232 233 234 235 236 237 238 239 240 241 242 243 244
          const mrNewCompareNode = document.querySelector('.js-merge-request-new-compare');
          if (mrNewCompareNode) {
            new Compare({
              targetProjectUrl: mrNewCompareNode.dataset.targetProjectUrl,
              sourceBranchUrl: mrNewCompareNode.dataset.sourceBranchUrl,
              targetBranchUrl: mrNewCompareNode.dataset.targetBranchUrl,
            });
          } else {
            const mrNewSubmitNode = document.querySelector('.js-merge-request-new-submit');
            new MergeRequest({
              action: mrNewSubmitNode.dataset.mrSubmitAction,
            });
          }
D
Douwe Maan 已提交
245
        case 'projects:merge_requests:creations:diffs':
F
Fatih Acet 已提交
246
        case 'projects:merge_requests:edit':
247
          new Diff();
F
Fatih Acet 已提交
248
          shortcut_handler = new ShortcutsNavigation();
249
          new GLForm($('.merge-request-form'), true);
F
Fatih Acet 已提交
250
          new IssuableForm($('.merge-request-form'));
251 252
          new LabelsSelect();
          new MilestoneSelect();
253
          new IssuableTemplateSelectors();
F
Fatih Acet 已提交
254 255
          break;
        case 'projects:tags:new':
256 257 258
          import('./pages/projects/tags/new')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
259
          break;
260
        case 'projects:snippets:show':
J
Jacob Schatz 已提交
261 262 263
          import('./pages/projects/snippets/show')
            .then(callDefault)
            .catch(fail);
264
          break;
265 266
        case 'projects:snippets:new':
        case 'projects:snippets:create':
J
Jacob Schatz 已提交
267 268 269 270
          import('./pages/projects/snippets/create')
            .then(callDefault)
            .catch(fail);
          break;
C
Clement Ho 已提交
271
        case 'projects:snippets:edit':
272
        case 'projects:snippets:update':
J
Jacob Schatz 已提交
273 274 275
          import('./pages/projects/snippets/update')
            .then(callDefault)
            .catch(fail);
276
          break;
277
        case 'snippets:new':
278 279 280 281
          import('./pages/snippets/new')
            .then(callDefault)
            .catch(fail);
          break;
282
        case 'snippets:edit':
283 284 285 286
          import('./pages/snippets/edit')
            .then(callDefault)
            .catch(fail);
          break;
287
        case 'snippets:create':
C
Clement Ho 已提交
288
          import('./pages/snippets/new')
289 290 291
            .then(callDefault)
            .catch(fail);
          break;
292
        case 'snippets:update':
C
Clement Ho 已提交
293
          import('./pages/snippets/edit')
294 295
            .then(callDefault)
            .catch(fail);
296
          break;
F
Fatih Acet 已提交
297
        case 'projects:releases:edit':
C
Clement Ho 已提交
298
          import('./pages/projects/releases/edit')
J
Jacob Schatz 已提交
299 300
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
301 302
          break;
        case 'projects:merge_requests:show':
303
          new Diff();
F
Fatih Acet 已提交
304
          new ZenMode();
305

306 307
          initIssuableSidebar();
          initNotes();
308

309 310 311 312
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
313
          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
314 315
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
316 317 318
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
319 320
          break;
        case 'projects:commit:show':
321 322 323 324
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
325
          break;
326
        case 'projects:commit:pipelines':
327 328 329
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
330
          break;
331
        case 'projects:activity':
332
          import('./pages/projects/activity')
333 334
            .then(callDefault)
            .catch(fail);
335
          shortcut_handler = true;
336
          break;
337
        case 'projects:commits:show':
338 339 340 341
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
342 343
          break;
        case 'projects:show':
344 345 346
          import('./pages/projects/show')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
347
          shortcut_handler = true;
F
Fatih Acet 已提交
348
          break;
349
        case 'projects:edit':
S
Simon Knox 已提交
350 351 352
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
353
          break;
354
        case 'projects:imports:show':
S
Simon Knox 已提交
355 356 357
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
358
          break;
359
        case 'projects:pipelines:new':
360
        case 'projects:pipelines:create':
361 362 363
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
364
          break;
F
Filipa Lacerda 已提交
365
        case 'projects:pipelines:builds':
366
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
367
        case 'projects:pipelines:show':
368 369 370
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
371
          break;
F
Fatih Acet 已提交
372
        case 'groups:activity':
373
          new Activities();
F
Fatih Acet 已提交
374 375
          break;
        case 'groups:show':
376
          const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup');
F
Fatih Acet 已提交
377 378
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
P
Phil Hughes 已提交
379
          notificationsDropdown();
380
          new ProjectsList();
381 382 383 384

          if (newGroupChildWrapper) {
            new NewGroupChild(newGroupChildWrapper);
          }
F
Fatih Acet 已提交
385 386
          break;
        case 'groups:group_members:index':
387 388
          memberExpirationDate();
          new Members();
F
Fatih Acet 已提交
389 390
          new UsersSelect();
          break;
391
        case 'projects:project_members:index':
392 393 394
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
395 396
          break;
        case 'groups:new':
397
        case 'groups:create':
Z
Z.J. van de Weg 已提交
398
          BindInOut.initAll();
399
          new Group();
400
          groupAvatar();
401
          break;
P
Phil Hughes 已提交
402 403
        case 'admin:groups:create':
        case 'admin:groups:new':
P
Phil Hughes 已提交
404 405 406
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
407
          break;
F
Fatih Acet 已提交
408
        case 'admin:groups:edit':
P
Phil Hughes 已提交
409 410 411
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
412 413
          break;
        case 'groups:edit':
414
          groupAvatar();
F
Fatih Acet 已提交
415
          break;
416
        case 'projects:tree:show':
417
          import('./pages/projects/tree/show')
418
            .then(callDefault)
419
            .catch(fail);
420
          shortcut_handler = true;
421
          break;
F
Fatih Acet 已提交
422
        case 'projects:find_file:show':
S
Simon Knox 已提交
423 424 425
          import('./pages/projects/find_file/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
426 427
          shortcut_handler = true;
          break;
428
        case 'projects:blob:show':
429 430 431 432
          import('./pages/projects/blob/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
433
          break;
F
Fatih Acet 已提交
434
        case 'projects:blame:show':
435 436 437 438
          import('./pages/projects/blame/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
439
          break;
440 441
        case 'groups:labels:new':
        case 'groups:labels:edit':
C
Clement Ho 已提交
442 443
          new Labels();
          break;
F
Fatih Acet 已提交
444
        case 'projects:labels:new':
J
Jacob Schatz 已提交
445 446 447 448
          import('./pages/projects/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
449
        case 'projects:labels:edit':
C
Clement Ho 已提交
450
          import('./pages/projects/labels/edit')
J
Jacob Schatz 已提交
451 452
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
453 454
          break;
        case 'projects:labels:index':
J
Jacob Schatz 已提交
455 456 457 458 459
          import('./pages/projects/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
        case 'groups:labels:index':
F
Fatih Acet 已提交
460
          if ($('.prioritized-labels').length) {
461
            new LabelManager();
F
Fatih Acet 已提交
462
          }
463 464 465 466
          $('.label-subscription').each((i, el) => {
            const $el = $(el);

            if ($el.find('.dropdown-group-label').length) {
467
              new GroupLabelSubscription($el);
468
            } else {
469
              new ProjectLabelSubscription($el);
470 471
            }
          });
F
Fatih Acet 已提交
472 473
          break;
        case 'projects:network:show':
474 475
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
476 477 478
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
S
Simon Knox 已提交
479
          import('./pages/projects/forks/new')
J
Jacob Schatz 已提交
480 481
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
482 483
          break;
        case 'projects:artifacts:browse':
484
          import('./pages/projects/artifacts/browse')
485 486
            .then(callDefault)
            .catch(fail);
487
          shortcut_handler = true;
F
Fatih Acet 已提交
488
          break;
489
        case 'projects:artifacts:file':
490
          import('./pages/projects/artifacts/file')
491 492
            .then(callDefault)
            .catch(fail);
493
          shortcut_handler = true;
494
          break;
495
        case 'help:index':
496 497 498
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
499
          break;
F
Fatih Acet 已提交
500
        case 'search:show':
C
Clement Ho 已提交
501 502 503
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
504
          break;
D
Douwe Maan 已提交
505
        case 'projects:settings:repository:show':
506 507 508
          import('./pages/projects/settings/repository/show')
            .then(callDefault)
            .catch(fail);
509
          break;
D
Douwe Maan 已提交
510
        case 'projects:settings:ci_cd:show':
511 512 513 514
          import('./pages/projects/settings/ci_cd/show')
            .then(callDefault)
            .catch(fail);
          break;
S
Shinya Maeda 已提交
515
        case 'groups:settings:ci_cd:show':
516 517 518 519 520
          const secretVariableTable = document.querySelector('.js-secret-variable-table');
          if (secretVariableTable) {
            const secretVariableTableValues = new SecretValues(secretVariableTable);
            secretVariableTableValues.init();
          }
S
Stan Hu 已提交
521
          break;
522 523
        case 'ci:lints:create':
        case 'ci:lints:show':
524
          import('./pages/ci/lints').then(m => m.default()).catch(fail);
525
          break;
526
        case 'users:show':
527
          import('./pages/users/show').then(callDefault).catch(fail);
528
          break;
529
        case 'admin:conversational_development_index:show':
530
          import('./pages/admin/conversational_development_index/show').then(m => m.default()).catch(fail);
531
          break;
D
Douwe Maan 已提交
532
        case 'snippets:show':
C
Clement Ho 已提交
533 534 535
          import('./pages/snippets/show')
            .then(callDefault)
            .catch(fail);
D
Douwe Maan 已提交
536
          break;
537
        case 'import:fogbugz:new_user_map':
538
          import('./pages/import/fogbugz/new_user_map').then(m => m.default()).catch(fail);
539
          break;
540
        case 'profiles:personal_access_tokens:index':
541 542 543 544
          import('./pages/profiles/personal_access_tokens')
            .then(callDefault)
            .catch(fail);
          break;
545
        case 'admin:impersonation_tokens:index':
P
Phil Hughes 已提交
546 547 548
          import('./pages/admin/impersonation_tokens')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
549
          break;
F
Filipa Lacerda 已提交
550
        case 'projects:clusters:show':
551 552
        case 'projects:clusters:update':
        case 'projects:clusters:destroy':
553 554 555
          import('./pages/projects/clusters/show')
            .then(callDefault)
            .catch(fail);
556 557
          break;
        case 'projects:clusters:index':
558 559 560
          import('./pages/projects/clusters/index')
            .then(callDefault)
            .catch(fail);
F
Filipa Lacerda 已提交
561
          break;
F
Fatih Acet 已提交
562
      }
563
      switch (path[0]) {
564 565 566
        case 'sessions':
        case 'omniauth_callbacks':
          if (!gon.u2f) break;
F
Filipa Lacerda 已提交
567
          const u2fAuthenticate = new U2FAuthenticate(
568 569 570 571 572 573
            $('#js-authenticate-u2f'),
            '#js-login-u2f-form',
            gon.u2f,
            document.querySelector('#js-login-2fa-device'),
            document.querySelector('.js-2fa-form'),
          );
F
Filipa Lacerda 已提交
574 575 576
          u2fAuthenticate.start();
          // needed in rspec
          gl.u2fAuthenticate = u2fAuthenticate;
F
Fatih Acet 已提交
577
        case 'admin':
P
Phil Hughes 已提交
578 579 580
          import('./pages/admin')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
581
          switch (path[1]) {
M
Mike Greiling 已提交
582
            case 'broadcast_messages':
P
Phil Hughes 已提交
583 584 585
              import('./pages/admin/broadcast_messages')
                .then(callDefault)
                .catch(fail);
M
Mike Greiling 已提交
586
              break;
S
Sean McGivern 已提交
587
            case 'cohorts':
P
Phil Hughes 已提交
588 589 590
              import('./pages/admin/cohorts')
                .then(callDefault)
                .catch(fail);
591
              break;
F
Fatih Acet 已提交
592
            case 'groups':
P
Phil Hughes 已提交
593 594
              switch (path[2]) {
                case 'show':
P
Phil Hughes 已提交
595 596 597
                  import('./pages/admin/groups/show')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
598 599
                  break;
              }
F
Fatih Acet 已提交
600 601
              break;
            case 'projects':
P
Phil Hughes 已提交
602 603 604
              import('./pages/admin/projects')
                .then(callDefault)
                .catch(fail);
605 606
              break;
            case 'labels':
607
              switch (path[2]) {
608
                case 'new':
P
Phil Hughes 已提交
609 610 611
                  import('./pages/admin/labels/new')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
612
                  break;
613
                case 'edit':
P
Phil Hughes 已提交
614 615 616
                  import('./pages/admin/labels/edit')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
617
                  break;
618
              }
619
            case 'abuse_reports':
P
Phil Hughes 已提交
620 621 622
              import('./pages/admin/abuse_reports')
                .then(callDefault)
                .catch(fail);
623
              break;
F
Fatih Acet 已提交
624 625 626 627
          }
          break;
        case 'dashboard':
        case 'root':
628
          new UserCallout();
F
Fatih Acet 已提交
629 630
          break;
        case 'profiles':
631 632 633
          import('./pages/profiles/index/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
634 635
          break;
        case 'projects':
636 637 638 639
          import('./pages/projects')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
640 641
          switch (path[1]) {
            case 'compare':
642 643 644
              import('./pages/projects/compare')
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
645
              break;
646 647 648
            case 'create':
            case 'new':
              import('./pages/projects/new')
J
Jacob Schatz 已提交
649 650
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
651 652
              break;
            case 'show':
653
              new Star();
P
Phil Hughes 已提交
654
              notificationsDropdown();
F
Fatih Acet 已提交
655 656
              break;
            case 'wikis':
657 658 659 660
              import('./pages/projects/wikis')
                .then(callDefault)
                .catch(fail);
              shortcut_handler = true;
F
Fatih Acet 已提交
661 662 663 664
              break;
            case 'snippets':
              if (path[2] === 'show') {
                new ZenMode();
D
Douwe Maan 已提交
665 666
                new LineHighlighter();
                new BlobViewer();
F
Fatih Acet 已提交
667 668 669
              }
              break;
          }
670
          break;
F
Fatih Acet 已提交
671
      }
672
      // If we haven't installed a custom shortcut handler, install the default one
F
Fatih Acet 已提交
673
      if (!shortcut_handler) {
674
        new Shortcuts();
F
Fatih Acet 已提交
675
      }
676 677 678 679

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
680 681 682
    };

    Dispatcher.prototype.initSearch = function() {
683
      // Only when search form is present
F
Fatih Acet 已提交
684
      if ($('.search').length) {
F
Filipa Lacerda 已提交
685
        return new SearchAutocomplete();
F
Fatih Acet 已提交
686 687 688
      }
    };

689
    Dispatcher.prototype.initFieldErrors = function() {
690
      $('.gl-show-field-errors').each((i, form) => {
691
        new GlFieldErrors(form);
692
      });
693 694
    };

F
Fatih Acet 已提交
695 696
    return Dispatcher;
  })();
697

698
  $(window).on('load', function() {
699 700
    new Dispatcher();
  });
701
}).call(window);