dispatcher.js.coffee 4.98 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(':')
16
    shortcut_handler = null
17 18

    switch page
19
      when 'projects:issues:index'
20
        Issues.init()
21
        shortcut_handler = new ShortcutsNavigation()
22 23
      when 'projects:issues:show'
        new Issue()
24
        shortcut_handler = new ShortcutsIssuable()
25
        new ZenMode()
26 27
      when 'projects:milestones:show'
        new Milestone()
28
      when 'projects:milestones:new', 'projects:milestones:edit'
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'
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'
skv's avatar
skv committed
40
        new Diff()
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'))
skv's avatar
skv committed
50 51
      when 'projects:merge_requests:show'
        new Diff()
52
        shortcut_handler = new ShortcutsIssuable(true)
53
        new ZenMode()
skv's avatar
skv committed
54 55
      when "projects:merge_requests:diffs"
        new Diff()
56
        new ZenMode()
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()
skv's avatar
skv committed
68
        new Diff()
69
        new ZenMode()
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'
76
        shortcut_handler = new ShortcutsNavigation()
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()
Stan Hu's avatar
Stan Hu committed
86
      when 'groups:new', 'groups:edit', 'admin:groups:edit', 'admin:groups:new'
87
        new GroupAvatar()
88 89
      when 'projects:tree:show'
        new TreeView()
90
        shortcut_handler = new ShortcutsNavigation()
91
      when 'projects:blob:show'
92
        new LineHighlighter()
93
        shortcut_handler = new ShortcutsNavigation()
94
      when 'projects:labels:new', 'projects:labels:edit'
95
        new Labels()
96 97 98 99
      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
100 101
      when 'projects:forks:new'
        new ProjectFork()
102 103
      when 'users:show'
        new User()
104
        new Activities()
105 106

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

144

145 146 147
    # If we haven't installed a custom shortcut handler, install the default one
    if not shortcut_handler
      new Shortcuts()
148

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