dispatcher.js.coffee 5.24 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
    switch page
18
      when 'projects:issues:index'
19
        Issuable.init()
20
        new IssuableBulkActions()
21
        shortcut_handler = new ShortcutsNavigation()
22 23
      when 'projects:issues:show'
        new Issue()
24
        shortcut_handler = new ShortcutsIssuable()
25
        new ZenMode()
26
      when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show'
27
        new Milestone()
28 29
      when 'dashboard:todos:index'
        new Todos()
30
      when 'projects:milestones:new', 'projects:milestones:edit'
31
        new ZenMode()
32
        new GLForm($('.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'
38
        shortcut_handler = new ShortcutsNavigation()
39
        new GLForm($('.issue-form'))
40
        new IssuableForm($('.issue-form'))
41
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
skv's avatar
skv committed
42
        new Diff()
43
        shortcut_handler = new ShortcutsNavigation()
44
        new GLForm($('.merge-request-form'))
45
        new IssuableForm($('.merge-request-form'))
46 47
      when 'projects:tags:new'
        new ZenMode()
48
        new GLForm($('.tag-form'))
49 50
      when 'projects:releases:edit'
        new ZenMode()
51
        new GLForm($('.release-form'))
skv's avatar
skv committed
52 53
      when 'projects:merge_requests:show'
        new Diff()
54
        shortcut_handler = new ShortcutsIssuable(true)
55
        new ZenMode()
skv's avatar
skv committed
56 57
      when "projects:merge_requests:diffs"
        new Diff()
58
        new ZenMode()
59 60
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
61
        Issuable.init()
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
        new TreeView() if $('#tree-slider').length
79
      when 'groups:activity'
80
        new Activities()
81
      when 'groups:show'
82
        shortcut_handler = new ShortcutsNavigation()
83
      when 'groups:group_members:index'
84
        new GroupMembers()
85
        new UsersSelect()
86 87 88
      when 'projects:project_members:index'
        new ProjectMembers()
        new UsersSelect()
Stan Hu's avatar
Stan Hu committed
89
      when 'groups:new', 'groups:edit', 'admin:groups:edit', 'admin:groups:new'
90
        new GroupAvatar()
91
      when 'projects:tree:show'
92
        shortcut_handler = new ShortcutsNavigation()
93
        new TreeView()
94 95
      when 'projects:find_file:show'
        shortcut_handler = true
96
      when 'projects:blob:show', 'projects:blame:show'
97
        new LineHighlighter()
98
        shortcut_handler = new ShortcutsNavigation()
99
      when 'projects:labels:new', 'projects:labels:edit'
100
        new Labels()
101
      when 'projects:labels:index'
102
        new LabelManager() if $('.prioritized-labels').length
103 104 105 106
      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
107 108
      when 'projects:forks:new'
        new ProjectFork()
109 110
      when 'projects:artifacts:browse'
        new BuildArtifacts()
111 112
      when 'projects:group_links:index'
        new GroupsSelect()
Phil Hughes's avatar
Phil Hughes committed
113
      when 'search:show'
Phil Hughes's avatar
Phil Hughes committed
114
        new Search()
115 116

    switch path.first()
117 118 119
      when 'admin'
        new Admin()
        switch path[1]
120 121
          when 'groups'
            new UsersSelect()
122 123
          when 'projects'
            new NamespaceSelect()
124
      when 'dashboard', 'root'
125
        shortcut_handler = new ShortcutsDashboardNavigation()
126 127
      when 'profiles'
        new Profile()
128
      when 'projects'
129
        new Project()
130
        new ProjectAvatar()
131
        switch path[1]
132 133
          when 'compare'
            shortcut_handler = new ShortcutsNavigation()
134 135 136 137 138 139 140
          when 'edit'
            shortcut_handler = new ShortcutsNavigation()
            new ProjectNew()
          when 'new'
            new ProjectNew()
          when 'show'
            new ProjectShow()
141 142 143
          when 'wikis'
            new Wikis()
            shortcut_handler = new ShortcutsNavigation()
144
            new ZenMode()
145
            new GLForm($('.wiki-form'))
146 147 148 149
          when 'snippets'
            shortcut_handler = new ShortcutsNavigation()
            new ZenMode() if path[2] == 'show'
          when 'labels', 'graphs'
150
            shortcut_handler = new ShortcutsNavigation()
151
          when 'project_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
152 153 154 155 156
            shortcut_handler = new ShortcutsNavigation()

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

158
  initSearch: ->
159 160 161

    # Only when search form is present
    new SearchAutocomplete() if $('.search').length