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

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

134

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

139
  initSearch: ->
140 141 142 143 144 145
    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)