custom.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. $(document).ready(function() {
  2. var lastOpenedBoxData; // Stores JSON-data of last opened editBox
  3. var notifications = []; // Stores noty-Notifications
  4. var reminders = []; // Stores reminder-noty-Notifications
  5. function noty_error_retry() {
  6. notifications.push(
  7. noty({
  8. layout : 'topCenter',
  9. text : 'Irgendwas ist schief gelaufen.<br>Bitte probieren Sie es später noch einmal.',
  10. type : 'error',
  11. timeout : 3000
  12. }));
  13. }
  14. window.noty_reminder = noty_reminder;
  15. function noty_reminder(reminderID, subject) {
  16. var reminderID = reminderID;
  17. reminders[reminderID] = noty({
  18. layout : 'topCenter',
  19. text : 'Erinnerung:<br>' + subject,
  20. type : 'alert',
  21. buttons : [
  22. {addClass: 'btn btn-primary', text: 'OK', onClick: function(noty) {
  23. data = {
  24. reminderID: reminderID
  25. };
  26. $.getJSON("ajax.php?action=setReminderReminded", data, function(r) {
  27. if(r['status'] == "OK") {
  28. noty.close();
  29. reminders[reminderID] = undefined;
  30. } else {
  31. noty_error_retry();
  32. }
  33. });
  34. }},
  35. {addClass: 'btn btn-danger', text: 'Snooze', onClick: function(noty) {
  36. data = {
  37. reminderID: reminderID
  38. };
  39. $.getJSON("ajax.php?action=setReminderSnooze", data, function(r) {
  40. if(r['status'] == "OK") {
  41. noty.close();
  42. reminders[reminderID] = undefined;
  43. } else {
  44. noty_error_retry();
  45. }
  46. });
  47. }}
  48. ]
  49. });
  50. $("audio")[0].play()
  51. }
  52. function getUrlGetParameter(val) {
  53. var result = "Not found",
  54. tmp = [];
  55. location.search
  56. .substr(1)
  57. .split("&")
  58. .forEach(function (item) {
  59. tmp = item.split("=");
  60. if (tmp[0] === val) result = decodeURIComponent(tmp[1]);
  61. });
  62. return result;
  63. }
  64. function handleEvents() {
  65. data = {
  66. userID: $("body").attr("data-user-id")
  67. };
  68. $.getJSON("ajax.php?action=getEvents", data, function(r) {
  69. switch (r['type']) {
  70. case 'reminder':
  71. r['reminders'].forEach(function(item) {
  72. if(reminders[item['id']] == undefined) {
  73. noty_reminder(item['id'], item['subject']);
  74. }
  75. });
  76. break;
  77. case 'ping':
  78. break;
  79. default:
  80. console.log("unknown event type:" + r['type']);
  81. }
  82. });
  83. }
  84. function addSpinner(element) {
  85. $(element).append("<div class=\"spinner\"><div class=\"bounce1\"></div><div class=\"bounce2\"></div><div class=\"bounce3\"></div></div>");
  86. }
  87. function removeSpinner(element) {
  88. element.children(".spinner").remove();
  89. }
  90. function loadBox(element, boxType, saveID, callback) {
  91. var saveButtonIDs = {
  92. saveMailFolder: {id: "save-mail-folder", text: "Mailkonto speichern"},
  93. saveDocument: {id: "save-document", text: "Dokument speichern"},
  94. saveLabel: {id: "save-label", text: "Label speichern"},
  95. saveCall: {id: "save-call", text: "Anruf speichern"}
  96. };
  97. if(boxType == "editBox") {
  98. $(document).on("click", element, function(e) {
  99. e.preventDefault();
  100. $.getJSON($(this).attr('href'), function(r) {
  101. lastOpenedBoxData = r;
  102. try {
  103. var optionsContainer = document.createElement('div');
  104. $.each(r['options'], function(i) {
  105. var option = this;
  106. switch(this.type) {
  107. case 'text':
  108. $(optionsContainer).append(this.name + "<input id=\"editbox-input-" + this.name + "\" type=\"text\" value=\"" + this.value + "\" class=\"editbox-input\" /><br><br>");
  109. break;
  110. case 'select':
  111. selectHtml = "<select id=\"editbox-input-" + this.name + "\" class=\"editbox-input\">";
  112. if(typeof this['values'] !== "undefined" && this['values']) {
  113. this['values'].forEach(function(item) {
  114. if(option['value'] == item) {
  115. selectHtml += "<option selected value=\"" + item + "\">" + item + "</option>"
  116. } else {
  117. selectHtml += "<option value=\"" + item + "\">" + item + "</option>"
  118. }
  119. });
  120. }
  121. selectHtml += "</select>";
  122. $(optionsContainer).append(this.name + selectHtml + "<br><br>");
  123. break;
  124. case 'datetime':
  125. nowDate = new Date();
  126. nowDateString = "" + nowDate.getDate() + "." + nowDate.getMonth() + "." + nowDate.getFullYear() + " " + nowDate.getHours() + ":" + nowDate.getMinutes();
  127. $(optionsContainer).append(this.name + "<input id=\"editbox-datetime-" + this.name + "\" class=\"datetimepicker editbox-input\" type=\"text\" vaue=\"" + nowDateString + "\"><br><br>");
  128. break;
  129. case 'textarea':
  130. $(optionsContainer).append(this.name + "<textarea id=\"editbox-textarea-" + this.name + "\" class=\"editbox-input\">" + this.value + "</textarea><br><br><br>");
  131. break;
  132. case 'checkbox':
  133. $(optionsContainer).append(this.name + "<input type=\"checkbox\" id=\"editbox-checkbox-" + this.name + "\" class=\"editbox-input\"><br><br>");
  134. break;
  135. default:
  136. console.log("Missing input-type: " + this.type);
  137. break;
  138. }
  139. });
  140. $.fancybox({
  141. maxWidth : 800,
  142. maxHeight : 600,
  143. fitToView : true,
  144. width : '70%',
  145. height : '70%',
  146. autoSize : false,
  147. title : "<h3>" + r['title'] + "</h3><hr>",
  148. content : optionsContainer.innerHTML,
  149. helpers : {
  150. title: {
  151. type : 'inside',
  152. position: 'top'
  153. }
  154. },
  155. afterShow : function() {
  156. callback();
  157. $('.fancybox-inner').append("<a href=\"#\"type=\"button\" id=\"" + saveButtonIDs[saveID]['id'] + "\" class=\"btn btn-success save-button\">" + saveButtonIDs[saveID]['text'] + "</a>");
  158. $(".datetimepicker").datetimepicker({ format: 'Y-m-d H:i', startDate: new Date() });
  159. }
  160. });
  161. } catch(e) {
  162. console.log(e); // DBG
  163. noty_error_retry();
  164. }
  165. });
  166. });
  167. }
  168. }
  169. function getMailboxStatus() {
  170. $("#settings-mailboxes tr").each(function(item) {
  171. var thisTr = this;
  172. if(this.attributes.length > 0) {
  173. if($(this).children("td:first").children().length > 0) {
  174. $(this).children("td:first").children().remove();
  175. }
  176. addSpinner($(this).children("td:first"));
  177. $.getJSON("ajax.php?action=getMailboxStatus&mailboxID=" + $(this).attr("data-mailbox-id"), function(r) {
  178. if(r['connected'] == true) {
  179. removeSpinner($(thisTr).children("td:first"));
  180. $(thisTr).children("td:first").append("<i class=\"fa fa-check-circle\"></i>");
  181. } else {
  182. removeSpinner($(thisTr).children("td:first"));
  183. $(thisTr).children("td:first").append("<i class=\"fa fa-exclamation-circle\"></i>");
  184. }
  185. });
  186. }
  187. });
  188. }
  189. function settingsListener() {
  190. $(document).on("click", "#refresh-mailaccounts", function(e) {
  191. e.preventDefault();
  192. getMailboxStatus();
  193. });
  194. }
  195. function manageLabelListener() {
  196. $(document).on("click", "#save-mail-folder", function(e) {
  197. e.preventDefault();
  198. data = {
  199. mailboxFolderID: lastOpenedBoxData['mailboxFolderID'],
  200. account: $("#editbox-input-account").val(),
  201. folder: $("#editbox-input-folder").val(),
  202. labelID: getUrlGetParameter("labelID")
  203. };
  204. $.getJSON("ajax.php?action=saveMailFolder", data, function(r) {
  205. if(r['status'] == "OK") {
  206. location.reload();
  207. } else {
  208. noty_error_retry();
  209. }
  210. });
  211. });
  212. $(document).on("change", "#editbox-input-account", function(e) {
  213. e.preventDefault();
  214. data = {
  215. account: $("#editbox-input-account").val()
  216. };
  217. $.getJSON("ajax.php?action=getMailaccountFoldersByUsername", data, function(r) {
  218. $("#editbox-input-folder").empty();
  219. $.each(r, function(val, key) {
  220. $("#editbox-input-folder").append($("<option></option>").attr("value", key).text(key));
  221. });
  222. });
  223. });
  224. }
  225. function manageLabelsListener() {
  226. $(document).on("click", "#save-label", function(e) {
  227. e.preventDefault();
  228. data = {
  229. name: $("#editbox-input-name").val(),
  230. path: $("#editbox-input-path").val()
  231. };
  232. $.getJSON("ajax.php?action=saveNewLabel", data, function(r) {
  233. if(r['status'] == "OK") {
  234. location.reload();
  235. } else {
  236. console.log(r);
  237. noty_error_retry();
  238. }
  239. });
  240. });
  241. $(document).on("click", ".remove-label", function(e) {
  242. e.preventDefault();
  243. tRow = $(this).parent().parent();
  244. data = {
  245. labelID: $(this).attr("data-id")
  246. };
  247. $.getJSON("ajax.php?action=removeLabel", data, function(r) {
  248. if(r['status'] == "OK") {
  249. tRow.fadeOut(400, function() {
  250. tRow.remove();
  251. });
  252. } else {
  253. console.log(r);
  254. noty_error_retry();
  255. }
  256. });
  257. });
  258. }
  259. function LabelListener() {
  260. $(document).on("change", ".fancybox-inner select", function(e) {
  261. reloadDraftVars();
  262. });
  263. $(document).on("click", "#save-document", function(e) {
  264. e.preventDefault();
  265. data = {
  266. draft: $("#editbox-input-vorlage").val(),
  267. filename: $("#editbox-input-filename").val(),
  268. labelID: getUrlGetParameter("labelID"),
  269. draftVars: {}
  270. };
  271. $(".editbox-draft-vars").each(function(i) {
  272. data['draftVars'][$(this).attr("id").replace("editbox-draft-vars-", "")] = $(this).val();
  273. });
  274. $.getJSON("ajax.php?action=saveNewDocument", data, function(r) {
  275. console.log(r);
  276. });
  277. });
  278. $(document).on("click", "#save-call", function(e) {
  279. e.preventDefault();
  280. data = {
  281. userID: $("body").attr("data-user-id"),
  282. callDate: $('#editbox-datetime-call-date').val(),
  283. callerTelNr: $('#editbox-input-caller-telnr').val(),
  284. labelID: $('#editbox-input-label-id').val(),
  285. callNotes: $('#editbox-textarea-call-notes').val(),
  286. callSetReminder: $('#editbox-checkbox-call-set-reminder').val()
  287. }
  288. $.getJSON("ajax.php?action=saveNewCall", data, function(r) {
  289. if(r['status'] == "OK") {
  290. $.fancybox.close();
  291. //$("a[href=\"#calls\"]").tab("show");
  292. } else {
  293. noty_error_retry();
  294. }
  295. });
  296. });
  297. $(document).on("click", "#refresh-documents", function(e) {
  298. e.preventDefault();
  299. $("#refresh-documents").hide();
  300. addSpinner($("#document-list th:nth-child(6)"));
  301. $.getJSON("ajax.php?action=scanDocuments", {}, function(r) {
  302. if(r['status'] == "OK") {
  303. if(r['new'] > 0) {
  304. location.reload();
  305. } else {
  306. removeSpinner($("#document-list th:nth-child(6)"));
  307. $("#refresh-documents").show();
  308. }
  309. } else {
  310. noty_error_retry();
  311. }
  312. });
  313. });
  314. $(document).on("click", ".reply-mail", function(e) {
  315. e.preventDefault();
  316. data = {
  317. mailID: $(this).attr("data-mail-id")
  318. };
  319. $.getJSON("ajax.php?action=getMailContent", data, function(r) {
  320. window.location.href = "mailto:" + r['to'] + "?subject=" + r['subject'] + "&body=" + r['body'];
  321. });
  322. });
  323. $(document).on("change", ".mail-processed", function(e) {
  324. data = {
  325. mailID: $(this).attr("id").replace("mail-processed-", ""),
  326. value: $(this).is(':checked')
  327. };
  328. $.getJSON("ajax.php?action=changeMailProcessed", data, function(r) {
  329. if(r['status'] != "OK") {
  330. noty_error_retry();
  331. }
  332. });
  333. });
  334. var calendar = $("#calendar").calendar({
  335. tmpl_path: "/tmpls/",
  336. events_source: "ajax.php?action=getCalendarEvents",
  337. first_day: 1, // Monday
  338. onAfterViewLoad: function(view) {
  339. $('.btn-group button').removeClass('active');
  340. $('button[data-calendar-view="' + view + '"]').addClass('active');
  341. }
  342. });
  343. $('.btn-group button[data-calendar-view]').each(function() {
  344. var $this = $(this);
  345. $this.click(function() {
  346. calendar.view($this.data('calendar-view'));
  347. });
  348. });
  349. $(document).on("click", "a[data-action='loadContact']", function(e) {
  350. e.preventDefault();
  351. $("#contact-list .contact-selected").removeClass("contact-selected");
  352. loadContact($(this).attr("data-contact-id"));
  353. $($(this).children()[0]).addClass("contact-selected");
  354. });
  355. reloadContactList(true);
  356. $(document).on("click", "a[data-action='save-contact']", function(e) {
  357. e.preventDefault();
  358. var communications = [];
  359. $("a[data-action='save-contact']").remove();
  360. addSpinner("#save-contact-wrapper > div");
  361. $("#contact-communication > div").each(function(e) {
  362. switch($(this).attr("data-contact-input-type")) {
  363. case 'tel':
  364. communications.push({
  365. type: 0,
  366. id: $(this).attr("data-id"),
  367. name: $(this).children(".col-xs-4").children("input").val(),
  368. value: $(this).children(".col-xs-7").children("input").val()
  369. });
  370. break;
  371. case 'email':
  372. communications.push({
  373. type: 1,
  374. id: $(this).attr("data-id"),
  375. name: '',
  376. value: $(this).children(".col-xs-11").children("input").val()
  377. });
  378. break;
  379. case 'web':
  380. communications.push({
  381. type: 2,
  382. id: $(this).attr("data-id"),
  383. name: '',
  384. value: $(this).children(".col-xs-11").children("input").val()
  385. });
  386. break;
  387. }
  388. });
  389. data = {
  390. contactID: $("#contact-tab").attr("data-contact-id"),
  391. organization: $("#contact-organization").val(),
  392. department: $("#contact-department").val(),
  393. title: $("#contact-title").val(),
  394. degree: $("#contact-degree").val(),
  395. forename: $("#contact-forename").val(),
  396. surname: $("#contact-surname").val(),
  397. street: $("#contact-street").val(),
  398. streetNumber: $("#contact-street-nr").val(),
  399. postalCode: $("#contact-postal-code").val(),
  400. city: $("#contact-city").val(),
  401. communications: communications
  402. };
  403. $.getJSON("ajax.php?action=updateContact", data, function(r) {
  404. if(r['status'] != "OK") {
  405. noty_error_retry();
  406. removeSpinner($("#save-contact-wrapper > div"));
  407. } else {
  408. removeSpinner($("#save-contact-wrapper > div"));
  409. $("#save-contact-wrapper > div").append("<a href=\"#\" data-action=\"save-contact\"><i class=\"fa fa-floppy-o pull-right\"></i></a>");
  410. reloadContactList(false, function() {
  411. $("a[data-action='loadContact'][data-contact-id='" + $("#contact-tab").attr("data-contact-id") + "'] > div").addClass("contact-selected");
  412. });
  413. }
  414. });
  415. });
  416. $(document).on("click", "a[data-action='add-contact']", function(e) {
  417. e.preventDefault();
  418. data = {
  419. userID: $("body").attr("data-user-id")
  420. };
  421. $.getJSON("ajax.php?action=addContact", data, function(r) {
  422. if(r['status'] == "OK") {
  423. reloadContactList(false);
  424. } else {
  425. noty_error_retry();
  426. }
  427. });
  428. });
  429. $(document).on("click", "a[data-action='add-phone-input']", function(e) {
  430. e.preventDefault();
  431. var html = "<div class=\"row\" data-contact-input-type=\"tel\" data-id=\"-1\"> <div class=\"col-xs-4\"> <input type=\"text\" class=\"form-control\" list=\"tel_kategorie\" placeholder=\"\" /> <datalist id=\"tel_kategorie\"> <option>Geschäftlich</option> <option>Privat</option> <option>Mobil</option> </datalist> </div> <div class=\"col-xs-7\"> <input type=\"tel\" class=\"form-control\" placeholder=\"Telefon\"> </div> <div class=\"col-xs-1\"> <div style=\"padding: 15%; margin-left: -15%;\"> <a href=\"#\" data-action=\"add-phone-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a> </div> </div> </div> <br>";
  432. if($($(this).parent()).attr("id") == "communication-buttons") {
  433. var telInputs = $("[data-contact-input-type='tel']");
  434. if(telInputs.length > 0) {
  435. $(html).insertAfter($(telInputs[telInputs.length - 1]).next());
  436. } else {
  437. $("#contact-communication").prepend(html);
  438. }
  439. } else {
  440. $(html).insertAfter($(this).closest("[data-contact-input-type='tel']").next());
  441. }
  442. });
  443. $(document).on("click", "a[data-action='add-email-input']", function(e) {
  444. e.preventDefault();
  445. var html = "<div class=\"row\" data-contact-input-type=\"email\" data-id=\"-1\"> <div class=\"col-xs-11\"> <input type=\"email\" class=\"form-control\" placeholder=\"Email\"> </div> <div class=\"col-xs-1\"> <div style=\"padding: 15%; margin-left: -15%;\"> <a href=\"#\" data-action=\"add-email-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a> </div> </div> </div> <br>";
  446. if($($(this).parent()).attr("id") == "communication-buttons") {
  447. var mailInputs = $("[data-contact-input-type='email']");
  448. if(mailInputs.length > 0) {
  449. $(html).insertAfter($(mailInputs[mailInputs.length - 1]).next());
  450. } else {
  451. var telInputs = $("[data-contact-input-type='tel']");
  452. if(telInputs.length > 0) {
  453. $(html).insertAfter($(telInputs[telInputs.length - 1]).next());
  454. } else {
  455. $("#contact-communication").prepend(html);
  456. }
  457. }
  458. } else {
  459. $(html).insertAfter($(this).closest("[data-contact-input-type='email']").next());
  460. }
  461. });
  462. $(document).on("click", "a[data-action='add-web-input']", function(e) {
  463. e.preventDefault();
  464. var html = "<div class=\"row\" data-contact-input-type=\"web\" data-id=\"-1\"> <div class=\"col-xs-11\"> <input type=\"url\" class=\"form-control\" placeholder=\"Webseite\"> </div> <div class=\"col-xs-1\"> <div style=\"padding: 15%; margin-left: -15%;\"> <a href=\"#\" data-action=\"add-web-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a> </div> </div> </div> <br>";
  465. if($($(this).parent()).attr("id") == "communication-buttons") {
  466. var urlInputs = $("[data-contact-input-type='web']");
  467. if(urlInputs.length > 0) {
  468. $(html).insertAfter($(urlInputs[urlInputs.length - 1]).next());
  469. } else {
  470. $("#contact-communication").append(html);
  471. }
  472. } else {
  473. $(html).insertAfter($(this).closest("[data-contact-input-type='web']").next());
  474. }
  475. });
  476. $(document).on("click", "a[data-action='remove-contact']", function(e) {
  477. e.preventDefault();
  478. data = {
  479. contactID: $("#contact-tab").attr("data-contact-id")
  480. };
  481. $.getJSON("ajax.php?action=removeContact", data, function(r) {
  482. if(r['status'] == "OK") {
  483. reloadContactList(true);
  484. } else {
  485. noty_error_retry();
  486. }
  487. });
  488. });
  489. $(document).on("click", "a[data-action='remove-communication']", function(e) {
  490. e.preventDefault();
  491. var communicationID = $(this).closest(".row").attr("data-id");
  492. if(communicationID == -1) { // just remove from DOM, not saved yet
  493. $(this).closest(".row").next().remove();
  494. $(this).closest(".row").remove();
  495. } else { // also remove from DB
  496. var row = $(this).closest(".row");
  497. data = {
  498. communicationID: communicationID
  499. };
  500. $.getJSON("ajax.php?action=removeCommunication", data, function(r) {
  501. if(r['status'] == "OK") {
  502. $(row).next().remove();
  503. $(row).remove();
  504. } else {
  505. noty_error_retry();
  506. }
  507. });
  508. }
  509. });
  510. }
  511. function loadContact(contactID) {
  512. data = {
  513. contactID: contactID
  514. };
  515. $.getJSON("ajax.php?action=getContactByID", data, function(r) {
  516. if(r['status'] != "OK") {
  517. noty_error_retry();
  518. }
  519. $("#contact-tab").attr("data-contact-id", r['contact'][0]['id']);
  520. $("#contact-organization").val(r['contact'][0]['organization']);
  521. $("#contact-department").val(r['contact'][0]['department']);
  522. $("#contact-title").val(r['contact'][0]['title']);
  523. $("#contact-degree").val(r['contact'][0]['degree']);
  524. $("#contact-forename").val(r['contact'][0]['forename']);
  525. $("#contact-surname").val(r['contact'][0]['surname']);
  526. $("#contact-street").val(r['contact'][0]['street']);
  527. $("#contact-street-nr").val(r['contact'][0]['streetNumber']);
  528. $("#contact-postal-code").val(r['contact'][0]['postalCode']);
  529. $("#contact-city").val(r['contact'][0]['city']);
  530. $("#contact-communication").empty();
  531. if(r['communications']) {
  532. $.each(r['communications'], function(i) {
  533. var html;
  534. switch(this['type']) {
  535. case "0":
  536. html = "<div class=\"row\" data-contact-input-type=\"tel\" data-id=\"" + this['id'] + "\"> <div class=\"col-xs-4\"> <input type=\"text\" class=\"form-control\" list=\"tel_kategorie\" placeholder=\"\" value=\"" + this['name'] + "\" /> <datalist id=\"tel_kategorie\"> <option>Geschäftlich</option> <option>Privat</option> <option>Mobil</option> </datalist> </div> <div class=\"col-xs-7\"> <input type=\"tel\" class=\"form-control\" placeholder=\"Telefon\" value=\"" + this['value'] + "\"> </div> <div class=\"col-xs-1\"> <div style=\"padding: 15%; margin-left: -15%;\"> <a href=\"#\" data-action=\"add-phone-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a> </div> </div> </div> <br>";
  537. break;
  538. case "1":
  539. html = "<div class=\"row\" data-contact-input-type=\"email\" data-id=\"" + this['id'] + "\"> <div class=\"col-xs-11\"> <input type=\"email\" class=\"form-control\" placeholder=\"Email\" value=\"" + this['value'] + "\"> </div> <div class=\"col-xs-1\"> <div style=\"padding: 15%; margin-left: -15%;\"> <a href=\"#\" data-action=\"add-email-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a> </div> </div> </div> <br>";
  540. break;
  541. case "2":
  542. html = "<div class=\"row\" data-contact-input-type=\"web\" data-id=\"" + this['id'] + "\"> <div class=\"col-xs-11\"> <input type=\"url\" class=\"form-control\" placeholder=\"Webseite\" value=\"" + this['value'] + "\"> </div> <div class=\"col-xs-1\"> <div style=\"padding: 15%; margin-left: -15%;\"> <a href=\"#\" data-action=\"add-web-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a> </div> </div> </div> <br>";
  543. break;
  544. }
  545. $("#contact-communication").append(html);
  546. });
  547. }
  548. });
  549. }
  550. function reloadContactList(firstRun, callBack) {
  551. data = {
  552. userID: $("body").attr("data-user-id")
  553. };
  554. $.getJSON("ajax.php?action=getContacts", data, function(r) {
  555. if(r['status'] != "OK") {
  556. noty_error_retry();
  557. } else {
  558. $("#contact-list > div").empty();
  559. $.each(r['contacts'], function(i) {
  560. $("#contact-list > div").append("<a href=\"#\" data-action=\"loadContact\" data-contact-id=\"" + this['id'] + "\"><div class=\"col-md-12\">" + this['forename'] + " " + this['surname'] + "</div></a>");
  561. });
  562. if(firstRun) {
  563. loadContact($($("a[data-action='loadContact']")[0]).attr("data-contact-id"));
  564. $($($("a[data-action='loadContact']")[0]).children()[0]).addClass("contact-selected");
  565. }
  566. callBack = typeof callBack !== 'undefined' ? callBack : function() {};
  567. callBack();
  568. }
  569. });
  570. }
  571. function reloadDraftVars() {
  572. $.getJSON("ajax.php?action=getDraftVars&draft=" + $(".fancybox-inner select").val(), function(r) {
  573. draftVarsContainer = $("#draft-vars");
  574. if(draftVarsContainer.length > 0) {
  575. draftVarsContainer.remove();
  576. }
  577. $(".fancybox-inner .save-button").before("<div id=\"draft-vars\"></div>");
  578. r.forEach(function(item) {
  579. $(".fancybox-inner #draft-vars").append(item + "<textarea id=\"editbox-draft-vars-" + item + "\" class=\"editbox-draft-vars\"></textarea><br><br><br>");
  580. })
  581. });
  582. }
  583. $.fn.editable.defaults.mode = 'inline';
  584. $.fn.editableform.buttons =
  585. '<button type="submit" class="btn btn-primary btn-sm editable-submit">'+
  586. '<i class="fa fa-fw fa-check"></i>'+
  587. '</button>'+
  588. '<button type="button" class="btn btn-default btn-sm editable-cancel">'+
  589. '<i class="fa fa-fw fa-times"></i>'+
  590. '</button>';
  591. $('.editable-element-text').editable({
  592. escape: false,
  593. success: function(response, newValue) {
  594. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  595. },
  596. error: function (xhr, status, error) {
  597. //var err = eval("(" + xhr.responseText + ")");
  598. return xhr.statusText;
  599. },
  600. params: function(params) {
  601. params.action = 'updateMailaccounts';
  602. return params;
  603. }
  604. });
  605. $('.editable-element-select-protocol').editable({
  606. defaultValue: 'imap',
  607. source: [
  608. {value: 'imap', text: 'IMAP'},
  609. {value: 'pop3', text: 'POP3'}
  610. ],
  611. success: function(response, newValue) {
  612. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  613. },
  614. error: function (xhr, status, error) {
  615. //var err = eval("(" + xhr.responseText + ")");
  616. return xhr.statusText;
  617. },
  618. params: function(params) {
  619. params.action = 'updateMailaccounts';
  620. return params;
  621. }
  622. });
  623. $('.editable-element-select-use-ssl').editable({
  624. defaultValue: '1',
  625. source: [
  626. {value: '1', text: 'On'},
  627. {value: '0', text: 'Off'}
  628. ],
  629. success: function(response, newValue) {
  630. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  631. },
  632. error: function (xhr, status, error) {
  633. //var err = eval("(" + xhr.responseText + ")");
  634. return xhr.statusText;
  635. },
  636. params: function(params) {
  637. params.action = 'updateMailaccounts';
  638. return params;
  639. }
  640. });
  641. $('.editable-element-select-no-valid-cert').editable({
  642. defaultValue: '0',
  643. source: [
  644. {value: '0', text: 'On'},
  645. {value: '1', text: 'Off'}
  646. ],
  647. success: function(response, newValue) {
  648. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  649. },
  650. error: function (xhr, status, error) {
  651. //var err = eval("(" + xhr.responseText + ")");
  652. return xhr.statusText;
  653. },
  654. params: function(params) {
  655. params.action = 'updateMailaccounts';
  656. return params;
  657. }
  658. });
  659. $('#add-mailaccount').on('click', function(e) {
  660. e.preventDefault();
  661. var uID = $(this).attr('data-uid');
  662. $.ajax({
  663. url: 'ajax.php',
  664. type: 'POST',
  665. data: {'action': 'addDefaultMailaccount', 'user-id': uID},
  666. success: function (result) {
  667. location.reload();
  668. }
  669. });
  670. });
  671. function fancyBoxLoader() {
  672. $.ajax({
  673. url: 'ajax.php',
  674. data: {'action': 'getMailAccountsByUid', 'uID': $('.manage-mailboxfolder').attr('data-uid')},
  675. type: 'GET',
  676. global: false,
  677. async: true,
  678. dataType: 'json',
  679. success: function(data) {
  680. result = data;
  681. $('.editable-element-select-mailaccount').editable({
  682. //defaultValue: '0',
  683. source: result,
  684. success: function(response, newValue) {
  685. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  686. },
  687. error: function (xhr, status, error) {
  688. //var err = eval("(" + xhr.responseText + ")");
  689. return xhr.statusText;
  690. },
  691. params: function(params) {
  692. params.action = 'updateMailfolder';
  693. return params;
  694. }
  695. });
  696. }
  697. });
  698. $('.editable-element-text').editable({
  699. escape: false,
  700. success: function(response, newValue) {
  701. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  702. },
  703. error: function (xhr, status, error) {
  704. //var err = eval("(" + xhr.responseText + ")");
  705. return xhr.statusText;
  706. },
  707. params: function(params) {
  708. params.action = 'updateMailfolder';
  709. return params;
  710. }
  711. });
  712. }
  713. $('.remove-mailaccount').on('click', function(e) {
  714. e.preventDefault();
  715. var id = $(this).attr('data-id');
  716. $.ajax({
  717. url: 'ajax.php',
  718. type: 'POST',
  719. data: {'action': 'removeMailaccount', 'id': id},
  720. success: function (result) {
  721. location.reload();
  722. }
  723. });
  724. });
  725. $('.remove-mailboxfolder').on('click', function(e) {
  726. e.preventDefault();
  727. var id = $(this).attr('data-id');
  728. $.ajax({
  729. url: 'ajax.php',
  730. type: 'POST',
  731. data: {'action': 'removeMailboxFolder', 'id': id},
  732. success: function (result) {
  733. location.reload();
  734. }
  735. });
  736. });
  737. $('#add-mailboxfolder').on('click', function(e) {
  738. e.preventDefault();
  739. var uID = $(this).attr('data-uid');
  740. var lID = $(this).attr('data-lid');
  741. $.ajax({
  742. url: 'ajax.php',
  743. type: 'POST',
  744. data: {'action': 'addDefaultMailfolder', 'user-id': uID, 'label-id': lID},
  745. success: function (result) {
  746. location.reload();
  747. },
  748. error: function(result) {
  749. noty_error_retry();
  750. }
  751. });
  752. });
  753. $(".datetimepicker").datetimepicker({
  754. format: 'Y-m-d H:i',
  755. startDate: new Date()
  756. });
  757. switch(getUrlGetParameter("action")) {
  758. case 'settings':
  759. getMailboxStatus();
  760. settingsListener();
  761. break;
  762. case 'manage-label':
  763. loadBox('.manage-mailboxfolder', "editBox", "saveMailFolder", function() {});
  764. manageLabelListener();
  765. break;
  766. case 'manage-labels':
  767. loadBox('#add-label', "editBox", "saveLabel", function() {});
  768. manageLabelsListener();
  769. break;
  770. case 'label':
  771. loadBox('#new-document', "editBox", "saveDocument", reloadDraftVars);
  772. loadBox('#new-call', 'editBox', 'saveCall', function() {});
  773. LabelListener();
  774. break;
  775. default:
  776. break;
  777. }
  778. handleEvents();
  779. setInterval(handleEvents, 60000);
  780. });