81 lines
2.9 KiB
JavaScript
81 lines
2.9 KiB
JavaScript
var Taloyhtio_FBAUsersSearch = {
|
|
init: function () {
|
|
$(".site-colls").each(function () {
|
|
var ths = $(this);
|
|
ths.html("Loading...");
|
|
var userName = ths.attr("username");
|
|
var url = Taloyhtio_FBAUsersSearch_CurrentSiteUrl + "/_layouts/15/Taloyhtio/FBA/sitecolls.ashx?op=new&userName=" + userName;
|
|
$.ajax({
|
|
url: url,
|
|
cache: false
|
|
})
|
|
.done(function (res) {
|
|
if (res.IsError) {
|
|
Taloyhtio_FBAUsersSearch.handleError(ths, "Error occured: " + res.ErrorMessage);
|
|
return;
|
|
}
|
|
|
|
var siteColls = res.SiteColls;
|
|
if (siteColls.length == 0) {
|
|
ths.html("<a href='javascript:Taloyhtio_FBAUsersSearch.populateUsingOldMethod(\"" + userName + "\")'>Populate</a>");
|
|
return;
|
|
}
|
|
var content = "";
|
|
for (var i = 0; i < siteColls.length; i++) {
|
|
if (i > 0) {
|
|
content = content.concat("<br/>");
|
|
}
|
|
content = content.concat("<a href='" + siteColls[i] + "' target='_blank'>" + siteColls[i] + "</a>");
|
|
}
|
|
ths.html(content);
|
|
})
|
|
.fail(function () {
|
|
Taloyhtio_FBAUsersSearch.handleError(ths, "Error occured");
|
|
});
|
|
});
|
|
},
|
|
|
|
populateUsingOldMethod: function (userName) {
|
|
var ths = $("span[username='" + userName + "']");
|
|
if (ths.length == 0) {
|
|
return;
|
|
}
|
|
ths.html("Loading...");
|
|
var url = Taloyhtio_FBAUsersSearch_CurrentSiteUrl + "/_layouts/15/Taloyhtio/FBA/sitecolls.ashx?op=old&userName=" + userName;
|
|
$.ajax({
|
|
url: url,
|
|
cache: false
|
|
})
|
|
.done(function (res) {
|
|
if (res.IsError) {
|
|
Taloyhtio_FBAUsersSearch.handleError(ths, "Error occured: " + res.ErrorMessage);
|
|
return;
|
|
}
|
|
|
|
var siteColls = res.SiteColls;
|
|
if (siteColls.length == 0) {
|
|
ths.html("No site collections found");
|
|
return;
|
|
}
|
|
var content = "";
|
|
for (var i = 0; i < siteColls.length; i++) {
|
|
if (i > 0) {
|
|
content = content.concat("<br/>");
|
|
}
|
|
content = content.concat("<a href='" + siteColls[i] + "' target='_blank'>" + siteColls[i] + "</a>");
|
|
}
|
|
ths.html(content);
|
|
})
|
|
.fail(function () {
|
|
Taloyhtio_FBAUsersSearch.handleError(ths, "Error occured");
|
|
});
|
|
},
|
|
|
|
handleError: function (el, errorMessage) {
|
|
el.html("<span class='error'>" + errorMessage + "</span>");
|
|
}
|
|
};
|
|
|
|
$(function () {
|
|
Taloyhtio_FBAUsersSearch.init();
|
|
}); |