Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.37 KB | None | 0 0
  1. /*
  2. mailbox
  3. - load
  4. - messages
  5. - load
  6. - select_all
  7. - refresh
  8. - move_to_trash_multi
  9. - pagination
  10. - new
  11. - create
  12. - recipient_remove
  13. - send
  14. - message
  15. - load
  16. - move_to_trash
  17. - attachment_download
  18. - attachments_download
  19. - move_attachments_to_organizer
  20. - forward
  21. - reply
  22. */
  23.  
  24.  
  25. $(function() {
  26. var mailbox = {
  27. loader: function() {
  28. $("#mailbox_ajax").html('<div class="overlay text-center" style="margin-top:20%"><i class="fa fa-refresh fa-spin fa-5x"></i></div>');
  29. },
  30. messages: {
  31. load: function() {
  32. mailbox.loader();
  33. var search_query = $("input[name=folder_search_query]").val(); // is search query?
  34.  
  35.  
  36. $(".mailbox_folder").removeClass('active'); // remove folder active from all sidebar folders
  37.  
  38. var type_name = '';
  39. var type_parameter = '';
  40. if( Object.prototype.toString.call(type) === '[object Array]' ) {
  41. if ("type" in type)
  42. var type_name = type.type;
  43. if ("parameter" in type)
  44. var type_parameter = type.parameter;
  45. }
  46. else
  47. {
  48. type_name = type;
  49. }
  50.  
  51. var folder = $("input[name=folder_active]").val();
  52. var folder_time = $("input[name=folder_time]").val();
  53. var limit = $("input[name=folder_limit]").val();
  54. var offset = $("input[name=folder_offset]").val();
  55. var type = $("input[name=folder_type]").val();
  56. var type_parameter = $("input[name=folder_type_parameter]").val();
  57. var type_parameter_1 = $("input[name=folder_type_parameter_1]").val();
  58. var unseen = $("input[name=folder_unseen]").val();
  59. var attachments = $("input[name=folder_attachments]").val();
  60.  
  61. ajax({action:'mailbox_messages',mailbox_id : mailbox_id,folder:folder,folder_time:folder_time,type:type,type_parameter:type_parameter,type_parameter_1:type_parameter_1,limit:limit,offset:offset,'title' : $('[data-folder="'+folder+'"]').attr('data-title'),unseen:unseen,attachments:attachments,search_query:search_query},function(data) {
  62. $("#mailbox_folders").html(data.html_folders);
  63. $("#mailbox_ajax").html(data.html);
  64. $("[data-pagination=page_previus]").prop('disabled',false);
  65. $("[data-pagination=page_next]").prop('disabled',false);
  66.  
  67. if (data.statistic.unseen > 0)
  68. $('[data-folder="'+folder+'"]').find('.nr').html(data.statistic.unseen).removeClass('hidden').fadeIn();
  69.  
  70. $("input[name=folder_active]").val(folder);
  71. $("[data-folder='"+folder+"']").parent().addClass('active');
  72. $("[data-pagination='total']").html(data.mailbox_data.messages_nr_total);
  73.  
  74. var pagination_from = data.mailbox_data.offset;
  75. var pagination_to = parseInt(data.mailbox_data.offset) + parseInt(data.mailbox_data.limit);
  76.  
  77. if (pagination_from <= 0)
  78. {
  79. pagination_from = 0;
  80. $("[data-pagination=page_previus]").prop('disabled',true);
  81. }
  82.  
  83. if (pagination_to == 0)
  84. pagination_to = data.mailbox_data.limit;
  85.  
  86. if (pagination_from > pagination_to)
  87. pagination_from = 1;
  88.  
  89. pagination_from ++;
  90. if (pagination_to >= data.mailbox_data.messages_nr_total)
  91. {
  92. pagination_to = data.mailbox_data.messages_nr_total;
  93. $("[data-pagination=page_next]").prop('disabled',true);
  94. }
  95.  
  96. $("[data-pagination='from']").html(pagination_from);
  97. $("[data-pagination='to']").html(pagination_to);
  98.  
  99. $('iframe').each(function() {
  100.  
  101. $height = $(this).height();
  102. //alert($height);
  103. });
  104.  
  105.  
  106. });
  107. },
  108. select_all: function($status) {
  109.  
  110. $(':checkbox').each(function() {
  111. if ($status == true)
  112. $(this).prop('checked',true);
  113. else
  114. $(this).prop('checked',false);
  115. });
  116. },
  117. refresh: function(mailbox_id,folder)
  118. {
  119. mailbox.messages.load(mailbox_id,folder,'all');
  120. },
  121. move_to_trash_multi: function(mailbox_id,folder,uids)
  122. {
  123. var checked_messages_nr = $('input[name="mailbox[]"]:checked').length;
  124. var checked_messages = $('input[name="mailbox[]"]:checked');
  125.  
  126. if (checked_messages_nr == 0)
  127. modal_make('warning','<div class="text-center lead">Označite zapise, ki jih želite izbrisati.</div>');
  128.  
  129. if (checked_messages_nr > 0)
  130. {
  131. modal_make('trash_multi');
  132. $(document.body).on('click','#modal_confirm',function(e) {
  133. var message_uids = selected_checkboxes_value("mailbox[]");
  134. mailbox.loader();
  135. ajax({'action':'messages_move_to_trash','mailbox_id' : mailbox_id, 'folder' : folder,'message_uids' : message_uids},function(data) {
  136. modal_close();
  137. mailbox.messages.load(mailbox_id,folder,'all');
  138. });
  139. });
  140. }
  141. },
  142. pagination: function($type) {
  143. limit = parseInt($("input[name=folder_limit").val());
  144. if ($type == 'next')
  145. {
  146. $nr = parseInt($("[data-pagination=total]").html());
  147. $max = $nr / $("input[name=folder_limit").val();
  148. $max = Math.ceil($max);
  149. $val = parseInt($("input[name=folder_offset]").val()) + limit;
  150. $("input[name=folder_offset]").val($val);
  151.  
  152. $to = parseInt($("[data-pagination=from]").html()) + parseInt(limit);
  153. $from = parseInt($("[data-pagination=to]").html()) + parseInt(limit);
  154.  
  155. $("[data-pagination=from]").html($to);
  156. $("[data-pagination=to]").html($from);
  157.  
  158. mailbox.messages.load(mailbox_id,$("input[name=folder_active]").val(),'all',$to,limit);
  159. }
  160.  
  161. if ($type == 'previus')
  162. {
  163. $offset = parseInt($("input[name=folder_offset]").val()) - limit;
  164. if ($offset < 0)
  165. $offset = 0;
  166.  
  167. $("input[name=folder_offset]").val($offset);
  168.  
  169. $from = parseInt($("[data-pagination=from]").html()) - parseInt($("input[name=folder_limit").val());
  170. if ($from < 0)
  171. $from = 0;
  172.  
  173. $to = parseInt($("[data-pagination=to]").html()) - parseInt($("input[name=folder_limit").val());
  174. if ($to < 1) // can not be 0
  175. $to = $("input[name=folder_limit]").val();
  176.  
  177. $("[data-pagination=from]").html($from);
  178. $("[data-pagination=to]").html($to);
  179.  
  180. mailbox.messages.load(mailbox_id,$("input[name=folder_active]").val(),'all',$to,limit);
  181. }
  182. }
  183. },
  184. new: {
  185. // create, new, reply
  186. create: function(mailbox_id,action_type,message_uid) {
  187.  
  188. // submit on shift + enter
  189. $(document.body).keypress(function(e) {
  190. if (e.keyCode == 13 && e.shiftKey) {
  191. mailbox.new.send();
  192. }
  193. });
  194.  
  195. // create proces
  196. hash = window.location.hash.substr(1);
  197. hash = hash_array(hash);
  198. console.log(hash);
  199.  
  200. if (hash[1] !== 'create')
  201. hash_set('create');
  202.  
  203. if (hash[3])
  204. {
  205. ajax({action:'create_recipient_add',recipient:hash[3]});
  206. }
  207.  
  208. mailbox.loader();
  209. console.log(action_type);
  210.  
  211. if (typeof action_type =='undefined')
  212. {
  213. var action_type = 'create';
  214. }
  215.  
  216. ajax({action:'create','action_type':action_type,'mailbox_id' : mailbox_id,message_uid : message_uid},function(data) {
  217. $("#mailbox_ajax").html(data.html);
  218. $("#mailbox_folders").html(data.html_folders);
  219.  
  220. $toolbar = [
  221. ['Format','FontSize','TextColor'],
  222. ['btgrid','media_embed','embed','embedbase'],
  223. ['Undo','Redo','RemoveFormat','Bold','Italic','Underline','Strike','NumberedList','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','Link','Unlink','Image','Table','Source'],
  224. ];
  225.  
  226. if (mobile)
  227. {
  228. $toolbar = [
  229. ['Undo','Redo','RemoveFormat','Bold','Italic','Underline','NumberedList','Link','Unlink','Image','Table','Source'],
  230. ]
  231. }
  232.  
  233. CKEDITOR.inline('email_content',{
  234. extraPlugins: 'autogrow,pastebase64,maximize',
  235. enableOnReadonly: true,
  236. enterMode: CKEDITOR.ENTER_BR,
  237. uiColor: '#ffffff',
  238. startupFocus: false,
  239. toolbar : $toolbar,
  240. });
  241.  
  242. // on create - on change textarea update template
  243. CKEDITOR.instances["email_content"].on('change', function() {
  244. $last_save = $("input[name=last_save]").val();
  245.  
  246. $time_diff = $.now() - $last_save;
  247. if ($time_diff > 5000)
  248. {
  249. $("input[name=last_save]").val($.now());
  250. ajax({mailbox_id : mailbox_id,action:'create_save_content',subject:$("input[name=subject]").val(),content:this.getData()},function(data) {
  251. });
  252. }
  253. });
  254.  
  255. // when in create mode show recipient fields which have valid email address
  256. $('.recipient_email').each(function() {
  257. if (valid_email($(this).val()))
  258. $(".recipient_nr_"+$(this).attr('mailbox-recipient-nr')).removeClass('hidden');
  259. });
  260. });
  261. },
  262. recipient_remove: function(recipient) {
  263. preloader();
  264. ajax({'action':'create_recipient_remove','recipient' : recipient},function(data) {
  265. $("#recipient_list").html(data.html);
  266. });
  267. },
  268. send: function() {
  269. error = false;
  270.  
  271. // collect data - recipients type and recipients (select + input)
  272. recipients = [];
  273. recipients_type = [];
  274.  
  275. $('.recipient_email').each(function() {
  276. if (valid_email($(this).val()))
  277. recipients.push($(this).val());
  278. });
  279.  
  280. i = 0;
  281. $("select.recipient_receive_type").each(function() {
  282. i++;
  283. if (valid_email($("[mailbox-recipient-nr="+i+"]").val()))
  284. recipients_type.push($(this).val());
  285. });
  286.  
  287. // collect data - subject
  288. subject = $("input[name=subject]").val();
  289.  
  290. // collect data - content
  291. var item = CKEDITOR.instances["email_content"];
  292. var body = item.getData();
  293.  
  294. ajax({action:'send_2',mailbox_id:mailbox_id,recipients_type:recipients_type,recipients:recipients,subject:subject,body:body,reply_to:$("input[name=reply_to]").val()},function(data) {
  295. $("input[name=subject]").attr('style','font-size:1.5em; color:black; padding-left:0.3em; border-bottom:2px solid green !important');
  296. if (typeof data.error.body != 'undefined') {
  297. $("textarea[name=email_content]").focus();
  298. $(".error_body").fadeIn(10).fadeOut(5000);
  299. }
  300. if (typeof data.error.subject != 'undefined') {
  301. $("input[name=subject]").focus();
  302. $("input[name=subject]").attr('style','font-size:1.5em; color:black; padding-left:0.3em; border-bottom:2px solid red !important');
  303. }
  304. if (typeof data.error.recipient != 'undefined') {
  305. $("input[name=email_recipient_1]").focus();
  306. $("input[name=email_recipient_1]").attr('style','border-bottom:2px solid red !important');
  307. }
  308.  
  309. if (data.sent == true)
  310. {
  311. $("#html_creating").addClass('hidden');
  312. $("#html_sent").removeClass('hidden');
  313. $html = $("#mailbox_ajax").html();
  314. $html = $html.replace('{sent_datetime}',data.sent_datetime);
  315. $html = $html.replace('{sent_recipient}',data.sent_recipient);
  316. $html = $html.replace('{sent_subject}',data.sent_subject);
  317. $html = $html.replace('{sent_message}',data.sent_message);
  318. $("#mailbox_ajax").html($html);
  319. }
  320.  
  321. });
  322. }
  323. },
  324. message: {
  325. load: function(mailbox_id,folder,uid) {
  326. mailbox.loader();
  327. ajax({'action':'message_view','mailbox_id' : mailbox_id, 'folder' : folder,'message_uid' : uid},function(data) {
  328. hash_set('message/' + uid);
  329. $("#mailbox_ajax").html(data.html);
  330. });
  331. },
  332. move_to_trash: function(mailbox_id,folder,uid,next_uid = false)
  333. {
  334. modal_make('trash');
  335. $(document.body).on('click','#modal_confirm',function(e) {
  336. ajax({'action':'message_move_to_trash','mailbox_id' : mailbox_id, 'folder' : folder,'message_uid' : uid},function(data) {
  337. modal_close();
  338.  
  339. if (next_uid == false)
  340. {
  341. if (ba == 'view')
  342. {
  343. $("#tr_"+uid).fadeOut();
  344. $("#tr_"+uid+'_preview').fadeOut();
  345.  
  346. }
  347. else
  348. {
  349. mailbox.loader();
  350. mailbox.messages.load();
  351. }
  352. }
  353. else
  354. {
  355. mailbox.message.load(mailbox_id,folder,next_uid);
  356. }
  357.  
  358. });
  359. });
  360. },
  361. attachment_download: function(mailbox_id,message_uid,attachment_id)
  362. {
  363. window.location = '/mailbox/'+s2+'/attachment/'+message_uid+'/'+attachment_id;
  364. },
  365. attachments_download: function(mailbox_id,message_uid,attachment_id)
  366. {
  367. window.location = '/mailbox/'+s2+'/attachments_download/'+message_uid;
  368. },
  369. move_attachments_to_organizer: function(mailbox_id,message_uid)
  370. {
  371. ajax({action:'move_attachments_to_organizer',mailbox_id:mailbox_id,message_uid:message_uid},function(data) {
  372. select2_organizer();
  373. });
  374. },
  375. forward: function(mailbox_id,message_uid)
  376. {
  377. console.log("forward");
  378. mailbox.new.create(mailbox_id,'forward',message_uid);
  379. },
  380. reply: function(mailbox_id,message_uid)
  381. {
  382. mailbox.new.create(mailbox_id,'reply',message_uid);
  383. console.log("reply");
  384. }
  385. }
  386. };
  387.  
  388. /*********************************************************************************************************************************************************************************
  389. MAILBOX CALLERS
  390. *********************************************************************************************************************************************************************************/
  391. uri = uri();
  392. console.log(uri[1]);
  393.  
  394. switch (uri[1])
  395. {
  396. default:
  397. mailbox.messages.load();
  398. break;
  399. case 'inbox':
  400. if (typeof uri[2] == 'undefined')
  401. $("input[name=folder_active]").val('inbox');
  402.  
  403. if (typeof uri[2] != 'undefined')
  404. $("input[name=folder_active]").val(uri[2]);
  405. $("input[name=folder_type]").val('all');
  406. $("input[name=folder_type_parameter]").val('');
  407. $("input[name=folder_unseen]").val('');
  408. $("input[name=folder_attachments]").val('');
  409. mailbox.messages.load();
  410. break;
  411. case 'create':
  412. mailbox.new.create(mailbox_id);
  413. break;
  414. case 'message':
  415. mailbox.message.load(mailbox_id,$(this).attr('data-folder'),uri[2]);
  416. break;
  417. case 'from':
  418. $("input[name=folder_type]").val('from');
  419. $("input[name=folder_type_parameter]").val(uri[2]);
  420. mailbox.messages.load();
  421. break;
  422. case 'status':
  423. $("input[name=folder_type]").val('status');
  424. $("input[name=folder_type_parameter]").val(uri[2]);
  425.  
  426. if (uri[2] == 'all')
  427. {
  428. $("input[name=folder_type]").val('all');
  429. $("input[name=folder_type_parameter]").val('');
  430. }
  431. mailbox.messages.load();
  432. break;
  433. case 'contacts':
  434. ajax({action:'mailbox_contacts',mailbox_id:mailbox_id,html_replace:'#mailbox_ajax'},function(data) {});
  435. break;
  436. }
  437.  
  438. // load box message - folder click - inbox, sent, etc..
  439. $(document.body).on('click','[data-modul=box_messages]',function(e) {
  440. hash_set('inbox/' + $(this).attr('data-folder'));
  441. $("input[name=folder_active]").val($(this).attr('data-folder'));
  442. $("input[name=folder_type]").val('all');
  443. $("input[name=folder_type_parameter]").val('');
  444. $("input[name=folder_unseen]").val('');
  445. $("input[name=folder_attachments]").val('');
  446.  
  447. if ($("input[name=folder_time]").val() == $(this).attr('data-time'))
  448. $("input[name=folder_time]").val(''); // reset if set same time
  449. else
  450. $("input[name=folder_time]").val($(this).attr('data-time'));
  451.  
  452. mailbox.messages.load();
  453. });
  454.  
  455. /* MAILBOX VIEW */
  456. // button - create new message
  457. $(document.body).on('click','[data-modul=message_create]',function(e) {
  458. mailbox.new.create(mailbox_id);
  459. });
  460.  
  461. // trash multi selected items
  462. $(document.body).on('click','[data-modul=trash_multi]',function(e) {
  463. var uids = false;
  464. mailbox.messages.move_to_trash_multi(mailbox_id,$("input[name=folder_active]").val(),uids);
  465. });
  466.  
  467. $(document.body).on('keypress','input[name=mailbox_search]', function(e){
  468. if(e.which === 13){
  469. $("input[name=folder_search_query]").val($("input[name=mailbox_search]").val());
  470. mailbox.messages.load(mailbox_id,$("input[name=folder_active]").val(),'all');
  471. e.preventDefault();
  472. }
  473. });
  474.  
  475. // click on message to see details of message
  476. $(document.body).on('click','[data-modul=message_view]',function(e) {
  477. if (!window.event.ctrlKey) {
  478. // $("input[name=folder_type]").val('from');
  479. // $("input[name=folder_type_parameter]").val($(this).attr('data-from'));
  480. mailbox.message.load(mailbox_id,$(this).attr('data-folder'),$(this).attr('data-uid'));
  481. }
  482. });
  483.  
  484. // show only unread messages
  485. $(document.body).on('click','[data-modul=show_only_unseen]',function(e) {
  486. var val = $("input[name=folder_unseen]").val();
  487. if (val == 1)
  488. $("input[name=folder_unseen]").val(0);
  489. else
  490. $("input[name=folder_unseen]").val(1);
  491. mailbox.messages.load();
  492. });
  493.  
  494. // show only messages with attachments
  495. $(document.body).on('click','[data-modul=show_only_with_attachment]',function(e) {
  496. var val = $("input[name=folder_attachments]").val();
  497. if (val == 1)
  498. $("input[name=folder_attachments]").val(0);
  499. else
  500. $("input[name=folder_attachments]").val(1);
  501. mailbox.messages.load();
  502.  
  503. });
  504.  
  505. // show messages by status - open, answered, closed, urgent
  506. $(document.body).on('click','[data-modul=show_by_status]',function(e) {
  507. if (!window.event.ctrlKey) {
  508. $("input[name=folder_type]").val('status');
  509. if ($(this).attr('data-status') !== 'reload')
  510. {
  511. $("input[name=folder_type_parameter]").val($(this).attr('data-status'));
  512. }
  513.  
  514. if ($(this).attr('data-status') == 'all')
  515. {
  516. $("input[name=folder_type]").val('all');
  517. $("input[name=folder_type_parameter]").val('');
  518. }
  519. mailbox.messages.load();
  520. }
  521. });
  522.  
  523. // message load from
  524. $(document.body).on('click','[data-modul=messages_from]',function(e) {
  525. if (!window.event.ctrlKey) {
  526. $("input[name=folder_type]").val('from');
  527. $("input[name=folder_type_parameter]").val($(this).attr('data-from'));
  528. mailbox.messages.load();
  529. }
  530. });
  531.  
  532. // select all messages
  533. $(document.body).on('click','[data-mailbox=select_all]',function(e) {
  534. mailbox.messages.select_all($(this).is(':checked'));
  535. });
  536.  
  537. // pagination next
  538. $(document.body).on('click','[data-pagination=page_next]',function(e) {
  539. mailbox.messages.pagination('next');
  540. e.preventDefault();
  541. });
  542.  
  543. // pagination previus
  544. $(document.body).on('click','[data-pagination=page_previus]',function(e) {
  545. mailbox.messages.pagination('previus');
  546. e.preventDefault();
  547. });
  548.  
  549. $(document.body).on('click','[data-modul=load_message]',function(e) {
  550. $message_uid = $(this).attr('data-ID');
  551. mailbox.message.load(mailbox_id,$("input[name=folder_active]").val(),$message_uid);
  552. e.preventDefault();
  553. })
  554.  
  555. // message status
  556. $(document.body).on('click','[data-modul=status]',function(e) {
  557. var message_uid = $(this).attr('data-uid');
  558. var email = $(this).attr('data-email');
  559. var status = $(this).attr('data-status');
  560.  
  561. ajax({action : 'message_status',mailbox_id : mailbox_id, folder : $("input[name=folder_active]").val(), message_uid : message_uid,email:email,status:status},function(data) {});
  562. });
  563.  
  564. // message status newsletter
  565. $(document.body).on('change','select[name=select_status]',function(e) {
  566. $val = $('select[name=select_status] option:selected').val();
  567. if ($val == 'newsletter')
  568. {
  569. $("#mailbox_newsletter_options").removeClass('hidden');
  570. }
  571. else
  572. {
  573. $("#mailbox_newsletter_options").addClass('hidden');
  574. }
  575. });
  576.  
  577.  
  578. // MAILBOX MESSAGE (DETAILS)
  579. // message move to trash
  580. $(document.body).on('click','[data-modul=message_move_to_trash]',function(e) {
  581.  
  582.  
  583. if ($(this).attr('data-from') == 'view')
  584. {
  585. // get uid from view
  586. $next_uid = false;
  587. $uid = $(this).attr('data-uid');
  588. }
  589. else
  590. {
  591. // get uid from -> when message is open
  592. $uid = $("#html_message").attr('data-uid');
  593. $next_uid = $(this).attr('data-nextuid');
  594. }
  595.  
  596. mailbox.message.move_to_trash(mailbox_id,$("#html_message").attr('data-folder'),$uid,$next_uid);
  597. });
  598.  
  599. // attachment download
  600. $(document.body).on('click','[data-mailbox=attachment]',function(e) {
  601. var attachment_id = $(this).attr('attachment-id');
  602. var message_uid = $(this).attr('message-uid');
  603.  
  604. mailbox.message.attachment_download(mailbox_id,message_uid,attachment_id);
  605. });
  606.  
  607. // attachments download
  608. $(document.body).on('click','[data-mailbox=download_attachments]',function(e) {
  609. var message_uid = $(this).attr('message-uid');
  610. mailbox.message.attachments_download(mailbox_id,message_uid);
  611. });
  612.  
  613. // attachments move to organizer
  614. $(document.body).on('click','[data-mailbox=move_attachments_to_organizer]',function(e) {
  615. var message_uid = $(this).attr('message-uid');
  616. mailbox.message.move_attachments_to_organizer(mailbox_id,message_uid);
  617. });
  618.  
  619. $(document.body).on('click','[data-mailbox=forward]',function(e) {
  620. var message_uid = $(this).attr('message-uid');
  621. mailbox.message.forward(mailbox_id,message_uid);
  622. });
  623.  
  624. $(document.body).on('click','[data-mailbox=reply]',function(e) {
  625. var message_uid = $(this).attr('message-uid');
  626. mailbox.message.reply(mailbox_id,message_uid);
  627. });
  628.  
  629.  
  630.  
  631. // CREATE MESSAGE
  632. // predefined content
  633. $(document.body).on('click','[data-create=predefined_content]',function(e) {
  634. ajax({action:'mailbox_create_predefined_messages',mailbox_id:mailbox_id},function(data) {
  635.  
  636. });
  637. });
  638.  
  639. // mailbox create new message modal, select predefined document
  640. $(document.body).on('click','.modal_dropdown_select_document',function(e) {
  641. ajax({action:'mailbox_create_predefined_messages_get_document',mailbox_id:mailbox_id,document_id:$(this).attr('data-value')},function(data) {
  642. if ($("input[name=subject]").val() == '')
  643. $("input[name=subject]").val(data.document.title);
  644.  
  645. var item = CKEDITOR.instances["email_content"];
  646. var body = item.setData(data.document.content);
  647. CKEDITOR.instances['email_content'].setData(data.document.content);
  648. });
  649. });
  650.  
  651. // message open - chevron left - open messages - show messages and hide message
  652. $(document.body).on('click','[data-modul=show_messages]',function(e) {
  653. mailbox.messages.load();
  654. });
  655.  
  656. // send message
  657. $(document.body).on('click','[data-create=send]',function(e) {
  658. preloader('show');
  659. mailbox.new.send();
  660. preloader('off');
  661. e.preventDefault();
  662. });
  663.  
  664. // mailbox modal message status - confirm selected status
  665. $(document.body).on('click','#message_status_confirm',function(e) {
  666. var status = jQuery("select[name=select_status] option:selected").val();
  667. var newsletter_auto_signup_email_to_newsletter = '';
  668. if (status == 'newsletter')
  669. {
  670. var newsletter_auto_signup_email_to_newsletter = $("input[name=mailbox_newsletter_set]").is(':checked');
  671. if (newsletter_auto_signup_email_to_newsletter == true)
  672. newsletter_auto_signup_email_to_newsletter = 1;
  673. else
  674. newsletter_auto_signup_email_to_newsletter = 0;
  675. }
  676. ajax({action : 'message_status_confirm',mailbox_id : mailbox_id, folder: $("input[name=folder_active]").val(),message_uid : $("input[name=message_uid]").val(),status : status,newsletter_auto_signup_email_to_newsletter:newsletter_auto_signup_email_to_newsletter,email:$("input[name=email]").val()},function(data) {
  677. $("#status_"+$("input[name=message_uid]").val()).html(data.status_html);
  678. modal_close();
  679. });
  680. });
  681. });
  682.  
  683. if (s1 == 'mailbox')
  684. {
  685. $(function() {
  686. $(document.body).on('click','#contact_save',function(e) {
  687. email = $("input[name=email]").val();
  688. company_title = $("input[name=company_title]").val();
  689. name = $("input[name=name]").val();
  690. surname = $("input[name=surname]").val();
  691. mobile = $("input[name=mobile]").val();
  692. comment = $("textarea[name=comment]").val();
  693.  
  694. var groups = [];
  695. $("input[name='groups[]']:checked").each(function()
  696. {
  697. groups.push(parseInt($(this).val()));
  698. });
  699.  
  700. ajax({mailbox_id:mailbox_id,action:'contact_save',email:email,company_title:company_title,name:name,surname:surname,mobile:mobile,comment:comment,groups:groups},function(data) {
  701.  
  702. });
  703. });
  704.  
  705. // message attachments modul to move into organizer - select all
  706. $(document.body).on('click','input[name=attachments_all]',function(e) {
  707. $is_checked = $(this).is(':checked');
  708. if ($is_checked == true)
  709. {
  710. $("[data-modul=mailbox_message_attachment]").attr('checked','checked');
  711. }
  712. if ($is_checked == false)
  713. {
  714. $("[data-modul=mailbox_message_attachment]").attr('checked',false);
  715. }
  716. });
  717.  
  718. // move - copy attachments to organizer - confirmation
  719. $(document.body).on('click','#move_attachments_now',function(e) {
  720. var organizer_id = $(".select2_object_organizer").val();
  721. var attachments = $('input[class=attachment]:checkbox:checked').map(function() {
  722. return this.value;
  723. }).get();
  724.  
  725. $("#error_attachments").addClass('hidden');
  726. $("#error_organizer_id").addClass('hidden');
  727.  
  728. var error = false;
  729. if (organizer_id == null)
  730. {
  731. $("#error_organizer_id").removeClass('hidden');
  732. error = true;
  733. }
  734.  
  735. if (attachments.length == 0)
  736. {
  737. $("#error_attachments").removeClass('hidden');
  738. error = true;
  739. }
  740.  
  741. if (error == false)
  742. {
  743. var uri = window.location.hash.substr(1);
  744. uri = uri.split('/');
  745. uri.unshift('');
  746. console.log(uri);
  747. ajax({action:'move_attachments_to_organizer_confirm',mailbox_id:mailbox_id,message_uid:uri[2],organizer_id:organizer_id,attachments:attachments},function(data) {
  748.  
  749. });
  750. }
  751. });
  752. });
  753.  
  754.  
  755. // view
  756. $(document.body).on('mouseover','.tr_message_item',function(e) {
  757. $(this).find('[data-modul=message_move_to_trash]').removeClass('hidden');
  758. });
  759. $(document.body).on('mouseout','.tr_message_item',function(e) {
  760. $(this).find('[data-modul=message_move_to_trash]').addClass('hidden');
  761. });
  762.  
  763. // contact3
  764. $(document.body).on('mouseover','.contact_card',function(e) {
  765. $(this).find('.contact_card_content').removeClass('hidden');
  766. });
  767. $(document.body).on('mouseout','.contact_card',function(e) {
  768. $(this).find('.contact_card_content').addClass('hidden');
  769. });
  770.  
  771. // create -> recipient hover
  772. $(document.body).on('mouseover','.recipient_list_item',function(e) {
  773. $(this).find('.recipient_remove_div').removeClass('hidden');
  774. });
  775. $(document.body).on('mouseout','.recipient_list_item',function(e) {
  776. $(this).find('.recipient_remove_div').addClass('hidden');
  777. });
  778.  
  779.  
  780.  
  781. // view - switch email account
  782. $(document.body).on('click','[data-mailbox=switch_email_account]',function(e) {
  783. ajax({action:'switch_email_account',mailbox_id:mailbox_id});
  784. });
  785.  
  786. /****************************************************************************************************************************************************************************************
  787. M A I L B O X 2
  788. ****************************************************************************************************************************************************************************************/
  789. // subject on change save to session
  790. $(document.body).on('keyup click','input[name=subject]',function(e) {
  791. if ($("input[name=subject]").val().length > 0)
  792. $("input[name=subject]").attr('style','font-size:1.5em; color:black; padding-left:0.3em; border-bottom:2px solid green !important');
  793. if ($("input[name=subject]").val().length < 3)
  794. $("input[name=subject]").attr('style','font-size:1.5em; color:black; padding-left:0.3em; border-bottom:2px solid red !important');
  795. if ($("input[name=subject]").val().length == 0)
  796. $("input[name=subject]").attr('style','font-size:1.5em; color:black; padding-left:0.3em; border-bottom:2px solid #f7f7f7 !important');
  797.  
  798. ajax({action:'mailbox_subject',mailbox_id:mailbox_id,subject:$("input[name=subject]").val()});
  799. });
  800. // recipient management
  801. $(document.body).on('keyup click','.recipient_email',function(e) {
  802. val = $(this).val();
  803. nr = $(this).attr('mailbox-recipient-nr');
  804.  
  805. if (parseInt(nr) < 10 && valid_email(val))
  806. $(document.body).find('.recipient_nr_'+(parseInt(nr)+1)).removeClass('hidden');
  807.  
  808. $('.recipient_email').each(function() {
  809. $(this).attr('style','border-bottom:2px solid #f1f1f1 !important');
  810. nr = $(this).attr('mailbox-recipient-nr');
  811. if ($(this).val().length > 0)
  812. {
  813. if (valid_email($(this).val()))
  814. {
  815. $(this).attr('style','border-bottom:2px solid green !important');
  816. $("#suggesstion-box-"+nr).hide();
  817. }
  818. else
  819. $(this).attr('style','border-bottom:2px solid red !important');
  820. }
  821. });
  822. });
  823.  
  824. // AJAX call for autocomplete
  825. $(document.body).on('keyup click',".recipient_email",function(e){
  826. recipient_nr = $(this).attr('mailbox-recipient-nr');
  827. email = $(this).val();
  828. if (!valid_email(email))
  829. {
  830. ajax_stop();
  831. ajax({action:'mailbox_suggest',mailbox_id:mailbox_id,email:email,recipient_nr:recipient_nr},function(data) {
  832. $("#suggesstion-box-"+data.recipient_nr).show();
  833. $("#suggesstion-box-"+data.recipient_nr).html(data.html);
  834. $("#suggesstion-box-"+data.recipient_nr).fadeOut(5000);
  835. });
  836. }
  837. });
  838. }
  839.  
  840. // autocomplete
  841. function select_recipient(val,nr) {
  842. $("input[name=email_recipient_"+nr+"]").val(val);
  843. $("#suggesstion-box-"+nr).hide();
  844.  
  845. if (valid_email($("input[name=email_recipient_"+nr+"]").val()))
  846. {
  847. $("input[name=email_recipient_"+nr+"]").attr('style','border-bottom:2px solid green !important');
  848. if (parseInt(nr) < 10 && valid_email(val))
  849. {
  850. $(document.body).find('.recipient_nr_'+(parseInt(nr)+1)).removeClass('hidden');
  851. ajax({action:'mailbox_suggest_confirm',mailbox_id:mailbox_id,email:val,recipient_nr:nr});
  852. }
  853. }
  854. else
  855. $("input[name=email_recipient_"+nr+"]").attr('style','border-bottom:2px solid red !important');
  856. }
  857.  
  858. function resizeIframe(obj) {
  859. obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  860. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement