Untitled

mail@pastecode.io avatar
unknown
javascript
7 months ago
14 kB
5
Indexable
Never
"use strict";
var _siteUrl = "";


let charLimitTitle = 50;
let charLimitDesc = 200;
var commonUrl="";
var _menuList="Menu";

var _listBannerImages ="TopBanner";
var _qucikLinksList = "QuickLinks";
var _quickLinksCollection=[];
var _lstNotice ="Notícias";
var _lstAnniversory = "Anniversory";
var _lstAnnouncement = "Anúncios";
var _lstNoticeCollection = [];
// var _lstGlobeGallery ="GlobeGallery";
var _bannerSliderCollection = [];
var _lstAnniversoryCollection=[];
var _AnnouncementCollection=[];

var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

//var _globalGalleryCollection = [];

$(document).ready(function () {
	debugger;
	document.title = "Home";
	_siteUrl = _spPageContextInfo.siteAbsoluteUrl;

	commonUrl=_siteUrl;
	setInterval(function () {
		UpdateFormDigest(_spPageContextInfo.webServerRelativeUrl, _spFormDigestRefreshInterval);
	}, 20 * 60000);
	SP.SOD.executeFunc('sp.js', 'SP.ClientContext', indexStart);
});

function indexStart() {

	var today = new  Date();

	var urlForParentMenuList = _siteUrl + "/_api/web/lists/GetByTitle('" + _menuList + "')/items?$orderby=Created asc";
	var getParentMenuList = SPRestCommon.GetItemAjaxCall(urlForParentMenuList);


	var urlforBanner = _siteUrl + "/_api/web/lists/GetByTitle('" + _listBannerImages + "')/items?$top=5&$orderby=Created desc";
	var getBannerData = SPRestCommon.GetItemAjaxCall(urlforBanner);

	var urlforQuickLinks = _siteUrl + "/_api/web/lists/GetByTitle('" + _qucikLinksList + "')/items?$top=15&$orderby=Order asc";
	var getQuickLinks = SPRestCommon.GetItemAjaxCall(urlforQuickLinks);

	var urlNotice = _siteUrl + "/_api/web/lists/GetByTitle('" + _lstNotice + "')/items?$top=2&$orderby=Created desc";
	var geturlNotice = SPRestCommon.GetItemAjaxCall(urlNotice);

	var urlforAnniversory = _siteUrl + "/_api/web/lists/GetByTitle('" + _lstAnniversory + "')/items?$select=*";
	var getAnniversory = SPRestCommon.GetItemAjaxCall(urlforAnniversory);

	var urlforAnnouncement = _siteUrl + "/_api/web/lists/GetByTitle('" + _lstAnnouncement + "')/items?$top=2&$orderby=Modified desc";
	var getAnnouncement = SPRestCommon.GetItemAjaxCall(urlforAnnouncement);

		$.when(getBannerData,getQuickLinks,geturlNotice,getParentMenuList,getAnniversory,getAnnouncement)
    .then(function (respBannerData,respQuickLinks,respurlNotice,respParentMenuList,respAnniversory,respAnnouncement) {
		try
		{
			debugger;
			if(respParentMenuList[0].d.results.length>0){
				bindMenus(respParentMenuList[0].d.results);
			}
			 
			if(respBannerData[0].d.results.length>0){
				BindBannerSlider(respBannerData[0].d.results);
			}
			if(respQuickLinks[0].d.results.length>0){
				BindQuickLinks(respQuickLinks[0].d.results);
			}
			

			if(respurlNotice[0].d.results.length>0){
				BindNotice(respurlNotice[0].d.results);
			}

			
			if(respAnniversory[0].d.results.length>0){
				BindAnniversory(respAnniversory[0].d.results);
			}



			if(respAnnouncement[0].d.results.length>0){
				BindAnnouncement(respAnnouncement[0].d.results);
			}

		
		}
		catch (error) {
			console.error(error);
		}

	
	}).fail(CommonUtil.OnRESTError);

}
function bindMenus(menus){
	console.log(menus);
			var output = "";
			if(!!menus){
					var output = "<ul class='navbar-nav mr-auto'>";
					for(let i=0;i<=menus.length-1;i++){
					
					let redirectURL = !!menus[i].RedirectURL?menus[i].RedirectURL:"#";	
					if(i==menus.length)
						break;
					let activeClass="";
					if(i==0)
						activeClass="active";
						output=output+"<li class='nav-item "+activeClass+"'>"+
										"<a class='nav-link' href='"+redirectURL+"'>"+menus[i].Title+"</a>"+
									"</li>";
					}
					output +="</ul>";

					$("#navbarsExample01").append(output);
				}
				else{
					//Do nothing
				}
}




