dispatcher.js.coffee 4.13 KB
Newer Older
1 2
$ ->
  new Dispatcher()
3

4 5
class Dispatcher
  constructor: () ->
6 7 8 9
    @initSearch()
    @initPageScripts()

  initPageScripts: ->
10
    page = $('body').attr('data-page')
11
    project_id = $('body').attr('data-project-id')
12

13 14 15
    unless page
      return false

16
    path = page.split(':')
17
    shortcut_handler = null
18 19

    switch page
20
      when 'projects:issues:index'
21
        Issues.init()
22
        shortcut_handler = new ShortcutsNavigation()
23 24
      when 'projects:issues:show'
        new Issue()
25
        shortcut_handler = new ShortcutsIssueable()
26
        new ZenMode()
27 28
      when 'projects:milestones:show'
        new Milestone()
29 30
      when 'projects:milestones:new'
        new ZenMode()
31
      when 'projects:issues:new','projects:issues:edit'
32
        GitLab.GfmAutoComplete.setup()
33
        shortcut_handler = new ShortcutsNavigation()
34
        new ZenMode()
35
        new DropzoneInput($('.issue-form'))
36
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
skv's avatar
skv committed
37 38
        GitLab.GfmAutoComplete.setup()
        new Diff()
39
        shortcut_handler = new ShortcutsNavigation()
40
        new ZenMode()
41
        new DropzoneInput($('.merge-request-form'))
skv's avatar
skv committed
42 43
      when 'projects:merge_requests:show'
        new Diff()
44
        shortcut_handler = new ShortcutsIssueable()
45
        new ZenMode()
skv's avatar
skv committed
46 47
      when "projects:merge_requests:diffs"
        new Diff()
48
        new ZenMode()
49 50
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
51 52
      when 'dashboard:show'
        new Dashboard()
53
        new Activities()
54
      when 'projects:commit:show'
55
        new Commit()
skv's avatar
skv committed
56
        new Diff()
57 58 59
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
60
      when 'groups:show', 'projects:show'
61
        new Activities()
62
        shortcut_handler = new ShortcutsNavigation()
63
      when 'groups:members'
64
        new GroupMembers()
65
        new UsersSelect()
66 67
      when 'groups:new', 'groups:edit', 'admin:groups:edit'
        new GroupAvatar()
68 69
      when 'projects:tree:show'
        new TreeView()
70
        shortcut_handler = new ShortcutsNavigation()
71 72
      when 'projects:blob:show'
        new BlobView()
73
        shortcut_handler = new ShortcutsNavigation()
74
      when 'projects:labels:new', 'projects:labels:edit'
75
        new Labels()
76 77 78 79
      when 'projects:network:show'
        # Ensure we don't create a particular shortcut handler here. This is
        # already created, where the network graph is created.
        shortcut_handler = true
80 81
      when 'projects:forks:new'
        new ProjectFork()
82 83
      when 'users:show'
        new User()
84 85

    switch path.first()
86 87 88
      when 'admin'
        new Admin()
        switch path[1]
89 90
          when 'groups'
            new UsersSelect()
91 92
          when 'projects'
            new NamespaceSelect()
93 94
      when 'dashboard'
        shortcut_handler = new ShortcutsDashboardNavigation()
95 96
      when 'profiles'
        new Profile()
97
      when 'projects'
98
        new Project()
99
        new ProjectAvatar()
100
        switch path[1]
101 102 103 104 105 106 107
          when 'edit'
            shortcut_handler = new ShortcutsNavigation()
            new ProjectNew()
          when 'new'
            new ProjectNew()
          when 'show'
            new ProjectShow()
108 109
          when 'issues', 'merge_requests'
            new ProjectUsersSelect()
110 111 112
          when 'wikis'
            new Wikis()
            shortcut_handler = new ShortcutsNavigation()
113
            new ZenMode()
114
            new DropzoneInput($('.wiki-form'))
115 116 117 118
          when 'snippets', 'labels', 'graphs'
            shortcut_handler = new ShortcutsNavigation()
          when 'team_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
            shortcut_handler = new ShortcutsNavigation()
119
            new UsersSelect()
120

121

122 123 124
    # If we haven't installed a custom shortcut handler, install the default one
    if not shortcut_handler
      new Shortcuts()
125

126
  initSearch: ->
127 128 129 130 131 132
    opts = $('.search-autocomplete-opts')
    path = opts.data('autocomplete-path')
    project_id = opts.data('autocomplete-project-id')
    project_ref = opts.data('autocomplete-project-ref')

    new SearchAutocomplete(path, project_id, project_ref)