BigW Consortium Gitlab

dispatcher.js.coffee 5.12 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
        Issuable.init()
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 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 committed
52 53
      when 'projects:merge_requests:show'
        new Diff()
54
        shortcut_handler = new ShortcutsIssuable(true)
55
        new ZenMode()
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 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()
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 102 103 104
      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
105 106
      when 'projects:forks:new'
        new ProjectFork()
107 108
      when 'projects:artifacts:browse'
        new BuildArtifacts()
109 110
      when 'projects:group_links:index'
        new GroupsSelect()
111
      when 'search:show'
Phil Hughes committed
112
        new Search()
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 GLForm($('.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 152 153 154
            shortcut_handler = new ShortcutsNavigation()

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

156
  initSearch: ->
157 158 159

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