From ca225d92c38d955f3c39fd80e031396fee7723a3 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 2 May 2013 11:18:29 +0300 Subject: [PATCH] Replace inline document.ready with dispatcher --- app/assets/javascripts/dispatcher.js.coffee | 17 +++++++++++++++++ app/helpers/application_helper.rb | 4 ++++ app/views/dashboard/show.html.haml | 3 --- app/views/groups/show.html.haml | 3 --- app/views/issues/index.html.haml | 5 ----- app/views/layouts/admin.html.haml | 2 +- app/views/layouts/application.html.haml | 2 +- app/views/layouts/group.html.haml | 2 +- app/views/layouts/profile.html.haml | 2 +- app/views/layouts/project_resource.html.haml | 2 +- app/views/layouts/user_team.html.haml | 2 +- app/views/projects/edit.html.haml | 3 --- app/views/projects/new.html.haml | 3 --- app/views/projects/show.html.haml | 2 -- app/views/teams/show.html.haml | 3 --- 15 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 app/assets/javascripts/dispatcher.js.coffee diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee new file mode 100644 index 00000000000..b9e5b87d1c2 --- /dev/null +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -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() diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d5e94204d86..6bae21cd6d8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/dashboard/show.html.haml b/app/views/dashboard/show.html.haml index ff2db0e3180..2305eae1f71 100644 --- a/app/views/dashboard/show.html.haml +++ b/app/views/dashboard/show.html.haml @@ -7,6 +7,3 @@ - else = render "zero_authorized_projects" - -:javascript - dashboardPage(); diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index e90abc71c0c..1ce008f7e85 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -24,6 +24,3 @@ %hr = render 'shared/promo' - -:javascript - $(function(){ Pager.init(20, true); }); diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index 81777869f4a..bf33769349a 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -23,8 +23,3 @@ = render 'filter', entity: 'issue' .span9.issues-holder = render "issues" - -:javascript - $(function(){ - Issues.init(); - }) diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index abe3f2ea854..3a23cbdb376 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 4e6831406e3..792fe5e4a28 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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 diff --git a/app/views/layouts/group.html.haml b/app/views/layouts/group.html.haml index 8296b8ae9a8..0e955d59ff8 100644 --- a/app/views/layouts/group.html.haml +++ b/app/views/layouts/group.html.haml @@ -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 diff --git a/app/views/layouts/profile.html.haml b/app/views/layouts/profile.html.haml index 535f94c4ef6..30a0532bc2b 100644 --- a/app/views/layouts/profile.html.haml +++ b/app/views/layouts/profile.html.haml @@ -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 diff --git a/app/views/layouts/project_resource.html.haml b/app/views/layouts/project_resource.html.haml index 7b0d4789f8e..f6c5b166ed2 100644 --- a/app/views/layouts/project_resource.html.haml +++ b/app/views/layouts/project_resource.html.haml @@ -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) diff --git a/app/views/layouts/user_team.html.haml b/app/views/layouts/user_team.html.haml index f2ead9d242a..e64e68d2446 100644 --- a/app/views/layouts/user_team.html.haml +++ b/app/views/layouts/user_team.html.haml @@ -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 diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml index c050f9454a5..e215ad6fd73 100644 --- a/app/views/projects/edit.html.haml +++ b/app/views/projects/edit.html.haml @@ -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(); }); diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index eb4ef5979cf..8ff873aac65 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -7,6 +7,3 @@ %center = image_tag "ajax_loader.gif" %h3 Creating project & repository. Please wait a moment, this page will automatically refresh when ready. - -:javascript - $(function(){ new Projects(); }); diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 2fe7daf8bb1..6edfd2ed401 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -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); }); diff --git a/app/views/teams/show.html.haml b/app/views/teams/show.html.haml index 4b9ff61203f..2ad7f743010 100644 --- a/app/views/teams/show.html.haml +++ b/app/views/teams/show.html.haml @@ -23,6 +23,3 @@ %hr = render 'shared/promo' - -:javascript - $(function(){ Pager.init(20, true); });