dispatcher.js.coffee 4.7 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 'projects:compare:show'
        new Diff()
33
      when 'projects:issues:new','projects:issues:edit'
R
Robert Schilling 已提交
34
        shortcut_handler = new ShortcutsNavigation()
35
        new DropzoneInput($('.issue-form'))
36
        new IssuableForm($('.issue-form'))
37
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
S
skv 已提交
38
        new Diff()
R
Robert Schilling 已提交
39
        shortcut_handler = new ShortcutsNavigation()
40
        new DropzoneInput($('.merge-request-form'))
41
        new IssuableForm($('.merge-request-form'))
S
skv 已提交
42 43
      when 'projects:merge_requests:show'
        new Diff()
R
Robert Speicher 已提交
44
        shortcut_handler = new ShortcutsIssuable()
45
        new ZenMode()
S
skv 已提交
46 47
      when "projects:merge_requests:diffs"
        new Diff()
48
        new ZenMode()
R
Robert Schilling 已提交
49 50
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
51
        MergeRequests.init()
52
      when 'dashboard:show', 'root:show'
53
        new Dashboard()
54
        new Activities()
55 56 57
      when 'dashboard:projects:starred'
        new Activities()
        new ProjectsList()
58
      when 'projects:commit:show'
59
        new Commit()
S
skv 已提交
60
        new Diff()
61
        new ZenMode()
R
Robert Schilling 已提交
62 63 64
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
65
      when 'projects:activity'
66
        new Activities()
67
        shortcut_handler = new ShortcutsNavigation()
68
      when 'projects:show'
R
Robert Schilling 已提交
69
        shortcut_handler = new ShortcutsNavigation()
D
Dmitriy Zaporozhets 已提交
70 71 72 73
      when 'groups:show'
        new Activities()
        shortcut_handler = new ShortcutsNavigation()
        new ProjectsList()
74
      when 'groups:group_members:index'
75
        new GroupMembers()
76
        new UsersSelect()
77 78 79
      when 'projects:project_members:index'
        new ProjectMembers()
        new UsersSelect()
80 81
      when 'groups:new', 'groups:edit', 'admin:groups:edit'
        new GroupAvatar()
82 83
      when 'projects:tree:show'
        new TreeView()
R
Robert Schilling 已提交
84
        shortcut_handler = new ShortcutsNavigation()
85
      when 'projects:blob:show'
86
        new LineHighlighter()
R
Robert Schilling 已提交
87
        shortcut_handler = new ShortcutsNavigation()
88
      when 'projects:labels:new', 'projects:labels:edit'
89
        new Labels()
R
Robert Schilling 已提交
90 91 92 93
      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
94 95
      when 'projects:forks:new'
        new ProjectFork()
96 97
      when 'users:show'
        new User()
98
        new Activities()
D
Douwe Maan 已提交
99 100
      when 'admin:users:show'
        new ProjectsList()
101 102

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

137

R
Robert Schilling 已提交
138 139 140
    # If we haven't installed a custom shortcut handler, install the default one
    if not shortcut_handler
      new Shortcuts()
141

142
  initSearch: ->
143 144 145 146 147 148
    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)