sibu 1.0.5 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83f747d2d0f30d44d8321ea252994eb72a246743
4
- data.tar.gz: 4e422b2041a2e3b8ca5eb86810e5440873c7c85e
3
+ metadata.gz: 81b1a892357b7809824ea579fe32219a9cc864c1
4
+ data.tar.gz: 121e9d7cec8dd2790bafc8d152aeff2f667d2014
5
5
  SHA512:
6
- metadata.gz: 22a3a04bb5835e8119274276106e99ab700cd85c55c47aecafd8111c7c7eaa633f1c57a5e35b088a3532de89d7250580e17965f411a974657df642ac3c6b8a3b
7
- data.tar.gz: 284b06e15ef29a30528f605d4c7b003781f17cad85be9a5c42daf78fff8520818189128abe907976ace0930b34f5c05d1f80cf3e7d367c523267e45734e9b1b1
6
+ metadata.gz: 481e3ce5022276de19aa596d15da11c99638a3b06fb9cb1eeac5ad8e38699810ece60c46a1cfeff01725dd2f5a5e5bd24dc1965d343325af161b1f1b76e1133d
7
+ data.tar.gz: c6dcd079e5672c7a702db7d9e117aa87cb90cc687171ad6d2110f51ba1fb6b5d8de4cdff7f1c3cb884da391bb64653910067b75998c3a7631804065cf31c3a0a
@@ -0,0 +1,4 @@
1
+ module Sibu
2
+ module ExtendableHelper
3
+ end
4
+ end
@@ -27,6 +27,13 @@ module Sibu
27
27
  options_from_collection_for_select(Sibu::Document.for_user(sibu_user), :file_url, :file_name, @element["value"])
28
28
  end
29
29
 
30
+ def input_categories
31
+ options_for_select([['Nom', 'name'], ['Adresse', 'address'], ['Email', 'email'], ['Téléphone', 'telephone'],
32
+ ['Arrivée', 'arrival_date'], ['Départ', 'departure_date'], ['Nombre de personnes', 'people'],
33
+ ['Message (texte libre)', 'message'], ['Inscription à la newsletter', 'newsletter']],
34
+ @element["field_name"])
35
+ end
36
+
30
37
  def link_type(val)
31
38
  if val.blank? || /^\d+$/.match(val.to_s)
32
39
  'internal'
@@ -162,10 +169,49 @@ module Sibu
162
169
  end
163
170
 
164
171
  def form_label(elt, html_opts = {}, &block)
165
- defaults = {"id" => elt.is_a?(Hash) ? elt["id"] : elt, "text" => Sibu::DEFAULT_TEXT}
172
+ t_id = elt.is_a?(Hash) ? elt["id"] : elt
173
+ defaults = {"id" => t_id, "text" => Sibu::DEFAULT_TEXT}
166
174
  content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
167
- html_opts.merge!({data: {id: elt_id(elt), type: "text"}}) if action_name != 'show'
168
- content_tag(:label, raw(content["text"]).html_safe, html_opts)
175
+ @sb_section = (@sb_section || []) + [t_id]
176
+ html_opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "text"}}) if action_name != 'show'
177
+ html_output = content_tag(:label, raw(content["text"]).html_safe, html_opts)
178
+ @sb_section -= [t_id]
179
+ html_output
180
+ end
181
+
182
+ def form_input(elt, html_opts = {})
183
+ repeat = html_opts.delete(:repeat)
184
+ children = html_opts.delete(:children)
185
+ t_id = elt.is_a?(Hash) ? elt["id"] : elt
186
+ opts = {"id" => t_id}.merge(html_opts.stringify_keys).merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
187
+ form_name = opts.delete('form_name') || 'contact'
188
+ field_name = opts.delete('field_name') || 'name'
189
+ name_attr = "#{form_name}[#{field_name}]"
190
+
191
+ @sb_section = (@sb_section || []) + [t_id]
192
+ opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "input", repeat: repeat, children: children}}) if action_name != 'show'
193
+
194
+ case field_name
195
+ when 'name', 'address'
196
+ html_output = content_tag(:input, nil, opts.merge('type' => 'text', 'name' => name_attr))
197
+ when 'email'
198
+ html_output = content_tag(:input, nil, opts.merge('type' => 'email', 'name' => name_attr))
199
+ when 'telephone'
200
+ html_output = content_tag(:input, nil, opts.merge('type' => 'tel', 'name' => name_attr))
201
+ when 'arrival_date', 'departure_date'
202
+ html_output = content_tag(:input, nil, opts.merge('type' => 'date', 'name' => name_attr))
203
+ when 'people'
204
+ html_output = content_tag(:input, nil, opts.merge('type' => 'number', 'name' => name_attr))
205
+ when 'message'
206
+ html_output = content_tag(:textarea, nil, opts.merge('name' => name_attr))
207
+ when 'newsletter'
208
+ html_output = content_tag(:input, nil, opts.merge('type' => 'checkbox', 'name' => name_attr))
209
+ else
210
+ html_output = content_tag(:input, nil, opts.merge('type' => 'text', 'name' => name_attr))
211
+ end
212
+
213
+ @sb_section -= [t_id]
214
+ html_output
169
215
  end
