Replace inline document.ready with dispatcher

This commit is contained in:
Dmitriy Zaporozhets 2013-05-02 11:18:29 +03:00
parent 4f5aae1d26
commit ca225d92c3
15 changed files with 27 additions and 28 deletions

View File

@ -0,0 +1,17 @@
$ ->
new Dispatcher()
class Dispatcher
constructor: () ->
page = $('body').attr('data-page')
console.log(page)
switch page
when 'issues:index' then Issues.init()
when 'dashboard:show' then dashboardPage()
when 'groups:show' then Pager.init(20, true)
when 'teams:show' then Pager.init(20, true)
when 'projects:show' then Pager.init(20, true)
when 'projects:new' then new Projects()
when 'projects:edit' then new Projects()

View File

@ -189,4 +189,8 @@ module ApplicationHelper
css_class << " multiselect" if opts[:multiple]
hidden_field_tag(id, '', class: css_class)
end
def body_data_page
controller.controller_name + ":" + controller.action_name
end
end

View File

@ -7,6 +7,3 @@
- else
= render "zero_authorized_projects"
:javascript
dashboardPage();

View File

@ -24,6 +24,3 @@
%hr
= render 'shared/promo'
:javascript
$(function(){ Pager.init(20, true); });

View File

@ -23,8 +23,3 @@
= render 'filter', entity: 'issue'
.span9.issues-holder
= render "issues"
:javascript
$(function(){
Issues.init();
})

View File

@ -1,7 +1,7 @@
!!! 5
%html{ lang: "en"}
= render "layouts/head", title: "Admin area"
%body{class: "#{app_theme} admin"}
%body{class: "#{app_theme} admin", :'data-page' => body_data_page}
= render "layouts/head_panel", title: "Admin area"
= render "layouts/flash"
%nav.main-nav

View File

@ -1,7 +1,7 @@
!!! 5
%html{ lang: "en"}
= render "layouts/head", title: "Dashboard"
%body{class: "#{app_theme} application"}
%body{class: "#{app_theme} application", :'data-page' => body_data_page }
= render "layouts/head_panel", title: "Dashboard"
= render "layouts/flash"
%nav.main-nav

View File

@ -1,7 +1,7 @@
!!! 5
%html{ lang: "en"}
= render "layouts/head", title: "#{@group.name}"
%body{class: "#{app_theme} application"}
%body{class: "#{app_theme} application", :'data-page' => body_data_page}
= render "layouts/head_panel", title: "group: #{@group.name}"
= render "layouts/flash"
%nav.main-nav

View File

@ -1,7 +1,7 @@
!!! 5
%html{ lang: "en"}
= render "layouts/head", title: "Profile"
%body{class: "#{app_theme} profile"}
%body{class: "#{app_theme} profile", :'data-page' => body_data_page}
= render "layouts/head_panel", title: "Profile"
= render "layouts/flash"
%nav.main-nav

View File

@ -1,7 +1,7 @@
!!! 5
%html{ lang: "en"}
= render "layouts/head", title: @project.name_with_namespace
%body{class: "#{app_theme} project"}
%body{class: "#{app_theme} project", :'data-page' => body_data_page}
= render "layouts/head_panel", title: project_title(@project)
= render "layouts/flash"
- if can?(current_user, :download_code, @project)

View File

@ -1,7 +1,7 @@
!!! 5
%html{ lang: "en"}
= render "layouts/head", title: "#{@team.name}"
%body{class: "#{app_theme} application"}
%body{class: "#{app_theme} application", :'data-page' => body_data_page}
= render "layouts/head_panel", title: "team: #{@team.name}"
= render "layouts/flash"
%nav.main-nav

View File

@ -8,6 +8,3 @@
%center
= image_tag "ajax_loader.gif"
%h3 Saving project. Please wait a moment, this page will automatically refresh when ready.
:javascript
$(function(){ new Projects(); });

View File

@ -7,6 +7,3 @@
%center
= image_tag "ajax_loader.gif"
%h3 Creating project &amp; repository. Please wait a moment, this page will automatically refresh when ready.
:javascript
$(function(){ new Projects(); });

View File

@ -17,5 +17,3 @@
%p Repo Size: #{@project.repository.size} MB
%p Created at: #{@project.created_at.stamp('Aug 22, 2013')}
%p Owner: #{link_to @project.owner_name, @project.owner}
:javascript
$(function(){ Pager.init(20); });

View File

@ -23,6 +23,3 @@
%hr
= render 'shared/promo'
:javascript
$(function(){ Pager.init(20, true); });