2015-03-05 14:53:42 +01:00
|
|
|
/**
|
|
|
|
* This software is governed by the CeCILL-B license. If a copy of this license
|
|
|
|
* is not distributed with this file, you can obtain one at
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
|
|
|
|
*
|
|
|
|
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
|
2016-08-04 21:51:37 +02:00
|
|
|
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
|
2015-03-05 14:53:42 +01:00
|
|
|
*
|
|
|
|
* =============================
|
|
|
|
*
|
|
|
|
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
|
|
|
|
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
|
|
|
|
*
|
|
|
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
|
|
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-04-20 22:16:17 +02:00
|
|
|
$(document).ready(function () {
|
|
|
|
$(document.formulaire).on('submit', function (e) {
|
|
|
|
if (!isSubmitChoicesAvalaible()) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var $next = $('button[name="fin_sondage_autre"]');
|
|
|
|
var $removeAChoice = $('#remove-a-choice');
|
|
|
|
var $addAChoice = $('#add-a-choice');
|
|
|
|
|
|
|
|
var updateButtonState = function() {
|
|
|
|
var $choiceFields = $('.choice-field');
|
|
|
|
$removeAChoice.prop('disabled', function() { return $choiceFields.length <= 2; });
|
|
|
|
$next.prop('disabled', !isSubmitChoicesAvalaible());
|
|
|
|
}
|
|
|
|
|
|
|
|
var isSubmitChoicesAvalaible = function () {
|
|
|
|
return (countFilledChoices() >= 2);
|
|
|
|
};
|
|
|
|
|
|
|
|
var countFilledChoices = function() {
|
2015-03-05 14:53:42 +01:00
|
|
|
var nb_filled_choices = 0;
|
|
|
|
$('.choice-field input').each(function () {
|
|
|
|
if ($(this).val() != '') {
|
|
|
|
nb_filled_choices++;
|
|
|
|
}
|
|
|
|
});
|
2018-04-20 22:16:17 +02:00
|
|
|
return nb_filled_choices;
|
2015-03-05 14:53:42 +01:00
|
|
|
};
|
|
|
|
|
2018-04-20 22:16:17 +02:00
|
|
|
$removeAChoice.on('click', function () {
|
|
|
|
$('.choice-field:last').remove();
|
|
|
|
updateButtonState();
|
2015-05-31 16:02:21 +02:00
|
|
|
});
|
|
|
|
|
2018-04-20 22:16:17 +02:00
|
|
|
$addAChoice.on('click', function () {
|
|
|
|
var $choiceFields = $('.choice-field');
|
|
|
|
var nb_choices = $choiceFields.length;
|
|
|
|
var last_choice = $choiceFields.last();
|
|
|
|
|
2015-03-05 14:53:42 +01:00
|
|
|
var new_choice = last_choice.html();
|
2018-04-20 22:16:17 +02:00
|
|
|
|
2015-03-05 14:53:42 +01:00
|
|
|
// label
|
|
|
|
var last_choice_label = last_choice.children('label').text();
|
|
|
|
var choice_text = last_choice_label.substring(0, last_choice_label.indexOf(' '));
|
2018-04-20 22:16:17 +02:00
|
|
|
|
2015-03-05 14:53:42 +01:00
|
|
|
// for and id
|
|
|
|
var re_id_choice = new RegExp('"choice' + (nb_choices - 1) + '"', 'g');
|
2018-04-20 22:16:17 +02:00
|
|
|
|
2015-03-05 14:53:42 +01:00
|
|
|
var new_choice_html = new_choice.replace(re_id_choice, '"choice' + nb_choices + '"')
|
|
|
|
.replace(last_choice_label, choice_text + ' ' + (nb_choices + 1))
|
|
|
|
.replace(/value="(.*?)"/g, 'value=""');
|
2018-04-20 22:16:17 +02:00
|
|
|
|
|
|
|
last_choice.after('<div class="form-group choice-field row">' + new_choice_html + '</div>');
|
2015-03-05 14:53:42 +01:00
|
|
|
$('#choice' + nb_choices).focus();
|
2018-04-20 22:16:17 +02:00
|
|
|
updateButtonState()
|
|
|
|
|
2015-03-05 14:53:42 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('keyup, change', '.choice-field input', function () {
|
2018-04-20 22:16:17 +02:00
|
|
|
updateButtonState();
|
2015-03-05 14:53:42 +01:00
|
|
|
});
|
2018-04-20 22:16:17 +02:00
|
|
|
|
|
|
|
updateButtonState();
|
2015-03-05 14:53:42 +01:00
|
|
|
|
|
|
|
// Button to build markdown from: link + image-url + text
|
|
|
|
|
|
|
|
var md_a_imgModal = $('#md-a-imgModal');
|
|
|
|
var md_text = $('#md-text');
|
|
|
|
var md_img = $('#md-img');
|
|
|
|
var md_val = $('#md-a');
|
|
|
|
|
2018-04-20 22:16:17 +02:00
|
|
|
$('.md-a-img').on('click' , function () {
|
2015-03-05 14:53:42 +01:00
|
|
|
md_a_imgModal.modal('show');
|
|
|
|
md_a_imgModal.find('.btn-primary').attr('value', $(this).prev().attr('id'));
|
|
|
|
$('#md-a-imgModalLabel').text($(this).attr('title'));
|
|
|
|
});
|
|
|
|
md_a_imgModal.find('.btn-primary').on('click', function () {
|
2016-05-10 17:53:47 +02:00
|
|
|
var text = md_text.val();
|
|
|
|
var img = md_img.val();
|
|
|
|
var link = md_val.val();
|
|
|
|
var element = $('#' + $(this).val());
|
|
|
|
|
|
|
|
if (img != '' && link != '') {
|
2016-05-11 17:38:34 +02:00
|
|
|
element.val('[![' + text + '](' + img + ')](' + link + ')');
|
2016-05-10 17:53:47 +02:00
|
|
|
} else if (img != '') {
|
|
|
|
element.val('![' + text + '](' + img + ')');
|
|
|
|
} else if (link != '') {
|
|
|
|
element.val('[' + (text?text:link) + '](' + link + ')');
|
2015-03-05 14:53:42 +01:00
|
|
|
} else {
|
2016-05-10 17:53:47 +02:00
|
|
|
element.val(text);
|
2015-03-05 14:53:42 +01:00
|
|
|
}
|
|
|
|
md_a_imgModal.modal('hide');
|
|
|
|
md_img.val('');
|
|
|
|
md_val.val('');
|
|
|
|
md_text.val('');
|
2018-04-20 22:16:17 +02:00
|
|
|
updateButtonState();
|
2015-03-05 14:53:42 +01:00
|
|
|
});
|
2018-04-20 22:16:17 +02:00
|
|
|
});
|