custom.js 8.6 KB

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