function BindAnniversory(anniversoryCollections)
{
	var _hireDayFinal=[];
	_lstAnniversoryCollection = anniversoryCollections;
	if(!!_lstAnniversoryCollection){
			var activeFlag=false;
		for (let i = 0; i < _lstAnniversoryCollection.length; i++) {

			if(!!_lstAnniversoryCollection[i].AniversaryDate){

				// if(i==_lstAnniversoryCollection.length)
				// 	break;
				// let activeClass="";
				// if(i==0)
				// 	activeClass=" active";
				var activeClass = "";
				let AniversaryDate=_lstAnniversoryCollection[i].AniversaryDate;
				
				let yearAnni = AniversaryDate.split('T')[0].split('-')[0];
				let monthAnni = AniversaryDate.split('T')[0].split('-')[1];
				let dayAnni = AniversaryDate.split('T')[0].split('-')[2];
	
				
				
				let finalHireDayYear = dayAnni+'/'+monthAnni+'/'+yearAnni;
				let _hDate = new Date(finalHireDayYear);
				let _date = _hDate.getDate();
				let _month = months[_hDate.getMonth()];
				let _today = new Date();
				let _dateFormat =  _date + "/" +(_hDate.getMonth()) + "/" + _today.getFullYear();
				let _date_for_day = new Date(_dateFormat);
				let _day = days[_date_for_day.getDay()];
				let _hToday = new Date();
				
				var ageDate="";
				var ageDifMs="";
				_hireDayFinal =[];	
				if(_hToday.getMonth() == _hDate.getMonth())
				{
					ageDifMs = _hToday - _hDate;
					ageDate = new Date(ageDifMs);
					ageDate = Math.abs(ageDate.getUTCFullYear() - 1970);
					
					if(dayAnni==_hToday.getDate()){
						if(!activeFlag){
							activeFlag = true;	
							activeClass=" active";
						}
						
					var Photo = _lstAnniversoryCollection[i].Photo!=null?JSON.parse(_lstAnniversoryCollection[i].Photo):"";
						Photo = !!Photo?Photo.serverUrl + Photo.serverRelativeUrl:"";
					_hireDayFinal.push({
						AniversaryDate: (AniversaryDate.length > 0 ? _day + " - " +  _month + " " + _date : ""),
						Title: (!!_lstAnniversoryCollection[i].Title ? _lstAnniversoryCollection[i].Title: ""),
						Email: (!!_lstAnniversoryCollection[i].Email? _lstAnniversoryCollection[i].Email: ""),
						Photo: Photo, 
						ThisYearHiredDay: dayAnni + "/" +monthAnni
					});
					
					_hireDayFinal.sort((a, b) => (a.ThisYearHiredDay > b.ThisYearHiredDay) ? 1 : -1);
					if(!!_hireDayFinal[0]){
							$("#divAnniversory").append("<div class='carousel-item"+activeClass+"'>"+
                                                    "<div class='aniversary_panel'>"+
                                                        "<div class='achievementblock'>"+
                                                            "<div class='profilepic'>"+
                                                          "<img src='"+_hireDayFinal[0].Photo+"' class='img-fluid' alt='...' />"+
                                                            "</div>"+
                                                            "<div class='titleprofile'>"+_hireDayFinal[0].Title+"</div>"+
                                                            "<div class='date_info'>"+_hireDayFinal[0].ThisYearHiredDay+"</div>"+
                                                        "</div>"+
                                                    "</div>"+
                                                "</div>");
						}
					}
					

					
				}
				

			}
			
				
		}
	}

			
		
}

function BindNotice(noticeCollections)
{
	_lstNoticeCollection = noticeCollections;
	try {
		var eachNoticeContent = "";
		for (let i = 0; i < _lstNoticeCollection.length; i++) {
			let eachNoticeItem = _lstNoticeCollection[i];
			var Title = !!eachNoticeItem.Title ? SlicingNoticeTitle(eachNoticeItem.Title):"";
			var NoticeContent = !!eachNoticeItem.NoticeContent ? SlicingNoticeDesc(eachNoticeItem.NoticeContent):"";
			var NoticeImage = eachNoticeItem.NoticeImage!=null?JSON.parse(eachNoticeItem.NoticeImage):"";
			NoticeImage = !!NoticeImage?NoticeImage.serverUrl + NoticeImage.serverRelativeUrl:"";
			var NoticePostDate = !!eachNoticeItem.NoticePostDate ? getFormattedDate(eachNoticeItem.NoticePostDate):"";
			var detailPage = commonUrl+"/Pages/NoticeDetailPage.aspx?ItemID="+eachNoticeItem.Id;
			let NoticeContentTest=$("<div></div>").append(NoticeContent);
			eachNoticeContent +="<a href='"+detailPage+"'>"+
						"<div class='btn-brc-tp border-2 bgc-white btn-outline-blue btn-h-outline-blue btn-a-outline-blue w-100 my-2 py-3 shadow-sm noticePadding'>"+ 
								"<div class='row'>"+
									"<div class='imgnotictflex' >"+
																"<div class='imageblock'>"+
												"<img src='"+NoticeImage+"' class='imgrouce' alt='...' />"+
												"</div>"+
											
												"<div class='noticdate'>"+
													"<div>"+
														"<p style='color: darkgray;'><b>"+SlicingTitle(Title)+"</b></p>"+
													"</div>"+
													"<div class='noticdescribtion'>"+
														"<p style='color:darkgray !important;'>"+SlicingDescription(NoticeContent)+"</p>"+
													"</div>"+
													"<div>"+
														//"<p style='font-size: 12px;'>"+NoticePostDate+"</p>"+
													"</div>"+
													
																							
												"</div>"+
												
									"</div>"+
								"</div>"+
							"</div></a>";

										

												
		}
		$("#divNoticeSection").append(eachNoticeContent);
		
	} catch (error) {
		console.error(error);
	}
}
function getFormattedDate(supplyDateTime) {
	const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
	let current_datetime = new Date(supplyDateTime);
	var formatted_date = ('0' + current_datetime.getDate()).slice(-2) + " " + months[current_datetime.getMonth()] + " " + current_datetime.getFullYear();
	return formatted_date;
}

