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

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

149

R
Robert Schilling 已提交
150 151 152
    # If we haven't installed a custom shortcut handler, install the default one
    if not shortcut_handler
      new Shortcuts()
153

154
  initSearch: ->
155 156 157 158 159 160
    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)