170
216
 
171
217
  def widget(elt, widget_type, opts = {}, &block)
@@ -258,7 +304,7 @@ module Sibu
258
304
  content["href"] = @links.keys.include?(val.to_s) ? (action_name == 'show' ? link_path(val) : site_page_edit_content_path(@site.id, val)) : '#'
259
305
  end
260
306
  if block_given?
261
- html_output = content_tag(:a, capture(link_elt, elts(elt), &block), content.merge(html_opts).except("elements"))
307
+ html_output = content_tag(:a, capture(link_elt, nested_elements(elt), &block), content.merge(html_opts).except("elements"))
262
308
  else
263
309
  html_output = content_tag(:a, raw(text), content.merge(html_opts).except("elements"))
264
310
  end
@@ -267,10 +313,10 @@ module Sibu
267
313
  end
268
314
 
269
315
  def interactive_map(elt, html_opts = {})
270
- defaults = {"data-lat" => "46.1988027", "data-lng" => "5.1748288", "data-title" => Sibu::DEFAULT_TEXT}
316
+ defaults = {"data-lat" => "46.1988027", "data-lng" => "5.1748288"}
271
317
  content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {"id" => elt}))
272
318
  html_opts.merge!({data: {id: elt_id(elt), type: "map"}}) if action_name != 'show'
273
- content_tag(:div, nil, content.merge(html_opts))
319
+ content_tag(:div, nil, content.merge(html_opts.stringify_keys))
274
320
  end
275
321
 
276
322
  def elt_id(elt)
@@ -1,31 +1,36 @@
1
1
  module Sibu
2
2
  class DynamicStyle
3
3
 
4
- attr_reader :site, :body, :env, :filename, :scss_file
4
+ attr_reader :site, :body, :env, :filename, :scss_file, :styles_changed
5
5
 
6
6
  def initialize(site_id)
7
7
  @site = Sibu::Site.find(site_id)
8
- @filename = "#{site_id}_#{Time.current.to_i}"
9
- @scss_file = File.new(scss_file_path, 'w')
10
- @body = ERB.new(File.read(template_file_path)).result(binding)
11
- @env = Rails.application.assets
8
+ @styles_changed = @site.style.nil? || styles_changed?(@site.style_url)
9
+ if @styles_changed
10
+ @filename = "#{site_id}_#{Time.current.to_i}"
11
+ @scss_file = File.new(scss_file_path, 'w')
12
+ @body = ERB.new(File.read(template_file_path)).result(binding)
13
+ @env = Rails.application.assets
14
+ end
12
15
  end
13
16
 
14
17
  def compile
15
- find_or_create_scss
18
+ if @styles_changed
19
+ find_or_create_scss
16
20
 
