custom.js 10 KB

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