sibu 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/sibu/pages_helper.rb +44 -2
- data/app/models/sibu/dynamic_style.rb +34 -18
- data/app/models/sibu/site.rb +0 -7
- data/app/views/layouts/sibu/edit_content.html.erb +25 -19
- data/app/views/sibu/pages/_input_edit_panel.html.erb +24 -0
- data/app/views/sibu/pages/edit_element.js.erb +9 -3
- data/app/views/sibu/pages/new_section.js.erb +7 -2
- data/lib/sibu/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91412642b584abf2717aedb917a915c773854e76
|
4
|
+
data.tar.gz: 862c35b00d09b62cae6a738666e631ede94f972a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a383d56e8a4569b124970bc021c9c9174383cfc047a0ad24df0bb6222af9cddd794f0a903615cae1c3af43c37170fc883c9a6ec6ee593840879a047d52a0f05
|
7
|
+
data.tar.gz: 2e6d288aefae771322512dfd80ebc786c82ce782600cfcce69c46f34b754bd8b992bad5b3c69a1f13bd8c58df20bcf6059b56df5e3d6408d12ba282e00ae94ef
|
@@ -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'
|
@@ -168,6 +175,41 @@ module Sibu
|
|
168
175
|
content_tag(:label, raw(content["text"]).html_safe, html_opts)
|
169
176
|
end
|
170
177
|
|
178
|
+
def form_input(elt, html_opts = {})
|
179
|
+
repeat = html_opts.delete(:repeat)
|
180
|
+
children = html_opts.delete(:children)
|
181
|
+
t_id = elt.is_a?(Hash) ? elt["id"] : elt
|
182
|
+
opts = {"id" => t_id}.merge(html_opts.stringify_keys).merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {}))
|
183
|
+
form_name = opts.delete('form_name') || 'contact'
|
184
|
+
field_name = opts.delete('field_name') || 'name'
|
185
|
+
name_attr = "#{form_name}[#{field_name}]"
|
186
|
+
|
187
|
+
@sb_section = (@sb_section || []) + [t_id]
|
188
|
+
opts.merge!({data: {id: @sb_section[1..-1].join('|'), type: "input", repeat: repeat, children: children}}) if action_name != 'show'
|
189
|
+
|
190
|
+
case field_name
|
191
|
+
when 'name', 'address'
|
192
|
+
html_output = content_tag(:input, nil, opts.merge('type' => 'text', 'name' => name_attr))
|
193
|
+
when 'email'
|
194
|
+
html_output = content_tag(:input, nil, opts.merge('type' => 'email', 'name' => name_attr))
|
195
|
+
when 'telephone'
|
196
|
+
html_output = content_tag(:input, nil, opts.merge('type' => 'tel', 'name' => name_attr))
|
197
|
+
when 'arrival_date', 'departure_date'
|
198
|
+
html_output = content_tag(:input, nil, opts.merge('type' => 'date', 'name' => name_attr))
|
199
|
+
when 'people'
|
200
|
+
html_output = content_tag(:input, nil, opts.merge('type' => 'number', 'name' => name_attr))
|
201
|
+
when 'message'
|
202
|
+
html_output = content_tag(:textarea, nil, opts.merge('name' => name_attr))
|
203
|
+
when 'newsletter'
|
204
|
+
html_output = content_tag(:input, nil, opts.merge('type' => 'checkbox', 'name' => name_attr))
|
205
|
+
else
|
206
|
+
html_output = content_tag(:input, nil, opts.merge('type' => 'text', 'name' => name_attr))
|
207
|
+
end
|
208
|
+
|
209
|
+
@sb_section -= [t_id]
|
210
|
+
html_output
|
211
|
+
end
|
212
|
+
|
171
213
|
def widget(elt, widget_type, opts = {}, &block)
|
172
214
|
content = elt.is_a?(Hash) ? elt : (select_element(elt) || {})
|
173
215
|
opts.merge!({data: {id: elt_id(elt), type: "widget_#{widget_type.to_s.split('::').last.underscore}"}}) if action_name != 'show'
|
@@ -267,10 +309,10 @@ module Sibu
|
|
267
309
|
end
|
268
310
|
|
269
311
|
def interactive_map(elt, html_opts = {})
|
270
|
-
defaults = {"data-lat" => "46.1988027", "data-lng" => "5.1748288"
|
312
|
+
defaults = {"data-lat" => "46.1988027", "data-lng" => "5.1748288"}
|
271
313
|
content = defaults.merge(elt.is_a?(Hash) ? elt : (select_element(elt) || {"id" => elt}))
|
272
314
|
html_opts.merge!({data: {id: elt_id(elt), type: "map"}}) if action_name != 'show'
|
273
|
-
content_tag(:div, nil, content.merge(html_opts))
|
315
|
+
content_tag(:div, nil, content.merge(html_opts.stringify_keys))
|
274
316
|
end
|
275
317
|
|
276
318
|
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
|
-
@
|
9
|
-
@
|
10
|
-
|
11
|
-
|
8
|
+
@styles_changed = 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
|
-
|
18
|
+
if @styles_changed
|
19
|
+
find_or_create_scss
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
data/app/models/sibu/site.rb
CHANGED
@@ -46,6 +46,8 @@
|
|
46
46
|
<% end %>
|
47
47
|
<%= javascript_include_tag 'sibu/sibu' %>
|
48
48
|
<script>
|
49
|
+
var sectionsState = {};
|
50
|
+
|
49
51
|
document.addEventListener("DOMContentLoaded", function() {
|
50
52
|
initOverlays("<%= @edit_section || '' %>");
|
51
53
|
sibuCallback("editContent");
|
@@ -211,25 +213,29 @@
|
|
211
213
|
}
|
212
214
|
|
213
215
|
function initInnerOverlays(section) {
|
214
|
-
var
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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
|
+
}
|
232
237
|
}
|
238
|
+
sectionsState[sectionId] = 'ready';
|
233
239
|
}
|
234
240
|
}
|
235
241
|
|
@@ -256,7 +262,7 @@
|
|
256
262
|
};
|
257
263
|
})(sections[i], sectionBox.left, yOffset, width, height));
|
258
264
|
}
|
259
|
-
if (activeSection) {
|
265
|
+
if (activeSection && document.querySelector("[data-sb-overlay='" + activeSection + "']")) {
|
260
266
|
document.querySelector("[data-sb-overlay='" + activeSection + "']").click();
|
261
267
|
}
|
262
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
|
-
|
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")
|
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
|
-
|
24
|
-
|
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
|
}
|
data/lib/sibu/version.rb
CHANGED
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.
|
4
|
+
version: 1.0.7
|
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-
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- app/views/sibu/pages/_error_panel.html.erb
|
178
178
|
- app/views/sibu/pages/_form.html.erb
|
179
179
|
- app/views/sibu/pages/_group_edit_panel.html.erb
|
180
|
+
- app/views/sibu/pages/_input_edit_panel.html.erb
|
180
181
|
- app/views/sibu/pages/_link_edit_panel.html.erb
|
181
182
|
- app/views/sibu/pages/_map_edit_panel.html.erb
|
182
183
|
- app/views/sibu/pages/_media_edit_panel.html.erb
|