96 lines
2.5 KiB
JavaScript
Executable File
96 lines
2.5 KiB
JavaScript
Executable File
/**
|
|
* 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');
|
|
jQuery.getJSON(HTTP_PWD + "/receiveds/popup", function( data ) {
|
|
$.each(data, function(key, val) {
|
|
showMessage('SMS reçu du ' + val.send_by.replace(/</g, "<").replace(/>/g, ">") + ' : ' + val.content.replace(/</g, "<").replace(/>/g, ">"), 1);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Cette fonction permet de scroller au dernier message
|
|
*/
|
|
function scrollDownDiscussion()
|
|
{
|
|
jQuery('.discussion-container').animate({scrollTop: 1000000});
|
|
}
|
|
|
|
jQuery(document).ready(function()
|
|
{
|
|
var verifReceivedInterval = setInterval(verifReceived, 10000);
|
|
|
|
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');
|
|
}
|
|
}
|
|
});
|
|
|
|
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");
|
|
});
|
|
});
|
|
|
|
scrollDownDiscussion();
|
|
});
|