dispatcher.js 24.1 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 TreeView from './tree';
29
import ZenMode from './zen_mode';
30
import initSettingsPanels from './settings_panels';
31
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
32 33
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
34
import NewGroupChild from './groups/new_group_child';
35
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
36 37
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
38 39 40
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
41
import U2FAuthenticate from './u2f/authenticate';
42 43
import Members from './members';
import memberExpirationDate from './member_expiration_date';
44
import Diff from './diff';
45
import ProjectLabelSubscription from './project_label_subscription';
F
Filipa Lacerda 已提交
46
import SearchAutocomplete from './search_autocomplete';
47
import Activities from './activities';
48

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

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

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

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

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

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

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

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

316 317
          initIssuableSidebar();
          initNotes();
318

319 320 321 322
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
323
          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
324 325
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
326 327 328
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
329 330
          break;
        case 'projects:commit:show':
331 332 333 334
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
335
          break;
336
        case 'projects:commit:pipelines':
337 338 339
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
340
          break;
341
        case 'projects:activity':
342
          import('./pages/projects/activity')
343 344
            .then(callDefault)
            .catch(fail);
345
          shortcut_handler = true;
346
          break;
347
        case 'projects:commits:show':
348 349 350 351
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
352 353 354 355
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
356 357 358 359
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
360 361

          if ($('#tree-slider').length) new TreeView();
362
          if ($('.blob-viewer').length) new BlobViewer();
363
          if ($('.project-show-activity').length) new Activities();
364
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
365
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
366
          });
F
Fatih Acet 已提交
367
          break;
368
        case 'projects:edit':
S
Simon Knox 已提交
369 370 371
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
372
          break;
373
        case 'projects:imports:show':
S
Simon Knox 已提交
374 375 376
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
377
          break;
378
        case 'projects:pipelines:new':
379
        case 'projects:pipelines:create':
380 381 382
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
383
          break;
F
Filipa Lacerda 已提交
384
        case 'projects:pipelines:builds':
385
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
386
        case 'projects:pipelines:show':
387 388 389
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
390
          break;
F
Fatih Acet 已提交
391
        case 'groups:activity':
392
          new Activities();
F
Fatih Acet 已提交
393 394
          break;
        case 'groups:show':
395
          const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup');
F
Fatih Acet 已提交
396 397
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
P
Phil Hughes 已提交
398
          notificationsDropdown();
399
          new ProjectsList();
400 401 402 403

          if (newGroupChildWrapper) {
            new NewGroupChild(newGroupChildWrapper);
          }
F
Fatih Acet 已提交
404 405
          break;
        case 'groups:group_members:index':
406 407
          memberExpirationDate();
          new Members();
F
Fatih Acet 已提交
408 409
          new UsersSelect();
          break;
410
        case 'projects:project_members:index':
411 412 413
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
414 415
          break;
        case 'groups:new':
416
        case 'groups:create':
Z
Z.J. van de Weg 已提交
417
          BindInOut.initAll();
418
          new Group();
419
          groupAvatar();
420
          break;
P
Phil Hughes 已提交
421 422
        case 'admin:groups:create':
        case 'admin:groups:new':
P
Phil Hughes 已提交
423 424 425
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
426
          break;
F
Fatih Acet 已提交
427
        case 'admin:groups:edit':
P
Phil Hughes 已提交
428 429 430
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
431 432
          break;
        case 'groups:edit':
433
          groupAvatar();
F
Fatih Acet 已提交
434
          break;
435
        case 'projects:tree:show':
436
          import('./pages/projects/tree/show')
437
            .then(callDefault)
438
            .catch(fail);
439
          shortcut_handler = true;
440
          break;
F
Fatih Acet 已提交
441
        case 'projects:find_file:show':
