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

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

139

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

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