sibu 0.1.10 → 0.1.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d78859af9d1f4d0a1146f7ef2e97b9d4c269b6b
4
- data.tar.gz: 4e0816b2b0b815010eb1cae2678a58a40f353562
3
+ metadata.gz: 9efa54f95bf9624f3e75050cab00861a3142662b
4
+ data.tar.gz: 3d84e0bfbfeb7fefd2c8c6fd4116c3de969dc2c2
5
5
  SHA512:
6
- metadata.gz: b799c22dfca0fa3a14ce15b96b70e0333ab7f8f8e9b019d0a0aae5ca3b618397bcd0fe8effebeed1c2324089c0b89c99fb2d082984a3df94036fcb2d02a4300f
7
- data.tar.gz: 4d784daf9463b355d0a128e25e3ea36fc2c4eb5f4c6eadb5608966dfb3582003bc02eb740cb0405eede9d191e360395218ee7f4a154efd01204fee87ed46552a
6
+ metadata.gz: 11644aaa295ba8e4f3732ee52328f69384976c24670c46a937405dd2dee498564e0f4b975f8e4090bad6f359afe7f0141df1d08714bcfcb93ca5a9524290aa66
7
+ data.tar.gz: 7f4821ac37a0cc4dea26cb920843e998c3dce0518c497c261b21a2ed7e5814b79bf460df2f834fe3baf94d47fbe51eca6a01d10c315c55ff612dded668788d3b
@@ -2,9 +2,10 @@ require_dependency "sibu/application_controller"
2
2
 
3
3
  module Sibu
4
4
  class PagesController < ApplicationController
5
- before_action :set_page, only: [:edit, :update, :destroy, :edit_element, :update_element, :edit_section]
5
+ before_action :set_page, only: [:edit, :update, :destroy, :edit_element, :update_element, :edit_section,
6
+ :clone_section, :delete_section]
6
7
  before_action :set_site, only: [:index, :new]
7
- before_action :set_edit_context, only: [:edit_element, :update_element]
8
+ before_action :set_edit_context, only: [:edit_element, :update_element, :clone_section, :delete_section]
8
9
  skip_before_action Rails.application.config.sibu[:auth_filter], only: [:show]
9
10
 
10
11
  def index
@@ -83,6 +84,16 @@ module Sibu
83
84
  def update_section
84
85
  end
85
86
 
87
+ def clone_section
88
+ @section_id = params[:section_id]
89
+ @cloned = @entity.clone_section(*@section_id.split('|'))
90
+ end
91
+
92
+ def delete_section
93
+ @section_id = params[:section_id]
94
+ @deleted = @entity.delete_section(*@section_id.split('|'))
95
+ end
96
+
86
97
  private
87
98
 
88
99
  def set_page
@@ -47,8 +47,21 @@ module Sibu
47
47
  def section(id, sub_id = nil, &block)
48
48
  @sb_entity = @page
49
49
  @sb_section = sub_id ? [id, sub_id] : [id]
50
- "<sb-edit data-id='#{@sb_section.join('|')}' data-entity='page'>#{capture(self, &block)}</sb-edit>".html_safe
51
- end
50
+ "<sb-edit data-id='#{@sb_section.join('|')}' data-entity='page' data-duplicate='#{!sub_id.nil?}'>#{capture(self, &block)}</sb-edit>".html_safe
51
+ end
52
+
53
+ # def site_sections(id, &block)
54
+ # @site.section(id).map {|s| s["id"]}.each do |s|
55
+ # site_section(id, sub_id, &block)
56
+ # end
57
+ # out = ''
58
+ # @sb_entity = @site
59
+ # @site.section(id).map do |s|
60
+ # @sb_section = [id, s["id"]]
61
+ # out += "<sb-edit data-id='#{@sb_section.join('|')}' data-entity='site' data-duplicate='true'>#{capture(self, &block)}</sb-edit>".html_safe
62
+ # end
63
+ # out.html_safe
64
+ # end
52
65
 
53
66
  def site_sections(id)
54
67
  @site.section(id).map {|s| s["id"]}
@@ -12,6 +12,7 @@ module Sibu
12
12
  s = sections[ids[0]]
13
13
  end
