dispatcher.js.coffee 4.9 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(':')
R
Robert Schilling 已提交
17
    shortcut_handler = null
18 19

    switch page
20
      when 'projects:issues:index'
21
        Issues.init()
R
Robert Schilling 已提交
22
        shortcut_handler = new ShortcutsNavigation()
23 24
      when 'projects:issues:show'
        new Issue()
R
Robert Schilling 已提交
25
        shortcut_handler = new ShortcutsIssueable()
26
        new ZenMode()
27 28
      when 'projects:milestones:show'
        new Milestone()
29
      when 'projects:milestones:new', 'projects:milestones:edit'
R
Robert Schilling 已提交
30
        new ZenMode()
31 32
      when 'projects:compare:show'
        new Diff()
33
      when 'projects:issues:new','projects:issues:edit'
D
Dmitriy Zaporozhets 已提交
34
        GitLab.GfmAutoComplete.setup()
R
Robert Schilling 已提交
35
        shortcut_handler = new ShortcutsNavigation()
36
        new ZenMode()
37
        new DropzoneInput($('.issue-form'))
38 39
        if page == 'projects:issues:new'
          new IssuableForm($('.issue-form'))
40
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
S
skv 已提交
41 42
        GitLab.GfmAutoComplete.setup()
        new Diff()
R
Robert Schilling 已提交
43
        shortcut_handler = new ShortcutsNavigation()
44
        new ZenMode()
45
        new DropzoneInput($('.merge-request-form'))
46 47
        if page == 'projects:merge_requests:new'
          new IssuableForm($('.merge-request-form'))
S
skv 已提交
48 49
      when 'projects:merge_requests:show'
        new Diff()
R
Robert Schilling 已提交
50
        shortcut_handler = new ShortcutsIssueable()
51
        new ZenMode()
S
skv 已提交
52 53
      when "projects:merge_requests:diffs"
        new Diff()
54
        new ZenMode()
R
Robert Schilling 已提交
55 56
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
57
        MergeRequests.init()
58 59
      when 'dashboard:show'
        new Dashboard()
60
        new Activities()
61 62 63
      when 'dashboard:projects:starred'
        new Activities()
        new ProjectsList()
64
      when 'projects:commit:show'
65
        new Commit()
S
skv 已提交
66
        new Diff()
67
        new ZenMode()
R
Robert Schilling 已提交
68 69 70
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
D
Dmitriy Zaporozhets 已提交
71
      when 'projects:show'
72
        new Activities()
R
Robert Schilling 已提交
73
        shortcut_handler = new ShortcutsNavigation()
D
Dmitriy Zaporozhets 已提交
74 75 76 77
      when 'groups:show'
        new Activities()
        shortcut_handler = new ShortcutsNavigation()
        new ProjectsList()
78
      when 'groups:group_members:index'
79
        new GroupMembers()
80
        new UsersSelect()
81 82 83
      when 'projects:project_members:index'
        new ProjectMembers()
        new UsersSelect()
84 85
      when 'groups:new', 'groups:edit', 'admin:groups:edit'
        new GroupAvatar()
86 87
      when 'projects:tree:show'
        new TreeView()
R
Robert Schilling 已提交
88
        shortcut_handler = new ShortcutsNavigation()
89 90
      when 'projects:blob:show'
        new BlobView()
R
Robert Schilling 已提交
91
        shortcut_handler = new ShortcutsNavigation()
92
      when 'projects:labels:new', 'projects:labels:edit'
93
        new Labels()
R
Robert Schilling 已提交
94 95 96 97
      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
98 99
      when 'projects:forks:new'
        new ProjectFork()
100 101
      when 'users:show'
        new User()
102
        new Activities()
D
Douwe Maan 已提交
103 104
      when 'admin:users:show'
        new ProjectsList()
105 106

    switch path.first()
107 108 109
      when 'admin'
        new Admin()
        switch path[1]
110 111
          when 'groups'
            new UsersSelect()
112 113
          when 'projects'
            new NamespaceSelect()
R
Robert Schilling 已提交
114 115
      when 'dashboard'
        shortcut_handler = new ShortcutsDashboardNavigation()
116 117
      when 'profiles'
        new Profile()
118
      when 'projects'
119
        new Project()
120
        new ProjectAvatar()
R
Robert Schilling 已提交
121
        switch path[1]
122 123
          when 'compare'
            shortcut_handler = new ShortcutsNavigation()
124 125 126 127 128 129 130
          when 'edit'
            shortcut_handler = new ShortcutsNavigation()
            new ProjectNew()
          when 'new'
            new ProjectNew()
          when 'show'
            new ProjectShow()
131
          when 'issues', 'merge_requests'
132
            new UsersSelect()
R
Robert Schilling 已提交
133 134 135
          when 'wikis'
            new Wikis()
            shortcut_handler = new ShortcutsNavigation()
R
Robert Schilling 已提交
136
            new ZenMode()
137
            new DropzoneInput($('.wiki-form'))
R
Robert Schilling 已提交
138 139
          when 'snippets', 'labels', 'graphs'
            shortcut_handler = new ShortcutsNavigation()
140
          when 'project_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
R
Robert Schilling 已提交
141 142
            shortcut_handler = new ShortcutsNavigation()

143

R
Robert Schilling 已提交
144 145 146
    # If we haven't installed a custom shortcut handler, install the default one
    if not shortcut_handler
      new Shortcuts()
147

148
  initSearch: ->
149 150 151 152 153 154
    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)