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-08-15 08:10:05 +02:00
|
|
|
|
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-07-27 15:19:25 +02:00
|
|
|
// Configuring editor
|
|
|
|
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 () {
|
|
|
|
alert('todo: implement discarding a draft');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return button.render(); // return button as jquery object
|
|
|
|
}
|
|
|
|
|
2018-06-22 19:44:21 +02:00
|
|
|
$(document).ready(function(){
|
|
|
|
|
|
|
|
// Tooltips
|
2018-07-14 14:17:11 +02:00
|
|
|
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
|
2018-06-22 19:44:21 +02:00
|
|
|
|
|
|
|
// Popover
|
|
|
|
$('[data-toggle="popover"]').popover({
|
|
|
|
container: 'body'
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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($) {
|
2018-08-16 13:28:58 +02:00
|
|
|
if (typeof($.summernote) != "undefined") {
|
|
|
|
$.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-06-28 07:35:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function mailboxUpdateInit(from_name_custom)
|
|
|
|
{
|
2018-07-06 05:19:49 +02:00
|
|
|
$(document).ready(function(){
|
|
|
|
// 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
|
|
|
|
$('#signature').summernote({
|
2018-07-30 17:11:35 +02:00
|
|
|
minHeight: 120,
|
2018-07-27 15:19:25 +02:00
|
|
|
dialogsInBody: true,
|
2018-07-30 17:11:35 +02:00
|
|
|
disableResizeEditor: true,
|
2018-08-02 18:17:13 +02:00
|
|
|
followingToolbar: false,
|
2018-07-06 05:19:49 +02:00
|
|
|
toolbar: [
|
|
|
|
// [groupName, [list of button]]
|
|
|
|
['style', ['bold', 'italic', 'underline', 'ul', 'ol', 'link', 'codeview']],
|
|
|
|
]
|
|
|
|
});
|
2018-07-30 17:11:35 +02:00
|
|
|
$('.note-statusbar').remove();
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
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({
|
|
|
|
"ordering": false
|
|
|
|
});
|
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('');
|
|
|
|
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-07-30 17:11:35 +02:00
|
|
|
$("button[data-loading-text!='']:disabled").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");
|
|
|
|
|
|
|
|
alerts.each(function(i, obj) {
|
|
|
|
$(obj).css('display', 'flex');
|
|
|
|
setTimeout(function(){
|
|
|
|
obj.remove();
|
|
|
|
}, 7000);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (alerts.length) {
|
|
|
|
$('body').click(function() {
|
|
|
|
alerts.remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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'),
|
|
|
|
conversation_id: fsGetGlobalAttr('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-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-27 08:01:34 +02:00
|
|
|
}
|
2018-08-15 08:10:05 +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'),
|
|
|
|
conversation_id: fsGetGlobalAttr('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){
|
|
|
|
if ($(".conv-reply-block").hasClass('hidden')) {
|
2018-08-09 11:22:12 +02:00
|
|
|
// Show
|
2018-07-30 17:11:35 +02:00
|
|
|
$(".conv-action-block").addClass('hidden');
|
|
|
|
$(".conv-reply-block").removeClass('hidden');
|
|
|
|
$(".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-07-25 16:09:20 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function fsGetGlobalAttr(attr)
|
|
|
|
{
|
|
|
|
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: {
|
|
|
|
'X-CSRF-TOKEN': $('meta[name="csrf-token"]:first').attr('content')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
jQuery(".btn-send-text").click(function(e){
|
|
|
|
var button = $(this);
|
|
|
|
|
|
|
|
// Validate before sending
|
|
|
|
form = $(".form-reply:first");
|
|
|
|
|
|
|
|
if (!form.parsley().validate()) {
|
|
|
|
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-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')) {
|
|
|
|
$(".subscriptions-"+$(this).val()+" input").attr('checked', 'checked');
|
|
|
|
} else {
|
|
|
|
$(".subscriptions-"+$(this).val()+" input").removeAttr('checked');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
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
|
|
|
|
function showModal(a, onshow)
|
|
|
|
{
|
|
|
|
var options = {};
|
|
|
|
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');
|
|
|
|
var body = a.attr('data-modal-body');
|
|
|
|
var footer = a.attr('data-modal-footer');
|
|
|
|
var no_close_btn = a.attr('data-no-close-btn');
|
|
|
|
var no_footer = a.attr('data-modal-no-footer');
|
|
|
|
var modal_class = a.attr('data-modal-class');
|
|
|
|
var modal;
|
|
|
|
|
|
|
|
var html = [
|
|
|
|
'<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="jsmodal-label" aria-hidden="true">',
|
|
|
|
'<div class="modal-dialog '+modal_class+'">',
|
|
|
|
'<div class="modal-content">',
|
|
|
|
'<div class="modal-header">',
|
|
|
|
'<button type="button" class="close" data-dismiss="modal" aria-label="'+Lang.get("messages.close")+'"><span aria-hidden="true">×</span></button>',
|
|
|
|
'<h3 class="modal-title" id="jsmodal-label">'+title+'</h3>',
|
|
|
|
'</div>',
|
|
|
|
'<div class="modal-body"><div class="text-center modal-loader"><img src="'+Vars.public_url+'/img/loader-grey.gif" width="31" height="31"/></div></div>',
|
|
|
|
'<div class="modal-footer '+(no_footer == 'true' ? 'hidden' : '')+'">',
|
|
|
|
(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);
|
|
|
|
|
|
|
|
if (typeof(onshow) !== "undefined") {
|
|
|
|
modal.on('shown.bs.modal', onshow);
|
|
|
|
}
|
|
|
|
|
|
|
|
modal.modal(options);
|
|
|
|
|
|
|
|
if (body) {
|
|
|
|
modal.children().find(".modal-body").html($(body).html());
|
|
|
|
} else {
|
|
|
|
setTimeout(function(){
|
|
|
|
$.ajax({
|
|
|
|
url: remote,
|
|
|
|
success: function(html) {
|
|
|
|
modal.children().find(".modal-body").html(html);
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
mailbox_id: fsGetGlobalAttr('mailbox_id'),
|
|
|
|
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
|
|
|
|
console.log('.dropdown-after-send [data-after-send='+value+']:first');
|
|
|
|
console.log($('.dropdown-after-send [data-after-send='+value+']:first'));
|
|
|
|
$('.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-08 09:52:53 +02:00
|
|
|
}
|