/* quickAccessLink component, write logic of quickAccessLink module in this class */
var quickAccessLink = new Component("quickAccessLink");
app.registerComponent(quickAccessLink);
quickAccessLink.on( "load", function(){
	var self = this;
//	return this.render(
//			"template/qlink.html",
//			"qucikLink",
//			{}
//	).pipe(function(){
//		var dtdList = [];
//		if(app.user.role.checkAdminRole() == "admin1"){
//			dtdList.push(self.trigger("loadAdmin1"));
//			$("#linkInsightsDiv").hide();
//		} else if(app.user.role.checkAdminRole() == "admin2") {
//			dtdList.push(self.trigger("loadAdmin2"));
//			$("#linkGeneralDiv").hide();
//		}else {
//			dtdList.push(self.trigger("loadAdmin1"));
//			dtdList.push(self.trigger("loadAdmin2"));			
//		}
//		
//		return $.when.apply(null, dtdList);
//		
//	});
	var dtdList = [];
	app.doAjaxRequest = true;
	var admin1Roles = $("#qucikLink").attr("wmd_role");
	var admin2Roles = $("#quickLinkAdmin2").attr("wmd_role");
	if (app.user.role.checkRole(admin1Roles)){
	//if(app.user.role.checkAdminRole() == "admin1"){
		dtdList.push(self.trigger("loadAdmin1"));
		$("#linkInsightsDiv").hide();
	} 
	if (app.user.role.checkRole(admin2Roles)) {
	//} else if(app.user.role.checkAdminRole() == "admin2") {
		dtdList.push(self.trigger("loadAdmin2"));
		$("#linkGeneralDiv").hide();
	}//else {
	//	dtdList.push(self.trigger("loadAdmin1"));
	//	dtdList.push(self.trigger("loadAdmin2"));			
	//}
	
	return $.when.apply(null, dtdList).done(function(){
		app.doAjaxRequest = false;
	});
});

quickAccessLink.on("loadAdmin1", function(){
	var currentAdmin1Page = this.currentAdmin1Page || 1;

	return this.render(
		"template/qlink.html",
		"qucikLink",
		"quickAccessLink/" + "admin1/" + "list/" + lang.currentLang + "/" + currentAdmin1Page + "?pageSize=" + app.QUICK_ACCESS_LINK_PAGESIZE
	).done(function(template, data){		
		var pageHtml = genPaginationFooter(data.pagination,"quickAccessLink.changeAdmin1Page");
		$("#qucikLink #linkPagination").append(pageHtml);
		$("#qucikLink").find(".QlinklintTitle").html(lang.getMessage('managerLinkGeneral'));
		$("#qucikLink").css({"min-height":"50px"});
		trackAction("QLinkGeneral - Visit");
	
	});
});

quickAccessLink.on("loadAdmin2", function(){
	var currentAdmin2Page = this.currentAdmin2Page || 1;
	return this.render(
			"template/qlink.html",
			"quickLinkAdmin2",
			"quickAccessLink/" + "admin2/" + "list/" + lang.currentLang + "/" + currentAdmin2Page + "?pageSize=" + app.QUICK_ACCESS_LINK_PAGESIZE
	).done(function(template, data){
		var pageHtml = genPaginationFooter(data.pagination,"quickAccessLink.changeAdmin2Page");
		$("#quickLinkAdmin2 #linkPagination").append(pageHtml);
		$("#quickLinkAdmin2").find(".QlinklintTitle").html(lang.getMessage('managerLinkMarketInsights'));
		$("#quickLinkAdmin2").css({"min-height":"50px"});
		trackAction("QLinkMarketInsights - Visit");
	});
});

quickAccessLink.on("admin1ChangePage", function(){
    var divHeight = $("#qucikLink #linkMainText").get(0).clientHeight;
    $("#qucikLink #linkMainText").css({"min-height":divHeight+"px"});
	return this.render(
		"template/qlinkTemp.html",
		"qucikLink #linkMainText",
		"quickAccessLink/" + "admin1/" + "list/" + lang.currentLang + "/" + quickAccessLink.currentAdmin1Page + "?pageSize=" + app.QUICK_ACCESS_LINK_PAGESIZE
	).done(function(template,data){
		var pageHtml = genPaginationFooter(data.pagination,"quickAccessLink.changeAdmin1Page");
		$("#qucikLink #linkPagination").empty().append(pageHtml);
		$("#qucikLink #linkMainText").css({"min-height":"50px"});
	});
});

quickAccessLink.on("admin2ChangePage", function(){
    var divHeight = $("#quickLinkAdmin2 #linkMainText").get(0).clientHeight;
    $("#quickLinkAdmin2 #linkMainText").css({"min-height":divHeight+"px"});
	return this.render(
		"template/qlinkTemp.html",
		"quickLinkAdmin2 #linkMainText",
		"quickAccessLink/" + "admin2/" + "list/" + lang.currentLang + "/" + quickAccessLink.currentAdmin2Page + "?pageSize=" + app.QUICK_ACCESS_LINK_PAGESIZE
	).done(function(template,data){
		var pageHtml = genPaginationFooter(data.pagination,"quickAccessLink.changeAdmin2Page");
		$("#quickLinkAdmin2 #linkPagination").empty().append(pageHtml);
		$("#quickLinkAdmin2 #linkMainText").css({"min-height":"50px"});
		
	});
});

quickAccessLink.changeAdmin1Page = function(pageNumber){
	quickAccessLink.currentAdmin1Page = pageNumber;
	quickAccessLink.trigger("admin1ChangePage");
	trackAction("QLinkGeneral - ChangePage");
};

quickAccessLink.changeAdmin2Page = function(pageNumber){
	quickAccessLink.currentAdmin2Page = pageNumber;
	quickAccessLink.trigger("admin2ChangePage");
	trackAction("QLinkMarketInsights - ChangePage");
};
