activeadmin-selleo-cms 0.0.32 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/app/admin/activeadmin_selleo_cms/asset.rb +1 -1
  2. data/app/admin/activeadmin_selleo_cms/attachment.rb +23 -0
  3. data/app/admin/activeadmin_selleo_cms/image.rb +23 -0
  4. data/app/admin/activeadmin_selleo_cms/page.rb +13 -10
  5. data/app/admin/activeadmin_selleo_cms/related_item.rb +1 -1
  6. data/app/admin/activeadmin_selleo_cms/section_translation.rb +50 -0
  7. data/app/assets/javascripts/activeadmin-selleo-cms/custom.js +49 -17
  8. data/app/assets/stylesheets/activeadmin-selleo-cms/custom.css +38 -1
  9. data/app/assets/stylesheets/activeadmin-selleo-cms/jquery-ui.css +38 -31
  10. data/app/helpers/pages_helper.rb +38 -0
  11. data/app/models/activeadmin_selleo_cms/asset.rb +3 -0
  12. data/app/models/activeadmin_selleo_cms/layout.rb +12 -12
  13. data/app/models/activeadmin_selleo_cms/locale.rb +1 -0
  14. data/app/models/activeadmin_selleo_cms/page.rb +9 -3
  15. data/app/models/activeadmin_selleo_cms/section.rb +31 -7
  16. data/app/modules/activeadmin_selleo_cms/content_translation.rb +6 -0
  17. data/app/views/admin/assets/destroy.js.erb +3 -1
  18. data/app/views/admin/attachments/_attachment.html.haml +6 -0
  19. data/app/views/admin/attachments/_form.html.haml +14 -0
  20. data/app/views/admin/attachments/create.js.erb +14 -0
  21. data/app/views/admin/attachments/edit.html.erb +9 -0
  22. data/app/views/admin/attachments/new.html.erb +1 -0
  23. data/app/views/admin/attachments/update.js.erb +2 -0
  24. data/app/views/admin/images/_form.html.haml +10 -0
  25. data/app/views/admin/images/_image.html.haml +6 -0
  26. data/app/views/admin/images/create.js.erb +14 -0
  27. data/app/views/admin/images/edit.html.erb +8 -0
  28. data/app/views/admin/images/new.html.erb +1 -0
  29. data/app/views/admin/images/update.js.erb +3 -0
  30. data/app/views/admin/pages/_form.html.haml +35 -5
  31. data/app/views/admin/pages/_translated_fields.html.haml +33 -68
  32. data/app/views/admin/pages/update.js.erb +1 -0
  33. data/app/views/admin/related_items/_form.html.haml +10 -0
  34. data/app/views/admin/related_items/_related_item.html.haml +5 -0
  35. data/app/views/admin/related_items/create.js.erb +6 -0
  36. data/app/views/admin/related_items/destroy.js.erb +3 -1
  37. data/app/views/admin/related_items/edit.html.erb +6 -0
  38. data/app/views/admin/related_items/update.js.erb +3 -0
  39. data/app/views/admin/section_translations/_attachments_form.html.haml +14 -0
  40. data/app/views/admin/section_translations/_form.html.haml +36 -0
  41. data/app/views/admin/section_translations/_images_form.html.haml +11 -0
  42. data/app/views/admin/section_translations/_related_items_form.html.haml +10 -0
  43. data/app/views/admin/section_translations/edit.html.erb +1 -0
  44. data/app/views/admin/sections/_form.html.haml +1 -1
  45. data/config/initializers/active_admin.rb +3 -1
  46. data/config/initializers/acts_as_list.rb +1 -0
  47. data/config/locales/cms.en.yml +30 -1
  48. data/db/migrate/20130531154539_add_position_to_assets.rb +9 -0
  49. data/db/migrate/20130601141800_add_position_to_related_items.rb +9 -0
  50. data/lib/activeadmin-selleo-cms/version.rb +1 -1
  51. metadata +67 -6
@@ -6,4 +6,4 @@ ActiveAdmin.register ActiveadminSelleoCms::Asset, { as: 'Asset' } do
6
6
  respond_to :html, :js
7
7
  end
8
8
 
