2015-03-27 12:55:32 +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
|
|
|
|
*
|
2015-04-02 17:25:01 +02:00
|
|
|
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
|
2016-08-04 22:26:37 +02:00
|
|
|
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
|
2015-03-27 12:55:32 +01:00
|
|
|
*
|
|
|
|
* =============================
|
|
|
|
*
|
2015-04-02 17:25:01 +02:00
|
|
|
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
|
2015-03-27 12:55:32 +01:00
|
|
|
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
|
|
|
|
*
|
2015-04-02 17:25:01 +02:00
|
|
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
|
2015-03-27 12:55:32 +01:00
|
|
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
|
|
|
*/
|
|
|
|
|
2015-03-29 16:02:48 +02:00
|
|
|
$(document).ready(function () {
|
2015-03-26 16:33:11 +01:00
|
|
|
|
2018-04-06 16:01:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a list of polls inside LocalStorage
|
|
|
|
* @param polls
|
|
|
|
*/
|
|
|
|
function setPolls(polls) {
|
|
|
|
localStorage.setItem('polls', JSON.stringify(polls));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an poll inside LocalStorage
|
|
|
|
* @param poll
|
|
|
|
*/
|
|
|
|
function addPoll(poll) {
|
2018-04-11 11:32:08 +02:00
|
|
|
var polls = localStorage.getItem('polls');
|
|
|
|
if (polls === null) {
|
|
|
|
polls = [];
|
|
|
|
} else {
|
|
|
|
polls = JSON.parse(polls);
|
|
|
|
}
|
2018-04-06 16:01:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if the poll is already inside the list
|
|
|
|
*/
|
|
|
|
var index = polls.findIndex(function (existingPoll) {
|
|
|
|
return existingPoll.url === poll.url;
|
|
|
|
});
|
|
|
|
if (index === -1) {
|
|
|
|
polls.push(poll);
|
|
|
|
} else { // if the poll is already present, we need to update the last access date
|
|
|
|
polls[index] = poll;
|
|
|
|
}
|
|
|
|
setPolls(polls);
|
|
|
|
}
|
|
|
|
|
|
|
|
var poll = {
|
|
|
|
url: window.location.href,
|
|
|
|
title: $('#title-form h3').get(0).childNodes[0].nodeValue,
|
|
|
|
accessed: (new Date()).toISOString()
|
|
|
|
};
|
|
|
|
|
|
|
|
function isAdmin() {
|
|
|
|
return $('.jumbotron').hasClass('bg-danger');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isAdmin()) {
|
|
|
|
if (!localStorage.getItem('polls')) {
|
|
|
|
setPolls([poll]);
|
|
|
|
} else {
|
|
|
|
addPoll(poll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 16:46:08 +01:00
|
|
|
$('#poll_form').submit(function (event) {
|
|
|
|
var name = $('#name').val().trim();
|
2015-03-29 16:02:48 +02:00
|
|
|
|
2015-10-12 21:26:13 +02:00
|
|
|
if (name.length == 0) {
|
2015-03-26 16:33:11 +01:00
|
|
|
event.preventDefault();
|
2015-10-26 16:46:08 +01:00
|
|
|
var newMessage = $('#nameErrorMessage').clone();
|
|
|
|
var messageContainer = $('#message-container');
|
|
|
|
messageContainer
|
|
|
|
.empty()
|
|
|
|
.append(newMessage);
|
|
|
|
newMessage.removeClass('hidden');
|
2015-03-26 16:33:11 +01:00
|
|
|
$('html, body').animate({
|
2015-10-26 16:46:08 +01:00
|
|
|
scrollTop: messageContainer.offset().top
|
2015-03-26 16:33:11 +01:00
|
|
|
}, 750);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-17 23:13:44 +02:00
|
|
|
$('.choice input:radio').on('change', function(){
|
|
|
|
$(this).parent().parent().find('.startunchecked').removeClass('startunchecked');
|
|
|
|
});
|
|
|
|
$('.startunchecked').on('click', function(){
|
|
|
|
$(this).removeClass('startunchecked');
|
|
|
|
});
|
|
|
|
$('.no input').on('focus', function(){
|
|
|
|
$(this).next().removeClass('startunchecked');
|
|
|
|
});
|
|
|
|
|
2016-05-09 17:59:42 +02:00
|
|
|
$('.remove-column').on('click', function(e){
|
|
|
|
var confirmTranslation = $(this).data('remove-confirmation');
|
|
|
|
if (confirm(confirmTranslation)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
e.stopPropagation();
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-22 22:48:30 +02:00
|
|
|
var form = $('#comment_form');
|
|
|
|
form.submit(function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2015-10-28 16:36:54 +01:00
|
|
|
if ($('#comment').val()) {
|
|
|
|
$('#add_comment').attr("disabled", "disabled");
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: form.attr('action'),
|
|
|
|
data: form.serialize(),
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data)
|
|
|
|
{
|
|
|
|
$('#comment').val('');
|
|
|
|
if (data.result) {
|
|
|
|
$('#comments_list')
|
|
|
|
.replaceWith(data.comments);
|
|
|
|
var lastComment = $('#comments_list')
|
|
|
|
.find('div.comment')
|
|
|
|
.last();
|
2018-04-06 11:44:11 +02:00
|
|
|
// TODO : replace old jQuery UI Effect with Modern CSS
|
|
|
|
// lastComment.effect('highlight', {color: 'green'}, 401);
|
2015-10-28 16:36:54 +01:00
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: lastComment.offset().top
|
|
|
|
}, 750);
|
|
|
|
} else {
|
|
|
|
var newMessage = $('#genericErrorTemplate').clone();
|
|
|
|
newMessage
|
|
|
|
.find('.contents')
|
|
|
|
.text(data.message.message);
|
2016-03-05 16:33:42 +01:00
|
|
|
newMessage.removeClass('hidden');
|
2015-10-28 16:36:54 +01:00
|
|
|
var commentsAlert = $('#comments_alerts');
|
|
|
|
commentsAlert
|
|
|
|
.empty()
|
|
|
|
.append(newMessage);
|
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: commentsAlert.offset().top
|
|
|
|
}, 750);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
$('#add_comment').removeAttr("disabled");
|
2015-10-22 22:48:30 +02:00
|
|
|
}
|
2015-10-28 16:36:54 +01:00
|
|
|
});
|
|
|
|
}
|
2015-10-22 22:48:30 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2018-02-20 11:55:14 +01:00
|
|
|
/**
|
|
|
|
* Disable view public results option when there's a password and the poll is not hidden
|
|
|
|
*/
|
|
|
|
$('#password').on('keyup change', function () {
|
|
|
|
if($('#password').val() && !($('#hidden').attr('checked'))){
|
|
|
|
$('#resultsPubliclyVisible').removeAttr('disabled');
|
|
|
|
} else {
|
|
|
|
$('#resultsPubliclyVisible').attr('disabled','disabled');
|
|
|
|
}
|
|
|
|
});
|
2015-06-17 23:13:44 +02:00
|
|
|
});
|