dispatcher.js.coffee 5.3 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 20
      when 'explore:projects:index', 'explore:projects:starred', 'explore:projects:trending'
        Dashboard.init()
21
      when 'projects:issues:index'
22
        Issues.init()
23
        shortcut_handler = new ShortcutsNavigation()
24 25
      when 'projects:issues:show'
        new Issue()
26
        shortcut_handler = new ShortcutsIssuable()
27
        new ZenMode()
28 29
      when 'projects:milestones:show'
        new Milestone()
30
      when 'projects:milestones:new', 'projects:milestones:edit'
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'
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'
skv's avatar
skv committed
42
        new Diff()
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'))
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
        MergeRequests.init()
62
      when 'dashboard:show', 'root:show'
Josh Frye's avatar
Josh Frye committed
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()
skv's avatar
skv committed
70
        new Diff()
71
        new ZenMode()
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'
78
        shortcut_handler = new ShortcutsNavigation()
79

80
        new TreeView() if $('#tree-slider').length
81 82 83
      when 'groups:show'
        new Activities()
        shortcut_handler = new ShortcutsNavigation()
84
      when 'groups:group_members:index'
85
        new GroupMembers()
86
        new UsersSelect()
87 88 89
      when 'projects:project_members:index'
        new ProjectMembers()
        new UsersSelect()
Stan Hu's avatar
Stan Hu committed
90
      when 'groups:new', 'groups:edit', 'admin:groups:edit', 'admin:groups:new'
91
        new GroupAvatar()
92
      when 'projects:tree:show'
93
        shortcut_handler = new ShortcutsNavigation()
94
        new TreeView()
95 96
      when 'projects:find_file:show'
        shortcut_handler = true
97
      when 'projects:blob:show', 'projects:blame:show'
98
        new LineHighlighter()
99
        shortcut_handler = new ShortcutsNavigation()
100
      when 'projects:labels:new', 'projects:labels:edit'
101
        new Labels()
102 103 104 105
      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
106 107
      when 'projects:forks:new'
        new ProjectFork()
108 109
      when 'projects:artifacts:browse'
        new BuildArtifacts()
110 111
      when 'users:show'
        new User()
112
        new Activities()
113 114

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

152

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

157
  initSearch: ->
158 159 160 161 162 163
    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)