 /*+*******************************************************************************
 * The content of this file is subject to the CRMTiger Pro license.
 * ("License"); You may not use this file except in compliance with the License
 * The Initial Developer of the Original Code is vTiger
 * The Modified Code of the Original Code owned by https://crmtiger.com/
 * Portions created by CRMTiger.com are Copyright(C) CRMTiger.com
 * All Rights Reserved.
  ***************************************************************************** */

jQuery(document).ready(function () {
	
	count = 0;
	var url = "index.php?module=CTMobileSettings&action=chkPermission&mode=GetRequirement";
	var params = {};
	params['module'] = 'CTMobileSettings';
	params['action'] = 'chkPermission';
	params['mode'] = 'GetRequirement';
	
	AppConnector.request(params).then(
		  function(data){
			count = data.result.count;
			var is_admin = data.result.is_admin;
			if(is_admin){
				if(count > 0){
					 var bgColor='FF0000';
					 var title = app.vtranslate('Click here to access CRMTiger Module Apps for vtiger Dashboard');
					 var msg = app.vtranslate('Extension installation has not been completed.');
					 var btntext = app.vtranslate('Complete Install');
					 var btn='<button class="btn btn-danger" style="margin-right:5px;" onclick="location.href=\'index.php?module=CTMobileSettings&parent=Settings&view=Details&mode=step1\'">'+btntext+'</button>';
					 var VTPremiumIcon = '<span class="dropdown span settingIcons" title="'+title+'">';
									 VTPremiumIcon += '<a class="dropdown-toggle" data-toggle="dropdown" href="#">';
									 VTPremiumIcon += '<img style="width:auto; height:auto; border-radius:0%;" src="layouts/vlayout/modules/CTMobileSettings/img/CRMTiger.png" >';
									 VTPremiumIcon += '</a>';
									 VTPremiumIcon += '<ul class="dropdown-menu pull-right" style="width: 100px">';
									 VTPremiumIcon += '<li style="padding-left: 10px; padding-right: 20px;">'+msg+'</li>';
									 VTPremiumIcon += '<li class="divider"></li>';
									 VTPremiumIcon += '<li style="text-align: center">'+btn+'</li>';
									 VTPremiumIcon += '</ul>';
									 VTPremiumIcon += '</span>';

						var headerIcons=document.getElementById('headerLinksBig');
						if(headerIcons){
							headerIcons.innerHTML = VTPremiumIcon + headerIcons.innerHTML ;
						}
				}else{
					var params = {};
					params['module'] = 'CTMobileSettings';
					params['action'] = 'chkPermission';
					params['mode'] = 'GetLicense';
					
					AppConnector.request(params).then(
					  function(data){
							if(data.result === 0){
								 var bgColor='FFFF00';
								 var title = app.vtranslate('Click here to access CRMTiger Module Apps for vtiger Dashboard');
								 var msg = app.vtranslate('License Key Setup has not been completed.');
								 var btntext = app.vtranslate('Setup License Key');
								 var btn='<button class="btn btn-warning" style="margin-right:5px;" onclick="location.href=\'index.php?module=CTMobileSettings&parent=Settings&view=LicenseDetail\'">'+btntext+'</button>';
								 var VTPremiumIcon = '<span class="dropdown span settingIcons" title="'+title+'">';
									 VTPremiumIcon += '<a class="dropdown-toggle" data-toggle="dropdown" href="#">';
									 VTPremiumIcon += '<img style="width:auto; height:auto; border-radius: 0%;" src="layouts/vlayout/modules/CTMobileSettings/img/CRMTiger.png" >';
									 VTPremiumIcon += '</a>';
									 VTPremiumIcon += '<ul class="dropdown-menu pull-right" style="width: 100px">';
									 VTPremiumIcon += '<li style="padding-left: 10px; padding-right: 20px;">'+msg+'</li>';
									 VTPremiumIcon += '<li class="divider"></li>';
									 VTPremiumIcon += '<li style="text-align: center">'+btn+'</li>';
									 VTPremiumIcon += '</ul>';
									 VTPremiumIcon += '</span>';

								var headerIcons=document.getElementById('headerLinksBig');
								if(headerIcons){
									headerIcons.innerHTML = VTPremiumIcon + headerIcons.innerHTML ;
								}
							}else{
								 var bgColor='008000';
								 var title = app.vtranslate('Click here to access CRMTiger Module Apps for vtiger Dashboard');
								 var msg = app.vtranslate('License Key Setup and Extension Installation has been completed.');
								 var btntext = app.vtranslate('CRMTiger Apps Dashboard');
								 var btn='<button class="btn btn-success" style="margin-right:5px;" onclick="location.href=\'index.php?module=CTMobileSettings&parent=Settings&view=Details\'">'+btntext+'</button>';
								 var VTPremiumIcon = '<span class="dropdown span settingIcons" title="'+title+'">';
									 VTPremiumIcon += '<a class="dropdown-toggle" data-toggle="dropdown" href="#">';
									 VTPremiumIcon += '<img style="width:auto; height:auto; border-radius:0%;" src="layouts/vlayout/modules/CTMobileSettings/img/CRMTiger.png" >';
									 VTPremiumIcon += '</a>';
									 VTPremiumIcon += '<ul class="dropdown-menu pull-right" style="width: 100px">';
									 VTPremiumIcon += '<li style="padding-left: 10px; padding-right: 20px;">'+msg+'</li>';
									 VTPremiumIcon += '<li class="divider"></li>';
									 VTPremiumIcon += '<li style="text-align: center">'+btn+'</li>';
									 VTPremiumIcon += '</ul>';
									 VTPremiumIcon += '</span>';

								var headerIcons=document.getElementById('headerLinksBig');
								if(headerIcons){
									headerIcons.innerHTML = VTPremiumIcon + headerIcons.innerHTML ;
								}
								
							}
					});
				}	
			}
	});
	
	jQuery('#popupPageContainer').find('.CTNonAddressEntries').on('click',function(){
        var id = jQuery(this).attr('data-id');
        var module =  jQuery('#popupPageContainer').find('#SOURCE_MODULE').val();
        var url = 'index.php?module='+module+'&view=Detail&record='+id;
        window.open(url,'_blank');
    });
			
});

