Commit ca225d92c38d955f3c39fd80e031396fee7723a3

Authored by Dmitriy Zaporozhets
1 parent 4f5aae1d

Replace inline document.ready with dispatcher

app/assets/javascripts/dispatcher.js.coffee 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +$ ->
  2 + new Dispatcher()
  3 +
  4 +class Dispatcher
  5 + constructor: () ->
  6 + page = $('body').attr('data-page')
  7 +
  8 + console.log(page)
  9 +
  10 + switch page
  11 + when 'issues:index' then Issues.init()
  12 + when 'dashboard:show' then dashboardPage()
  13 + when 'groups:show' then Pager.init(20, true)
  14 + when 'teams:show' then Pager.init(20, true)
  15 + when 'projects:show' then Pager.init(20, true)
  16 + when 'projects:new' then new Projects()
  17 + when 'projects:edit' then new Projects()
... ...
app/helpers/application_helper.rb
... ... @@ -189,4 +189,8 @@ module ApplicationHelper
189 189 css_class << " multiselect" if opts[:multiple]
190 190 hidden_field_tag(id, '', class: css_class)
191 191 end
  192 +
  193 + def body_data_page
  194 + controller.controller_name + ":" + controller.action_name
  195 + end
192 196 end
... ...
app/views/dashboard/show.html.haml
... ... @@ -7,6 +7,3 @@
7 7  
8 8 - else
9 9 = render "zero_authorized_projects"
10   -
11   -:javascript
12   - dashboardPage();
... ...
app/views/groups/show.html.haml
... ... @@ -24,6 +24,3 @@
24 24  
25 25 %hr
26 26 = render 'shared/promo'
27   -
28   -:javascript
29   - $(function(){ Pager.init(20, true); });
... ...
app/views/issues/index.html.haml
... ... @@ -23,8 +23,3 @@
23 23 = render 'filter', entity: 'issue'
24 24 .span9.issues-holder
25 25 = render "issues"
26   -
27   -:javascript
28   - $(function(){
29   - Issues.init();
30   - })
... ...
app/views/layouts/admin.html.haml
1 1 !!! 5
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: "Admin area"
4   - %body{class: "#{app_theme} admin"}
  4 + %body{class: "#{app_theme} admin", :'data-page' => body_data_page}
5 5 = render "layouts/head_panel", title: "Admin area"
6 6 = render "layouts/flash"
7 7 %nav.main-nav
... ...
app/views/layouts/application.html.haml
1 1 !!! 5
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: "Dashboard"
4   - %body{class: "#{app_theme} application"}
  4 + %body{class: "#{app_theme} application", :'data-page' => body_data_page }
5 5 = render "layouts/head_panel", title: "Dashboard"
6 6 = render "layouts/flash"
7 7 %nav.main-nav
... ...
app/views/layouts/group.html.haml
1 1 !!! 5
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: "#{@group.name}"
4   - %body{class: "#{app_theme} application"}
  4 + %body{class: "#{app_theme} application", :'data-page' => body_data_page}
5 5 = render "layouts/head_panel", title: "group: #{@group.name}"
6 6 = render "layouts/flash"
7 7 %nav.main-nav
... ...
app/views/layouts/profile.html.haml
1 1 !!! 5
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: "Profile"
4   - %body{class: "#{app_theme} profile"}
  4 + %body{class: "#{app_theme} profile", :'data-page' => body_data_page}
5 5 = render "layouts/head_panel", title: "Profile"
6 6 = render "layouts/flash"
7 7 %nav.main-nav
... ...
app/views/layouts/project_resource.html.haml
1 1 !!! 5
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: @project.name_with_namespace
4   - %body{class: "#{app_theme} project"}
  4 + %body{class: "#{app_theme} project", :'data-page' => body_data_page}
5 5 = render "layouts/head_panel", title: project_title(@project)
6 6 = render "layouts/flash"
7 7 - if can?(current_user, :download_code, @project)
... ...
app/views/layouts/user_team.html.haml
1 1 !!! 5
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: "#{@team.name}"
4   - %body{class: "#{app_theme} application"}
  4 + %body{class: "#{app_theme} application", :'data-page' => body_data_page}
5 5 = render "layouts/head_panel", title: "team: #{@team.name}"
6 6 = render "layouts/flash"
7 7 %nav.main-nav
... ...
app/views/projects/edit.html.haml
... ... @@ -8,6 +8,3 @@
8 8 %center
9 9 = image_tag "ajax_loader.gif"
10 10 %h3 Saving project. Please wait a moment, this page will automatically refresh when ready.
11   -
12   -:javascript
13   - $(function(){ new Projects(); });
... ...
app/views/projects/new.html.haml
... ... @@ -7,6 +7,3 @@
7 7 %center
8 8 = image_tag "ajax_loader.gif"
9 9 %h3 Creating project &amp; repository. Please wait a moment, this page will automatically refresh when ready.
10   -
11   -:javascript
12   - $(function(){ new Projects(); });
... ...
app/views/projects/show.html.haml
... ... @@ -17,5 +17,3 @@
17 17 %p Repo Size: #{@project.repository.size} MB
18 18 %p Created at: #{@project.created_at.stamp('Aug 22, 2013')}
19 19 %p Owner: #{link_to @project.owner_name, @project.owner}
20   -:javascript
21   - $(function(){ Pager.init(20); });
... ...
app/views/teams/show.html.haml
... ... @@ -23,6 +23,3 @@
23 23  
24 24 %hr
25 25 = render 'shared/promo'
26   -
27   -:javascript
28   - $(function(){ Pager.init(20, true); });
... ...