9
- end
9
+ end
@@ -0,0 +1,23 @@
1
+ ActiveAdmin.register ActiveadminSelleoCms::Attachment, as: 'Attachment' do
2
+ menu false
3
+
4
+ form :partial => "form"
5
+
6
+ controller do
7
+ respond_to :html, :js
8
+
9
+ def edit
10
+ super do |format|
11
+ format.html { render action: :edit, layout: false }
12
+ end
13
+ end
14
+
15
+ def new
16
+ super do |format|
17
+ format.html { render action: :new, layout: false }
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ ActiveAdmin.register ActiveadminSelleoCms::Image, as: 'Image' do
2
+ menu false
3
+
4
+ form :partial => "form"
5
+
6
+ controller do
7
+ respond_to :html, :js
8
+
9
+ def edit
10
+ super do |format|
11
+ format.html { render action: :edit, layout: false }
12
+ end
13
+ end
14
+
15
+ def new
16
+ super do |format|
17
+ format.html { render action: :new, layout: false }
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -53,19 +53,19 @@ ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_as
53
53
  end
54
54
 
55
55
  action_item only:[:show] do
56
- link_to "Edit Page", edit_admin_page_path(page.id)
56
+ link_to t("active_admin.edit_model", model: nil), edit_admin_page_path(page.id)
57
57
  end
58
58
 
59
59
  action_item only:[:index] do
60
- link_to "New Page", new_admin_page_path
60
+ link_to t("active_admin.new_model", model: active_admin_config.resource_label), new_admin_page_path
61
61
  end
62
62
 
63
63
  action_item only:[:show,:edit] do
64
- link_to "View on site", page.url, target: '_blank'
64
+ link_to t("active_admin.cms.view_on_site"), page.url, target: '_blank'
65
65
  end
66
66
 
67
67
  action_item only:[:show,:edit] do
68
- link_to "Delete Page", admin_page_path(page.id), method: 'DELETE', confirm: 'Are you sure?'
68
+ link_to t("active_admin.delete_model", model: nil), admin_page_path(page.id), method: 'DELETE', confirm: 'Are you sure?'
69
69
  end
70
70
 
71
71
  collection_action :reorder, :method => :get do
@@ -98,23 +98,26 @@ ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_as
98
98
  else
99
99
  update! do |success, failure|
100
100
  success.html { redirect_to admin_page_path(@page.id) }
101
+ success.js { render action: :update }
101
102
  failure.html { render action: :edit }
102
103
  end
103
104
  end
104
105
  end
105
106
  end
106
107
 
107
- sidebar "Sub pages", only: [:show, :edit] do
108
+ sidebar I18n.t("active_admin.cms.navigation"), only: [:edit, :new] do
109
+ h4 link_to t("active_admin.cms.general_options"), '#id-general-options'
110
+ h4 link_to t("active_admin.cms.metadata"), '#id-meta-data'
108
111
  ol do
109
- if resource.children.any?
110
- resource.children.each do |child|
111
- li link_to child, [:edit, :admin, child]
112
+ if resource.sections.any?
113
+ resource.sections.order(:name).each do |section|
114
+ li link_to section.name.titleize, "#id-#{section.name}", onclick: "$('#id-#{section.name}').effect('highlight')"
112
115
  end
113
116
  else
114
- li "No pages"
117
+ li t("active_admin.cms.no_sections_defined")
115
118
  end
116
119
  end
120
+ button_to_function(t("active_admin.cms.save_changes"), "savePage()")
117
121
  end
118
122
 
119
-
120
123
  end
@@ -6,4 +6,4 @@ ActiveAdmin.register ActiveadminSelleoCms::RelatedItem, { as: 'RelatedItem' } do
6
6
  respond_to :html, :js
7
7
  end
8
8
 
