dispatcher.js 22.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 */
F
Filipa Lacerda 已提交
2
import Milestone from './milestone';
3
import IssuableForm from './issuable_form';
4
import LabelsSelect from './labels_select';
C
Constance Okoghenun 已提交
5
import MilestoneSelect from './milestone_select';
P
Phil Hughes 已提交
6 7
import NotificationsForm from './notifications_form';
import notificationsDropdown from './notifications_dropdown';
P
Phil Hughes 已提交
8 9 10
import LineHighlighter from './line_highlighter';
import MergeRequest from './merge_request';
import Sidebar from './right_sidebar';
11
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
12
import Flash from './flash';
13
import SecretValues from './behaviors/secret_values';
M
Mike Greiling 已提交
14
import UserCallout from './user_callout';
D
Douwe Maan 已提交
15
import BlobViewer from './blob/viewer/index';
16
import GfmAutoComplete from './gfm_auto_complete';
17
import Star from './star';
18
import TreeView from './tree';
19
import ZenMode from './zen_mode';
20
import initSettingsPanels from './settings_panels';
21
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
22 23
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
24
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
25 26
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
27 28 29
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
30
import U2FAuthenticate from './u2f/authenticate';
31
import Diff from './diff';
F
Filipa Lacerda 已提交
32
import SearchAutocomplete from './search_autocomplete';
33
import Activities from './activities';
34

F
Fatih Acet 已提交
35 36 37 38 39 40
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
41
      this.initFieldErrors();
F
Fatih Acet 已提交
42 43 44 45
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
46
      var path, shortcut_handler;
47
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
48 49 50
      if (!page) {
        return false;
      }
51

52
      const fail = () => Flash('Error loading dynamic module');
53
      const callDefault = m => m.default();
54

F
Fatih Acet 已提交
55 56
      path = page.split(':');
      shortcut_handler = null;
57

F
Filipa Lacerda 已提交
58
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
59
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
60
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
61 62 63 64 65 66 67 68 69
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
70

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

277 278
          initIssuableSidebar();
          initNotes();
279

280 281 282 283
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
284
          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
285 286
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
287 288 289
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
290 291
          break;
        case 'projects:commit:show':
292 293 294 295
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
296
          break;
297
        case 'projects:commit:pipelines':
298 299 300
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
301
          break;
302
        case 'projects:activity':
303
          import('./pages/projects/activity')
304 305
            .then(callDefault)
            .catch(fail);
306
          shortcut_handler = true;
307
          break;
308
        case 'projects:commits:show':
309 310 311 312
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
313 314 315 316
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
317 318 319 320
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
321 322

          if ($('#tree-slider').length) new TreeView();
323
          if ($('.blob-viewer').length) new BlobViewer();
324
          if ($('.project-show-activity').length) new Activities();
325
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
326
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
327
          });
F
Fatih Acet 已提交
328
          break;
329
        case 'projects:edit':
S
Simon Knox 已提交
330 331 332
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
333
          break;
334
        case 'projects:imports:show':
S
Simon Knox 已提交
335 336 337
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
338
          break;
339
        case 'projects:pipelines:new':
340
        case 'projects:pipelines:create':
341 342 343
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
344
          break;
F
Filipa Lacerda 已提交
345
        case 'projects:pipelines:builds':
346
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
347
        case 'projects:pipelines:show':
348 349 350
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
351
          break;
F
Fatih Acet 已提交
352
        case 'groups:activity':
