Commit b2d342e9 by François

Ajout horaire dans config module membre (avec intégration éditeur WYSYWYG)

parent 683fab8a
Pipeline #1327 failed with stage
in 1 minute 43 seconds
...@@ -15,6 +15,11 @@ default_msettings = {'msg_accueil': {'title': 'Message borne accueil', ...@@ -15,6 +15,11 @@ default_msettings = {'msg_accueil': {'title': 'Message borne accueil',
'type': 'textarea', 'type': 'textarea',
'value': '' 'value': ''
}, },
'shop_opening_hours' : {
'title': 'Horaires ouverture magasin',
'type': 'textarea',
'value': ''
}
} }
def config(request): def config(request):
......
...@@ -3,20 +3,34 @@ var param_template = $('#templates #param'), ...@@ -3,20 +3,34 @@ var param_template = $('#templates #param'),
main_content = $('#main_content'); main_content = $('#main_content');
function save_module_settings() { function save_module_settings() {
var form_data = new FormData(main_content.get(0)); var form_elts = $('.input-container'),
var data = {}; data = {};
for (var pair of form_data.entries()) { form_elts.each(function(i, elt){
let val = pair[1], const label = $(elt).closest('.param').find('label'),
key = pair[0]; key = label.attr('for'),
let elt = main_content.find('[name="' + key +'"]'); title = label.text();
if (key.length > 0 && key != 'iname') {
data[key] = {title: elt.closest('.param').find('label') let value = "",
.text(), type = "";
type: elt.get(0).type,
value: val}; if ($(elt).hasClass('ql-container')) {
type = 'textarea';
} value = $(elt).find('.ql-editor').html().replace('<p><br></p>','')
} else {
type = 'input';
value = $(elt).find('input').val();
}
data[key] = {
title: title,
type: type,
value: value
};
}
});
post_form( post_form(
'settings', {params: JSON.stringify(data)}, 'settings', {params: JSON.stringify(data)},
function(err, result) { function(err, result) {
...@@ -39,17 +53,35 @@ function save_module_settings() { ...@@ -39,17 +53,35 @@ function save_module_settings() {
); );
} }
function quillify(params) {
let quill = new Quill(params.id, {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'color': [] }, { 'background': [] }],
]
},
placeholder: '',
theme: 'snow'
});
quill.root.innerHTML = params.content;
}
function get_module_settings() { function get_module_settings() {
$.ajax('settings') $.ajax('settings')
.done(function(rData) { .done(function(rData) {
try { try {
if (typeof rData.res.settings != "undefined") { if (typeof rData.res.settings != "undefined") {
var added_elts = []; var added_elts = [],
quill_containers = [];
for (let key in rData.res.settings) { for (let key in rData.res.settings) {
var param = $(param_template.clone().html()); var param = $(param_template.clone().html());
var input = null; var input = null;
let data = rData.res.settings[key]; let data = rData.res.settings[key];
param.find('label').text(data.title) param.find('label').text(data.title)
.attr('for', key); .attr('for', key);
...@@ -57,6 +89,16 @@ function get_module_settings() { ...@@ -57,6 +89,16 @@ function get_module_settings() {
param.find('input').remove(); param.find('input').remove();
input = param.find('textarea'); input = param.find('textarea');
input.attr('name', key).text(data.value); input.attr('name', key).text(data.value);
input.closest('div').attr('id', 'quill-' + key)
.css('height', '375px')
quill_containers.push(
{
id: '#quill-' + key,
content: data.value
}
)
} else { } else {
param.find('textarea').remove(); param.find('textarea').remove();
input = param.find('input'); input = param.find('input');
...@@ -69,12 +111,20 @@ function get_module_settings() { ...@@ -69,12 +111,20 @@ function get_module_settings() {
console.log(param) console.log(param)
*/ */
param.appendTo(main_content); param.appendTo(main_content);
added_elts.push(key); added_elts.push(key);
} }
if (added_elts.length > 0) { if (added_elts.length > 0) {
submit_btn.appendTo(main_content); submit_btn.appendTo(main_content);
} }
submit_btn.click(save_module_settings); submit_btn.click(save_module_settings);
quill_containers.forEach(function(params){
quillify(params);
});
// setTimeout(function() {
// }, 5000);
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
{% block additionnal_css %} {% block additionnal_css %}
<link rel="stylesheet" href="{% static 'css/module_config.css' %}"> <link rel="stylesheet" href="{% static 'css/module_config.css' %}">
<link rel="stylesheet" href="{% static 'quill/quill.snow.css' %}">
{% endblock %}
{% block additionnal_scripts %}
<script type="text/javascript" src="{% static 'quill/quill.min.js' %}"></script>
{% endblock %} {% endblock %}
...@@ -20,8 +25,10 @@ ...@@ -20,8 +25,10 @@
<div id="param"> <div id="param">
<div class="param"> <div class="param">
<label for="iname"></label> <label for="iname"></label>
<input type="text" name="iname" value="" /> <div class="input-container">
<textarea name="iname" value="" cols="255" rows="10"></textarea> <input type="text" name="iname" value="" />
<textarea name="iname" value="" cols="255" rows="10"></textarea>
</div>
</div> </div>
</div> </div>
<div id="submit_button"> <div id="submit_button">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment