etabliocms_core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +38 -0
  4. data/app/assets/images/admin/background-heading.png +0 -0
  5. data/app/assets/images/admin/background-main.gif +0 -0
  6. data/app/assets/images/admin/background-sidebar-bottom.png +0 -0
  7. data/app/assets/images/admin/background-sidebar-item.png +0 -0
  8. data/app/assets/images/admin/background-sidebar-top.png +0 -0
  9. data/app/assets/images/admin/background-sidebar.png +0 -0
  10. data/app/assets/images/admin/background-th.png +0 -0
  11. data/app/assets/images/admin/background.gif +0 -0
  12. data/app/assets/images/admin/bullet.gif +0 -0
  13. data/app/assets/images/admin/icon-close.png +0 -0
  14. data/app/assets/images/admin/line-heading.gif +0 -0
  15. data/app/assets/images/admin/line-heading.png +0 -0
  16. data/app/assets/images/admin/lock.gif +0 -0
  17. data/app/assets/images/admin/news.png +0 -0
  18. data/app/assets/images/admin/sidebar-users.png +0 -0
  19. data/app/assets/images/icons/arrow_refresh.png +0 -0
  20. data/app/assets/images/icons/icon-add-email.gif +0 -0
  21. data/app/assets/images/icons/icon-add-heading.gif +0 -0
  22. data/app/assets/images/icons/icon-add-image.gif +0 -0
  23. data/app/assets/images/icons/icon-add-news.gif +0 -0
  24. data/app/assets/images/icons/icon-add-text.gif +0 -0
  25. data/app/assets/images/icons/icon-add-video.gif +0 -0
  26. data/app/assets/images/icons/icon-add.gif +0 -0
  27. data/app/assets/images/icons/icon-backward.gif +0 -0
  28. data/app/assets/images/icons/icon-board.gif +0 -0
  29. data/app/assets/images/icons/icon-cart.gif +0 -0
  30. data/app/assets/images/icons/icon-comments.gif +0 -0
  31. data/app/assets/images/icons/icon-delete.gif +0 -0
  32. data/app/assets/images/icons/icon-down-dark.gif +0 -0
  33. data/app/assets/images/icons/icon-down-down.gif +0 -0
  34. data/app/assets/images/icons/icon-down.gif +0 -0
  35. data/app/assets/images/icons/icon-edit.gif +0 -0
  36. data/app/assets/images/icons/icon-information.gif +0 -0
  37. data/app/assets/images/icons/icon-news.gif +0 -0
  38. data/app/assets/images/icons/icon-pack.gif +0 -0
  39. data/app/assets/images/icons/icon-pages.gif +0 -0
  40. data/app/assets/images/icons/icon-pause.gif +0 -0
  41. data/app/assets/images/icons/icon-pdf.gif +0 -0
  42. data/app/assets/images/icons/icon-play.gif +0 -0
  43. data/app/assets/images/icons/icon-print.gif +0 -0
  44. data/app/assets/images/icons/icon-refresh.gif +0 -0
  45. data/app/assets/images/icons/icon-sound.png +0 -0
  46. data/app/assets/images/icons/icon-stop.gif +0 -0
  47. data/app/assets/images/icons/icon-unpack.gif +0 -0
  48. data/app/assets/images/icons/icon-up-dark.gif +0 -0
  49. data/app/assets/images/icons/icon-up-up.gif +0 -0
  50. data/app/assets/images/icons/icon-up.gif +0 -0
  51. data/app/assets/images/icons/newspaper_add.png +0 -0
  52. data/app/assets/images/icons/printer.png +0 -0
  53. data/app/assets/javascripts/admin-core.js +6 -0
  54. data/app/assets/javascripts/admin.js +11 -0
  55. data/app/assets/javascripts/shared.js +12 -0
  56. data/app/assets/stylesheets/admin-core.css +13 -0
  57. data/app/assets/stylesheets/admin.css.scss +190 -0
  58. data/app/assets/stylesheets/shared.css.scss +28 -0
  59. data/app/controllers/etabliocms_core/admin/base_controller.rb +13 -0
  60. data/app/controllers/etabliocms_core/admin/static_controller.rb +14 -0
  61. data/app/controllers/etabliocms_core/admin/users_controller.rb +49 -0
  62. data/app/controllers/etabliocms_core/application_controller_extension.rb +29 -0
  63. data/app/helpers/etabliocms_core/admin/table_tree_helper.rb +90 -0
  64. data/app/helpers/etabliocms_core/application_helper.rb +52 -0
  65. data/app/helpers/etabliocms_core/output_helper.rb +33 -0
  66. data/app/helpers/etabliocms_core/pages_helper.rb +33 -0
  67. data/app/models/etabliocms_core/user.rb +9 -0
  68. data/app/views/etabliocms_core/admin/static/index.html.erb +3 -0
  69. data/app/views/etabliocms_core/admin/static/textile.html.erb +250 -0
  70. data/app/views/etabliocms_core/admin/users/_form.html.erb +25 -0
  71. data/app/views/etabliocms_core/admin/users/edit.html.erb +7 -0
  72. data/app/views/etabliocms_core/admin/users/index.html.erb +35 -0
  73. data/app/views/etabliocms_core/admin/users/new.html.erb +7 -0
  74. data/app/views/layouts/_errors.html.erb +10 -0
  75. data/app/views/layouts/_flashes.html.erb +11 -0
  76. data/app/views/layouts/_footer.html.erb +39 -0
  77. data/app/views/layouts/_sidebar_core.html.erb +5 -0
  78. data/app/views/layouts/admin.html.erb +72 -0
  79. data/app/views/layouts/email.html.erb +93 -0
  80. data/config/initializers/configatron.rb +1 -0
  81. data/config/initializers/devise.rb +223 -0
  82. data/config/locales/core.cs.yml +48 -0
  83. data/config/locales/cs.rb +229 -0
  84. data/config/locales/devise.cs.yml +55 -0
  85. data/config/routes.rb +14 -0
  86. data/db/migrate/20120222142355_create_users.etabliocms_core_engine.rb +26 -0
  87. data/lib/etabliocms_core/engine.rb +29 -0
  88. data/lib/etabliocms_core/version.rb +3 -0
  89. data/lib/etabliocms_core.rb +14 -0
  90. data/lib/form_helper.rb +40 -0
  91. metadata +190 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = EtabliocmsCore
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'EtabliocmsCore'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,6 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require ../../../vendor/assets/javascripts/markitup/jquery.markitup.pack
4
+ //= require ../../../vendor/assets/javascripts/markitup/sets/textile/set
5
+ //= require admin
6
+ //= require shared
@@ -0,0 +1,11 @@
1
+ var Admin = function() {
2
+
3
+ return {
4
+ initPopUp : function(){
5
+ $('a[data-popup=true]').click(function(e){
6
+ e.preventDefault();
7
+ window.open($(this).attr('href'));
8
+ })
9
+ }
10
+ }
11
+ }();
@@ -0,0 +1,12 @@
1
+ var Shared = function() {
2
+
3
+ return {
4
+ initFlashClose : function() {
5
+ $("#flash .flash-close").click(function(e) {
6
+ e.preventDefault();
7
+ $(this).closest("p").fadeOut();
8
+ });
9
+ }
10
+
11
+ }
12
+ }();
@@ -0,0 +1,13 @@
1
+ /*
2
+ *= require boilerplate.screen
3
+ *= require ../../../vendor/assets/javascripts/markitup/skins/simple/style
4
+ *= require ../../../vendor/assets/javascripts/markitup/sets/textile/style
5
+ *= require admin
6
+ *= require shared
7
+ */
8
+
9
+
10
+
11
+
12
+
13
+
@@ -0,0 +1,190 @@
1
+ /* SETTINGS */
2
+ $background: #e2e2e2;
3
+ $blue_light: #66b0e6;
4
+ $blue: #007bd6;
5
+ $grey_dark: #737373;
6
+ $grey_light: #f0f0f0;
7
+ $grey_lighter: #F9F9F9;
8
+ $grey: #696969;
9
+ $green: #6C6F13;
10
+ $error: #b84804;
11
+ $error_dark: #b72727;
12
+ $error_light: #ffe2d0;
13
+ $valid: #3a7436;
14
+ $valid_dark: #20491d;
15
+ $valid_light: #d3e0d2;
16
+ $background_dark: #636363;
17
+
18
+ @mixin opacity($opacity: .50) {
19
+ -moz-opacity: $opacity; opacity: $opacity;
20
+ }
21
+
22
+ @mixin round($radius: 7px){
23
+ -moz-border-radius: $radius;
24
+ -webkit-border-radius: $radius;
25
+ border-radius: $radius;
26
+ }
27
+
28
+ /* GENERAL */
29
+ body { background: $background image_url('admin/background.gif') repeat-x; font-family: Tahoma, 'Lucida Grande CE', lucida, sans-serif;}
30
+
31
+ a {color: $blue_light; }
32
+ .container { width: 980px; margin: auto; }
33
+
34
+ /* TOPBAR */
35
+ header#topbar { color: white; font-weight: bold; background: $background_dark; padding: 5px 0;
36
+ nav#user-information { padding: 5px 0 5px 30px; background: image_url('admin/lock.gif') no-repeat center left;
37
+ strong { font-size: 1.1em;
38
+ a { color: white; text-decoration: none;
39
+ &:hover { text-decoration: underline; }
40
+ }
41
+ }
42
+ ul { margin:0 0 0 10px; padding: 0; display: inline;
43
+ li { display:inline; list-style-type:none; color:white; font-size:0.9em; padding-right:10px;
44
+ a { color:white; text-decoration:none;
45
+ &:hover { text-decoration:underline; }
46
+ }
47
+ }
48
+ }
49
+
50
+ }
51
+ }
52
+
53
+
54
+
55
+ /* MAIN */
56
+ #main { border: 2px solid white; background:#f3fcff image_url('admin/background-main.gif') repeat-x; overflow: hidden; padding-bottom: 40px;
57
+ #content { padding: 0 20px; width: 700px; float: left;
58
+ h1 { color: $blue; font-size:1.8em; text-align: right; text-transform: uppercase; font-weight: normal;
59
+ padding: 0.5em 0 0 0; margin:0.7em 10px 0.7em 0; clear:both; position: relative; border-bottom: 1px solid $blue_light;
60
+ img { position:absolute; top:-15px; left:0 }
61
+ span { font-size: 0.8em; text-transform: lowercase; }
62
+ }
63
+ h2 { color: $blue; font-size:1.6em; font-variant:small-caps; }
64
+ table { border-collapse:collapse; width: 700px;
65
+ thead {
66
+ th, th a { color: $grey_dark; text-transform:uppercase; background: $grey_light; }
67
+ }
68
+ tbody td, thead th { border:1px solid $grey_dark; }
69
+ th.center, td.center { text-align: center; }
70
+ }
71
+ hr.cleaner { visibility:hidden; clear:both; }
72
+ ul {
73
+ &.no-bullets { margin:0; padding:0; list-style-type:none;
74
+ ul { list-style-type: none; }
75
+ }
76
+ }
77
+ .strap { width: auto; padding:3px 0 3px 5px; margin:0 0px 20px 0; clear:both; display:block; text-align: right;
78
+ p { margin: 0;
79
+ a { color: $green; }
80
+ strong {color: $grey; }
81
+ }
82
+ #search-form { float: left; margin-top: -3px;
83
+ input[type=text] { width: 150px; }
84
+ input[type=submit] { width: 30px; cursor: pointer; }
85
+ }
86
+ }
87
+ .table-strap { background: $grey_lighter; border:none; width:555px; padding:3px 0; margin:0;
88
+ p {font-size: 0.9em; }
89
+ label { font-size:0.8em; font-weight:normal!important; }
90
+ .text-field { font-size: 0.9em; }
91
+ .button { margin:0!important; padding:0; }
92
+ }
93
+ .smaller-text-field { width:50px; }
94
+ .inline-label { display:inline; float:none; padding:0 5px 0 20px; }
95
+ .fieldWithErrors { clear:both; }
96
+ .toggle-editor-link { padding-left:90px; padding-bottom:10px; margin-top:-10px; }
97
+ }
98
+ }
99
+
100
+
101
+
102
+ /* SIDEBAR */
103
+ #sidebar { margin: 10px 0 0 0; width: 190px; float: right; background:image_url('admin/background-sidebar.png') repeat-y top left;
104
+ #sidebar-inner { margin-top:-7px; padding-top: 6px; position: relative;float: right; width: 190px;
105
+ background: image_url('admin/background-sidebar-top.png') no-repeat top left;
106
+ #sidebar-inner-inner { padding: 0; margin-bottom:-30px; padding-bottom: 30px; float: right; width: 190px;
107
+ background: image_url('admin/background-sidebar-bottom.png') no-repeat bottom left; }
108
+ }
109
+ h3 {color: $grey; font-size:1.1em; text-transform: uppercase ; line-height: 30px; font-weight: normal;
110
+ height:35px; margin:0px 7px 0 7px; padding:0 0 0 10px; background: image_url('admin/background-sidebar-item.png') no-repeat top right;
111
+ img { float: right; display:block; }
112
+ }
113
+ ul { margin-top: 5px; margin-bottom: 15px;
114
+ li {list-style-image: image_url('admin/bullet.gif'); margin-left: 30px; }
115
+ }
116
+ }
117
+
118
+
119
+
120
+ /* FORM */
121
+ fieldset { border:0; clear:both;
122
+ p {clear:both; margin: 10px 0 20px 0; }
123
+ legend { font-size:1.5em; font-weight:normal; }
124
+ label {color: $grey; width: 80px; padding-right:10px; display:block; float:left; text-align:right; margin-top: 3px }
125
+ select { margin:0; }
126
+ textarea { width: 500px;
127
+ &.small-text-area { height:50px; }
128
+ }
129
+ .submit { float:right; margin-right:3px; }
130
+ .checkbox label {width:160px; }
131
+ .multiple-select { height:5em; }
132
+ input {
133
+ &.text-field { border:1px solid #BBBBBB; margin:0; width:350px; padding: 3px;
134
+ &:focus { border-color:#666666; }
135
+ }
136
+ &.short {width: 50px; }
137
+ &.small-text-field {width:25px; }
138
+ &.smaller-text-field { width:150px; }
139
+ &.price-text-field { width:50px; }
140
+
141
+ }
142
+ .helpbox { clear:both; padding-left:90px; }
143
+ .image-box { padding:10px; float:left;
144
+ .icon { margin-top:5px; }
145
+ img { display:block; }
146
+ }
147
+ .file-box { clear:both; }
148
+ .markItUp { clear:both; padding-top:15px; }
149
+ .tagsinput { margin: 10px 0 0 90px; width: 300px; }
150
+ }
151
+
152
+
153
+
154
+ /* TABLES */
155
+ table {
156
+ th { padding: 7px 5px; }
157
+ &.admin-table { border-collapse: collapse;
158
+ td { padding: 3px; border: 1px solid $grey_dark; }
159
+ }
160
+ .centered { text-align: center; display: block; }
161
+ .thumbnail { max-width: 250px; overflow: hidden;
162
+ img { max-width: 240px; }
163
+ }
164
+ }
165
+
166
+
167
+
168
+ /* OTHER */
169
+ .submit { border: 4px solid $background_dark; background: $background_dark; font-weight: bold; color: white; font-size: 1.1em; @include round(); }
170
+
171
+ #flash { text-align:center; margin: 10px 100px;
172
+ p { margin:0; border:0; padding: 10px; background: none;
173
+ &.notice { color: $valid; background: $background; @include round(); }
174
+ &.error { border: 2px solid $error; color: $error; background: $background; }
175
+ &.alert { border: 2px solid $error; color: $error; background: $background; }
176
+ a.flash-close { float:right; margin-bottom: 10px; margin-top: -3px; @include opacity(); }
177
+ }
178
+ }
179
+
180
+ .pagination { width: 700px; margin: 10px 0px 15px 0; padding-right: 10px; overflow: hidden; text-align: center;
181
+ .next, .prev { background: white; padding: 5px;
182
+ a { color: grey;
183
+ &:hover { text-decoration: none; }
184
+ }
185
+ }
186
+ .next { float: right; }
187
+ .prev { float: left; }
188
+ }
189
+
190
+ #errorExplanation { margin: 0 0 20px 0;}
@@ -0,0 +1,28 @@
1
+ /* ICONS */
2
+ .icon { line-height: 24px; text-indent:20px; background-position:top left; background-repeat:no-repeat!important;
3
+ width: 18px; height:18px; overflow:hidden; float: left; display:block; margin:0 3px; }
4
+ .text-icon { padding:10px; padding-left:20px; background-position:center left!important; background-repeat:no-repeat!important; }
5
+ .icon-edit { background-image: image_url('icons/icon-edit.gif'); }
6
+ .icon-up { background-image: image_url('icons/icon-up.gif'); }
7
+ .icon-up-up { background-image: image_url('icons/icon-up-up.gif'); }
8
+ .icon-down { background-image: image_url('icons/icon-down.gif'); }
9
+ .icon-down-down { background-image: image_url('icons/icon-down-down.gif'); }
10
+ .icon-destroy { background-image: image_url('icons/icon-delete.gif'); }
11
+ .icon-add { background-image: image_url('icons/icon-add.gif'); }
12
+ .icon-backward { background-image: image_url('icons/icon-backward.gif'); }
13
+ .icon-add-text { background-image: image_url('icons/icon-add-text.gif'); }
14
+ .icon-add-heading { background-image: image_url('icons/icon-add-heading.gif'); }
15
+ .icon-add-video { background-image: image_url('icons/icon-add-video.gif'); }
16
+ .icon-add-image { background-image: image_url('icons/icon-add-image.gif'); }
17
+ .icon-add-news { background-image: image_url('icons/icon-add-news.gif'); }
18
+ .icon-information { background: image_url('icons/icon-information.gif'); }
19
+ .icon-pages { background: image_url('icons/icon-pages.gif'); }
20
+ .icon-news { background: image_url('icons/icon-news.gif'); }
21
+ .icon-delete { background: image_url('icons/icon-delete.gif'); }
22
+ .icon-unpack { background: image_url('icons/icon-unpack.gif'); }
23
+ .icon-pack { background: image_url('icons/icon-pack.gif'); }
24
+ .icon-refresh { background: image_url('icons/icon-refresh.gif'); }
25
+ .icon-pause { background: image_url('icons/icon-pause.gif'); }
26
+ .icon-stop { background: image_url('icons/icon-stop.gif'); }
27
+
28
+ .public-icon-top { background-image: image_url('public/icon-top.png'); }
@@ -0,0 +1,13 @@
1
+ module EtabliocmsCore
2
+ module Admin
3
+ class BaseController < ::ApplicationController
4
+
5
+ before_filter :authenticate_etabliocms_core_user!
6
+
7
+ layout "admin"
8
+
9
+ helper "etabliocms_core/admin/table_tree"
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module EtabliocmsCore
2
+ module Admin
3
+ class StaticController < BaseController
4
+
5
+ def index
6
+ end
7
+
8
+ def textile_parser
9
+ render :text => ::RedCloth.new(params[:data]).to_html
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ module EtabliocmsCore
2
+ module Admin
3
+ class UsersController < BaseController
4
+
5
+ def index
6
+ @users = User.all
7
+ end
8
+
9
+ def new
10
+ @user = User.new
11
+ end
12
+
13
+ def create
14
+ @user = User.new(params[:etabliocms_core_user])
15
+ if @user.save
16
+ flash[:notice] = t('etabliocms_core_user.created')
17
+ redirect_to :action => 'index'
18
+ else
19
+ render :action => 'new'
20
+ end
21
+ end
22
+
23
+ def edit
24
+ @user = User.find(params[:id])
25
+ end
26
+
27
+ def update
28
+ @user = User.find(params[:id])
29
+ if params[:etabliocms_core_user][:password].blank? and params[:etabliocms_core_user][:password_confirmation].blank?
30
+ params[:etabliocms_core_user].delete(:password)
31
+ params[:etabliocms_core_user].delete(:password_confirmation)
32
+ end
33
+ if @user.update_attributes(params[:etabliocms_core_user])
34
+ flash[:notice] = t('etabliocms_core_user.updated')
35
+ redirect_to :action => 'index'
36
+ else
37
+ render :action => 'edit'
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ User.find(params[:id]).destroy
43
+ flash[:notice] = t('etabliocms_core_user.destroyed')
44
+ redirect_to :action => 'index'
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,29 @@
1
+ module EtabliocmsCore
2
+ module ApplicationControllerExtension
3
+
4
+ def self.included(base)
5
+ base.send(:include, InstanceMethods)
6
+ base.before_filter :setup_breadcrumbs, :setup_locale
7
+ end
8
+
9
+ module InstanceMethods
10
+
11
+ def after_sign_in_path_for(resource_or_scope)
12
+ admin_path
13
+ end
14
+
15
+ private
16
+ def setup_breadcrumbs
17
+ @breadcrumbs ||= []
18
+ end
19
+
20
+ def setup_locale
21
+ I18n.locale = I18n.default_locale
22
+ I18n.locale = params[:locale] if params[:locale].present?
23
+ end
24
+
25
+
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,90 @@
1
+ module EtabliocmsCore
2
+ module Admin
3
+ module TableTreeHelper
4
+
5
+ def render_table_tree(items = [])
6
+ stack = []
7
+ html = ""
8
+ items.each do |node|
9
+ if stack.empty?
10
+ html << item_html(node, stack)
11
+ stack.push(node)
12
+ next
13
+ end
14
+ if stack.last.lft < node.lft && node.lft < stack.last.rgt
15
+ if node.leaf?
16
+ html << item_html(node, stack)
17
+ else
18
+ html << item_html(node, stack)
19
+ stack.push(node)
20
+ end
21
+ if node.rgt + 1 == stack.last.rgt
22
+ stack.pop
23
+ end
24
+ else
25
+ stack.pop
26
+ redo
27
+ end
28
+ end
29
+ html.html_safe
30
+ end
31
+
32
+ def item_html(item, stack)
33
+ html = [
34
+ link_to(item.title, edit_path(item), :style => "padding-left:#{stack.size*10}px"),
35
+ content_tag(:span, I18n.l(item.created_at, :format => :short), :class => "centered"),
36
+ content_tag(:span, item.locale, :class => 'centered'),
37
+ actions_links(item, stack.last)
38
+ ].inject("") { |line, cell_content| line + content_tag(:td, cell_content) }
39
+ content_tag(:tr, html.html_safe)
40
+ end
41
+
42
+ def actions_links(item, parent)
43
+ links = [
44
+ link_to(I18n.t('hierarchy.edit'), edit_path(item),
45
+ :class => "icon icon-edit",
46
+ :title => I18n.t('hierarchy.edit')),
47
+ link_to(I18n.t('hierarchy.destroy'), destroy_path(item),
48
+ :method => :delete,
49
+ :confirm => t("#{item.class.to_s.demodulize.underscore}.destroy_confirmation"),
50
+ :class => 'icon icon-destroy', :title => I18n.t('hierarchy.destroy'))
51
+ ]
52
+ unless item.is_first_of_siblings?(parent)
53
+ links << link_to(I18n.t('hierarchy.up'), move_path(item, "move_higher"),
54
+ :method => :put,
55
+ :class => "icon icon-up",
56
+ :title => I18n.t('hierarchy.up'))
57
+ links << link_to(I18n.t('hierarchy.top'), move_path(item, "move_to_top"),
58
+ :method => :put,
59
+ :class => "icon icon-up-up",
60
+ :title => I18n.t('hierarchy.top'))
61
+ end
62
+
63
+ unless item.is_last_of_siblings?(parent)
64
+ links << link_to(I18n.t('hierarchy.down'), move_path(item, "move_lower"),
65
+ :method => :put,
66
+ :class => "icon icon-down",
67
+ :title => I18n.t('hierarchy.down'))
68
+ links << link_to(I18n.t('hierarchy.bottom'), move_path(item, "move_to_bottom"),
69
+ :method => :put,
70
+ :class => "icon icon-down-down",
71
+ :title => I18n.t('hierarchy.bottom'))
72
+ end
73
+ links.join("").html_safe
74
+ end
75
+
76
+ def edit_path(item)
77
+ send "edit_admin_#{item.class.to_s.demodulize.underscore}_path", item.id
78
+ end
79
+
80
+ def destroy_path(item)
81
+ send "admin_#{item.class.to_s.demodulize.underscore}_path", item.id
82
+ end
83
+
84
+ def move_path(item, method)
85
+ send "move_admin_#{item.class.to_s.demodulize.underscore}_path", {:id => item.id, :method => method}
86
+ end
87
+
88
+ end
89
+ end
90
+ end