dispatcher.js.coffee 5.08 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
        Issues.init()
20
        shortcut_handler = new ShortcutsNavigation()
21 22
      when 'projects:issues:show'
        new Issue()
23
        shortcut_handler = new ShortcutsIssuable()
24
        new ZenMode()
25
      when 'projects:milestones:show', 'groups:milestones:show', 'dashboard:milestones:show'
26
        new Milestone()
27 28
      when 'dashboard:todos:index'
        new Todos()
29
      when 'projects:milestones:new', 'projects:milestones:edit'
30
        new ZenMode()
31
        new GLForm($('.milestone-form'))
32 33
      when 'groups:milestones:new'
        new ZenMode()
34 35
      when 'projects:compare:show'
        new Diff()
36
      when 'projects:issues:new','projects:issues:edit'
37
        shortcut_handler = new ShortcutsNavigation()
38
        new GLForm($('.issue-form'))
39
        new IssuableForm($('.issue-form'))
40
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
skv's avatar
skv committed
41
        new Diff()
42
        shortcut_handler = new ShortcutsNavigation()
43
        new GLForm($('.merge-request-form'))
44
        new IssuableForm($('.merge-request-form'))
45 46 47
      when 'projects:tags:new'
        new ZenMode()
        new DropzoneInput($('.tag-form'))
48 49 50
      when 'projects:releases:edit'
        new ZenMode()
        new DropzoneInput($('.release-form'))
skv's avatar
skv committed
51 52
      when 'projects:merge_requests:show'
        new Diff()
53
        shortcut_handler = new ShortcutsIssuable(true)
54
        new ZenMode()
skv's avatar
skv committed
55 56
      when "projects:merge_requests:diffs"
        new Diff()
57
        new ZenMode()
58 59
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
60
        MergeRequests.init()
61
      when 'dashboard:activity'
62
        new Activities()
63 64
      when 'dashboard:projects:starred'
        new Activities()
65
      when 'projects:commit:show'
66
        new Commit()
skv's avatar
skv committed
67
        new Diff()
68
        new ZenMode()
69 70 71
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
72
      when 'projects:activity'
73
        shortcut_handler = new ShortcutsNavigation()
74
      when 'projects:show'
75
        shortcut_handler = new ShortcutsNavigation()
76

77
        new TreeView() if $('#tree-slider').length
78
      when 'groups:activity'
79
        new Activities()
80
      when 'groups:show'
81
        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()
Stan Hu's avatar
Stan Hu committed
88
      when 'groups:new', 'groups:edit', 'admin:groups:edit', 'admin:groups:new'
89
        new GroupAvatar()
90
      when 'projects:tree:show'
91
        shortcut_handler = new ShortcutsNavigation()
92
        new TreeView()
93 94
      when 'projects:find_file:show'
        shortcut_handler = true
95
      when 'projects:blob:show', 'projects:blame:show'
96
        new LineHighlighter()
97
        shortcut_handler = new ShortcutsNavigation()
98
      when 'projects:labels:new', 'projects:labels:edit'
99
        new Labels()
100 101 102 103
      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
104 105
      when 'projects:forks:new'
        new ProjectFork()
106 107
      when 'projects:artifacts:browse'
        new BuildArtifacts()
108 109
      when 'projects:group_links:index'
        new GroupsSelect()
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()
119 120
      when 'dashboard'
        shortcut_handler = new ShortcutsDashboardNavigation()
121 122
      when 'profiles'
        new Profile()
123
      when 'projects'
124
        new Project()
125
        new ProjectAvatar()
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()
136 137 138
          when 'wikis'
            new Wikis()
            shortcut_handler = new ShortcutsNavigation()
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'
145
            shortcut_handler = new ShortcutsNavigation()
146
          when 'project_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
147 148 149 150 151
            shortcut_handler = new ShortcutsNavigation()

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

153
  initSearch: ->
154 155 156

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