14
14
  if s.nil?
15
+ logger.debug("init section #{ids[0]}")
15
16
  s = []
16
17
  self.sections[ids[0]] = s
17
18
  save
@@ -28,6 +29,7 @@ module Sibu
28
29
  if sub_idx
29
30
  sub = s[sub_idx]
30
31
  else
32
+ logger.debug("init section #{subid}")
31
33
  sub = {"id" => subid, "elements" => []}
32
34
  self.sections[id] << sub
33
35
  save
@@ -37,9 +39,12 @@ module Sibu
37
39
 
38
40
  def element(*ids, element_id)
39
41
  elt = section(*ids).select {|e| e["id"] == element_id}.first
40
- elt || {}
42
+ elt || {"id" => element_id}
41
43
  end
42
44
 
45
+ # Todo : add an "elements" method
46
+ # and make section and subsection return sections
47
+
43
48
  def update_section(*ids, value)
44
49
  end
45
50
 
@@ -55,6 +60,26 @@ module Sibu
55
60
  value if save
56
61
  end
57
62
 
63
+ def clone_section(*ids)
64
+ siblings = section(ids.first)
65
+ ref_index = siblings.index {|s| s["id"] == ids.last}
66
+ new_section = siblings[ref_index].deep_dup
67
+ new_section["id"] = ids.last + '§'
68
+ siblings.insert(ref_index + 1, new_section)
69
+ save ? new_section : nil
70
+ end
71
+
72
+ def delete_section(*ids)
73
+ siblings = section(ids.first)
74
+ if siblings.length == 1
75
+ nil
76
+ else
77
+ ref_index = siblings.index {|s| s["id"] == ids.last}
78
+ siblings.delete_at(ref_index)
79
+ save
80
+ end
81
+ end
82
+
58
83
  def sanitize_value(value)
59
84
  unless value["text"].blank?
60
85
  value["text"].gsub!(/<\/?(div|p|ul|li)>/, '')
@@ -25,8 +25,10 @@
25
25
  <div class="overlay_left"></div>
26
26
  <div class="overlay_bottom"></div>
27
27
  <div class="edit_mode_actions">
28
- <p>Modifier la section</p>
29
- <button onclick="cancelEditMode()">Fermer</button>
28
+ <p id="edit_section_msg">Modifier la section</p>
29
+ <button id="clone_section" onclick="cloneSection()">Dupliquer</button>
30
+ <button id="delete_section" onclick="deleteSection()">Supprimer</button>
31
+ <button onclick="cancelEditMode()">Annuler</button>
30
32
  </div>
31
33
  </div>
32
34
  <% end %>
@@ -47,13 +49,23 @@
47
49
  var width = elt.width(), height = elt.height();
48
50
  var overlay = $("#edit_mode_overlay");
49
51
  var yPosition = offset.top - $(".sibu_content_panel").offset().top;
52
+ var section = elt.parents("sb-edit").first();
50
53
  overlay.find(".overlay_top").css("height", yPosition);
51
54
  overlay.find(".overlay_bottom").css("top", yPosition + height);
52
55
  overlay.find(".overlay_left").css({"height": height, "width": offset.left, "top": yPosition});
53
56
  overlay.find(".overlay_right").css({"height": height, "left": offset.left + width, "top": yPosition});
54
57
  overlay.find(".edit_mode_actions").css({"top": (yPosition <= 40 ? (yPosition + height) : (yPosition - 40)), left: offset.left, width: width});
58
+ overlay.find("#edit_section_msg").text("Modifier la section");
55
59
  overlay.show();
60
+ if(!section.data('duplicate')) {
61
+ overlay.find("#clone_section").hide();
62
+ overlay.find("#delete_section").hide();
63
+ } else {
64
+ overlay.find("#clone_section").show();
65
+ overlay.find("#delete_section").show();
66
+ }
56
67
  window.scrollTo(0, yPosition);
68
+ section.addClass('sb-editing');
57
69
  initInnerOverlays(elt);
58
70
  elt.remove();
59
71
  }
@@ -61,9 +73,38 @@
61
73
  function cancelEditMode() {
62
74
  $("#edit_mode_overlay").hide();
63
75
  cancelEdit();
76
+ $("sb-edit.sb-editing").removeClass("sb-editing");
64
77
  initOverlays();
65
78
  }
