dispatcher.js 23.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 14
import Labels from './labels';
import LabelManager from './label_manager';
P
Phil Hughes 已提交
15
import Sidebar from './right_sidebar';
16
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
17
import Flash from './flash';
Z
Z.J. van de Weg 已提交
18
import BindInOut from './behaviors/bind_in_out';
19
import SecretValues from './behaviors/secret_values';
20
import Group from './group';
21
import ProjectsList from './projects_list';
M
Mike Greiling 已提交
22
import UserCallout from './user_callout';
D
Douwe Maan 已提交
23
import BlobViewer from './blob/viewer/index';
24
import UsersSelect from './users_select';
25
import GfmAutoComplete from './gfm_auto_complete';
26
import Star from './star';
27
import TreeView from './tree';
28
import ZenMode from './zen_mode';
29
import initSettingsPanels from './settings_panels';
30
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
31 32
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
33
import NewGroupChild from './groups/new_group_child';
34
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
35 36
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
37 38 39
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
40
import U2FAuthenticate from './u2f/authenticate';
41 42
import Members from './members';
import memberExpirationDate from './member_expiration_date';
43
import Diff from './diff';
44
import ProjectLabelSubscription from './project_label_subscription';
F
Filipa Lacerda 已提交
45
import SearchAutocomplete from './search_autocomplete';
46
import Activities from './activities';
47

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

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

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

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

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

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

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

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

290 291
          initIssuableSidebar();
          initNotes();
292

293 294 295 296
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
297
          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
298 299
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
300 301 302
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
303 304
          break;
        case 'projects:commit:show':
305 306 307 308
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
309
          break;
310
        case 'projects:commit:pipelines':
311 312 313
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
314
          break;
315
        case 'projects:activity':
316
          import('./pages/projects/activity')
317 318
            .then(callDefault)
            .catch(fail);
319
          shortcut_handler = true;
320
          break;
321
        case 'projects:commits:show':
322 323 324 325
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
326 327 328 329
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
330 331 332 333
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
334 335

          if ($('#tree-slider').length) new TreeView();
336
          if ($('.blob-viewer').length) new BlobViewer();
337
          if ($('.project-show-activity').length) new Activities();
338
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
339
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
340
          });
F
Fatih Acet 已提交
341
          break;
342
        case 'projects:edit':
S
Simon Knox 已提交
343 344 345
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
346
          break;
347
        case 'projects:imports:show':
S
Simon Knox 已提交
348 349 350
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
351
          break;
352
        case 'projects:pipelines:new':
353
        case 'projects:pipelines:create':
354 355 356
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
357
          break;
F
Filipa Lacerda 已提交
358
        case 'projects:pipelines:builds':
359
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
360
        case 'projects:pipelines:show':
361 362 363
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
364
          break;
F
Fatih Acet 已提交
365
        case 'groups:activity':
366
          new Activities();
F
Fatih Acet 已提交
367 368
          break;
        case 'groups:show':
369
          const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup');
F
Fatih Acet 已提交
370 371
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
P
Phil Hughes 已提交
372
          notificationsDropdown();
373
          new ProjectsList();
374 375 376 377

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

            if ($el.find('.dropdown-group-label').length) {
460
              new GroupLabelSubscription($el);
461
            } else {
462
              new ProjectLabelSubscription($el);
463 464
            }
          });
F
Fatih Acet 已提交
465 466
          break;
        case 'projects:network:show':
467 468
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
469 470 471
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
S
Simon Knox 已提交
472
          import('./pages/projects/forks/new')
J
Jacob Schatz 已提交
473 474
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
475 476
          break;
        case 'projects:artifacts:browse':
477
          import('./pages/projects/artifacts/browse')
478 479
            .then(callDefault)
            .catch(fail);
480
          shortcut_handler = true;
F
Fatih Acet 已提交
481
          break;
482
        case 'projects:artifacts:file':
483
          import('./pages/projects/artifacts/file')
484 485
            .then(callDefault)
            .catch(fail);
486
          shortcut_handler = true;
487
          break;
488
        case 'help:index':
489 490 491
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
492
          break;
F
Fatih Acet 已提交
493
        case 'search:show':
C
Clement Ho 已提交
494 495 496
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
497
          break;
D
Douwe Maan 已提交
498
        case 'projects:settings:repository:show':
499 500
          // Initialize expandable settings panels
          initSettingsPanels();
501
          break;
D
Douwe Maan 已提交
502
        case 'projects:settings:ci_cd:show':
503 504
          // Initialize expandable settings panels
          initSettingsPanels();
505 506 507 508 509 510

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

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
676 677 678
    };

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

685
    Dispatcher.prototype.initFieldErrors = function() {
686
      $('.gl-show-field-errors').each((i, form) => {
687
        new GlFieldErrors(form);
688
      });
689 690
    };

F
Fatih Acet 已提交
691 692
    return Dispatcher;
  })();
693

694
  $(window).on('load', function() {
695 696
    new Dispatcher();
  });
697
}).call(window);