S
Simon Knox 已提交
442 443 444
          import('./pages/projects/find_file/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
445 446
          shortcut_handler = true;
          break;
447
        case 'projects:blob:show':
448 449 450 451
          import('./pages/projects/blob/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
452
          break;
F
Fatih Acet 已提交
453
        case 'projects:blame:show':
454 455 456 457
          import('./pages/projects/blame/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
458
          break;
459 460
        case 'groups:labels:new':
        case 'groups:labels:edit':
C
Clement Ho 已提交
461 462
          new Labels();
          break;
F
Fatih Acet 已提交
463
        case 'projects:labels:new':
J
Jacob Schatz 已提交
464 465 466 467
          import('./pages/projects/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
468
        case 'projects:labels:edit':
C
Clement Ho 已提交
469
          import('./pages/projects/labels/edit')
J
Jacob Schatz 已提交
470 471
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
472 473
          break;
        case 'projects:labels:index':
J
Jacob Schatz 已提交
474 475 476 477 478
          import('./pages/projects/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
        case 'groups:labels:index':
F
Fatih Acet 已提交
479
          if ($('.prioritized-labels').length) {
480
            new LabelManager();
F
Fatih Acet 已提交
481
          }
482 483 484 485
          $('.label-subscription').each((i, el) => {
            const $el = $(el);

            if ($el.find('.dropdown-group-label').length) {
486
              new GroupLabelSubscription($el);
487
            } else {
488
              new ProjectLabelSubscription($el);
489 490
            }
          });
F
Fatih Acet 已提交
491 492
          break;
        case 'projects:network:show':
493 494
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
495 496 497
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
S
Simon Knox 已提交
498
          import('./pages/projects/forks/new')
J
Jacob Schatz 已提交
499 500
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
501 502
          break;
        case 'projects:artifacts:browse':
503
          import('./pages/projects/artifacts/browse')
504 505
            .then(callDefault)
            .catch(fail);
506
          shortcut_handler = true;
F
Fatih Acet 已提交
507
          break;
508
        case 'projects:artifacts:file':
509
          import('./pages/projects/artifacts/file')
510 511
            .then(callDefault)
            .catch(fail);
512
          shortcut_handler = true;
513
          break;
514
        case 'help:index':
515 516 517
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
518
          break;
F
Fatih Acet 已提交
519
        case 'search:show':
C
Clement Ho 已提交
520 521 522
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
523
          break;
D
Douwe Maan 已提交
524
        case 'projects:settings:repository:show':
525 526
          // Initialize expandable settings panels
          initSettingsPanels();
527
          break;
D
Douwe Maan 已提交
528
        case 'projects:settings:ci_cd:show':
529 530
          // Initialize expandable settings panels
          initSettingsPanels();
531 532 533 534 535 536

          const runnerToken = document.querySelector('.js-secret-runner-token');
          if (runnerToken) {
            const runnerTokenSecretValue = new SecretValues(runnerToken);
            runnerTokenSecretValue.init();
          }
S
Shinya Maeda 已提交
537
        case 'groups:settings:ci_cd:show':
538 539 540 541 542
          const secretVariableTable = document.querySelector('.js-secret-variable-table');
          if (secretVariableTable) {
            const secretVariableTableValues = new SecretValues(secretVariableTable);
            secretVariableTableValues.init();
          }
S
Stan Hu 已提交
543
          break;
544 545
        case 'ci:lints:create':
        case 'ci:lints:show':
546
          import('./pages/ci/lints').then(m => m.default()).catch(fail);
547
          break;
548
        case 'users:show':
549
          import('./pages/users/show').then(callDefault).catch(fail);
550
          break;
551
        case 'admin:conversational_development_index:show':
552
          import('./pages/admin/conversational_development_index/show').then(m => m.default()).catch(fail);
553
          break;
D
Douwe Maan 已提交
554
        case 'snippets:show':
C
Clement Ho 已提交
555 556 557
          import('./pages/snippets/show')
            .then(callDefault)
            .catch(fail);
D
Douwe Maan 已提交
558
          break;
559
        case 'import:fogbugz:new_user_map':
560
          import('./pages/import/fogbugz/new_user_map').then(m => m.default()).catch(fail);
561
          break;
562
        case 'profiles:personal_access_tokens:index':
563 564 565 566
          import('./pages/profiles/personal_access_tokens')
            .then(callDefault)
            .catch(fail);
          break;
567
        case 'admin:impersonation_tokens:index':
P
Phil Hughes 已提交
568 569 570
          import('./pages/admin/impersonation_tokens')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
571
          break;
F
Filipa Lacerda 已提交
572
        case 'projects:clusters:show':
573 574
        case 'projects:clusters:update':
        case 'projects:clusters:destroy':
575 576 577
          import('./pages/projects/clusters/show')
            .then(callDefault)
            .catch(fail);
578 579
          break;
        case 'projects:clusters:index':
580 581 582
          import('./pages/projects/clusters/index')
            .then(callDefault)
            .catch(fail);
F
Filipa Lacerda 已提交
583
          break;
F
Fatih Acet 已提交
584
      }
585
      switch (path[0]) {
586 587 588
        case 'sessions':
        case 'omniauth_callbacks':
          if (!gon.u2f) break;
F
Filipa Lacerda 已提交
589
          const u2fAuthenticate = new U2FAuthenticate(
590 591 592 593 594 595
            $('#js-authenticate-u2f'),
            '#js-login-u2f-form',
            gon.u2f,
            document.querySelector('#js-login-2fa-device'),
            document.querySelector('.js-2fa-form'),
          );
F
Filipa Lacerda 已提交
596 597 598
          u2fAuthenticate.start();
          // needed in rspec
          gl.u2fAuthenticate = u2fAuthenticate;
F
Fatih Acet 已提交
599
        case 'admin':
P
Phil Hughes 已提交
600 601 602
          import('./pages/admin')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
603
          switch (path[1]) {
M
Mike Greiling 已提交
604
            case 'broadcast_messages':
P
Phil Hughes 已提交
605 606 607
              import('./pages/admin/broadcast_messages')
                .then(callDefault)
                .catch(fail);
M
Mike Greiling 已提交
608
              break;
S
Sean McGivern 已提交
609
            case 'cohorts':
P
Phil Hughes 已提交
610 611 612
              import('./pages/admin/cohorts')
                .then(callDefault)
                .catch(fail);
613
              break;
F
Fatih Acet 已提交
614
            case 'groups':
P
Phil Hughes 已提交
615 616
              switch (path[2]) {
                case 'show':
P
Phil Hughes 已提交
617 618 619
                  import('./pages/admin/groups/show')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
620 621
                  break;
              }
F
Fatih Acet 已提交
622 623
              break;
            case 'projects':
P
Phil Hughes 已提交
624 625 626
              import('./pages/admin/projects')
                .then(callDefault)
                .catch(fail);
627 628
              break;
            case 'labels':
629
              switch (path[2]) {
630
                case 'new':
P
Phil Hughes 已提交
631 632 633
                  import('./pages/admin/labels/new')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
634
                  break;
635
                case 'edit':
P
Phil Hughes 已提交
636 637 638
                  import('./pages/admin/labels/edit')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
639
                  break;
640
              }
641
            case 'abuse_reports':
P
Phil Hughes 已提交
642 643 644
              import('./pages/admin/abuse_reports')
                .then(callDefault)
                .catch(fail);
645
              break;
F
Fatih Acet 已提交
646 647 648 649
          }
          break;
        case 'dashboard':
        case 'root':
650
          new UserCallout();
F
Fatih Acet 已提交
651 652
          break;
        case 'profiles':
653 654 655
          import('./pages/profiles/index/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
656 657
          break;
        case 'projects':
658 659 660 661
          import('./pages/projects')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
662 663
          switch (path[1]) {
            case 'compare':
664 665 666
              import('./pages/projects/compare')
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
667
              break;
668 669 670
            case 'create':
            case 'new':
              import('./pages/projects/new')
J
Jacob Schatz 已提交
671 672
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
673 674
              break;
            case 'show':
675
              new Star();
P
Phil Hughes 已提交
676
              notificationsDropdown();
F
Fatih Acet 已提交
677 678
              break;
            case 'wikis':
679 680 681 682
              import('./pages/projects/wikis')
                .then(callDefault)
                .catch(fail);
              shortcut_handler = true;
F
Fatih Acet 已提交
683 684 685 686
              break;
            case 'snippets':
              if (path[2] === 'show') {
                new ZenMode();
D
Douwe Maan 已提交
687 688
                new LineHighlighter();
                new BlobViewer();
F
Fatih Acet 已提交
689 690 691
              }
              break;
          }
692
          break;
F
Fatih Acet 已提交
693
      }
694
      // If we haven't installed a custom shortcut handler, install the default one
F
Fatih Acet 已提交
695
      if (!shortcut_handler) {
696
        new Shortcuts();
F
Fatih Acet 已提交
697
      }
698 699 700 701

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
702 703 704
    };

    Dispatcher.prototype.initSearch = function() {
705
      // Only when search form is present
F
Fatih Acet 已提交
706
      if ($('.search').length) {
F
Filipa Lacerda 已提交
707
        return new SearchAutocomplete();
F
Fatih Acet 已提交
708 709 710
      }
    };

711
    Dispatcher.prototype.initFieldErrors = function() {
712
      $('.gl-show-field-errors').each((i, form) => {
713
        new GlFieldErrors(form);
714
      });
715 716
    };

F
Fatih Acet 已提交
717 718
    return Dispatcher;
  })();
719

720
  $(window).on('load', function() {
721 722
    new Dispatcher();
  });
723
}).call(window);