custom.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. $(document).ready(function() {
  2. function getUrlGetParameter(val) {
  3. var result = "Not found",
  4. tmp = [];
  5. location.search
  6. .substr(1)
  7. .split("&")
  8. .forEach(function (item) {
  9. tmp = item.split("=");
  10. if (tmp[0] === val) result = decodeURIComponent(tmp[1]);
  11. });
  12. return result;
  13. }
  14. function addSpinner(element) {
  15. element.append("<div class=\"spinner\"><div class=\"bounce1\"></div><div class=\"bounce2\"></div><div class=\"bounce3\"></div></div>");
  16. }
  17. function removeSpinner(element) {
  18. element.children(".spinner").remove();
  19. }
  20. function loadBox(element) {
  21. $(document).on("click", element, function(e) {
  22. e.preventDefault();
  23. $.get($(this).attr('href'), function(r) {
  24. try {
  25. editBox = $.parseJSON(r);
  26. var optionsContainer = document.createElement('div');
  27. $.each(editBox['options'], function(i) {
  28. $(optionsContainer).append(this.name + "<input type=\"" + this.type + "\" value=\"" + this.value + "\" style=\"float: right;\"/><br><br>")
  29. });
  30. $.fancybox({
  31. maxWidth : 800,
  32. maxHeight : 600,
  33. fitToView : true,
  34. width : '70%',
  35. height : '70%',
  36. autoSize : false,
  37. title : "<h3>" + editBox['title'] + "</h3><hr>",
  38. content : optionsContainer.innerHTML,
  39. helpers : {
  40. title: {
  41. type : 'inside',
  42. position: 'top'
  43. }
  44. }
  45. });
  46. } catch(e) {
  47. console.log(e); // DBG
  48. var n = noty({
  49. layout : 'topCenter',
  50. text : 'Irgendwas ist schief gelaufen.<br>Bitte probieren Sie es später noch einmal.',
  51. type : 'error',
  52. timeout : 5000
  53. });
  54. }
  55. });
  56. });
  57. }
  58. function getMailboxStatus() {
  59. $("#settings-mailboxes tr").each(function(item) {
  60. var thisTr = this;
  61. if(this.attributes.length > 0) {
  62. addSpinner($(this).children("td:first"));
  63. $.getJSON("ajax.php?action=getMailboxStatus&mailboxId=" + $(this).attr("data-mailbox-id"), function(r) {
  64. if(r['connected'] == true) {
  65. removeSpinner($(thisTr).children("td:first"));
  66. $(thisTr).children("td:first").append("<i class=\"fa fa-check-circle\"></i>");
  67. } else {
  68. removeSpinner($(thisTr).children("td:first"));
  69. $(thisTr).children("td:first").append("<i class=\"fa fa-exclamation-circle\"></i>");
  70. }
  71. });
  72. }
  73. });
  74. }
  75. $.fn.editable.defaults.mode = 'inline';
  76. $.fn.editableform.buttons =
  77. '<button type="submit" class="btn btn-primary btn-sm editable-submit">'+
  78. '<i class="fa fa-fw fa-check"></i>'+
  79. '</button>'+
  80. '<button type="button" class="btn btn-default btn-sm editable-cancel">'+
  81. '<i class="fa fa-fw fa-times"></i>'+
  82. '</button>';
  83. $('.editable-element-text').editable({
  84. escape: false,
  85. success: function(response, newValue) {
  86. console.log(response); // Debug output from ajax.php
  87. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  88. },
  89. error: function (xhr, status, error) {
  90. //var err = eval("(" + xhr.responseText + ")");
  91. return xhr.statusText;
  92. },
  93. params: function(params) {
  94. params.action = 'updateMailaccounts';
  95. return params;
  96. }
  97. });
  98. $('.editable-element-select-protocol').editable({
  99. defaultValue: 'imap',
  100. source: [
  101. {value: 'imap', text: 'IMAP'},
  102. {value: 'pop3', text: 'POP3'}
  103. ],
  104. success: function(response, newValue) {
  105. console.log(response); // Debug output from ajax.php
  106. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  107. },
  108. error: function (xhr, status, error) {
  109. //var err = eval("(" + xhr.responseText + ")");
  110. return xhr.statusText;
  111. },
  112. params: function(params) {
  113. params.action = 'updateMailaccounts';
  114. return params;
  115. }
  116. });
  117. $('.editable-element-select-use-ssl').editable({
  118. defaultValue: '1',
  119. source: [
  120. {value: '1', text: 'On'},
  121. {value: '0', text: 'Off'}
  122. ],
  123. success: function(response, newValue) {
  124. console.log(response); // Debug output from ajax.php
  125. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  126. },
  127. error: function (xhr, status, error) {
  128. //var err = eval("(" + xhr.responseText + ")");
  129. return xhr.statusText;
  130. },
  131. params: function(params) {
  132. params.action = 'updateMailaccounts';
  133. return params;
  134. }
  135. });
  136. $('.editable-element-select-no-valid-cert').editable({
  137. defaultValue: '0',
  138. source: [
  139. {value: '0', text: 'On'},
  140. {value: '1', text: 'Off'}
  141. ],
  142. success: function(response, newValue) {
  143. console.log(response); // Debug output from ajax.php
  144. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  145. },
  146. error: function (xhr, status, error) {
  147. //var err = eval("(" + xhr.responseText + ")");
  148. return xhr.statusText;
  149. },
  150. params: function(params) {
  151. params.action = 'updateMailaccounts';
  152. return params;
  153. }
  154. });
  155. $('#add-mailaccount').on('click', function(e) {
  156. e.preventDefault();
  157. var uId = $(this).attr('data-uid');
  158. $.ajax({
  159. url: 'ajax.php',
  160. type: 'POST',
  161. data: {'action': 'addDefaultMailaccount', 'user-id': uId},
  162. success: function (result) {
  163. console.log(result);
  164. location.reload();
  165. }
  166. });
  167. });
  168. function fancyBoxLoader() {
  169. $.ajax({
  170. url: 'ajax.php',
  171. data: {'action': 'getMailAccountsByUid', 'uId': $('.manage-mailboxfolder').attr('data-uid')},
  172. type: 'GET',
  173. global: false,
  174. async: true,
  175. dataType: 'json',
  176. success: function(data) {
  177. result = data;
  178. $('.editable-element-select-mailaccount').editable({
  179. //defaultValue: '0',
  180. source: result,
  181. success: function(response, newValue) {
  182. console.log(response); // Debug output from ajax.php
  183. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  184. },
  185. error: function (xhr, status, error) {
  186. //var err = eval("(" + xhr.responseText + ")");
  187. return xhr.statusText;
  188. },
  189. params: function(params) {
  190. params.action = 'updateMailfolder';
  191. return params;
  192. }
  193. });
  194. }
  195. });
  196. $('.editable-element-text').editable({
  197. escape: false,
  198. success: function(response, newValue) {
  199. console.log(response); // Debug output from ajax.php
  200. if(response.status == 'error') return response.msg; //msg will be shown in editable form
  201. },
  202. error: function (xhr, status, error) {
  203. //var err = eval("(" + xhr.responseText + ")");
  204. return xhr.statusText;
  205. },
  206. params: function(params) {
  207. params.action = 'updateMailfolder';
  208. return params;
  209. }
  210. });
  211. }
  212. $('.remove-mailaccount').on('click', function(e) {
  213. e.preventDefault();
  214. var id = $(this).attr('data-id');
  215. $.ajax({
  216. url: 'ajax.php',
  217. type: 'POST',
  218. data: {'action': 'removeMailaccount', 'id': id},
  219. success: function (result) {
  220. console.log(result);
  221. location.reload();
  222. }
  223. });
  224. });
  225. $('.remove-mailboxfolder').on('click', function(e) {
  226. e.preventDefault();
  227. var id = $(this).attr('data-id');
  228. $.ajax({
  229. url: 'ajax.php',
  230. type: 'POST',
  231. data: {'action': 'removeMailboxFolder', 'id': id},
  232. success: function (result) {
  233. console.log(result);
  234. location.reload();
  235. }
  236. });
  237. });
  238. $('#add-mailboxfolder').on('click', function(e) {
  239. e.preventDefault();
  240. var uId = $(this).attr('data-uid');
  241. var lId = $(this).attr('data-lid');
  242. $.ajax({
  243. url: 'ajax.php',
  244. type: 'POST',
  245. data: {'action': 'addDefaultMailfolder', 'user-id': uId, 'label-id': lId},
  246. success: function (result) {
  247. console.log(result);
  248. location.reload();
  249. },
  250. error: function(result) {
  251. console.log(result);
  252. }
  253. });
  254. });
  255. switch(getUrlGetParameter("action")) {
  256. case 'settings':
  257. getMailboxStatus();
  258. break;
  259. case 'manage-label':
  260. loadBox('.manage-mailboxfolder');
  261. break;
  262. case 'label':
  263. loadBox('#new-document');
  264. break;
  265. default:
  266. break;
  267. }
  268. });