9
- end
9
+ end
@@ -0,0 +1,50 @@
1
+ ActiveAdmin.register ActiveadminSelleoCms::Section::Translation, as: 'SectionTranslation' do
2
+ menu false
3
+
4
+ form :partial => "form"
5
+
6
+ controller do
7
+ respond_to :html
8
+
9
+ def edit
10
+ super do |format|
11
+ format.html { render action: :edit, layout: false }
12
+ end
13
+ end
14
+
15
+ def create
16
+ create! do |success, failure|
17
+ success.html { redirect_to admin_sections_path }
18
+ failure.html { render action: :new }
19
+ end
20
+ end
21
+
22
+ def update
23
+ update! do |success, failure|
24
+ success.html { redirect_to admin_sections_path }
25
+ failure.html { render action: :edit }
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ member_action :sort_assets, :method => :post do
32
+ if params[:asset]
33
+ _collection = resource.assets
34
+ _hash = params[:asset]
35
+ elsif params[:related_item]
36
+ _collection = resource.related_items
37
+ _hash = params[:related_item]
38
+ else
39
+ _collection = []
40
+ _hash = {}
41
+ end
42
+
43
+ _collection.each do |sortable|
44
+ sortable.position = _hash.index(sortable.id.to_s) + 1
45
+ sortable.save
46
+ end
47
+
48
+ render nothing: true
49
+ end
50
+ end
@@ -16,22 +16,44 @@ var slug = function(str) {
16
16
  return str;
17
17
  };
18
18
 
19
- function delete_asset(page_id, asset_id) {
20
- $.ajax({
21
- url: '/admin/assets/' + asset_id + '.js',
22
- type: 'DELETE'
23
- }).error(function(){
24
- alert('Could not delete attachment');
25
- });
19
+ function fileManager(url){
20
+ $('#file-manager').html('').load(url, function() {
21
+ $(this).dialog("option", "position", ['center', 'center'] );
22
+ }).dialog('open');
26
23
  }
27
24
 
28
- function delete_related(page_id, related_item_id) {
29
- $.ajax({
30
- url: '/admin/related_items/' + related_item_id + '.js',
31
- type: 'DELETE'
32
- }).error(function(){
33
- alert('Could not delete related item');
34
- });
25
+ function delete_asset(asset_id) {
26
+ if(confirm('Are you sure?')) {
27
+ $.ajax({
28
+ url: '/admin/assets/' + asset_id + '.js',
29
+ type: 'DELETE'
30
+ }).error(function(){
31
+ alert('An error occured while trying to delete the asset');
32
+ });
33
+ }
34
+ }
35
+
36
+ function edit_attachment(attachment_id) {
37
+ fileManager('/admin/attachments/' + attachment_id + '/edit.js');
38
+ }
39
+
40
+ function edit_image(image_id) {
41
+ fileManager('/admin/images/' + image_id + '/edit.js');
42
+ }
43
+
44
+ function edit_related_item(related_item_id) {
45
+ fileManager('/admin/related_items/' + related_item_id + '/edit.js');
46
+ }
47
+
48
+ function delete_related_item(related_item_id) {
49
+ if(confirm('Are you sure?')) {
50
+ $.ajax({
51
+ url: '/admin/related_items/' + related_item_id + '.js',
52
+ type: 'DELETE'
53
+ }).error(function(){
54
+ alert('An error occured while trying to delete the related item');
55
+ });
56
+ }
35
57
  }
36
58
 
37
59
  function update_positions(pagesArray) {
@@ -85,8 +107,6 @@ $(function(){
85
107
  $(this).closest('fieldset').find('ol').toggle();
86
108
  });
87
109
 
88
- // $('i.folded').click();
89
-
90
110
  $('input[multiple]').each(function(){
91
111
  $(this).attr('name', $(this).attr('name').replace(/\[\]$/, '') );
92
112
  });
@@ -94,4 +114,16 @@ $(function(){
94
114
  $( ".sortable" ).sortable();
95
115
  $( ".sortable" ).disableSelection();
96
116
 
97
- });
117
+ });
118
+
119
+ function savePage(){
120
+ form = $('form[id*="_page_"]');
121
+ $.ajax( {
122
+ type: "POST",
123
+ url: form.attr('action'),
124
+ data: form.serialize(),
125
+ success: function(resp) {
126
+ $('body').effect('highlight')
127
+ }
128
+ } );
129
+ }
@@ -60,4 +60,41 @@ table#translations td.key {
60
60
 
61
61
  .sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
62
62
  .sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
63
- .sortable li span { position: absolute; margin-left: -1.3em; }
63
+ .sortable li span { position: absolute; margin-left: -1.3em; }
64
+
65
+ div.ui-dialog {
66
+ border: 1px solid #d0d0d0 !important;
67
+ }
68
+
69
+ #file-manager form fieldset.assets {
70
+ padding: 5px;
71
+ }
72
+
73
+ #file-manager form fieldset.assets ol li {
74
+ -moz-border-radius-topleft: 4px;
75
+ -webkit-border-top-left-radius: 4px;
76
+ -khtml-border-top-left-radius: 4px;
77
+ border-top-left-radius: 4px;
78
+ border: 1px solid #ccc;
79
+ margin: 5px;
80
+ overflow: hidden;
81
+ max-width: 100px;
82
+ float: left;
83
+ }
84
+
85
+ #file-manager h3.upload-file {
86
+ margin: 5px 0 10px 0;
87
+ }
88
+
89
+ #file-manager h3.manage-files {
90
+ margin-top: 10px;
91
+ margin-bottom: 5px;
92
+ }
93
+
94
+ #sidebar h4 {
95
+ margin-bottom: 0.25em;
96
+ }
97
+
98
+ .fltr {
99
+ float: right;
100
+ }
@@ -470,7 +470,7 @@ body .ui-tooltip { border-width: 2px; }
470
470
  .ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 4px/*{cornerRadius}*/; -webkit-border-bottom-right-radius: 4px/*{cornerRadius}*/; -khtml-border-bottom-right-radius: 4px/*{cornerRadius}*/; border-bottom-right-radius: 4px/*{cornerRadius}*/; }
