1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-25 20:02:30 +01:00
freescout/public/js/main.js

1541 lines
42 KiB
JavaScript
Raw Normal View History

2018-06-22 19:44:21 +02:00
var fs_sidebar_menu_applied = false;
2018-07-30 17:11:35 +02:00
var fs_loader_timeout;
2018-09-03 10:11:29 +02:00
var fs_processing_send_reply = false;
2018-08-15 08:10:05 +02:00
2018-09-07 15:08:34 +02:00
// Ajax based notifications;
var poly;
2018-07-30 17:11:35 +02:00
// Default validation options
// https://devhints.io/parsley
window.ParsleyConfig = window.ParsleyConfig || {};
$.extend(window.ParsleyConfig, {
excluded: '.note-codable, [data-parsley-exclude]',
errorClass: 'has-error',
//successClass: 'has-success',
classHandler: function(ParsleyField) {
return ParsleyField.$element.parents('.form-group:first');
},
errorsContainer: function(ParsleyField) {
var help_block = ParsleyField.$element.parent().children('.help-block:first');
if (help_block) {
return help_block;
} else {
return ParsleyField.$element;
//return ParsleyField.$element.parents('.form-group:first');
}
},
errorsWrapper: '<div class="help-block"></div>',
errorTemplate: '<div></div>'
});
2018-06-22 19:44:21 +02:00
2018-09-10 17:24:20 +02:00
// Push notifications
/*Push.config({
serviceWorker: './customServiceWorker.js', // Sets a custom service worker script
fallback: function(payload) {
// Code that executes on browsers with no notification support
// "payload" is an object containing the
// title, body, tag, and icon of the notification
}
});*/
2018-07-27 15:19:25 +02:00
// Configuring editor
2018-09-03 09:23:56 +02:00
2018-07-27 15:19:25 +02:00
var EditorAttachmentButton = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<i class="glyphicon glyphicon-paperclip"></i>',
tooltip: Lang.get("messages.upload_attachments"),
container: 'body',
click: function () {
2018-08-15 08:10:05 +02:00
var element = document.createElement('div');
element.innerHTML = '<input type="file" multiple>';
var fileInput = element.firstChild;
fileInput.addEventListener('change', function() {
if (fileInput.files) {
for (var i = 0; i < fileInput.files.length; i++) {
editorSendFile(fileInput.files[i], true);
}
}
});
fileInput.click();
2018-07-27 15:19:25 +02:00
}
});
return button.render(); // return button as jquery object
}
var EditorSavedRepliesButton = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
2018-07-30 17:11:35 +02:00
contents: '<i class="glyphicon glyphicon-comment"></i>',
2018-07-27 15:19:25 +02:00
tooltip: Lang.get("messages.saved_replies"),
container: 'body',
click: function () {
alert('todo: implement saved replies');
}
});
return button.render(); // return button as jquery object
}
var EditorSaveDraftButton = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<i class="glyphicon glyphicon-ok-circle"></i>',
tooltip: Lang.get("messages.save_draft"),
container: 'body',
click: function () {
alert('todo: implement saving draft');
}
});
return button.render(); // return button as jquery object
}
var EditorDiscardButton = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<i class="glyphicon glyphicon-trash"></i>',
tooltip: Lang.get("messages.discard"),
container: 'body',
click: function () {
2018-08-18 14:21:14 +02:00
$(".conv-action-block").addClass('hidden');
$(".conv-action").removeClass('inactive');
2018-07-27 15:19:25 +02:00
}
});
return button.render(); // return button as jquery object
}
2018-08-25 11:52:53 +02:00
var EditorInsertVarButton = function (context) {
var ui = $.summernote.ui;
// todo: fallback=
var contents =
'<select class="form-control summernote-inservar" tabindex="-1">'+
'<option value="">'+Lang.get("messages.insert_var")+' ...</option>'+
'<optgroup label="'+Lang.get("messages.mailbox")+'">'+
'<option value="{%mailbox.email%}">'+Lang.get("messages.email")+'</option>'+
'<option value="{%mailbox.name%}">'+Lang.get("messages.name")+'</option>'+
'</optgroup>'+
'<optgroup label="'+Lang.get("messages.conversation")+'">'+
'<option value="{%conversation.number%}">'+Lang.get("messages.number")+'</option>'+
'</optgroup>'+
'<optgroup label="'+Lang.get("messages.customer")+'">'+
'<option value="{%customer.fullName%}">'+Lang.get("messages.full_name")+'</option>'+
'<option value="{%customer.firstName%}">'+Lang.get("messages.first_name")+'</option>'+
'<option value="{%customer.lastName%}">'+Lang.get("messages.last_name")+'</option>'+
'<option value="{%customer.email%}">'+Lang.get("messages.email_addr")+'</option>'+
'</optgroup>'+
'</select>';
// create button
var button = ui.button({
contents: contents,
tooltip: Lang.get("messages.insert_var"),
container: 'body'
});
return button.render(); // return button as jquery object
}
2018-07-27 15:19:25 +02:00
2018-06-22 19:44:21 +02:00
$(document).ready(function(){
2018-08-23 10:46:08 +02:00
triggersInit();
2018-06-22 19:44:21 +02:00
// Submenu
$('.sidebar-menu-toggle').click(function(event) {
event.stopPropagation();
$(this).parent().children('.sidebar-menu:first').toggleClass('active');
$(this).toggleClass('active');
if (!fs_sidebar_menu_applied) {
$('body').click(function() {
$('.sidebar-menu, .sidebar-menu-toggle').removeClass('active');
});
}
});
2018-07-25 16:09:20 +02:00
// Floating alerts
fsFloatingAlertsInit();
2018-08-15 08:10:05 +02:00
// Editor
(function($) {
if (typeof($.summernote) != "undefined") {
2018-09-03 09:23:56 +02:00
// DIV instead of P
// https://github.com/summernote/summernote/issues/546
// https://github.com/summernote/summernote/issues/702
// This causes TypeError: Cannot read property 'childNodes' of undefined
//$.summernote.dom.emptyPara = "<div><br></div>";
$.summernote.lang['en-US'].image.dragImageHere = Lang.get("messages.drag_image_file");
$.summernote.lang['en-US'].image.dropImage = Lang.get("messages.drag_image_file");
}
})(jQuery);
2018-09-07 15:08:34 +02:00
polycastInit();
webNotificationsInit();
2018-08-23 10:46:08 +02:00
});
function triggersInit()
{
// Tooltips
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
// Popover
$('[data-toggle="popover"]').popover({
container: 'body'
});
2018-08-20 19:41:51 +02:00
// Modal windows
$('a[data-trigger="modal"]').click(function(e) {
showModal($(this));
e.preventDefault();
});
2018-08-23 10:46:08 +02:00
}
2018-06-28 07:35:33 +02:00
function mailboxUpdateInit(from_name_custom)
{
2018-07-06 05:19:49 +02:00
$(document).ready(function(){
2018-08-23 14:11:52 +02:00
summernoteInit('#signature');
2018-06-28 07:35:33 +02:00
2018-07-06 05:19:49 +02:00
$('#from_name').change(function(event) {
if ($(this).val() == from_name_custom) {
$('#from_name_custom_container').removeClass('hidden');
} else {
$('#from_name_custom_container').addClass('hidden');
}
});
2018-06-28 07:35:33 +02:00
});
2018-07-04 11:38:00 +02:00
}
2018-08-23 14:11:52 +02:00
// Init summernote editor with default settings
//
// https://github.com/Studio-42/elFinder/wiki/Integration-with-Multiple-Summernote-%28fixed-functions%29
// https://stackoverflow.com/questions/21628222/summernote-image-upload
// https://www.kerneldev.com/2018/01/11/using-summernote-wysiwyg-editor-with-laravel/
// https://gist.github.com/abr4xas/22caf07326a81ecaaa195f97321da4ae
function summernoteInit(selector)
{
$(selector).summernote({
minHeight: 120,
dialogsInBody: true,
disableResizeEditor: true,
followingToolbar: false,
2018-08-25 11:52:53 +02:00
disableDragAndDrop: true,
2018-08-23 14:11:52 +02:00
toolbar: [
// [groupName, [list of button]]
2018-08-24 14:24:11 +02:00
['style', ['bold', 'italic', 'underline', 'color', 'ul', 'ol', 'link', 'codeview']],
2018-08-25 11:52:53 +02:00
['actions-select', ['insertvar']]
],
buttons: {
insertvar: EditorInsertVarButton
},
callbacks: {
onInit: function() {
// Remove statusbar
$('.note-statusbar').remove();
// Insert variables
$(selector).parent().children().find('.summernote-inservar:first').on('change', function(event) {
$(selector).summernote('insertText', $(this).val());
$(this).val('');
});
}
}
2018-08-23 14:11:52 +02:00
});
}
2018-07-04 13:52:25 +02:00
function permissionsInit()
2018-07-04 11:38:00 +02:00
{
2018-07-06 05:19:49 +02:00
$(document).ready(function(){
$('.sel-all').click(function(event) {
$("#permissions-fields input").attr('checked', 'checked');
});
$('.sel-none').click(function(event) {
$("#permissions-fields input").removeAttr('checked');
});
2018-07-04 11:38:00 +02:00
});
2018-07-06 05:19:49 +02:00
}
function mailboxConnectionInit(out_method_smtp)
{
$(document).ready(function(){
$(':input[name="out_method"]').on('change', function(event) {
2018-07-06 07:58:29 +02:00
var method = $(':input[name="out_method"]:checked').val();
2018-07-06 05:19:49 +02:00
$('.out_method_options').addClass('hidden');
2018-07-06 07:58:29 +02:00
$('#out_method_'+method+'_options').removeClass('hidden');
if (parseInt(method) == parseInt(out_method_smtp)) {
$('#out_method_'+out_method_smtp+'_options :input').attr('required', 'required');
} else {
$('#out_method_'+out_method_smtp+'_options :input').removeAttr('required');
}
2018-07-06 05:19:49 +02:00
});
2018-07-04 11:38:00 +02:00
});
2018-07-07 08:42:21 +02:00
}
2018-08-30 10:48:42 +02:00
function mailSettingsInit()
{
$(document).ready(function(){
$(':input[name="settings[mail_driver]"]').on('change', function(event) {
var method = $(':input[name="settings[mail_driver]"]').val();
2018-08-31 18:17:38 +02:00
2018-08-30 10:48:42 +02:00
$('.mail_driver_options').addClass('hidden');
$('#mail_driver_options_'+method).removeClass('hidden');
if (parseInt(method) == 'smtp') {
$('#mail_driver_options_smtp :input').attr('required', 'required');
} else {
$('#mail_driver_options_smtp :input').removeAttr('required');
}
});
});
}
2018-07-07 08:42:21 +02:00
function userCreateInit()
{
$(document).ready(function(){
$('#send_invite').on('change', function(event) {
if ($(this).is(':checked')) {
$('.no-send-invite').addClass('hidden');
$('#password').removeAttr('required');
} else {
$('.no-send-invite').removeClass('hidden');
$('#password').attr('required', 'required');
}
});
});
2018-07-08 09:39:12 +02:00
}
function logsInit()
{
$(document).ready(function() {
2018-08-02 18:17:13 +02:00
$('#table-logs').DataTable({
2018-08-25 14:42:33 +02:00
"ordering": false,
"paging": false,
"info": false,
"searching": false
2018-08-02 18:17:13 +02:00
});
2018-07-08 09:39:12 +02:00
} );
2018-07-10 12:15:58 +02:00
}
function multiInputInit()
{
$(document).ready(function() {
$('.multi-add').click(function() {
var clone = $(this).parents('.multi-container:first').children('.multi-item:first').clone(true, true);
clone.find(':input').val('');
2018-08-29 08:45:15 +02:00
clone.find('.help-block').remove();
clone.removeClass('has-error');
2018-07-10 12:15:58 +02:00
clone.insertAfter($(this).parents('.multi-container:first').children('.multi-item:last'));
});
$('.multi-remove').click(function() {
if ($(this).parents('.multi-container:first').children('.multi-item').length > 1) {
$(this).parents('.multi-item:first').remove();
} else {
$(this).parents('.multi-item:first').children(':input').val('');
}
});
} );
}
2018-08-10 16:28:35 +02:00
function fsAjax(data, url, success_callback, no_loader, error_callback)
2018-07-25 16:09:20 +02:00
{
// Setup AJAX
2018-08-15 08:10:05 +02:00
ajaxSetup();
2018-07-25 16:09:20 +02:00
// Show loader
if (typeof(no_loader) == "undefined" || !no_loader) {
2018-08-15 08:10:05 +02:00
loaderShow(true);
2018-07-25 16:09:20 +02:00
}
if (typeof(error_callback) == "undefined" || !error_callback) {
error_callback = function() {
2018-08-15 08:10:05 +02:00
showFloatingAlert('error', Lang.get("messages.ajax_error"));
loaderHide();
2018-08-31 18:17:38 +02:00
// Buttons
$(".btn[data-loading-text!='']:disabled").button('reset');
// Links
$(".btn.disabled[data-loading-text!='']").button('reset');
2018-07-25 16:09:20 +02:00
};
}
2018-08-10 16:28:35 +02:00
// If this is conversation ajax request, add folder_id to the URL
if (url.indexOf('/conversation/') != -1) {
var folder_id = getQueryParam('folder_id');
if (folder_id) {
url += '?folder_id='+folder_id;
}
}
2018-07-25 16:09:20 +02:00
$.ajax({
url: url,
method: 'post',
dataType: 'json',
data: data,
success: success_callback,
error: error_callback
});
}
2018-07-30 17:11:35 +02:00
// Show loader
2018-08-15 08:10:05 +02:00
function loaderShow(delay)
2018-07-25 16:09:20 +02:00
{
2018-07-30 17:11:35 +02:00
if (typeof(delay) != "undefined" && delay) {
fs_loader_timeout = setTimeout(function() {
2018-08-15 08:10:05 +02:00
$("#loader-main").fadeIn();
2018-07-30 17:11:35 +02:00
}, 1000);
} else {
2018-08-15 08:10:05 +02:00
$("#loader-main").fadeIn();
2018-07-30 17:11:35 +02:00
}
2018-07-25 16:09:20 +02:00
}
2018-08-15 08:10:05 +02:00
function loaderHide()
2018-07-25 16:09:20 +02:00
{
$("#loader-main").hide();
2018-07-30 17:11:35 +02:00
clearTimeout(fs_loader_timeout);
2018-07-25 16:09:20 +02:00
}
// Display floating alerts
function fsFloatingAlertsInit()
{
var alerts = $(".alert-floating:hidden");
2018-09-02 08:45:13 +02:00
alerts.each(function(i, el) {
// Stack alerts
var top = 0;
$(".alert-floating:visible").each(function(sub_i, sub_el) {
top = top + $(sub_el).position().top + $(sub_el).outerHeight(true);
});
if (top) {
$(el).css('top', top+'px');
}
$(el).css('display', 'flex');
2018-08-31 18:17:38 +02:00
// If error do not close automatically
2018-09-02 08:45:13 +02:00
if (!$(el).hasClass('alert-danger')) {
2018-08-31 18:17:38 +02:00
setTimeout(function(){
2018-09-02 08:45:13 +02:00
el.remove();
2018-08-31 18:17:38 +02:00
}, 7000);
}
2018-07-25 16:09:20 +02:00
});
if (alerts.length) {
2018-08-30 10:48:42 +02:00
setTimeout(function(){
$('body').click(function() {
alerts.remove();
});
}, 2000);
2018-07-25 16:09:20 +02:00
}
}
2018-08-15 08:10:05 +02:00
function showFloatingAlert(type, msg)
2018-07-25 16:09:20 +02:00
{
var icon = 'ok';
var alert_class = 'success';
if (type == 'error') {
icon = 'exclamation-sign';
alert_class = 'danger';
}
var html = '<div class="alert alert-'+alert_class+' alert-floating">'+
'<i class="glyphicon glyphicon-'+icon+'"></i>'+
'<div>'+msg+'</div>'+
'</div>';
$('body:first').append(html);
fsFloatingAlertsInit();
}
function conversationInit()
{
$(document).ready(function(){
2018-07-27 08:01:34 +02:00
// Change conversation assignee
jQuery(".conv-user li > a").click(function(e){
if (!$(this).hasClass('active')) {
fsAjax({
action: 'conversation_change_user',
user_id: $(this).attr('data-user_id'),
2018-08-22 20:34:44 +02:00
conversation_id: getGlobalAttr('conversation_id')
2018-07-30 17:11:35 +02:00
},
laroute.route('conversations.ajax'),
function(response) {
2018-07-27 08:01:34 +02:00
if (typeof(response.status) != "undefined" && response.status == 'success') {
if (typeof(response.redirect_url) != "undefined") {
window.location.href = response.redirect_url;
} else {
window.location.href = '';
}
2018-07-27 10:10:51 +02:00
} else if (typeof(response.msg) != "undefined") {
2018-08-15 08:10:05 +02:00
showFloatingAlert('error', response.msg);
2018-09-07 15:08:34 +02:00
loaderHide();
2018-07-27 10:10:51 +02:00
} else {
2018-08-15 08:10:05 +02:00
showFloatingAlert('error', Lang.get("messages.error_occured"));
2018-09-07 15:08:34 +02:00
loaderHide();
2018-07-27 08:01:34 +02:00
}
});
}
e.preventDefault();
});
// Change conversation status
2018-07-25 16:09:20 +02:00
jQuery(".conv-status li > a").click(function(e){
if (!$(this).hasClass('active')) {
2018-07-27 08:01:34 +02:00
fsAjax({
action: 'conversation_change_status',
2018-07-25 16:09:20 +02:00
status: $(this).attr('data-status'),
2018-08-22 20:34:44 +02:00
conversation_id: getGlobalAttr('conversation_id')
2018-07-30 17:11:35 +02:00
},
laroute.route('conversations.ajax'),
function(response) {
2018-07-25 16:09:20 +02:00
if (typeof(response.status) != "undefined" && response.status == 'success') {
if (typeof(response.redirect_url) != "undefined") {
window.location.href = response.redirect_url;
} else {
window.location.href = '';
}
2018-07-27 10:10:51 +02:00
} else if (typeof(response.msg) != "undefined") {
2018-08-15 08:10:05 +02:00
showFloatingAlert('error', response.msg);
2018-07-27 10:10:51 +02:00
} else {
2018-08-15 08:10:05 +02:00
showFloatingAlert('error', Lang.get("messages.error_occured"));
2018-07-25 16:09:20 +02:00
}
2018-08-15 08:10:05 +02:00
loaderHide();
2018-07-25 16:09:20 +02:00
});
}
e.preventDefault();
});
2018-07-30 17:11:35 +02:00
// Reply
jQuery(".conv-reply").click(function(e){
2018-08-18 14:21:14 +02:00
if ($(".conv-reply-block").hasClass('hidden') || $(this).hasClass('inactive')) {
2018-08-09 11:22:12 +02:00
// Show
2018-07-30 17:11:35 +02:00
$(".conv-action-block").addClass('hidden');
2018-08-18 14:21:14 +02:00
$(".conv-reply-block").removeClass('hidden')
.removeClass('conv-note-block')
.children().find(":input[name='is_note']:first").val('')
2018-07-30 17:11:35 +02:00
$(".conv-action").addClass('inactive');
$(this).removeClass('inactive');
2018-08-09 11:22:12 +02:00
if (!$('#to').length) {
$('#body').summernote('focus');
}
2018-07-30 17:11:35 +02:00
} else {
2018-08-09 11:22:12 +02:00
// Hide
2018-07-30 17:11:35 +02:00
$(".conv-action-block").addClass('hidden');
$(".conv-action").removeClass('inactive');
}
e.preventDefault();
});
2018-08-18 14:21:14 +02:00
// Add note
jQuery(".conv-add-note").click(function(e){
if ($(".conv-reply-block").hasClass('hidden') || $(this).hasClass('inactive')) {
// Show
$(".conv-action-block").addClass('hidden');
$(".conv-reply-block").removeClass('hidden')
.addClass('conv-note-block')
.children().find(":input[name='is_note']:first").val(1);
$(".conv-action").addClass('inactive');
$(this).removeClass('inactive');
$('#body').summernote('focus');
} else {
// Hide
$(".conv-action-block").addClass('hidden');
$(".conv-action").removeClass('inactive');
}
e.preventDefault();
});
2018-08-20 19:41:51 +02:00
// View Send Log
jQuery(".thread-send-log-trigger").click(function(e){
var thread_id = $(this).parents('.thread:first').attr('data-thread_id');
if (!thread_id) {
return;
}
e.preventDefault();
});
2018-07-25 16:09:20 +02:00
});
}
2018-08-22 20:34:44 +02:00
function getGlobalAttr(attr)
2018-07-25 16:09:20 +02:00
{
return $("body:first").attr('data-'+attr);
2018-07-27 15:19:25 +02:00
}
2018-07-30 17:11:35 +02:00
// Initialize conversation body editor
function convEditorInit()
{
$('#body').summernote({
minHeight: 200,
dialogsInBody: true,
dialogsFade: true,
disableResizeEditor: true,
2018-08-02 18:17:13 +02:00
followingToolbar: false,
2018-07-30 17:11:35 +02:00
toolbar: [
// [groupName, [list of button]]
['style', ['attachment', 'bold', 'italic', 'underline', 'ul', 'ol', 'link', 'picture', 'codeview', 'savedreplies']],
['actions', ['savedraft', 'discard']],
],
buttons: {
attachment: EditorAttachmentButton,
savedreplies: EditorSavedRepliesButton,
savedraft: EditorSaveDraftButton,
discard: EditorDiscardButton
2018-08-15 08:10:05 +02:00
},
callbacks: {
onImageUpload: function(files) {
if (!files) {
return;
}
for (var i = 0; i < files.length; i++) {
editorSendFile(files[i]);
}
}
}
2018-07-30 17:11:35 +02:00
});
var html = $('#editor_bottom_toolbar').html();
$('.note-statusbar').addClass('note-statusbar-toolbar form-inline').html(html);
}
2018-08-15 08:10:05 +02:00
function ajaxSetup()
{
$.ajaxSetup({
headers: {
2018-09-07 15:08:34 +02:00
'X-CSRF-TOKEN': getCsrfToken()
2018-08-15 08:10:05 +02:00
}
});
}
// Generate random unique ID
function generateDummyId()
{
// Math.random should be unique because of its seeding algorithm.
// Convert it to base 36 (numbers + letters), and grab the first 9 characters
// after the decimal.
return '_' + Math.random().toString(36).substr(2, 9);
}
// Save file uploaded in editor
function editorSendFile(file, attach)
{
if (!file || typeof(file.type) == "undefined") {
return false;
}
var attachments_container = $(".attachments-upload:first");
var attachment_dummy_id = generateDummyId();
ajaxSetup();
if (typeof(attach) == "undefined") {
attach = false;
}
// Images are embedded by default, other files attached
if (file.type.indexOf('image/') == -1) {
attach = true;
}
// Show loader
if (attach) {
var attachment_html = '<li class="atachment-upload-'+attachment_dummy_id+'"><img src="'+Vars.public_url+'/img/loader-tiny.gif" width="16" height="16"/> <a href="javascript:void(0);" class="break-words disabled" target="_blank">'+file.name+'<span class="ellipsis">…</span> </a> <span class="text-help">('+formatBytes(file.size)+')</span> <i class="glyphicon glyphicon-remove" onclick="removeAttachment(\''+attachment_dummy_id+'\')"></i></li>';
$('.attachments-upload:first ul:first').append(attachment_html);
attachments_container.show();
} else {
loaderShow();
}
data = new FormData();
data.append("file", file);
if (attach) {
data.append("attach", 1);
} else {
data.append("attach", 0);
}
$.ajax({
url: laroute.route('conversations.upload'),
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(response){
if (typeof(response.url) == "undefined" || !response.url) {
showFloatingAlert('error', Lang.get("messages.error_occured"));
loaderHide();
removeAttachment(attachment_dummy_id);
return;
}
// Finish loading
if (attach) {
$('li.atachment-upload-'+attachment_dummy_id+':first').addClass('attachment-loaded');
$('li.atachment-upload-'+attachment_dummy_id+':first a').removeClass('disabled').attr('href', response.url);
} else {
loaderHide();
}
if (typeof(response.status) == "undefined" || response.status != "success") {
showAjaxError(response);
removeAttachment(attachment_dummy_id);
return;
}
if (attach) {
} else {
// Embed image
$('#body').summernote('insertImage', response.url, function (image) {
var editor_width = $('.note-editable:first:visible').width();
if (image.width() > editor_width-85) {
image.css('width', editor_width-85);
}
image.attr('width', image.css('width').replace('px', ''));
});
}
if (typeof(response.attachment_id) != "undefined" || response.attachment_id) {
var input_html = '<input type="hidden" name="attachments_all[]" value="'+response.attachment_id+'" />';
input_html += '<input type="hidden" name="attachments[]" value="'+response.attachment_id+'" class="atachment-upload-'+attachment_dummy_id+'" />';
if (!attach) {
input_html += '<input type="hidden" name="embeds[]" value="'+response.attachment_id+'" class="atachment-upload-'+attachment_dummy_id+'" />';
}
attachments_container.prepend(input_html);
}
},
error: function(jqXHR, textStatus, errorThrown) {
if (attach) {
removeAttachment(attachment_dummy_id);
} else {
loaderHide();
}
console.log(textStatus+": "+errorThrown);
showFloatingAlert('error', Lang.get("messages.error_occured"));
}
});
}
function removeAttachment(attachment_dummy_id)
{
$('.atachment-upload-'+attachment_dummy_id).remove();
}
function formatBytes(size)
{
precision = 2;
size = parseInt(size);
if (!isNaN(size) && size > 0) {
base = Math.log(size) / Math.log(1024);
suffixes = [' b', ' KB', ' MB', ' GB', ' TB'];
return Math.round(Math.pow(1024, base - Math.floor(base)), precision)+''+suffixes[Math.floor(base)];
} else {
return size;
}
}
2018-07-27 15:19:25 +02:00
// New conversation page
function newConversationInit()
{
$(document).ready(function() {
2018-07-30 17:11:35 +02:00
convEditorInit();
2018-07-27 15:19:25 +02:00
2018-08-10 16:28:35 +02:00
// Show CC
2018-07-27 15:19:25 +02:00
$('.toggle-cc a:first').click(function() {
$('.field-cc').removeClass('hidden');
$(this).parent().remove();
});
2018-07-30 17:11:35 +02:00
2018-08-10 16:28:35 +02:00
// After send
$('.dropdown-after-send a:lt(3)').click(function(e) {
if (!$(this).parent().hasClass('active')) {
$("#after_send").val($(this).attr('data-after-send'));
$('.dropdown-after-send li').removeClass('active');
$(this).parent().addClass('active');
}
e.preventDefault();
});
// After send
$('.after-send-change').click(function(e) {
showModal($(this));
2018-07-30 17:11:35 +02:00
});
// Send reply or new conversation
2018-09-03 10:11:29 +02:00
$(".btn-reply-submit").click(function(e) {
// This is extra protection from double click on Send button
// DOM operation are slow sometimes
if (fs_processing_send_reply) {
return;
}
fs_processing_send_reply = true;
2018-07-30 17:11:35 +02:00
var button = $(this);
// Validate before sending
form = $(".form-reply:first");
if (!form.parsley().validate()) {
2018-09-03 10:11:29 +02:00
fs_processing_send_reply = false;
2018-07-30 17:11:35 +02:00
return;
}
button.button('loading');
data = form.serialize();
data += '&action=send_reply';
2018-08-15 08:10:05 +02:00
2018-07-30 17:11:35 +02:00
fsAjax(data, laroute.route('conversations.ajax'), function(response) {
if (typeof(response.status) != "undefined" && response.status == 'success') {
if (typeof(response.redirect_url) != "undefined") {
window.location.href = response.redirect_url;
} else {
window.location.href = '';
}
} else {
2018-08-15 08:10:05 +02:00
showAjaxError(response);
2018-07-30 17:11:35 +02:00
button.button('reset');
}
2018-08-15 08:10:05 +02:00
loaderHide();
2018-09-03 10:11:29 +02:00
fs_processing_send_reply = false;
2018-09-08 20:02:01 +02:00
},
true,
function() {
2018-09-03 10:11:29 +02:00
showFloatingAlert('error', Lang.get("messages.ajax_error"));
loaderHide();
button.button('reset');
fs_processing_send_reply = false;
2018-07-30 17:11:35 +02:00
});
2018-09-03 10:11:29 +02:00
2018-07-30 17:11:35 +02:00
e.preventDefault();
});
2018-07-27 15:19:25 +02:00
});
2018-07-30 17:11:35 +02:00
}
2018-08-08 09:52:53 +02:00
function notificationsInit()
{
$(document).ready(function() {
$('.sel-all').click(function(event) {
if ($(this).is(':checked')) {
2018-09-10 17:24:20 +02:00
if ($(this).val() == 'browser' && !Push.Permission.has()) {
return;
}
2018-08-08 09:52:53 +02:00
$(".subscriptions-"+$(this).val()+" input").attr('checked', 'checked');
} else {
$(".subscriptions-"+$(this).val()+" input").removeAttr('checked');
}
});
2018-09-10 17:24:20 +02:00
// Browser push-notifications permissions
if (getGlobalAttr('own_profile')) {
$('.sel-all[value="browser"], .subscriptions-browser input').click(function(event) {
var checkbox = $(this);
if ($(this).is(':checked')) {
// Check protocol
if (location.protocol != 'https:') {
var alert_html = '<div>'+
'<div class="text-center">'+
'<div class="text-larger margin-top-10">'+Lang.get("messages.push_protocol_alert")+'</div>'+
'<div class="form-group margin-top">'+
'<button class="btn btn-primary reset-password-ok" data-dismiss="modal">OK</button>'+
'</div>';
'</div>';
'</div>';
showModalDialog(alert_html);
checkbox.prop('checked', false);
return;
}
if (!Push.Permission.has()) {
Push.Permission.request(function() {}, function() {
$.featherlight($('<img src="'+Vars.public_url+'/img/enable-push.png" />'), {});
checkbox.prop('checked', false);
});
}
}
});
}
2018-08-08 09:52:53 +02:00
});
2018-08-10 16:28:35 +02:00
}
function getQueryParam(name, qs) {
if (typeof(qs) == "undefined") {
qs = document.location.search;
}
qs = qs.split('+').join(' ');
var params = {},
tokens,
re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
if (typeof(params[name]) != "undefined") {
return params[name];
} else {
return '';
}
}
// Show bootstrap modal
2018-08-29 08:45:15 +02:00
function showModal(a, params)
2018-08-10 16:28:35 +02:00
{
var options = {};
2018-08-29 08:45:15 +02:00
if (typeof(params) == "undefined") {
params = {};
}
if (typeof(a) == "undefined" || !a) {
// Create dummy link
a = $(document.createElement('a'));
}
2018-08-10 16:28:35 +02:00
var title = a.attr('data-modal-title');
if (title && title.charAt(0) == '#') {
title = $(title).html();
}
if (!title) {
title = a.text();
}
var remote = a.attr('data-remote');
2018-08-20 19:41:51 +02:00
if (!remote) {
remote = a.attr('href');
}
2018-08-10 16:28:35 +02:00
var body = a.attr('data-modal-body');
2018-08-29 08:45:15 +02:00
if (typeof(params.body) != "undefined") {
body = params.body;
}
2018-08-10 16:28:35 +02:00
var footer = a.attr('data-modal-footer');
var no_close_btn = a.attr('data-no-close-btn');
2018-08-29 08:45:15 +02:00
if (typeof(params.no_footer) == "undefined") {
params.no_footer = a.attr('data-modal-no-footer');
}
if (typeof(params.no_header) == "undefined") {
params.no_header = a.attr('data-modal-no-header');
}
if (typeof(params.no_fade) == "undefined") {
params.no_fade = a.attr('data-modal-no-fade');
}
2018-08-10 16:28:35 +02:00
var modal_class = a.attr('data-modal-class');
2018-08-29 08:45:15 +02:00
var on_show = a.attr('data-modal-on-show');
if (typeof(params.on_show) != "undefined") {
on_show = params.on_show;
}
// Size: lg or sm
if (typeof(params.size) == "undefined") {
params.size = a.attr('data-modal-size');
}
if (typeof(params.width_auto) == "undefined") {
params.width_auto = a.attr('data-modal-width-auto');
}
2018-08-21 08:49:13 +02:00
// Fit modal body into the screen
var fit = a.attr('data-modal-fit');
2018-08-29 08:45:15 +02:00
2018-08-10 16:28:35 +02:00
var modal;
2018-08-29 08:45:15 +02:00
if (params.size) {
modal_class += ' modal-'+params.size;
}
if (params.width_auto) {
modal_class += ' modal-width-auto';
}
if (typeof(modal_class) == "undefined") {
modal_class = '';
2018-08-22 09:26:42 +02:00
}
2018-08-10 16:28:35 +02:00
var html = [
2018-08-29 08:45:15 +02:00
'<div class="modal '+(params.no_fade == 'true' ? '' : 'fade')+'" tabindex="-1" role="dialog" aria-labelledby="jsmodal-label" aria-hidden="true">',
2018-08-10 16:28:35 +02:00
'<div class="modal-dialog '+modal_class+'">',
'<div class="modal-content">',
2018-08-29 08:45:15 +02:00
'<div class="modal-header '+(params.no_header == 'true' ? 'hidden' : '')+'">',
2018-08-10 16:28:35 +02:00
'<button type="button" class="close" data-dismiss="modal" aria-label="'+Lang.get("messages.close")+'"><span aria-hidden="true">&times;</span></button>',
'<h3 class="modal-title" id="jsmodal-label">'+title+'</h3>',
'</div>',
2018-08-21 08:49:13 +02:00
'<div class="modal-body '+(fit == 'true' ? 'modal-body-fit' : '')+'"><div class="text-center modal-loader"><img src="'+Vars.public_url+'/img/loader-grey.gif" width="31" height="31"/></div></div>',
2018-08-29 08:45:15 +02:00
'<div class="modal-footer '+(params.no_footer == 'true' ? 'hidden' : '')+'">',
2018-08-10 16:28:35 +02:00
(no_close_btn == 'true' ? '': '<button type="button" class="btn btn-default" data-dismiss="modal">'+Lang.get("messages.close")+'</button>'),
footer,
'</div>',
'</div>',
'</div>',
'</div>'].join('');
modal = $(html);
2018-08-29 08:45:15 +02:00
// if (typeof(onshow) !== "undefined") {
// modal.on('shown.bs.modal', onshow);
// }
2018-08-10 16:28:35 +02:00
modal.modal(options);
if (body) {
2018-08-29 08:45:15 +02:00
var body_html = $(body).html();
if (!body_html) {
body_html = $('<div>'+body+'</div>').html()
}
modal.children().find(".modal-body").html(body_html);
if (on_show) {
if (typeof(window[on_show]) == "function") {
window[on_show](modal);
} else if (typeof(on_show) == "function") {
on_show(modal);
}
2018-08-27 14:09:51 +02:00
}
2018-08-10 16:28:35 +02:00
} else {
setTimeout(function(){
$.ajax({
url: remote,
success: function(html) {
modal.children().find(".modal-body").html(html);
2018-08-27 14:09:51 +02:00
2018-08-29 08:45:15 +02:00
if (on_show) {
if (typeof(window[on_show]) == "function") {
window[on_show](modal);
} else if (typeof(on_show) == "function") {
on_show(modal);
}
2018-08-27 14:09:51 +02:00
}
2018-08-10 16:28:35 +02:00
},
error: function(data) {
modal.children().find(".modal-body").html('<p class="alert alert-danger">'+Lang.get("messages.error_occured")+'</p>');
}
});
}, 500);
}
}
// Show floating error message on ajax error
function showAjaxError(response)
{
if (typeof(response.msg) != "undefined") {
2018-08-15 08:10:05 +02:00
showFloatingAlert('error', response.msg);
2018-08-10 16:28:35 +02:00
} else {
2018-08-15 08:10:05 +02:00
showFloatingAlert('error', Lang.get("messages.error_occured"));
2018-08-10 16:28:35 +02:00
}
}
// Save default redirect
function saveAfterSend(el)
{
var button = $(el);
button.button('loading');
var value = $(el).parents('.modal-body:first').children().find('[name="after_send_default"]:first').val();
data = {
value: value,
2018-08-22 20:34:44 +02:00
mailbox_id: getGlobalAttr('mailbox_id'),
2018-08-10 16:28:35 +02:00
action: 'save_after_send'
};
fsAjax(data, laroute.route('conversations.ajax'), function(response) {
if (typeof(response.status) != "undefined" && response.status == 'success') {
// Show selected option in the dropdown
$('.dropdown-after-send [data-after-send='+value+']:first').click();
2018-08-15 08:10:05 +02:00
showFloatingAlert('success', Lang.get("messages.settings_saved"));
2018-08-10 16:28:35 +02:00
$('.modal').modal('hide');
} else {
showAjaxError(response);
}
button.button('reset');
}, true);
2018-08-22 20:34:44 +02:00
}
function viewMailboxInit()
{
conversationPagination();
}
2018-08-23 10:46:08 +02:00
function searchInit()
{
// Open all links in new window
$(".conv-row a").attr('target', '_blank');
conversationPagination();
}
2018-08-22 20:34:44 +02:00
function conversationPagination()
{
$(".table-conversations .pager-nav").click(function(e){
2018-09-04 14:50:15 +02:00
var filter = {
q: getQueryParam('q') // For search
};
var table = $(this).parents('.table-conversations:first');
var datas = table.data();
for (data_name in datas) {
if (/^filter_/.test(data_name)) {
filter[data_name.replace(/^filter_/, '')] = datas[data_name];
}
}
2018-08-22 20:34:44 +02:00
fsAjax(
{
action: 'conversations_pagination',
mailbox_id: getGlobalAttr('mailbox_id'),
folder_id: getGlobalAttr('folder_id'),
2018-09-04 14:50:15 +02:00
filter: filter,
2018-08-22 20:34:44 +02:00
page: $(this).attr('data-page')
},
laroute.route('conversations.ajax'),
function(response) {
if (typeof(response.status) != "undefined" && response.status == 'success') {
if (typeof(response.html) != "undefined") {
$(".table-conversations:first").html(response.html);
conversationPagination();
2018-08-23 10:46:08 +02:00
triggersInit();
2018-08-22 20:34:44 +02:00
}
} else {
showAjaxError(response);
}
loaderHide();
}
);
e.preventDefault();
});
2018-08-27 14:09:51 +02:00
}
function changeCustomerInit()
{
2018-08-29 08:45:15 +02:00
$(document).ready(function() {
var input = $(".change-customer-input");
input.select2({
ajax: {
url: laroute.route('customers.ajax_search'),
dataType: 'json',
delay: 250,
cache: true,
data: function (params) {
return {
q: params.term,
exclude_email: input.attr('data-customer_email')
//use_id: true
};
}/*,
beforeSend: function(){
showSelect2Loader(input);
},
complete: function(){
hideSelect2Loader(input);
}*/
},
containerCssClass: "select2-multi-container", // select2-with-loader
dropdownCssClass: "select2-multi-dropdown",
dropdownParent: $('.modal-dialog:visible:first'),
multiple: true,
maximumSelectionLength: 1,
placeholder: input.attr('placeholder'),
minimumInputLength: 1
});
// Show confirmation dialog on customer select
input.on('select2:selecting', function (e) {
if (typeof(e.params) == "undefined" || typeof(e.params.args.data) == "undefined") {
console.log(e);
return;
}
var data = e.params.args.data;
//el.select2('close');
var confirm_html = '<div>'+
'<div class="text-center">'+
'<div class="text-larger margin-top-10">'+Lang.get("messages.confirm_change_customer", {customer_email: data.id})+'</div>'+
'<div class="form-group margin-top">'+
'<button class="btn btn-primary change-customer-ok" data-customer_email='+data.id+'>OK</button>'+
'<button class="btn btn-link" data-dismiss="modal">'+Lang.get("messages.cancel")+'</button>'+
'</div>';
'</div>';
'</div>';
showModal(null, {
body: confirm_html,
width_auto: 'true',
no_header: 'true',
no_footer: 'true',
no_fade: 'true',
size: 'sm',
on_show: function(modal) {
modal.children().find('.change-customer-ok:first').click(function(e) {
fsAjax({
action: 'conversation_change_customer',
customer_email: $(this).attr('data-customer_email'),
conversation_id: getGlobalAttr('conversation_id')
},
laroute.route('conversations.ajax'),
function(response) {
if (typeof(response.status) != "undefined" && response.status == 'success') {
if (typeof(response.redirect_url) != "undefined") {
window.location.href = response.redirect_url;
} else {
window.location.href = '';
}
} else {
showAjaxError(response);
loaderHide();
}
}
);
});
}
});
e.preventDefault();
});
});
}
2018-09-02 19:52:18 +02:00
function showModalDialog(body, options)
{
var standard_options = {
body: body,
width_auto: 'true',
no_header: 'true',
no_footer: 'true',
no_fade: 'true',
size: 'sm'
};
if (typeof(options) == "undefined") {
options = {};
}
options = Object.assign(standard_options, options);
showModal(null, options);
}
2018-08-29 08:45:15 +02:00
/*function showSelect2Loader(input)
{
input.closest('.select2-with-loader:first').addClass('loading');
}
function hideSelect2Loader(input)
{
input.closest('.select2-with-loader:first').removeClass('loading');
2018-08-31 18:17:38 +02:00
}*/
function userProfileInit()
{
2018-09-02 19:52:18 +02:00
// Send or re-send invite
2018-08-31 18:17:38 +02:00
$(".send-invite-trigger, .resend-invite-trigger").click(function(e){
var button = $(this);
var is_resend = false;
button.button('loading');
if (button.hasClass('resend-invite-trigger')) {
is_resend = true;
}
fsAjax(
{
action: 'send_invite',
user_id: getGlobalAttr('user_id')
},
laroute.route('users.ajax'),
function(response) {
if (typeof(response.status) != "undefined" && response.status == 'success') {
if (is_resend) {
showFloatingAlert('success', Lang.get("messages.invite_resent"));
} else {
showFloatingAlert('success', Lang.get("messages.invite_sent"));
}
} else {
showAjaxError(response);
}
button.button('reset');
},
true
);
2018-09-02 19:52:18 +02:00
e.preventDefault();
});
// Reset password
$(".reset-password-trigger").click(function(e){
var button = $(this);
var confirm_html = '<div>'+
'<div class="text-center">'+
'<div class="text-larger margin-top-10">'+Lang.get("messages.confirm_reset_password")+'</div>'+
'<div class="form-group margin-top">'+
'<button class="btn btn-primary reset-password-ok">OK</button>'+
'<button class="btn btn-link" data-dismiss="modal">'+Lang.get("messages.cancel")+'</button>'+
'</div>';
'</div>';
'</div>';
showModalDialog(confirm_html, {
on_show: function(modal) {
modal.children().find('.reset-password-ok:first').click(function(e) {
button.button('loading');
modal.modal('hide');
fsAjax(
{
action: 'reset_password',
user_id: getGlobalAttr('user_id')
},
laroute.route('users.ajax'),
function(response) {
showAjaxResult(response);
button.button('reset');
}
);
});
}
});
2018-08-31 18:17:38 +02:00
e.preventDefault();
});
2018-09-02 19:52:18 +02:00
}
function showAjaxResult(response)
{
loaderHide();
if (typeof(response.status) != "undefined" && response.status == 'success') {
if (typeof(response['success_msg']) != "undefined") {
showFloatingAlert('success', response['success_msg']);
}
} else {
showAjaxError(response);
}
2018-09-07 15:08:34 +02:00
}
function getCsrfToken()
{
return $('meta[name="csrf-token"]:first').attr('content');
}
2018-09-10 11:50:53 +02:00
// Real-time website notifications in the menu and browser push notifications
2018-09-07 15:08:34 +02:00
function polycastInit()
{
2018-09-08 20:02:01 +02:00
var auth_user_id = getGlobalAttr('auth_user_id');
if (!auth_user_id) {
return;
}
2018-09-07 15:08:34 +02:00
// create the connection
poly = new Polycast('/polycast', {
token: getCsrfToken()
});
// register callbacks for connection events
2018-09-10 11:50:53 +02:00
// poly.on('connect', function(obj){
// console.log('connect event fired!');
// console.log(obj);
// });
2018-09-07 15:08:34 +02:00
2018-09-10 11:50:53 +02:00
// poly.on('disconnect', function(obj){
// console.log('disconnect event fired!');
// console.log(obj);
// });
2018-09-07 15:08:34 +02:00
// subscribe to channel(s)
2018-09-10 11:50:53 +02:00
var channel = poly.subscribe('private-App.User.'+auth_user_id);
2018-09-07 15:08:34 +02:00
2018-09-10 11:50:53 +02:00
// fired when event on channel is received
channel.on('App\\Events\\RealtimeBroadcastNotificationCreated', function(data, event){
2018-09-07 15:08:34 +02:00
/*
event.id = mysql id
event.channels = array of channels
event.event = event name
event.payload = object containing event data (same as the first data argument)
event.created_at = timestamp from mysql
event.requested_at = when the ajax request was performed
event.delay = the delay in seconds from when the request was made and when the event happened (used internally to delay callbacks)
*/
2018-09-10 11:50:53 +02:00
// console.log(data);
// console.log(event);
console.log(event);
2018-09-10 17:24:20 +02:00
if (typeof(event.data) != "undefined") {
// Show notification in the menu
if (typeof(event.data.web) != "undefined"
&& typeof(event.data.web.html) != "undefined"
&& event.data.web.html
) {
showMenuNotification(event.data.web.html);
}
// Browser push-notification
if (typeof(event.data.browser) != "undefined"
&& typeof(event.data.browser.text) != "undefined"
&& event.data.browser.text
) {
showBrowserNotification(event.data.browser.text, event.data.browser.url);
}
}
2018-09-07 15:08:34 +02:00
});
// at any point you can disconnect
//poly.disconnect();
// and when you disconnect, you can again at any point reconnect
//poly.reconnect();
}
2018-09-10 11:50:53 +02:00
// Show notification in the menu
function showMenuNotification(html)
{
$(html).prependTo($(".web-notifications-list:first"));
var counter = $('.web-notifications-count:first');
if (counter) {
var count = parseInt($('.web-notifications-count:first').text());
if (isNaN(count)) {
count = 0;
}
count++;
counter.text(count).removeClass('hidden');
}
$('.web-notifications-mark-read:first').removeClass('hidden');
// Remove double TODAY
var first_date = $('.web-notification-date:first');
$('.web-notification-date[data-date="'+first_date.attr('data-date')+'"]:gt(0)').remove();
$('.web-notifications .dropdown-toggle:first').addClass('has-unread');
}
2018-09-10 17:24:20 +02:00
// Show browser push-notification
function showBrowserNotification(text, url)
{
Push.create("", {
body: text,
icon: Vars.public_url+'/img/logo-icon-white-300.png',
tag: url,
timeout: 4000,
//requireInteraction: true
onClick: function () {
if (url) {
var win = window.open(url, '_blank');
win.focus();
this.close();
//Push.close(url);
}
}
});
}
2018-09-08 14:40:21 +02:00
// Take notifications bell out of the dropdown menu
function takeNotificationsOut()
{
if ($(window).width() >= 768) {
// Move to the menu
var container = $('.navbar-header .web-notifications:first');
if (container) {
container.prependTo(".navbar-right:first");
}
} else {
// Move to the header
var container = $('.navbar-right .web-notifications:first');
if (container) {
container.prependTo(".navbar-header:first");
}
}
}
2018-09-07 15:08:34 +02:00
// Display notification in the menu
function webNotificationsInit()
{
2018-09-08 14:40:21 +02:00
// Take notifications bell out of the dropdown menu
takeNotificationsOut();
$(window).on('resize', function(){
takeNotificationsOut();
});
// Load more
2018-09-07 15:08:34 +02:00
var button = $('.web-notification-more:first .btn:first');
button.click(function(e) {
button.button('loading');
var wn_page = parseInt(button.attr('data-wn_page'));
if (isNaN(wn_page)) {
wn_page = 2;
}
fsAjax(
{
action: 'web_notifications',
2018-09-08 14:40:21 +02:00
wn_page: wn_page
2018-09-07 15:08:34 +02:00
},
laroute.route('users.ajax'),
function(response) {
if (typeof(response.status) != "undefined" && response.status == "success") {
$(response.html).insertBefore(button.parent());
} else {
showAjaxError(response);
}
if (typeof(response.has_more_pages) == "undefined" || !response.has_more_pages) {
button.parent().hide();
}
button.button('reset');
button.attr('data-wn_page', wn_page+1);
},
true
);
e.preventDefault();
e.stopPropagation();
});
2018-09-08 14:40:21 +02:00
// Mark all as read
$('.web-notifications-mark-read:first').click(function(e) {
var mark_button = $(this);
if (mark_button.hasClass('disabled')) {
return;
}
mark_button.button('loading');
fsAjax(
{
action: 'mark_notifications_as_read'
},
laroute.route('users.ajax'),
function(response) {
if (typeof(response.status) != "undefined" && response.status == "success") {
mark_button.remove();
2018-09-10 11:50:53 +02:00
$('.web-notifications-count:first').addClass('hidden');
2018-09-08 14:40:21 +02:00
$('.web-notification.is-unread').removeClass('is-unread');
$('.web-notifications .dropdown-toggle.has-unread:first').removeClass('has-unread');
} else {
showAjaxError(response);
}
mark_button.button('reset');
},
true
);
e.preventDefault();
e.stopPropagation();
});
// Mark notification as read on click
// $('.web-notifications:first .web-notification a').click(function(e) {
// $(this).parent().removeClass('is-unread');
// });
2018-09-11 09:56:31 +02:00
}
function systemInit()
{
if (location.protocol == 'https:') {
$('#system-app-protocol').text('HTTPS');
} else {
var html = 'HTTP'+
'<div class="alert alert-danger margin-top">'+Lang.get("messages.push_protocol_alert")+'</div>';
$('#system-app-protocol').html(html);
}
2018-08-31 18:17:38 +02:00
}