var CurrentUrl = "";
var SiteUrl = "";
var queryLimit = 4000;
$(document).ready(function () {
if (document.getElementById("NavegacionPQ") != null) {
setNavigationNodes();
}
}
);
function setNavigationNodes() {
SiteUrl = _spPageContextInfo.webAbsoluteUrl;
var Modulos = getModulesNode();
PaintMainNodes(Modulos);
$("#NavegacionAuxiliarPQ").prop("style", "position:absolute");
if (document.location.href.indexOf('NewForm.aspx') == -1 && document.location.href.indexOf('EditForm.aspx') == -1 && document.location.href.indexOf('DispForm.aspx') == -1) {
PaintIconos();
}
}
function PaintMainNodes(Nodes) {
$("#NavegacionPrincipalPQ").prop("style", "display:flex;");
for (var i = 0; i < Nodes.length; i++) {
if (Nodes[i].Tipo == "Enlace" || Nodes[i].Tipo == "") {
$("#NavegacionPrincipalPQ").append("
" + $(Nodes[i]).attr("Titulo") + "
");
}
}
}
function SetNavegacion(Modulo) {
$("#NavegacionPQ").empty();
$("#NavegacionAuxiliarPQ1").empty();
$("#NavegacionAuxiliarPQ2").empty();
var List = [];
var EnableSearch = true;
if (sessionStorage.getItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl) != null) {
List = JSON.parse(sessionStorage.getItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl));
}
else {
var Method = "GetListItems";
var ListName = "NavegacionNodos";
var Fields = "" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
var Query = "" + Modulo + "";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
List = [];
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var Record = {
URL: $(this).attr("ows_Link"),
Image: $(this).attr("ows_Imagen"),
Titulo: $(this).attr("ows_Title"),
Tipo: ($(this).attr("ows_TipoNodo") == "" || $(this).attr("ows_TipoNodo") == undefined) ? "" : $(this).attr("ows_TipoNodo"),
Modulo: $(this).attr("ows_Modulo"),
Hijo: ($(this).attr("ows_ModuloHijo") == "" || $(this).attr("ows_ModuloHijo") == undefined) ? "" : $(this).attr("ows_ModuloHijo"),
NombreCorto: ($(this).attr("ows_NombreCorto") == "" || $(this).attr("ows_NombreCorto") == undefined) ? "" : $(this).attr("ows_NombreCorto"),
NuevaPestanya: ($(this).attr("ows_NuevaPestanya") == "1") ? true : false,
EnlaceExterno: ($(this).attr("ows_EnlaceExterno") == "1") ? true : false,
};
List.push(Record);
});
}
});
sessionStorage.setItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl, JSON.stringify(List));
}
PaintNodes(List, "NavegacionPQ");
}
function SetNavegacionAuxiliar(Modulo, nivel) {
if (Modulo != "") {
if (nivel == 2) { $("#NavegacionAuxiliarPQ2").empty(); }
else { $("#NavegacionAuxiliarPQ1").empty(); $("#NavegacionAuxiliarPQ2").empty(); }
var List = [];
var EnableSearch = true;
if (sessionStorage.getItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl) != null) {
List = JSON.parse(sessionStorage.getItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl));
}
else {
var Method = "GetListItems";
var ListName = "NavegacionNodos";
var Fields = "" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
var Query = "" + Modulo + "";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
List = [];
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var Record = {
URL: $(this).attr("ows_Link"),
Image: $(this).attr("ows_Imagen"),
Titulo: $(this).attr("ows_Title"),
Tipo: ($(this).attr("ows_TipoNodo") == "" || $(this).attr("ows_TipoNodo") == undefined) ? "" : $(this).attr("ows_TipoNodo"),
Modulo: $(this).attr("ows_Modulo"),
Hijo: ($(this).attr("ows_ModuloHijo") == "" || $(this).attr("ows_ModuloHijo") == undefined) ? "" : $(this).attr("ows_ModuloHijo"),
NombreCorto: ($(this).attr("ows_NombreCorto") == "" || $(this).attr("ows_NombreCorto") == undefined) ? "" : $(this).attr("ows_NombreCorto"),
NuevaPestanya: ($(this).attr("ows_NuevaPestanya") == "1") ? true : false,
EnlaceExterno: ($(this).attr("ows_EnlaceExterno") == "1") ? true : false,
};
List.push(Record);
});
}
});
sessionStorage.setItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl, JSON.stringify(List));
}
PaintNodes(List, "NavegacionAuxiliarPQ" + nivel);
}
}
function PaintNodes(Nodes, selector) {
for (var i = 0; i < Nodes.length; i++) {
var Action = "", Pestanya = "", Externo = "";
switch (selector) {
case "NavegacionPQ":
Action = "onclick='javascript:SetNavegacionAuxiliar("" + $(Nodes[i]).attr("Hijo") + "",1)'";
$("#NavegacionPQIconos").css("margin-top", "4em");
break;
case "NavegacionAuxiliarPQ1":
Action = "onclick='javascript:SetNavegacionAuxiliar("" + $(Nodes[i]).attr("Hijo") + "",2)'";
if (i == 0) { $("#" + selector).append("
"); }
$("#NavegacionPQIconos").css("margin-top", "7em");
break;
case "NavegacionAuxiliarPQ2":
if (i == 0) {
$("#" + selector).append("
");
$("#" + selector).append("
");
}
$("#NavegacionPQIconos").css("margin-top", "9em");
break;
}
$("#" + selector).prop("style", "display:flex");
var titulo = "";
($(Nodes[i]).attr("NombreCorto") == "") ? titulo = $(Nodes[i]).attr("Titulo") : titulo = $(Nodes[i]).attr("NombreCorto");
var enlace = "#";
var replace = "";
if ($(Nodes[i]).attr("EnlaceExterno") == true) {
enlace = '"' + $(Nodes[i]).attr("URL") + '"';
}
else {
replace = "navigationReplace";
enlace = '"' + SiteUrl + $(Nodes[i]).attr("URL") + '"';
}
if (i == 0) {
Action = "onclick='window.location= " + enlace + "'";
$("#" + selector).append("" + titulo + "
");
}
else {
if ($(Nodes[i]).attr("Hijo") == "") {
if ($(Nodes[i]).attr("NuevaPestanya") == true) {
Action = "onclick='window.open(" + enlace + ")'";
}
else {
Action = "onclick='window.location=" + enlace + "'";
}
}
$("#" + selector).append("" + titulo + "
");
}
}
disableNavButtons();
}
function getModulesNode() {
var Modulo = "";
var Modules = [];
var Nodos = [];
if (sessionStorage.getItem("NavegacionPrincipal" + "_" + _spPageContextInfo.webServerRelativeUrl) != null) {
Nodos = JSON.parse(sessionStorage.getItem("NavegacionPrincipal" + "_" + _spPageContextInfo.webServerRelativeUrl));
}
else {
var Method = "GetListItems";
var ListName = "NavegacionNodos";
var Fields = "" +
"" +
"" +
"" +
"" +
"";
var Query = "1";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var Record = {
URL: $(this).attr("ows_Link"),
Titulo: $(this).attr("ows_Title"),
Modulo: $(this).attr("ows_Modulo"),
Tipo: ($(this).attr("ows_TipoNodo") == "" || $(this).attr("ows_TipoNodo") == undefined) ? "" : $(this).attr("ows_TipoNodo"),
};
Nodos.push(Record);
})
}
});
sessionStorage.setItem("NavegacionPrincipal" + "_" + _spPageContextInfo.webServerRelativeUrl, JSON.stringify(Nodos));
}
console.log("Nodos: " + Nodos)
return Nodos;
}
function PaintIconos() {
$("#ContentArea").prop("style", "margin:15px auto 40px")
if (document.location.href.indexOf('SitePages') > -1) {
CurrentUrl = document.location.href;
}
else {
var url = document.location.href.split('.aspx')[0].split('/');
var vista = url[url.length - 1];
CurrentUrl = document.location.href.split("/" + vista + ".aspx")[0].replace("/Forms", "");
}
var Nodes = getNavigationNodes(CurrentUrl.split(SiteUrl)[1]);
for (var i = 0; i < Nodes.length; i++) {
var replace = "";
if (Nodes[i].EnlaceExterno != true) { replace = "navigationReplace"; }
if (i == 0) {
$("#NavegacionPQIconos").append("")
}
else {
if (Nodes[i].Tipo == "Enlace" || Nodes[i].Tipo == "") {
if ($(Nodes[i]).attr("URL") == decodeURI(CurrentUrl.split(SiteUrl)[1])) {
$("#NavegacionPQIconos").append("")
}
else {
var tempLink = "";
if (Nodes[i].EnlaceExterno == true) { tempLink = $(Nodes[i]).attr("URL") + "' target='_blank"; }
else { tempLink = SiteUrl + $(Nodes[i]).attr("URL"); }
$("#NavegacionPQIconos").append("")
}
}
else if (Nodes[i].Tipo == "Calendario") {
var calendarLink = GetCalendarURL(Nodes[i]);
$("#NavegacionPQIconos").append("")
}
}
}
disableNavButtons();
}
function getNavigationNodes(relativeURL) {
var Modulo = "";
var Method = "GetListItems";
var ListName = "NavegacionNodos";
var Fields = "" +
"" +
"";
var Query = "" + decodeURI(relativeURL) + "0";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
$(xData.responseXML).SPFilterNode("z:row").each(function () {
Modulo = $(this).attr("ows_Modulo");
console.log("Modulo: " + Modulo);
});
}
});
var List = [];
var EnableSearch = true;
if (sessionStorage.getItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl) != null) {
List = JSON.parse(sessionStorage.getItem("Navegacion" + Modulo + "_" + _spPageContextInfo.webServerRelativeUrl));
}
else {
var Method = "GetListItems";
var ListName = "NavegacionNodos";
var Fields = "" +
"" +
"" +
"" +
"" +
"";
var Query = "" + Modulo + "";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
List = [];
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var Record = {
URL: $(this).attr("ows_Link"),
Image: $(this).attr("ows_Imagen"),
Titulo: $(this).attr("ows_Title"),
Tipo: ($(this).attr("ows_TipoNodo") == "" || $(this).attr("ows_TipoNodo") == undefined) ? "" : $(this).attr("ows_TipoNodo"),
};
List.push(Record);
});
}
});
//sessionStorage.setItem("Navegacion"+Modulo+"_"+_spPageContextInfo.webServerRelativeUrl, JSON.stringify(List));
}
return List;
}
function GetCalendarURL(Nodo) {
var SiteURL = _spPageContextInfo.webAbsoluteUrl;
var ListURL = Nodo.URL;
var ListGUID = "";
var SiteName = _spPageContextInfo.webTitle;
var ListName = "";
var Method = "GetListItems";
var ListName = "GUIDS";
var Fields = "" +
"" +
"" +
"" +
"";
var Query = "" + ListURL + "";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLRowLimit: queryLimit,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
$(xData.responseXML).SPFilterNode("z:row").each(function () {
ListGUID = $(this).attr("ows_Clave");
ListName = $(this).attr("ows_Title");
});
}
});
var link = "stssync://sts/?ver=1.1&type=calendar&cmd=add-folder&base-url=" + encodeURIComponent(SiteURL) + "&list-url=" + encodeURIComponent(ListURL) + "&guid=" + encodeURIComponent("{" + ListGUID + "}") + "&site-name=" + encodeURIComponent(SiteName) + "&list-name=" + encodeURIComponent(ListName);
return link;
}
/* Des-habilita los botones en caso de que no exista su Link */
function disableNavButtons() {
var i = 0;
var elemEnlaces = $('[class*="navigationReplace"]');
var siteAbsoluteUrl = _spPageContextInfo.webAbsoluteUrl;
if (elemEnlaces.length > 0) {
var allLists;
var allPages;
if (sessionStorage.getItem("allLists" + "_" + _spPageContextInfo.webServerRelativeUrl) != null && sessionStorage.getItem("allPages" + "_" + _spPageContextInfo.webServerRelativeUrl)) {
allPages = JSON.parse(sessionStorage.getItem("allPages" + "_" + _spPageContextInfo.webServerRelativeUrl));
allLists = JSON.parse(sessionStorage.getItem("allLists" + "_" + _spPageContextInfo.webServerRelativeUrl));
}
else {
var SitepagesGUID = "";
devolverListas(["SitePagesLog"], false, function (guids) { SitepagesGUID = guids[0] })
allPages = []
if (SitepagesGUID != "SitePagesLog") { allPages = getAllSitePages(); }
else { return; }
allLists = getAllLists();
sessionStorage.setItem("allPages" + "_" + _spPageContextInfo.webServerRelativeUrl, JSON.stringify(allPages));
sessionStorage.setItem("allLists" + "_" + _spPageContextInfo.webServerRelativeUrl, JSON.stringify(allLists));
}
for (linkCount = 0; linkCount < elemEnlaces.length; linkCount++) {
var Exists = false;
var link = elemEnlaces[linkCount];
var linkURL = "";
if ($(link).prop("tagName") == "A") {
linkURL = link.attributes['href'].value.trim().replace(siteAbsoluteUrl, '');
}
else if ($(link).prop("tagName") == "DIV") {
linkURL = link.attributes['data-href'].value.trim().replace(siteAbsoluteUrl, '');
}
// Check.
if (linkURL.indexOf('SitePages/') > -1) {
for (pageCount = 0; pageCount < allPages.length; pageCount++) {
if (allPages[pageCount].RelativeURL.toLowerCase().trim().replace(/ /g, "%20") == linkURL.toLowerCase().trim().replace(/ /g, "%20")) { Exists = true; }
}
} else if (linkURL.indexOf('Lists/') > -1) {
for (guidCount = 0; guidCount < allLists.length; guidCount++) {
if (allLists[guidCount].RelativeURL.toLowerCase().trim().replace(/ /g, "%20") == linkURL.toLowerCase().trim().replace(/ /g, "%20")) { Exists = true; }
}
} else {
// Biblioteca.
for (guidCount = 0; guidCount < allLists.length; guidCount++) {
if (allLists[guidCount].RelativeURL.toLowerCase().trim().replace(/ /g, "%20") == linkURL.toLowerCase().trim().replace(/ /g, "%20").replace("/forms", "")) { Exists = true; }
}
}
// Disable.
if (Exists != true) {
$(link).closest('div').remove();
}
}
}
}
/* Recupera la información de la lista GUIDS */
function getAllLists() {
var List = [];
var EnableSearch = true;
var StartID = 0;
var Method = "GetListItems";
var ListName = "GUIDS";
var Fields = "" +
"" +
"" +
"" +
"";
var Query = "" + StartID + "";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLRowLimit: queryLimit,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var Record = {
ID: parseInt($(this).attr("ows_ID")),
Title: (($(this).attr("ows_Title") != undefined) ? $(this).attr("ows_Title") : ''),
Clave: (($(this).attr("ows_Clave") != undefined) ? $(this).attr("ows_Clave") : ''),
RelativeURL: (($(this).attr("ows_RelativeURL") != undefined) ? $(this).attr("ows_RelativeURL") : ''),
};
List.push(Record);
});
// Ask for more
EnableSearch = false;
if ($(xData.responseXML).SPFilterNode("z:row").length >= queryLimit) {
StartID += queryLimit;
EnableSearch = true;
}
}
});
return List;
}
/* Recupera la información de la lista GUIDS */
function getAllSitePages() {
var List = [];
var EnableSearch = true;
var StartID = 0;
var Method = "GetListItems";
var ListName = "SitePagesLog";
var Fields = "" +
"" +
"" +
"" +
"";
var Query = "" + StartID + "";
$().SPServices({
operation: Method,
async: false,
listName: ListName,
CAMLRowLimit: queryLimit,
CAMLViewFields: Fields,
CAMLQuery: Query,
completefunc: function (xData, Status) {
// Get Data
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var Record = {
ID: parseInt($(this).attr("ows_ID")),
Title: (($(this).attr("ows_Title") != undefined) ? $(this).attr("ows_Title") : ''),
Clave: (($(this).attr("ows_Clave") != undefined) ? $(this).attr("ows_Clave") : ''),
RelativeURL: (($(this).attr("ows_RelativeURL") != undefined) ? $(this).attr("ows_RelativeURL") : ''),
};
List.push(Record);
});
// Ask for more
EnableSearch = false;
if ($(xData.responseXML).SPFilterNode("z:row").length >= queryLimit) {
StartID += queryLimit;
EnableSearch = true;
}
}
});
return List;
}