0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.226.17.3


Current Path : /var/www/website/gack/assets/scripts/custom/
Upload File :
Current File : /var/www/website/gack/assets/scripts/custom/inbox.js

var Inbox = function () {

    var content = $('#messages .inbox-content');
    var loading = $('#messages .inbox-loading');
    var sending = $('#messages .sending');
    var listListing = '';
    var msg_int_code=0;

    var initWysihtml5 = function () {
        if (CKEDITOR.instances['inbox_ckeditor']) {
		CKEDITOR.instances['inbox_ckeditor'].destroy();
		}
		CKEDITOR.replace( 'inbox_ckeditor')	;		
    }

	var initFileupload = function () {

        $('#fileupload').fileupload({
            // Uncomment the following to send cross-domain cookies:
            //xhrFields: {withCredentials: true},
            url: 'mail_attachments/',
            autoUpload: true
        });

        // Upload server status check for browsers with CORS support:
        if ($.support.cors) {
            $.ajax({
                url: 'mail_attachments/',
                type: 'HEAD'
            }).fail(function () {
                $('<span class="alert alert-error"/>')
                    .text('Upload server currently unavailable - ' +
                    new Date())
                    .appendTo('#fileupload');
            });
        }
    } 

	var GetUserLists = function(el,call_type){
		 $.ajax({
            type: "GET",
			url: $host_url+"GetUserLists",
            // data: "message_id="+message_id, 		
            success: function(responce) 
            {
				responce = eval('(' + responce + ')');   
				if (responce.error_code == 0)
				{
					$("#inbox #compose_to,#inbox #compose_cc").html(responce.data['users_lists']);
					  $('#inbox #compose_to,#inbox #compose_cc').select2({
									placeholder: " ", 
									allowClear: true
									}); 
					if(call_type=='Replay' || call_type=='Replay_all'|| call_type=='forward')
					{
						Inbox.loadReply(el,call_type);
					}
					//var ar=new Array();$("#s2id_compose_to div").each(function(){ar.push($(this).text())});ar
				}
			}
		});
	}

   

    var handleCCInput = function () {
        var the = $('#inbox .inbox-compose .mail-to .inbox-cc');
        var input = $('#inbox .inbox-compose .input-cc');
        the.hide();
        input.show();
        $('#inbox .close', input).click(function () {
            input.hide();
            the.show();
			$("#inbox #compose_cc").select2("val",'');
        });
    }

    var handleBCCInput = function () {

        var the = $('.inbox-compose .mail-to .inbox-bcc');
        var input = $('.inbox-compose .input-bcc');
        the.hide();
        input.show();
        $('.close', input).click(function () {
            input.hide();
            the.show();
        });
    }

    var toggleButton = function(el) {
        if (typeof el == 'undefined') {
            return;
        }
        if (el.attr("disabled")) {
            el.attr("disabled", false);
        } else {
            el.attr("disabled", true);
        }
    }
	
	
	
	
	
    return {
        //main function to initiate the module
        init: function () {
		
			Inbox.loadInbox($(this),'inbox',1);
        
			
        },
		HandlePrevPage:function() {
		
				var start_lmt=$('#inbox.inbox-content .pagination-control #pgnt_frst_lmt').text();
					 
				start_lmt=parseFloat(start_lmt)-10;
				
				var type=$('#inbox_head.inbox-header > h1').text();
					type=type.toLowerCase(); 
					Inbox.loadInbox($(this), type,start_lmt)
		},
		HandleNextPage:function() {
		
				var start_lmt=$('#inbox.inbox-content .pagination-control #pgnt_frst_lmt').text();
				
				start_lmt=parseFloat(start_lmt)+10;
				
				var type=$('#inbox_head.inbox-header > h1').text();
					type=type.toLowerCase(); 
					Inbox.loadInbox($(this), type,start_lmt);
		},
		loadCompose : function (el,call_type) {
		
			var url = 'html_modules/inbox_compose.html';
			
			loading.show();
			content.html('');
			toggleButton(el);

			// load the form via ajax
			$.ajax({
				type: "GET",
				cache: false,
				url: url,
				dataType: "html",
				success: function(res) 
				{
					toggleButton(el);
					$('#messages .inbox-nav > li.active').removeClass('active');
					$('#inbox_head.inbox-header > h1').text('Compose');

					loading.hide();
					$('#messages .inbox-content').html(res);
					$('#messages .inbox-compose').on('click', '.mail-to .inbox-cc', function () {
					handleCCInput();
					});
		
					if(call_type=='Compose')
					{
						// initFileupload();
						initWysihtml5();
						$('#inbox .inbox-wysihtml5').focus();
						App.fixContentHeight();
						App.initUniform();
					}
					GetUserLists(el,call_type);
				},
				error: function(xhr, ajaxOptions, thrownError)
				{
					toggleButton(el);
				},
				// async: false
			});
		},
		loadInbox : function (el, name,start_limit) {
			var title = $('#messages .inbox-nav > li.' + name + ' a').attr('data-title');
			listListing = "type="+name;
			listListing += "&start_limit="+start_limit;
		
			$('#messages .inbox-loading').show();
			$('#messages .inbox-content').html('');
			toggleButton(el);
			
		   $.ajax({
				type: "GET",
				// async:false,
				url: $host_url+"GetInboxFileName",
				data: listListing, 			
				success: function(responce) 
				{
					responce = eval('(' + responce + ')');   
					if (responce.error_code == 0)
					{
							toggleButton(el);
							$('#messages .inbox-nav > li.inbox > a').html("Inbox "+responce.data['mgs_cnt_html']);
							$('#messages .inbox-nav > li.active').removeClass('active');
							$('#messages .inbox-nav > li.' + name).addClass('active');
							$('#inbox_head.inbox-header > h1').text(title);

							$('#messages .inbox-loading').hide();
							$('#messages .inbox-content').load(responce.data['message_html']);
							App.fixContentHeight();
							App.initUniform();
					}
				},
				error: function(xhr, ajaxOptions, thrownError)
				{
					toggleButton(el);
				},
				// async: false
			});

			// handle group checkbox:
			jQuery('body').on('change', '.mail-group-checkbox', function () {
				var set = jQuery('.mail-checkbox');
				var checked = jQuery(this).is(":checked");
				jQuery(set).each(function () {
					$(this).attr("checked", checked);
				});
				jQuery.uniform.update(set);
			});
		},
		loadMessage : function (el, message_id, resetMenu) {
		
			var view_from=$.trim($("#messages .inbox-header").text());
			loading.show();
			$('#messages .inbox-content').html('');
			toggleButton(el);
			// var message_id = el.parent('tr').attr("data-messageid");  
			
			$.ajax({
				type: "GET",
				url: $host_url+"ViewMessage",
				data: "message_id="+message_id+"&view_from="+view_from, 		
				success: function(responce) 
				{
					responce = eval('(' + responce + ')');   
					if (responce.error_code == 0)
					{
						toggleButton(el);
						if (resetMenu) {
							$('#messages .inbox-nav > li.active').removeClass('active');
						}
						$('#inbox_head.inbox-header > h1').text('View Message');
						loading.hide();
					
						$('#messages .inbox-nav > li.inbox > a').html("Inbox "+responce.data['mgs_cnt_html']);
						msg_int_code=responce.data['msg_int_code'];
						$('#messages .inbox-content').load(responce.data['message_html'],function(){
						App.fixContentHeight();
						App.initUniform();
						App.init();
						});
					}
				},
				error: function(xhr, ajaxOptions, thrownError)
				{
					toggleButton(el);
				},
				async: false
			});
		},
		SendMessageDetails : function() {
		
			var message = encodeURIComponent(CKEDITOR.instances.inbox_message.getData());
			var subject = $("#inbox #subject").val();
			var to_arr=$("#inbox #compose_to").select2("val");
			var cc_arr=$("#inbox #compose_cc").select2("val");
			 
			if(empty(to_arr))
			{
				alert("Please Enter to address");
				return false;
			} 
			
			if(empty(subject))
			{
				alert("Do you Want to send message without subject");
			}
			
			$('#messages .sending').show();
			$('#messages .inbox-content').html('');
			
			$.ajax({
			type: "POST",
			// async:false,
			url: $host_url+"SendMessageDetails",
			data: "to_arr="+to_arr+"&cc_arr="+cc_arr+"&compose_subject="+subject+"&compose_message="+message, 			
			success: function(responce) 
					{
						responce = eval('(' + responce + ')');   
						if (responce.error_code == 0)
						{
							$('#messages .sending').hide();
							Inbox.loadInbox($(this), 'inbox',1);
							alert("Message Sent Sucessfully");
							
						}
						else
						{
							alert("Sending Message failed");
							return false;
						}	
					}
			 });
		},
		//Handling Multi delete messages
	    deleteMessages : function (){
	
			var msg_ids = $('#inbox .inbox-small-cells input:checkbox:checked').map(function() {
								return this.id;
								}).get();
								
			var current_page=$('#inbox_head.inbox-header > h1').text();
		
			if(empty(msg_ids))
			{
				alert("Please Select atlest one Row to delete ");
				return flase;
			}
			
			$('#messages .delete').show();
			$('#messages .inbox-content').html('');
			
			var delete_from=$.trim($("#inbox_head.inbox-header").text());
			$.ajax({
				type: "POST",
				url : $host_url+"deleteMessages",
				data: "msg_ids="+msg_ids+"&delete_from="+delete_from,
				success :  function (responce) 
							{
								responce = eval('(' + responce + ')');   
								if (responce.error_code == 0)
								{
									$('#messages .delete').hide();
									if(current_page=='Inbox')
										Inbox.loadInbox($(this), 'inbox',1);
									else
										Inbox.loadInbox($(this), 'sent',1);
									alert(responce.data);
										
								}
							}
			});
		},
		loadReply : function (el,call_type) {
			loading.show();
			content.html('');
			toggleButton(el);

			// load the form via ajax
			$.ajax({
				type: "GET",
				cache: false,
				url: $host_url+"replayMesssage",
				data: "msg_int_code="+msg_int_code,
				success: function(responce) 
				{
					responce = eval('(' + responce + ')');   
					if (responce.error_code == 0)
					{
						toggleButton(el);
						$('#messages .inbox-nav > li.active').removeClass('active');
						loading.hide();
						$('[name="message"]').val($('#reply_email_content_body').html());
						initWysihtml5();
						$('#message').val(responce.data['message']);
						$('.inbox-wysihtml5').focus();
						App.fixContentHeight();
						App.initUniform();
						
						if(call_type=='forward')
						{
							$('#inbox #subject').val("Fw: "+responce.data['subject']);
							$('#inbox_head.inbox-header > h1').text('Forward');
						}
						else
						{	
							$('#inbox #subject').val("Re: "+responce.data['subject']);
							$('#inbox_head.inbox-header > h1').text('Reply');
						}
						
						var cc_arr=responce.data['cc_addr_html'].split(",");
						var to_arr=responce.data['to_addr_html'].split(",");
						if(call_type=='Replay')
						{
							$("#inbox #compose_to").select2("val", to_arr);
						}

						if(call_type=='Replay_all')
						{
							$("#inbox #compose_to").select2("val", to_arr);
							$("#inbox #compose_cc").select2("val", cc_arr);
							handleCCInput();
						}
						// $("#compose_to").select2("val", ["admin", "shafeeq_old", "anusuya", "suhas", "shruthi", "ganesh"]);
					}
				},
				error: function(xhr, ajaxOptions, thrownError)
				{
					toggleButton(el);
				}
				// async: false
			});
		}
    };
}();
$g_inbox_init=0;