function BindBannerSlider(bannerCollections)
{
	_bannerSliderCollection = bannerCollections;
	var OuterSlider="";
			var SliderData="";
			var SliderNavigation="";
			var SliderIndicators="";
			
			
			for(var i=0; i<_bannerSliderCollection.length; i++){
				var BannerImage = _bannerSliderCollection[i].BannerImage!=null?JSON.parse(_bannerSliderCollection[i].BannerImage):"";
				BannerImage = !!BannerImage?BannerImage.serverUrl + BannerImage.serverRelativeUrl:"";
				let quicklink = _bannerSliderCollection[i].RedirectURL!=null?_bannerSliderCollection[i].RedirectURL.Url:"#";
									
				if(i==4)
					break;
				let activeClass="";
				if(i==0)
					activeClass="active";
				SliderData=SliderData+"<div class='carousel-item "+activeClass+"'>"+
																"<a href="+quicklink+">"+
																	"<img src='"+ BannerImage +"' class='d-block w-100 img-fluid' alt='...'>"+
																"</a>"+
															"</div>";
			}
			
			OuterSlider=SliderData;
			$("#BannerSlider").append(OuterSlider);
}

function BindQuickLinks(quickLinksCollection){
	try {
		debugger;
		_quickLinksCollection = quickLinksCollection;
		var eachQuickContent = "";
		for (let i = 0; i < _quickLinksCollection.length; i++) {
			
			let eachQuickItem = _quickLinksCollection[i];
			let quicklink = eachQuickItem.RedirectURL!=null?eachQuickItem.RedirectURL.Url:"#";
			var IconPath = eachQuickItem.IconPath!=null?JSON.parse(eachQuickItem.IconPath):"";
			IconPath = !!IconPath?IconPath.serverUrl + IconPath.serverRelativeUrl:"";
			var QucikItemTitle = !!eachQuickItem.Title ? eachQuickItem.Title:"";
			                       
			eachQuickContent=eachQuickContent+ "<div class='col-md-4'>"+
																						"<div class='administrationpanel'>"+
																							"<a class='btn btn-info' href='"+quicklink+"'  role='button'>"+
																								"<img class='documentimage' src='"+IconPath+"' alt='...' />"+QucikItemTitle+
																							"</a>"+
																						"</div>"+
																					"</div>";

		}
		$("#quickLinkSection").append(eachQuickContent);
		
	} catch (error) {
		console.error(error);
	}
}



function BindAnnouncement(announcementCollections)
{
	_AnnouncementCollection = announcementCollections;
	var OuterSlider="";
			var SliderData="";
			var SliderNavigation="";
			var SliderIndicators="";

			for(var i=0; i<_AnnouncementCollection.length; i++){
				var Image = _AnnouncementCollection[i].Image!=null?JSON.parse(_AnnouncementCollection[i].Image):"";
				Image = !!Image?Image.serverUrl + Image.serverRelativeUrl:"";
				var detailPage = commonUrl+"/Pages/AnnouncementDetails.aspx?ItemID="+_AnnouncementCollection[i].Id;
				SliderData=SliderData+"<div class='imgcont1'>"+
											"<a href='"+detailPage+"'>"+
											"<img class='d-block img-fluid' src='"+Image+"' alt='First slide'>"+
											"</a>"+
											"<div class='news_describtion'>"+
						"<div class='date_news'><h4>"+getFormattedDate(_AnnouncementCollection[i].AnnouncementDate)+"</h4></div>"+
											"</div>"+
										"</div>";

									
									
			}
			
			OuterSlider=SliderData;
			$("#divAnnouncement").append(OuterSlider);

		
		
}
function SlicingTitle(srcStr) {
	if(srcStr)
		return srcStr.slice(0, 100);
	else
		return "";
}
function SlicingNoticeTitle(srcStr) {
	if(srcStr)
		return srcStr.slice(0, 70);
	else
		return "";
}

function SlicingNoticeDesc(srcStr) {
	if(srcStr)
		return srcStr.slice(0, 198);
	else
		return "";
}

function SlicingDescription(srcStr) {
	if(srcStr)
		return srcStr.slice(0, 200);
	else
		return "";
}

function GetMonthName(monthNumber) {
	var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	return months[monthNumber - 1];
}