66
79
 
80
+ function cloneSection() {
81
+ if (window.confirm("Dupliquer la section ?")) {
82
+ var section = $("sb-edit.sb-editing");
83
+ $.ajax({
84
+ url: "<%= clone_section_site_page_path(@site.id, @page.id) %>",
85
+ method: "POST",
86
+ data: {
87
+ section_id: section.data("id"),
88
+ entity: section.data("entity")
89
+ }
90
+ })
91
+ }
92
+ }
93
+
94
+ function deleteSection() {
95
+ if (window.confirm("Supprimer la section ?")) {
96
+ var section = $("sb-edit.sb-editing");
97
+ $.ajax({
98
+ url: "<%= delete_section_site_page_path(@site.id, @page.id) %>",
99
+ method: "DELETE",
100
+ data: {
101
+ section_id: section.data("id"),
102
+ entity: section.data("entity")
103
+ }
104
+ })
105
+ }
106
+ }
107
+
67
108
  function cancelEdit() {
68
109
  $("#edit_panel").slideUp("fast");
69
110
  }
@@ -1,6 +1,6 @@
1
1
  <h2>Modifier le lien</h2>
2
2
  <div id="edit_msg"></div>
3
- <div class="sibu_form">
3
+ <div class="sibu_edit_form">
4
4
  <%= form_tag(update_element_site_page_path(@site.id, @page.id), method: :patch, remote: true) do |f| %>
5
5
  <div class="sibu_field">
6
6
  <%= label_tag 'element[text]', 'Libellé' %>
@@ -1,6 +1,6 @@
1
1
  <h2>Modifier le texte</h2>
2
2
  <div id="edit_msg"></div>
3
- <div class="sibu_form">
3
+ <div class="sibu_edit_form">
4
4
  <%= form_tag(update_element_site_page_path(@site.id, @page.id), method: :patch, remote: true) do |f| %>
5
5
  <%= trix_editor_tag 'element[text]', '', input: 'element_text' %>
6
6
  <%= hidden_field_tag 'element[id]', @element["id"] %>
@@ -0,0 +1,10 @@
1
+ <% if @cloned %>
2
+ var section = $(".sibu_content_panel").find("[data-id='<%= @section_id %>']").first();
3
+ var newSection = section.clone();
4
+ newSection.data("id", "<%= [@section_id.split('|')[0], @cloned["id"]].join('|') %>");
5
+ section.after(newSection);
6
+ cancelEditMode();
7
+ <% else %>
8
+ $("#edit_section_msg").html("<p class='sibu_alert'>Une erreur s'est produite lors de l'enregistrement.</p>");
9
+ <% end %>
10
+
@@ -0,0 +1,7 @@
1
+ <% if @deleted %>
2
+ $(".sibu_content_panel").find("[data-id='<%= @section_id %>']").first().remove();
3
+ cancelEditMode();
4
+ <% else %>
5
+ $("#edit_section_msg").text("Une erreur s'est produite lors de la suppression.");
6
+ <% end %>
7
+
data/config/routes.rb CHANGED
@@ -11,6 +11,8 @@ Sibu::Engine.routes.draw do
11
11
  get :edit_section, on: :member
12
12
  patch 'update_element', on: :member
13
13
  patch 'update_section', on: :member
14
+ post 'clone_section', on: :member
15
+ delete 'delete_section', on: :member
14
16
  end
15
17
 
16
18
  resources :images
data/lib/sibu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-12 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -151,6 +151,8 @@ files:
151
151
  - app/views/sibu/pages/_link_edit_panel.html.erb
152
152
  - app/views/sibu/pages/_media_edit_panel.html.erb
153
153
  - app/views/sibu/pages/_text_edit_panel.html.erb
154
+ - app/views/sibu/pages/clone_section.js.erb
155
+ - app/views/sibu/pages/delete_section.js.erb
154
156
  - app/views/sibu/pages/destroy.html.erb
155
157
  - app/views/sibu/pages/edit.html.erb
156
158
  - app/views/sibu/pages/edit_content.html.erb