dispatcher.js.coffee 4.75 KB
Newer Older
1 2
$ ->
  new Dispatcher()
3

4 5
class Dispatcher
  constructor: () ->
6 7 8 9
    @initSearch()
    @initPageScripts()

  initPageScripts: ->
10
    page = $('body').attr('data-page')
11
    project_id = $('body').attr('data-project-id')
12

13 14 15
    unless page
      return false

16
    path = page.split(':')
17
    shortcut_handler = null
18 19

    switch page
20
      when 'projects:issues:index'
21
        Issues.init()
22
        shortcut_handler = new ShortcutsNavigation()
23 24
      when 'projects:issues:show'
        new Issue()
25
        shortcut_handler = new ShortcutsIssueable()
26
        new ZenMode()
27 28
      when 'projects:milestones:show'
        new Milestone()
29
      when 'projects:milestones:new', 'projects:milestones:edit'
30
        new ZenMode()
31
      when 'projects:issues:new','projects:issues:edit'
32
        GitLab.GfmAutoComplete.setup()
33
        shortcut_handler = new ShortcutsNavigation()
34
        new ZenMode()
35
        new DropzoneInput($('.issue-form'))
36 37
        if page == 'projects:issues:new'
          new IssuableForm($('.issue-form'))
38
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
skv's avatar
skv committed
39 40
        GitLab.GfmAutoComplete.setup()
        new Diff()
41
        shortcut_handler = new ShortcutsNavigation()
42
        new ZenMode()
43
        new DropzoneInput($('.merge-request-form'))
44 45
        if page == 'projects:merge_requests:new'
          new IssuableForm($('.merge-request-form'))
skv's avatar
skv committed
46 47
      when 'projects:merge_requests:show'
        new Diff()
48
        shortcut_handler = new ShortcutsIssueable()
49
        new ZenMode()
skv's avatar
skv committed
50 51
      when "projects:merge_requests:diffs"
        new Diff()
52
        new ZenMode()
53 54
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
55
        MergeRequests.init()
56 57
      when 'dashboard:show'
        new Dashboard()
58
        new Activities()
59 60 61
      when 'dashboard:projects:starred'
        new Activities()
        new ProjectsList()
62
      when 'projects:commit:show'
63
        new Commit()
skv's avatar
skv committed
64
        new Diff()
65
        new ZenMode()
66 67 68
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
69
      when 'projects:show'
70
        new Activities()
71
        shortcut_handler = new ShortcutsNavigation()
72 73 74 75
      when 'groups:show'
        new Activities()
        shortcut_handler = new ShortcutsNavigation()
        new ProjectsList()
76
      when 'groups:group_members:index'
77
        new GroupMembers()
78
        new UsersSelect()
79 80 81
      when 'projects:project_members:index'
        new ProjectMembers()
        new UsersSelect()
82 83
      when 'groups:new', 'groups:edit', 'admin:groups:edit'
        new GroupAvatar()
84 85
      when 'projects:tree:show'
        new TreeView()
86
        shortcut_handler = new ShortcutsNavigation()
87 88
      when 'projects:blob:show'
        new BlobView()
89
        shortcut_handler = new ShortcutsNavigation()
90
      when 'projects:labels:new', 'projects:labels:edit'
91
        new Labels()
92 93 94 95
      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
96 97
      when 'projects:forks:new'
        new ProjectFork()
98 99
      when 'users:show'
        new User()
100
        new Activities()
101 102
      when 'admin:users:show'
        new ProjectsList()
103 104

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

139

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

144
  initSearch: ->
145 146 147 148 149 150
    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)