$(document).ready(function() {
function getUrlGetParameter(val) {
var result = "Not found",
tmp = [];
location.search
.substr(1)
.split("&")
.forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === val) result = decodeURIComponent(tmp[1]);
});
return result;
}
function addSpinner(element) {
element.append("
");
}
function removeSpinner(element) {
element.children(".spinner").remove();
}
function loadBox(element) {
$(document).on("click", element, function(e) {
e.preventDefault();
$.get($(this).attr('href'), function(r) {
try {
editBox = $.parseJSON(r);
var optionsContainer = document.createElement('div');
$.each(editBox['options'], function(i) {
$(optionsContainer).append(this.name + "
")
});
$.fancybox({
maxWidth : 800,
maxHeight : 600,
fitToView : true,
width : '70%',
height : '70%',
autoSize : false,
title : "" + editBox['title'] + "
",
content : optionsContainer.innerHTML,
helpers : {
title: {
type : 'inside',
position: 'top'
}
}
});
} catch(e) {
console.log(e); // DBG
var n = noty({
layout : 'topCenter',
text : 'Irgendwas ist schief gelaufen.
Bitte probieren Sie es später noch einmal.',
type : 'error',
timeout : 5000
});
}
});
});
}
function getMailboxStatus() {
$("#settings-mailboxes tr").each(function(item) {
var thisTr = this;
if(this.attributes.length > 0) {
addSpinner($(this).children("td:first"));
$.getJSON("ajax.php?action=getMailboxStatus&mailboxId=" + $(this).attr("data-mailbox-id"), function(r) {
if(r['connected'] == true) {
removeSpinner($(thisTr).children("td:first"));
$(thisTr).children("td:first").append("");
} else {
removeSpinner($(thisTr).children("td:first"));
$(thisTr).children("td:first").append("");
}
});
}
});
}
$.fn.editable.defaults.mode = 'inline';
$.fn.editableform.buttons =
''+
'';
$('.editable-element-text').editable({
escape: false,
success: function(response, newValue) {
console.log(response); // Debug output from ajax.php
if(response.status == 'error') return response.msg; //msg will be shown in editable form
},
error: function (xhr, status, error) {
//var err = eval("(" + xhr.responseText + ")");
return xhr.statusText;
},
params: function(params) {
params.action = 'updateMailaccounts';
return params;
}
});
$('.editable-element-select-protocol').editable({
defaultValue: 'imap',
source: [
{value: 'imap', text: 'IMAP'},
{value: 'pop3', text: 'POP3'}
],
success: function(response, newValue) {
console.log(response); // Debug output from ajax.php
if(response.status == 'error') return response.msg; //msg will be shown in editable form
},
error: function (xhr, status, error) {
//var err = eval("(" + xhr.responseText + ")");
return xhr.statusText;
},
params: function(params) {
params.action = 'updateMailaccounts';
return params;
}
});
$('.editable-element-select-use-ssl').editable({
defaultValue: '1',
source: [
{value: '1', text: 'On'},
{value: '0', text: 'Off'}
],
success: function(response, newValue) {
console.log(response); // Debug output from ajax.php
if(response.status == 'error') return response.msg; //msg will be shown in editable form
},
error: function (xhr, status, error) {
//var err = eval("(" + xhr.responseText + ")");
return xhr.statusText;
},
params: function(params) {
params.action = 'updateMailaccounts';
return params;
}
});
$('.editable-element-select-no-valid-cert').editable({
defaultValue: '0',
source: [
{value: '0', text: 'On'},
{value: '1', text: 'Off'}
],
success: function(response, newValue) {
console.log(response); // Debug output from ajax.php
if(response.status == 'error') return response.msg; //msg will be shown in editable form
},
error: function (xhr, status, error) {
//var err = eval("(" + xhr.responseText + ")");
return xhr.statusText;
},
params: function(params) {
params.action = 'updateMailaccounts';
return params;
}
});
$('#add-mailaccount').on('click', function(e) {
e.preventDefault();
var uId = $(this).attr('data-uid');
$.ajax({
url: 'ajax.php',
type: 'POST',
data: {'action': 'addDefaultMailaccount', 'user-id': uId},
success: function (result) {
console.log(result);
location.reload();
}
});
});
function fancyBoxLoader() {
$.ajax({
url: 'ajax.php',
data: {'action': 'getMailAccountsByUid', 'uId': $('.manage-mailboxfolder').attr('data-uid')},
type: 'GET',
global: false,
async: true,
dataType: 'json',
success: function(data) {
result = data;
$('.editable-element-select-mailaccount').editable({
//defaultValue: '0',
source: result,
success: function(response, newValue) {
console.log(response); // Debug output from ajax.php
if(response.status == 'error') return response.msg; //msg will be shown in editable form
},
error: function (xhr, status, error) {
//var err = eval("(" + xhr.responseText + ")");
return xhr.statusText;
},
params: function(params) {
params.action = 'updateMailfolder';
return params;
}
});
}
});
$('.editable-element-text').editable({
escape: false,
success: function(response, newValue) {
console.log(response); // Debug output from ajax.php
if(response.status == 'error') return response.msg; //msg will be shown in editable form
},
error: function (xhr, status, error) {
//var err = eval("(" + xhr.responseText + ")");
return xhr.statusText;
},
params: function(params) {
params.action = 'updateMailfolder';
return params;
}
});
}
$('.remove-mailaccount').on('click', function(e) {
e.preventDefault();
var id = $(this).attr('data-id');
$.ajax({
url: 'ajax.php',
type: 'POST',
data: {'action': 'removeMailaccount', 'id': id},
success: function (result) {
console.log(result);
location.reload();
}
});
});
$('.remove-mailboxfolder').on('click', function(e) {
e.preventDefault();
var id = $(this).attr('data-id');
$.ajax({
url: 'ajax.php',
type: 'POST',
data: {'action': 'removeMailboxFolder', 'id': id},
success: function (result) {
console.log(result);
location.reload();
}
});
});
$('#add-mailboxfolder').on('click', function(e) {
e.preventDefault();
var uId = $(this).attr('data-uid');
var lId = $(this).attr('data-lid');
$.ajax({
url: 'ajax.php',
type: 'POST',
data: {'action': 'addDefaultMailfolder', 'user-id': uId, 'label-id': lId},
success: function (result) {
console.log(result);
location.reload();
},
error: function(result) {
console.log(result);
}
});
});
switch(getUrlGetParameter("action")) {
case 'settings':
getMailboxStatus();
break;
case 'manage-label':
loadBox('.manage-mailboxfolder');
break;
case 'label':
loadBox('#new-document');
break;
default:
break;
}
});