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

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

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

12 13 14
    unless page
      return false

15
    path = page.split(':')
R
Robert Schilling 已提交
16
    shortcut_handler = null
17 18

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

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

145

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

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