S
Simon Knox 已提交
353 354 355
          import('./pages/groups/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
356 357
          break;
        case 'groups:show':
S
Simon Knox 已提交
358 359 360 361
          import('./pages/groups/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
362 363
          break;
        case 'groups:group_members:index':
S
Simon Knox 已提交
364 365 366
          import('./pages/groups/group_members/index')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
367
          break;
368
        case 'projects:project_members:index':
369 370 371
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
372
          break;
373
        case 'groups:create':
S
Simon Knox 已提交
374 375 376 377 378 379 380 381 382
        case 'groups:new':
          import('./pages/groups/new')
            .then(callDefault)
            .catch(fail);
          break;
        case 'groups:edit':
          import('./pages/groups/edit')
            .then(callDefault)
            .catch(fail);
383
          break;
P
Phil Hughes 已提交
384 385
        case 'admin:groups:create':
        case 'admin:groups:new':
P
Phil Hughes 已提交
386 387 388
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
389
          break;
F
Fatih Acet 已提交
390
        case 'admin:groups:edit':
P
Phil Hughes 已提交
391 392 393
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
394
          break;
395
        case 'projects:tree:show':
396
          import('./pages/projects/tree/show')
397
            .then(callDefault)
398
            .catch(fail);
399
          shortcut_handler = true;
400
          break;
F
Fatih Acet 已提交
401
        case 'projects:find_file:show':
S
Simon Knox 已提交
402 403 404
          import('./pages/projects/find_file/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
405 406
          shortcut_handler = true;
          break;
407
        case 'projects:blob:show':
408 409 410 411
          import('./pages/projects/blob/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
412
          break;
F
Fatih Acet 已提交
413
        case 'projects:blame:show':
414 415 416 417
          import('./pages/projects/blame/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
418
          break;
419
        case 'groups:labels:new':
S
Simon Knox 已提交
420 421 422 423
          import('./pages/groups/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
424
        case 'groups:labels:edit':
S
Simon Knox 已提交
425 426 427
          import('./pages/groups/labels/edit')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
428
          break;
F
Fatih Acet 已提交
429
        case 'projects:labels:new':
J
Jacob Schatz 已提交
430 431 432 433
          import('./pages/projects/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
434
        case 'projects:labels:edit':
C
Clement Ho 已提交
435
          import('./pages/projects/labels/edit')
J
Jacob Schatz 已提交
436 437
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
438
          break;
S
Simon Knox 已提交
439 440 441 442 443
        case 'groups:labels:index':
          import('./pages/groups/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
444
        case 'projects:labels:index':
J
Jacob Schatz 已提交
445 446 447 448
          import('./pages/projects/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
449
        case 'projects:network:show':
450 451
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
452 453 454
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
S
Simon Knox 已提交
455
          import('./pages/projects/forks/new')
J
Jacob Schatz 已提交
456 457
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
458 459
          break;
        case 'projects:artifacts:browse':
460
          import('./pages/projects/artifacts/browse')
461 462
            .then(callDefault)
            .catch(fail);
463
          shortcut_handler = true;
F
Fatih Acet 已提交
464
          break;
465
        case 'projects:artifacts:file':
466
          import('./pages/projects/artifacts/file')
467 468
            .then(callDefault)
            .catch(fail);
469
          shortcut_handler = true;
470
          break;
471
        case 'help:index':
472 473 474
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
475
          break;
F
Fatih Acet 已提交
476
        case 'search:show':
C
Clement Ho 已提交
477 478 479
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
480
          break;
D
Douwe Maan 已提交
481
        case 'projects:settings:repository:show':
482 483
          // Initialize expandable settings panels
          initSettingsPanels();
484
          break;
D
Douwe Maan 已提交
485
        case 'projects:settings:ci_cd:show':
486 487
          // Initialize expandable settings panels
          initSettingsPanels();
488 489 490 491 492 493

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

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
657 658 659
    };

    Dispatcher.prototype.initSearch = function() {
660
      // Only when search form is present
F
Fatih Acet 已提交
661
      if ($('.search').length) {
F
Filipa Lacerda 已提交
662
        return new SearchAutocomplete();
F
Fatih Acet 已提交
663 664 665
      }
    };

666
    Dispatcher.prototype.initFieldErrors = function() {
667
      $('.gl-show-field-errors').each((i, form) => {
668
        new GlFieldErrors(form);
669
      });
670 671
    };

F
Fatih Acet 已提交
672 673
    return Dispatcher;
  })();
674

675
  $(window).on('load', function() {
676 677
    new Dispatcher();
  });
678
}).call(window);