17
- begin
18
- scss_file.write generate_css
19
- scss_file.flush
20
- scss_file.close
21
- css_file_path = scss_file_path.gsub('scss', 'css')
22
- File.rename(scss_file_path, css_file_path)
23
- site.update(style: File.new(css_file_path))
24
- rescue Exception => ex
25
- Rails.logger.error(ex)
26
- ensure
27
- File.delete(scss_file_path) if scss_file_path && File.exist?(scss_file_path)
28
- File.delete(css_file_path) if css_file_path && File.exist?(css_file_path)
21
+ begin
22
+ scss_file.write generate_css
23
+ scss_file.flush
24
+ scss_file.close
25
+ css_file_path = scss_file_path.gsub('scss', 'css')
26
+ File.rename(scss_file_path, css_file_path)
27
+ site.update(style: File.new(css_file_path))
28
+ rescue Exception => ex
29
+ Rails.logger.error(ex)
30
+ ensure
31
+ File.delete(scss_file_path) if scss_file_path && File.exist?(scss_file_path)
32
+ File.delete(css_file_path) if css_file_path && File.exist?(css_file_path)
33
+ end
29
34
  end
30
35
  end
31
36
 
@@ -73,5 +78,16 @@ module Sibu
73
78
  env.load(asset.uri).source
74
79
  end
75
80
  end
81
+
82
+ def styles_changed?(site_style_url)
83
+ templates_styles_path = File.join(Rails.root, 'app', 'assets', 'stylesheets', 'templates', '**/*')
84
+ style_updated_at = File.new(File.join(Rails.root, 'public', site_style_url)).mtime
85
+ Dir.glob(templates_styles_path) do |style_file|
86
+ if File.new(style_file).mtime > style_updated_at
87
+ return true
88
+ end
89
+ end
90
+ false
91
+ end
76
92
  end
77
93
  end
@@ -51,13 +51,6 @@ module Sibu
51
51
  pages.where(id: page_id).select(:id, :path).first
52
52
  end
53
53
 
54
- def update_paths
55
- pages.each do |p|
56
- p.update_path(true)
57
- p.save
58
- end
59
- end
60
-
61
54
  def save_and_init
62
55
  if valid?
63
56
  self.sections = site_template.sections
@@ -4,11 +4,14 @@
4
4
  <title><%= conf[:title] %></title>
5
5
  <%= stylesheet_link_tag 'sibu/sibu', media: 'all' %>
6
6
  <%= stylesheet_link_tag "#{conf[:stylesheet]}-edit", media: 'all' %>
7
- <%= javascript_include_tag "#{conf[:javascript]}-edit" %>
8
7
  <% if @site %>
9
8
  <%= stylesheet_link_tag (conf[:custom_styles] ? @site.style_url : @site.site_template.path), media: "all" %>
9
+ <% end %>
10
+
11
+ <% if @site %>
10
12
  <%= javascript_include_tag @site.site_template.path %>
11
13
  <% end %>
14
+ <%= javascript_include_tag "#{conf[:javascript]}-edit" %>
12
15
  <%= csrf_meta_tags %>
13
16
  <%= yield :styles %>
14
17
  </head>
@@ -43,6 +46,8 @@
43
46
  <% end %>
44
47
  <%= javascript_include_tag 'sibu/sibu' %>
45
48
  <script>
