2019-10-29 14:57:13 +01:00
|
|
|
/**
|
|
|
|
* Ce script contient toutes les fonctions javascript utilisées globalement dans RaspiSMS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction affiche un message de succès ou d'erreur dans une popup
|
|
|
|
*/
|
|
|
|
function showMessage(message, type)
|
|
|
|
{
|
|
|
|
if (type == 1) //Si message de succès
|
|
|
|
{
|
|
|
|
var type = 'alert-success';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var type = 'alert-danger';
|
|
|
|
}
|
|
|
|
|
|
|
|
var alerthtml = '<div class="col-xs-10 col-xs-offset-1 col-md-6 col-md-offset-3 popup-alert alert ' + type + '"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>' + message + '</div>';
|
|
|
|
jQuery('body .popup-alerts-container').prepend(alerthtml);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction vérifie si un message a été reçu
|
|
|
|
*/
|
|
|
|
function verifReceived()
|
|
|
|
{
|
|
|
|
jQuery('.popup-alert').fadeOut('slow');
|
2019-11-09 03:35:12 +01:00
|
|
|
jQuery.getJSON(HTTP_PWD + "/received/popup", function( data ) {
|
2019-10-29 14:57:13 +01:00
|
|
|
$.each(data, function(key, val) {
|
2019-11-10 17:32:59 +01:00
|
|
|
showMessage('SMS reçu du ' + val.origin.replace(/</g, "<").replace(/>/g, ">") + ' : ' + val.text.replace(/</g, "<").replace(/>/g, ">"), 1);
|
2019-10-29 14:57:13 +01:00
|
|
|
playReceptionSound();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction permet de scroller au dernier message
|
|
|
|
*/
|
|
|
|
function scrollDownDiscussion()
|
|
|
|
{
|
|
|
|
var discussion_height = jQuery('.discussion-container').innerHeight();
|
|
|
|
var discussion_scroll_height = jQuery('.discussion-container')[0].scrollHeight;
|
|
|
|
var discussion_scroll_top = jQuery('.discussion-container').scrollTop();
|
|
|
|
var scroll_before_end = discussion_scroll_height - (discussion_scroll_top + discussion_height);
|
|
|
|
|
|
|
|
//On scroll uniquement si on a pas remonté plus haut que la moitié de la fenetre de discussion
|
|
|
|
if (scroll_before_end <= discussion_height / 2)
|
|
|
|
{
|
|
|
|
jQuery('.discussion-container').animate({scrollTop: 1000000});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cette fonction jou le son de reception d'un SMS
|
|
|
|
*/
|
|
|
|
function playReceptionSound ()
|
|
|
|
{
|
|
|
|
var receptionSound = jQuery('body').find('#reception-sound');
|
|
|
|
if (receptionSound.length)
|
|
|
|
{
|
|
|
|
receptionSound[0].play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery(document).ready(function()
|
|
|
|
{
|
|
|
|
var verifReceivedInterval = setInterval(verifReceived, 10000);
|
2019-11-28 19:41:10 +01:00
|
|
|
|
|
|
|
jQuery('body').on('click', '.btn-confirm', function (e)
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
jQuery(this).addClass('btn-warning');
|
|
|
|
jQuery(this).removeClass('btn-confirm');
|
|
|
|
jQuery(this).html('<span class="fa fa-trash-o"></span> Valider la suppression');
|
|
|
|
return false;
|
|
|
|
});
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
jQuery('body').on('click', '.goto', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (jQuery(this).attr('url'))
|
|
|
|
{
|
|
|
|
if (jQuery(this).attr('target'))
|
|
|
|
{
|
|
|
|
window.open(jQuery(this).attr('url'), jQuery(this).attr('target'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.location = jQuery(this).attr('url');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-29 01:19:31 +01:00
|
|
|
jQuery('body :checkbox').shiftcheckbox();
|
|
|
|
|
2019-10-29 14:57:13 +01:00
|
|
|
jQuery('body').on('submit', '.send-message-discussion', function (e)
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var form = jQuery(this);
|
|
|
|
var message = form.find('textarea').val();
|
|
|
|
var formData = new FormData(form[0]);
|
|
|
|
jQuery('.discussion-container').find('#send-message-spiner').remove();
|
|
|
|
jQuery('.discussion-container').append('<div class="text-center" id="send-message-spiner"><i class="fa fa-spinner fa-spin"></i></div>');
|
|
|
|
scrollDownDiscussion();
|
|
|
|
jQuery.ajax({
|
|
|
|
url: form.attr('action'),
|
|
|
|
type: form.attr('method'),
|
|
|
|
data: formData,
|
|
|
|
contentType: false,
|
|
|
|
processData: false,
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data)
|
|
|
|
{
|
|
|
|
if (!data.success)
|
|
|
|
{
|
|
|
|
showMessage(data.message.replace(/</g, "<").replace(/>/g, ">"), 0);
|
|
|
|
jQuery('.discussion-container').find('#send-message-spiner').remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).done(function()
|
|
|
|
{
|
|
|
|
form.trigger("reset");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|