471
471
 
472
472
  /* Overlays */
473
- .ui-widget-overlay { background: #aaaaaa/*{bgColorOverlay}*/ url(images/ui-bg_flat_0_aaaaaa_40x100.png)/*{bgImgUrlOverlay}*/ 50%/*{bgOverlayXPos}*/ 50%/*{bgOverlayYPos}*/ repeat-x/*{bgOverlayRepeat}*/; opacity: .3;filter:Alpha(Opacity=30)/*{opacityOverlay}*/; }
473
+ .ui-widget-overlay { background: #aaaaaa/*{bgColorOverlay}*/ url(images/ui-bg_flat_0_aaaaaa_40x100.png)/*{bgImgUrlOverlay}*/ 50%/*{bgOverlayXPos}*/ 50%/*{bgOverlayYPos}*/ repeat-x/*{bgOverlayRepeat}*/; opacity: .7;filter:Alpha(Opacity=70)/*{opacityOverlay}*/; }
474
474
  .ui-widget-shadow { margin: -8px/*{offsetTopShadow}*/ 0 0 -8px/*{offsetLeftShadow}*/; padding: 8px/*{thicknessShadow}*/; background: #aaaaaa/*{bgColorShadow}*/ url(images/ui-bg_flat_0_aaaaaa_40x100.png)/*{bgImgUrlShadow}*/ 50%/*{bgShadowXPos}*/ 50%/*{bgShadowYPos}*/ repeat-x/*{bgShadowRepeat}*/; opacity: .3;filter:Alpha(Opacity=30)/*{opacityShadow}*/; -moz-border-radius: 8px/*{cornerRadiusShadow}*/; -khtml-border-radius: 8px/*{cornerRadiusShadow}*/; -webkit-border-radius: 8px/*{cornerRadiusShadow}*/; border-radius: 8px/*{cornerRadiusShadow}*/; }
475
475
 
476
476
  li.hidden {
@@ -480,38 +480,45 @@ li.hidden {
480
480
 
481
481
  /*******************************************************************************
482
482
  * Language Tabs
483
- *
484
483
  *******************************************************************************/
485
- .ui-widget-content {
486
- border: none;
487
- }
488
- .ui-widget-header {
489
- border: 0;
490
- border-bottom: 1px solid #ccc;
491
- background: none;
492
- }
493
- .ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active {
494
- border: 1px solid #ccc;
495
- }
496
- .ui-tabs {
497
- padding: 0;
498
- }
499
- .ui-tabs .ui-tabs-panel {
484
+ .language-tabs .ui-tabs-panel {
500
485
  padding: 0;
501
- padding-top: 1px;
502
- }
503
- .ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl, {
504
- -moz-border-radius-bottomleft: 0;
505
- -webkit-border-bottom-left-radius: 0;
506
- border-bottom-left-radius: 0;
507
- }
508
- .ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br {
509
- -moz-border-radius-bottomright: 0;
510
- -webkit-border-bottom-right-radius: 0;
511
- border-bottom-right-radius: 0;
512
486
  }
513
487
 
514
- div.index_as_list > ol.ui-sortable { list-style-type: disc; margin: 0; padding: 0; zoom: 1; }
515
- div.index_as_list > ol.ui-sortable > li > ol { list-style-type: circle; margin: 0; padding: 0; zoom: 1; padding-left: 20px; }
488
+ .ui-sortable-placeholder {
489
+ float: left;
490
+ }
516
491
 
517
- div.index_as_list > ol.ui-sortable > li { margin: 0 5px 5px 5px; padding: 3px; width: 90%; }
492
+ /*.language-tabs.ui-widget-content {*/
493
+ /*border: none;*/
494
+ /*}*/
495
+ /*.language-tabs.ui-widget-header {*/
496
+ /*border: 0;*/
497
+ /*border-bottom: 1px solid #ccc;*/
498
+ /*background: none;*/
499
+ /*}*/
500
+ /*.language-tabs.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active {*/
501
+ /*border: 1px solid #ccc;*/
502
+ /*}*/
503
+ /*.language-tabs.ui-tabs {*/
504
+ /*padding: 0;*/
505
+ /*}*/
506
+ /*.language-tabs.ui-tabs .ui-tabs-panel {*/
507
+ /*padding: 0;*/
508
+ /*padding-top: 1px;*/
509
+ /*}*/
510
+ /*.language-tabs.ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl, {*/
511
+ /*-moz-border-radius-bottomleft: 0;*/
512
+ /*-webkit-border-bottom-left-radius: 0;*/
513
+ /*border-bottom-left-radius: 0;*/
514
+ /*}*/
515
+ /*.language-tabs.ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br {*/
516
+ /*-moz-border-radius-bottomright: 0;*/
517
+ /*-webkit-border-bottom-right-radius: 0;*/
518
+ /*border-bottom-right-radius: 0;*/
519
+ /*}*/
520
+
521
+ /*div.index_as_list > ol.ui-sortable { list-style-type: disc; margin: 0; padding: 0; zoom: 1; }*/
522
+ /*div.index_as_list > ol.ui-sortable > li > ol { list-style-type: circle; margin: 0; padding: 0; zoom: 1; padding-left: 20px; }*/
523
+
524
+ /*div.index_as_list > ol.ui-sortable > li { margin: 0 5px 5px 5px; padding: 3px; width: 90%; }*/
@@ -39,4 +39,42 @@ module PagesHelper
39
39
  body += link_to(t("active_admin.cms.edit"), edit_admin_section_path(section)) if current_user and current_user.respond_to? :admin? and current_user.admin?
40
40
  body.html_safe
41
41
  end
42
+
43
+ def menu(options={})
44
+ options[:ul] ||= {}
45
+ options[:li] ||= {}
46
+
47
+ content_tag :ul, class: options[:ul][:class] do
48
+ ActiveadminSelleoCms::Page.published.show_in_menu.where(parent_id: options[:root]).reorder("lft ASC").collect{ |page|
49
+ classes = [options[:li][:class], options[:li][:selected]].compact.join(" ") if page == @page
50
+ if block_given?
51
+ concat(content_tag :li, yield(page), class: classes)
52
+ else
53
+ concat(content_tag :li, link_to_page(page), class: classes)
54
+ end
55
+ }
56
+ end
57
+ end
58
+
59
+ def locales(options={}, &block)
60
+ options[:ul] ||= {}
61
+ options[:li] ||= {}
62
+ locales_scope = ActiveadminSelleoCms::Locale.enabled
63
+ locales_scope = locales_scope.exclude(I18n.locale) unless options[:current_locale]
64
+
65
+ content_tag :ul, class: options[:ul][:class] do
66
+ locales_scope.collect{ |locale|
67
+ classes = [options[:li][:class], options[:li][:selected]].compact.join(" ") if locale == I18n.locale
68
+ if block_given?
69
+ concat(content_tag :li, yield(locale), class: classes)
70
+ else
71
+ concat(content_tag :li, link_to_locale(locale.code.to_s.upcase, locale, @page), class: classes)
72
+ end
73
+ }
74
+ end
75
+ end
76
+
77
+ def root
78
+ page_path(I18n.locale, ActiveadminSelleoCms::Page.root)
79
+ end
42
80
  end
@@ -3,6 +3,8 @@ module ActiveadminSelleoCms
3
3
  attr_protected :id
4
4
  attr_accessor :cover_width, :cover_height, :cover_resize_method
5
5
 
6
+ acts_as_list :scope => [:assetable_type, :assetable_id]
7
+
6
8
  belongs_to :assetable, polymorphic: true
7
9
 
8
10
  has_attached_file :cover,
@@ -12,6 +14,7 @@ module ActiveadminSelleoCms
12
14
  :default_style => :normal
13
15
 
14
16
  validates_attachment_size :cover, :less_than => 10.megabytes
17
+ validates_presence_of :assetable
15
18
 
16
19
  def url(format=nil)
17
20
  data.url(format)
@@ -40,18 +40,18 @@ module ActiveadminSelleoCms
40
40
  attr_accessor :name, :type, :toolbar, :width, :height, :resize_method, :cover_width, :cover_height, :cover_resize_method
41
41
 
42
42
  def initialize(node)
43
- @name = node.attributes["name"].content
44
- @type = node.attributes["data-type"] ? node.attributes["data-type"].content : 'ckeditor'
45
- @attachments = node.attributes["data-attachments"] ? node.attributes["data-attachments"].content.eql?("true") : false
46
- @attachment = node.attributes["data-attachment"] ? node.attributes["data-attachment"].content.eql?("true") : false
47
- @related = node.attributes["data-related"] ? node.attributes["data-related"].content.eql?("true") : false
48
- @toolbar = node.attributes["data-toolbar"] ? node.attributes["data-toolbar"].content : 'Minimal'
49
- @width = node.attributes["data-width"] ? node.attributes["data-width"].content : 640
50
- @height = node.attributes["data-height"] ? node.attributes["data-height"].content : 480
51
- @resize_method = node.attributes["data-resize-method"] ? node.attributes["data-resize-method"].content : "#"
52
- @cover_width = node.attributes["data-cover-width"] ? node.attributes["data-cover-width"].content : 140
53
- @cover_height = node.attributes["data-cover-height"] ? node.attributes["data-cover-height"].content : 199
54
- @cover_resize_method = node.attributes["data-cover-resize-method"] ? node.attributes["data-cover-resize-method"].content : ">"
43
+ @name = node.attributes["name"].content
44
+ @type = node.attributes["data-type"] ? node.attributes["data-type"].content : 'ckeditor'
45
+ @attachments = node.attributes["data-attachments"].present?
46
+ @attachment = node.attributes["data-attachment"].present?
47
+ @related = node.attributes["data-related"].present?
48
+ @toolbar = node.attributes["data-toolbar"] ? node.attributes["data-toolbar"].content : 'Minimal'
49
+ @width = node.attributes["data-width"] ? node.attributes["data-width"].content : 640
50
+ @height = node.attributes["data-height"] ? node.attributes["data-height"].content : 480
51
+ @resize_method = node.attributes["data-resize-method"] ? node.attributes["data-resize-method"].content : "#"
52
+ @cover_width = node.attributes["data-cover-width"] ? node.attributes["data-cover-width"].content : 140
53
+ @cover_height = node.attributes["data-cover-height"] ? node.attributes["data-cover-height"].content : 199
54
+ @cover_resize_method = node.attributes["data-cover-resize-method"] ? node.attributes["data-cover-resize-method"].content : ">"
55
55
  end
56
56
 
57
57
  def text?
@@ -7,6 +7,7 @@ module ActiveadminSelleoCms
7
7
 
8
8
  scope :enabled, where(enabled: true)
9
9
  scope :available_locales, enabled
10
+ scope :exclude, ->(codes){ where("code NOT IN (?)", Array(codes)) }
10
11
 
11
12
  scope :popular, where(code: %w(da de el en es fr hu it lt lv nl no pl pt ru sk sl sv))
12
13
 
@@ -70,6 +70,12 @@ module ActiveadminSelleoCms
70
70
  end
71
71
  end
72
72
 
73
+ def create_missing_sections
74
+ section_names.each do |section_name|
75
+ sections.create(name: section_name) unless sections.detect{|section| section.name == section_name}
76
+ end
77
+ end
78
+
73
79
  def to_s
74
80
  title
75
81
  end
@@ -95,7 +101,7 @@ module ActiveadminSelleoCms
95
101
  end
96
102
 
97
103
  def breadcrumb
98
- self_and_ancestors.map(&:title).join(' » ').html_safe
104
+ self_and_ancestors.map{|p| p.translated_attribute(:title, I18n.default_locale)}.join(' » ').html_safe
99
105
  end
100
106
 
101
107
  def url(options={locale: true})
@@ -136,8 +142,8 @@ module ActiveadminSelleoCms
136
142
 
137
143
  belongs_to :activeadmin_selleo_cms_page, class_name: 'ActiveadminSelleoCms::Page'
138
144
 
139
- validates :title, presence: true, if: ->(translation){ translation.locale.eql? I18n.locale }
140
- validates :slug, presence: true, format: { with: /^[a-z0-9\-_]+$/i }, if: ->(translation) { translation.locale.eql? I18n.locale }
145
+ validates :title, presence: true, if: ->(translation){ translation.locale.eql? I18n.default_locale }
146
+ validates :slug, presence: true, format: { with: /^[a-z0-9\-_]+$/i }, if: ->(translation) { translation.locale.eql? I18n.default_locale }
141
147
  validate do |translation|
142
148
  if slug.present? and translation.class.joins(:activeadmin_selleo_cms_page).
143
149
  where(locale: locale, slug: slug, activeadmin_selleo_cms_pages: { parent_id: activeadmin_selleo_cms_page.parent_id }).all.reject{|p| p == self}.any?
@@ -29,7 +29,7 @@ module ActiveadminSelleoCms
29
29
  end
30
30
 
31
31
  def image
32
- if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.image}
32
+ @image ||= if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.image}
33
33
  current_translation.image
34
34
  else
35
35
  nil
@@ -37,7 +37,7 @@ module ActiveadminSelleoCms
37
37
  end
38
38
 
39
39
  def attachment
40
- if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.attachment}
40
+ @attachment ||= if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.attachment}
41
41
  current_translation.attachment
42
42
  else
43
43
  nil
@@ -45,25 +45,49 @@ module ActiveadminSelleoCms
45
45
  end
46
46
 
47
47
  def images
48
- if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.images.any? }
48
+ @images ||= if current_translation = translations.with_locales(I18n.fallbacks[I18n.locale]).detect{|t| t.images.any? }
49
49
  current_translation.images
50
50
  else
51
51
  []
52
52
  end
53
53
  end
54
54
 
55
+ def to_s
56
+ section_definition = sectionable.layout.find_section(name) if sectionable and sectionable.respond_to? :layout
57
+ if section_definition
58
+ if section_definition.text?
59
+ body.to_s.html_safe
60
+ elsif section_definition.image?
61
+ image ? image.url : ""
62
+ end
63
+ end
64
+ end
65
+
66
+ def layout_section
67
+ @layout_section ||= layout ? layout.find_section(name) : nil
68
+ end
69
+
70
+ def method_missing(sym, *args)
71
+ if layout_section and layout_section.respond_to? sym
72
+ layout_section.send(sym)
73
+ else
74
+ super
75
+ end
76
+ end
77
+
55
78
  class Translation
56
79
  attr_protected :id
57
80
 
58
- has_many :attachments, as: :assetable, dependent: :destroy
59
- has_many :images, as: :assetable, dependent: :destroy
81
+ has_many :assets, as: :assetable, dependent: :destroy
82
+ has_many :attachments, as: :assetable, dependent: :destroy, order: 'position ASC'
83
+ has_many :images, as: :assetable, dependent: :destroy, order: 'position ASC'
60
84
  has_one :attachment, as: :assetable, dependent: :destroy
61
85
  has_one :image, as: :assetable, dependent: :destroy
62
- has_many :related_items, as: :relatable, dependent: :destroy
86
+ has_many :related_items, as: :relatable, dependent: :destroy, order: 'position ASC'
63
87
 
64
88
  accepts_nested_attributes_for :attachments, reject_if: lambda{ |a| a[:data].blank? }
65
89
  accepts_nested_attributes_for :attachment, reject_if: lambda{ |a| a[:data].blank? }
66
- accepts_nested_attributes_for :image, reject_if: lambda{ |i| i[:data].blank? }
90
+ accepts_nested_attributes_for :image, reject_if: lambda{ |i| i[:data].blank? and i[:caption].blank? }
67
91
  accepts_nested_attributes_for :images, reject_if: lambda{ |i| i[:data].blank? }
68
92
  accepts_nested_attributes_for :related_items, reject_if: lambda{ |ri| ri[:related_url].blank? and ri[:page_id].blank? }
69
93
  end
@@ -14,6 +14,12 @@ module ActiveadminSelleoCms
14
14
  end
15
15
  end
16
16
 
17
+ def create_missing_translations
18
+ Locale.available_locale_codes.each do |locale_code|
19
+ translations.create(locale: locale_code) unless translations.detect{|t| t.locale == locale_code}
20
+ end
21
+ end
22
+
17
23
  def translated_attribute(attr, locale)
18
24
  _locale = I18n.locale
19
25
  I18n.locale = locale
@@ -1 +1,3 @@
1
- $('li[data-asset-id="<%= @asset.id %>"]').remove();
1
+ $('li[data-asset-id="<%= @asset.id %>"]').fadeOut('slow', function() {
2
+ $(this).remove();
3
+ });
@@ -0,0 +1,6 @@
1
+ %li{"id" => "asset_#{attachment.id}", "data-asset-id" => attachment.id}
2
+ .attachment
3
+ .cover-image= attachment.cover.exists? ? image_tag(attachment.cover.url, style: "max-width:100px") : image_tag("http://placehold.it/100x80&text=No%20cover", style: "max-width:100px")
4
+ .file-name= attachment.caption.blank? ? attachment.data_file_name : attachment.caption
5
+ = link_to_function t("active_admin.cms.edit"), "edit_attachment(#{attachment.id})"
6
+ = link_to_function t("active_admin.cms.delete"), "delete_asset(#{attachment.id})", class: 'fltr'
@@ -0,0 +1,14 @@
1
+ = semantic_form_for [:admin, resource], remote: true, html: { multipart: true } do |form|
2
+
3
+ -#= @page.errors.full_messages
4
+
5
+ = form.inputs id: 'attachment_fields' do
6
+ = form.input :data, hint: resource.data_file_name
7
+ = form.input :assetable_type, as: :hidden, value: resource.assetable_type
8
+ = form.input :assetable_id, as: :hidden, value: resource.assetable_id
9
+ = form.input :cover_width, as: :hidden, value: resource.assetable.activeadmin_selleo_cms_section.cover_width
10
+ = form.input :cover_height, as: :hidden, value: resource.assetable.activeadmin_selleo_cms_section.cover_height
11
+ = form.input :cover_resize_method, as: :hidden, value: resource.assetable.activeadmin_selleo_cms_section.cover_resize_method
12
+ = form.input :cover, hint: (resource.cover.exists? ? image_tag(resource.cover.url) : t("active_admin.cms.file_manager.no_cover"))
13
+ = form.input :caption
14
+ = form.actions :submit
@@ -0,0 +1,14 @@
1
+ <% if resource.valid? %>
2
+ <% if resource.assetable.activeadmin_selleo_cms_section.attachments? %>
3
+ $('<%= j render partial: 'attachment', locals: { attachment: resource } %>').appendTo('ol#assets');
4
+ $('#new_attachment').replaceWith('<%= j render partial: '/admin/section_translations/attachments_form', locals: { attachment: ActiveadminSelleoCms::Attachment.new, section_translation: resource.assetable } %>');
5
+ <% elsif resource.assetable.activeadmin_selleo_cms_section.attachment? %>
6
+ $('#file-manager').html('<%= j render partial: 'form' %>');
7
+ <% end %>
8
+ <% else %>
9
+ <% if resource.assetable.activeadmin_selleo_cms_section.attachments? %>
10
+ $('#new_attachment').replaceWith('<%= j render partial: '/admin/section_translations/attachments_form', locals: { attachment: resource, section_translation: resource.assetable } %>');
11
+ <% elsif resource.assetable.activeadmin_selleo_cms_section.attachment? %>
12
+ $('#file-manager').html('<%= j render partial: 'form' %>');
13
+ <% end %>
14
+ <% end %>