49
+ var sectionsState = {};
50
+
46
51
  document.addEventListener("DOMContentLoaded", function() {
47
52
  initOverlays("<%= @edit_section || '' %>");
48
53
  sibuCallback("editContent");
@@ -208,25 +213,29 @@
208
213
  }
209
214
 
210
215
  function initInnerOverlays(section) {
211
- var editables = section.querySelectorAll("[data-type]");
212
- for (var i = 0; i < editables.length; i++) {
213
- if (editables[i].getAttribute("data-type") !== 'group' || editables[i].getAttribute("data-repeat") === 'true' || editables[i].getAttribute("data-children") === 'true') {
214
- editables[i].addEventListener("mouseenter", function(evt) {
215
- evt.stopPropagation();
216
- evt.currentTarget.classList.add("sb-editable");
217
- });
218
- editables[i].addEventListener("mouseleave", function(evt) {
219
- evt.currentTarget.classList.remove("sb-editable");
220
- });
221
- editables[i].addEventListener("click", function(evt) {
222
- evt.stopPropagation();
223
- evt.preventDefault();
224
- var elt = evt.currentTarget, eltId = elt.getAttribute("data-id"), repeat = elt.getAttribute("data-repeat"),
225
- type = elt.getAttribute("data-type"), size = elt.getAttribute("data-size"), children = elt.getAttribute("data-children");
226
- var sectionId = section.getAttribute("data-sb-id"), entity = section.getAttribute("data-sb-entity");
227
- editContent(eltId, sectionId, entity, repeat, type, size, children);
228
- });
216
+ var sectionId = section.getAttribute('data-sb-id');
217
+ if (!sectionsState[sectionId]) {
218
+ var editables = section.querySelectorAll("[data-type]");
219
+ for (var i = 0; i < editables.length; i++) {
220
+ if (editables[i].getAttribute("data-type") !== 'group' || editables[i].getAttribute("data-repeat") === 'true' || editables[i].getAttribute("data-children") === 'true') {
221
+ editables[i].addEventListener("mouseenter", function(evt) {
222
+ evt.stopPropagation();
223
+ evt.currentTarget.classList.add("sb-editable");
224
+ });
225
+ editables[i].addEventListener("mouseleave", function(evt) {
226
+ evt.currentTarget.classList.remove("sb-editable");
227
+ });
228
+ editables[i].addEventListener("click", function(evt) {
229
+ evt.stopPropagation();
230
+ evt.preventDefault();
231
+ var elt = evt.currentTarget, eltId = elt.getAttribute("data-id"), repeat = elt.getAttribute("data-repeat"),
232
+ type = elt.getAttribute("data-type"), size = elt.getAttribute("data-size"), children = elt.getAttribute("data-children");
233
+ var sectionId = section.getAttribute("data-sb-id"), entity = section.getAttribute("data-sb-entity");
234
+ editContent(eltId, sectionId, entity, repeat, type, size, children);
235
+ });
236
+ }
229
237
  }
238
+ sectionsState[sectionId] = 'ready';
230
239
  }
231
240
  }
232
241
 
@@ -253,7 +262,7 @@
253
262
  };
254
263
  })(sections[i], sectionBox.left, yOffset, width, height));
255
264
  }
256
- if (activeSection) {
265
+ if (activeSection && document.querySelector("[data-sb-overlay='" + activeSection + "']")) {
257
266
  document.querySelector("[data-sb-overlay='" + activeSection + "']").click();
258
267
  }
259
268
  }, 800);
@@ -0,0 +1,24 @@
1
+ <h2>Modifier le champ de saisie</h2>
2
+ <div id="edit_msg"></div>
3
+ <%= render 'element_actions' %>
4
+ <div class="sibu_edit_form">
5
+ <form class="edit_element_form" action="<%= update_element_site_page_path(@site.id, @page.id, format: :js) %>" accept-charset="UTF-8" method="patch">
6
+ <div class="sibu_field">
7
+ <%= label_tag 'element[field_name]', 'Type de champ' %>
8
+ <%= select_tag 'element[field_name]', input_categories, prompt: 'Sélectionnez un type de champ' %>
9
+ </div>
10
+ <div class="sibu_field">
11
+ <%= label_tag 'element[placeholder]', "Texte d'aide (optionnel)" %>
12
+ <%= text_field_tag 'element[placeholder]', @element["placeholder"] %>
13
+ </div>
14
+
15
+ <%= hidden_field_tag 'element[id]', @element["id"] %>
16
+ <%= hidden_field_tag :element_id, @element_id %>
17
+ <%= hidden_field_tag :section_id, @section_id %>
18
+ <%= hidden_field_tag :entity, @entity_type %>
19
+ <div class="sibu_actions">
20
+ <%= submit_tag 'Valider' %>
21
+ <%= link_to 'Annuler', '#', onclick: 'cancelEdit(); return false;' %>
22
+ </div>
23
+ </form>
24
+ </div>
@@ -18,6 +18,8 @@ editPanel.innerHTML = "";
18
18
  editPanel.innerHTML = "<%= j(render 'map_edit_panel') %>";
19
19
  <% when /^widget/ %>
20
20
  editPanel.innerHTML = "<%= j(render "shared/sibu/#{@content_type}_panel") %>";
21
+ <% when 'input' %>
22
+ editPanel.innerHTML = "<%= j(render 'input_edit_panel') %>";
21
23
  <% else %>
