dispatcher.js 24.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
import LineHighlighter from './line_highlighter';
12 13
import Project from './project';
import projectAvatar from './project_avatar';
P
Phil Hughes 已提交
14
import MergeRequest from './merge_request';
15
import Compare from './compare';
16
import initCompareAutocomplete from './compare_autocomplete';
17
import ProjectNew from './project_new';
18 19
import Labels from './labels';
import LabelManager from './label_manager';
P
Phil Hughes 已提交
20
import Sidebar from './right_sidebar';
21
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
22
import Flash from './flash';
Z
Z.J. van de Weg 已提交
23
import BindInOut from './behaviors/bind_in_out';
24
import SecretValues from './behaviors/secret_values';
25
import Group from './group';
26
import ProjectsList from './projects_list';
M
Mike Greiling 已提交
27
import UserCallout from './user_callout';
G
geoandri 已提交
28
import ShortcutsWiki from './shortcuts_wiki';
D
Douwe Maan 已提交
29
import BlobViewer from './blob/viewer/index';
30
import AutoWidthDropdownSelect from './issuable/auto_width_dropdown_select';
31
import UsersSelect from './users_select';
32
import GfmAutoComplete from './gfm_auto_complete';
33
import Star from './star';
34
import TreeView from './tree';
35
import Wikis from './wikis';
36
import ZenMode from './zen_mode';
37
import initSettingsPanels from './settings_panels';
38
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
39 40
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
41
import initProjectVisibilitySelector from './project_visibility';
42
import NewGroupChild from './groups/new_group_child';
43
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
44 45
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
46 47 48
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
49
import U2FAuthenticate from './u2f/authenticate';
50 51
import Members from './members';
import memberExpirationDate from './member_expiration_date';
F
Filipa Lacerda 已提交
52
import DueDateSelectors from './due_date_select';
53
import Diff from './diff';
54
import ProjectLabelSubscription from './project_label_subscription';
F
Filipa Lacerda 已提交
55
import SearchAutocomplete from './search_autocomplete';
56
import Activities from './activities';
57

F
Fatih Acet 已提交
58 59 60 61 62 63
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
64
      this.initFieldErrors();
F
Fatih Acet 已提交
65 66 67 68
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
69
      var path, shortcut_handler;
70
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
71 72 73
      if (!page) {
        return false;
      }
74

75
      const fail = () => Flash('Error loading dynamic module');
76
      const callDefault = m => m.default();
77

F
Fatih Acet 已提交
78 79
      path = page.split(':');
      shortcut_handler = null;
80

F
Filipa Lacerda 已提交
81
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
82
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
83
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
84 85 86 87 88 89 90 91 92
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
93

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

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

296 297
          initIssuableSidebar();
          initNotes();
298

299 300 301 302
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
303 304

          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
305 306
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
307 308 309
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
310 311
          break;
        case 'projects:commit:show':
312 313 314 315
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
316
          break;
317
        case 'projects:commit:pipelines':
318 319 320
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
321
          break;
322
        case 'projects:activity':
323
          import('./pages/projects/activity')
324 325
            .then(callDefault)
            .catch(fail);
326
          shortcut_handler = true;
327
          break;
328
        case 'projects:commits:show':
329 330 331 332
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
333 334 335 336
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
337 338 339 340
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
341 342

          if ($('#tree-slider').length) new TreeView();
343
          if ($('.blob-viewer').length) new BlobViewer();
344
          if ($('.project-show-activity').length) new Activities();
345
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
346
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
347
          });
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
          // Initialize expandable settings panels
          initSettingsPanels();
508
          break;
D
Douwe Maan 已提交
509
        case 'projects:settings:ci_cd:show':
510 511
          // Initialize expandable settings panels
          initSettingsPanels();
512 513 514 515 516 517

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

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
697 698 699
    };

    Dispatcher.prototype.initSearch = function() {
700
      // Only when search form is present
F
Fatih Acet 已提交
701
      if ($('.search').length) {
F
Filipa Lacerda 已提交
702
        return new SearchAutocomplete();
F
Fatih Acet 已提交
703 704 705
      }
    };

706
    Dispatcher.prototype.initFieldErrors = function() {
707
      $('.gl-show-field-errors').each((i, form) => {
708
        new GlFieldErrors(form);
709
      });
710 711
    };

F
Fatih Acet 已提交
712 713
    return Dispatcher;
  })();
714

715
  $(window).on('load', function() {
716 717
    new Dispatcher();
  });
718
}).call(window);