22
24
  editPanel.innerHTML = "<%= j(render 'error_panel') %>";
23
25
  <% end %>
@@ -43,7 +45,9 @@ setTimeout(function() {
43
45
  for (var i = 0; i < images.length; i++) {
44
46
  images[i].addEventListener("click", function(evt) {
45
47
  if(!evt.currentTarget.classList.contains('selected')) {
46
- evt.currentTarget.classList.remove('selected');
48
+ if (editPanel.querySelector('.sibu_image.selected')) {
49
+ editPanel.querySelector('.sibu_image.selected').classList.remove('selected');
50
+ }
47
51
  evt.currentTarget.classList.add('selected');
48
52
  var imgElt = evt.currentTarget.querySelector("img");
49
53
  document.querySelector("#element_src").value = imgElt.getAttribute("data-src");
@@ -52,7 +56,9 @@ setTimeout(function() {
52
56
  '<img src="' + $("#element_src").val() + '"/>' +
53
57
  '<div id="sibu_center_pos" style="display: none;">✕</div>' +
54
58
  '<div id="sibu_center_desc" style="display: none;"><em>Cliquez sur l\'image pour la recentrer sur un point donné (à utiliser lorsque l\'image est tronquée car la zone d\'affichage est trop petite)</em></div>';
55
- editPanel.querySelector(".sibu_selected_image > p:first-child").style.display = "none";
59
+ if (editPanel.querySelector(".sibu_selected_image > p:first-child")) {
60
+ editPanel.querySelector(".sibu_selected_image > p:first-child").style.display = "none";
61
+ }
56
62
  editPanel.querySelector(".sibu_selected_image .sibu_custom_center").style.display = "block";
57
63
  editPanel.querySelector(".sibu_selected_image .sibu_field").style.display = "";
58
64
  if(customCenter.checked) {
@@ -93,7 +99,7 @@ setTimeout(function() {
93
99
  <% if @children %>
94
100
  document.querySelector("#child_elt").style.display = "inline-block";
95
101
  <% else %>
96
- document.querySelector("#child_elt").remove();
102
+ if (document.querySelector("#child_elt")) document.querySelector("#child_elt").remove();
97
103
  <% end %>
98
104
  var formElt = document.querySelector("form.edit_element_form");
99
105
  if (formElt) {
@@ -20,9 +20,14 @@ if (sectionsPanel) {
20
20
  }
21
21
  });
22
22
  }
23
- if(typeof initSectionsForm === "function") {
24
- initSectionsForm();
23
+
24
+ var tabs = sectionsPanel.querySelectorAll(".sibu_sections a.tabs__link");
25
+ for (var j = 0; j < tabs.length; j++) {
26
+ tabs[j].addEventListener("click", function(evt) {
27
+ sibuCallback("selectSectionsTab", evt.currentTarget.getAttribute('aria-controls'));
28
+ });
25
29
  }
30
+
26
31
  document.body.style.overflow = "hidden";
27
32
  sibuCallback("newSection");
28
33
  }
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.10'
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: 1.0.5
4
+ version: 1.0.10
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: 2020-09-04 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -143,6 +143,7 @@ files:
143
143
  - app/controllers/sibu/sites_controller.rb
144
144
  - app/helpers/sibu/application_helper.rb
145
145
  - app/helpers/sibu/documents_helper.rb
146
+ - app/helpers/sibu/extendable_helper.rb
146
147
  - app/helpers/sibu/images_helper.rb
147
148
  - app/helpers/sibu/pages_helper.rb
148
149
  - app/helpers/sibu/sites_helper.rb
@@ -177,6 +178,7 @@ files:
177
178
  - app/views/sibu/pages/_error_panel.html.erb
178
179
  - app/views/sibu/pages/_form.html.erb
179
180
  - app/views/sibu/pages/_group_edit_panel.html.erb
181
+ - app/views/sibu/pages/_input_edit_panel.html.erb
180
182
  - app/views/sibu/pages/_link_edit_panel.html.erb
181
183
  - app/views/sibu/pages/_map_edit_panel.html.erb
182
184
  - app/views/sibu/pages/_media_edit_panel.html.erb