Get all Sharepoint site collection groups and Delete them using custom ui.
<script type="text/javascript" src="/SiteAssets/Tabs/jquery.min.js"></script>
<style type="text/css" rel="stylesheet">
a:visited{ color: gray }
delete:visited{ color: gray }
#delete{
color:red;
}
</style>
<script type="text/javascript" language="javascript">
var webs;
function loadWebs() {
var clientContext = SP.ClientContext.get_current();
this.webs = clientContext.get_site().get_rootWeb().get_webs();
clientContext.load(this.webs);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onWebsLoaded), Function.createDelegate(this, this.onQueryFailed));
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
var grpdescription2 = "Description.";
function onWebsLoaded(sender, args) {
for (var i = 0; i < this.webs.get_count(); i++) {
var sitetitle = this.webs.itemAt(i).get_title();
var url = this.webs.itemAt(i).get_serverRelativeUrl();
var itemid = replacespecialitems(url);
jQuery("#data").append(" <li id='"+itemid+"'><table><tr><td class='ms-vb'><a href='/_layouts/Deletesite.aspx'>" +sitetitle +"</a> </td><td> "+url +"</td><td> <a id='noSub ""+itemid+""' href='javascript:;' onclick='javascript:DeleteSubWeb( ""+url+"" )' > Delete Web sites </a> </td></tr></table></li>");
}
}
function replacespecialitems( url){
// to escape special charecters. wright ur own
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
return url;
}
//var subwebs;
var selectedweb ="",currentweburl="";
function GetallWebs( relurl){
currentweburl = relurl;
selectedweb = replacespecialitems(relurl);
//var CurrentclientContext = SP.ClientContext.get_current(relurl);
var CurrentclientContext = new SP.ClientContext(relurl);
this.subwebs = CurrentclientContext.get_web().get_webs();
CurrentclientContext.load(this.subwebs);
CurrentclientContext.executeQueryAsync(Function.createDelegate(this, this.onSubWebsLoaded), Function.createDelegate(this, this.onQueryFailed));
}
function onSubWebsLoaded(){
var count = this.subwebs.get_count();
if(count > 0){
jQuery( "#"+selectedweb).append("<ul id='"+selectedweb+"sub'></ul>>");
for (var i = 0; i < this.subwebs.get_count(); i++){
var subtitle = this.subwebs.itemAt(i).get_title();
var subsiteurl = this.subwebs.itemAt(i).get_url();
jQuery( "#"+selectedweb+"sub").append("<li><a href='/_layouts/Deletesite.aspx'>" +subtitle +"</a> <a>"+subsiteurl +"</a> <span><a id='delete' href='javascript:;' onclick='javascript:DeleteSubWeb(""+subsiteurl+"" )'> Delete Web </a></span></li>");
}
}
else{
currentweburl
jQuery("#noSub"+selectedweb).append("<a onclick='javascript:DeleteSubWeb(""+currentweburl+"" )'> Delete this web </a>");
}
currentweburl="";
selectedweb="";
}
function DeleteSubWeb(loc){
var clientContext = new SP.ClientContext(loc);
var oweb = clientContext.get_web();
oweb.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSubWebDeleted), Function.createDelegate(this, this.onQueryFailed));
}
function onSubWebDeleted(){
console.log("Web deleted successfully.");
}
ExecuteOrDelayUntilScriptLoaded(loadWebs, "sp.js");
</script>
<div>
<ul id="data">
</ul>
</div>
<script type="text/javascript" src="/SiteAssets/Tabs/jquery.min.js"></script>
<style type="text/css" rel="stylesheet">
a:visited{ color: gray }
delete:visited{ color: gray }
#delete{
color:red;
}
</style>
<script type="text/javascript" language="javascript">
var webs;
function loadWebs() {
var clientContext = SP.ClientContext.get_current();
this.webs = clientContext.get_site().get_rootWeb().get_webs();
clientContext.load(this.webs);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onWebsLoaded), Function.createDelegate(this, this.onQueryFailed));
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
var grpdescription2 = "Description.";
function onWebsLoaded(sender, args) {
for (var i = 0; i < this.webs.get_count(); i++) {
var sitetitle = this.webs.itemAt(i).get_title();
var url = this.webs.itemAt(i).get_serverRelativeUrl();
var itemid = replacespecialitems(url);
jQuery("#data").append(" <li id='"+itemid+"'><table><tr><td class='ms-vb'><a href='/_layouts/Deletesite.aspx'>" +sitetitle +"</a> </td><td> "+url +"</td><td> <a id='noSub ""+itemid+""' href='javascript:;' onclick='javascript:DeleteSubWeb( ""+url+"" )' > Delete Web sites </a> </td></tr></table></li>");
}
}
function replacespecialitems( url){
// to escape special charecters. wright ur own
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace("/","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
url = url.replace(" ","_");
return url;
}
//var subwebs;
var selectedweb ="",currentweburl="";
function GetallWebs( relurl){
currentweburl = relurl;
selectedweb = replacespecialitems(relurl);
//var CurrentclientContext = SP.ClientContext.get_current(relurl);
var CurrentclientContext = new SP.ClientContext(relurl);
this.subwebs = CurrentclientContext.get_web().get_webs();
CurrentclientContext.load(this.subwebs);
CurrentclientContext.executeQueryAsync(Function.createDelegate(this, this.onSubWebsLoaded), Function.createDelegate(this, this.onQueryFailed));
}
function onSubWebsLoaded(){
var count = this.subwebs.get_count();
if(count > 0){
jQuery( "#"+selectedweb).append("<ul id='"+selectedweb+"sub'></ul>>");
for (var i = 0; i < this.subwebs.get_count(); i++){
var subtitle = this.subwebs.itemAt(i).get_title();
var subsiteurl = this.subwebs.itemAt(i).get_url();
jQuery( "#"+selectedweb+"sub").append("<li><a href='/_layouts/Deletesite.aspx'>" +subtitle +"</a> <a>"+subsiteurl +"</a> <span><a id='delete' href='javascript:;' onclick='javascript:DeleteSubWeb(""+subsiteurl+"" )'> Delete Web </a></span></li>");
}
}
else{
currentweburl
jQuery("#noSub"+selectedweb).append("<a onclick='javascript:DeleteSubWeb(""+currentweburl+"" )'> Delete this web </a>");
}
currentweburl="";
selectedweb="";
}
function DeleteSubWeb(loc){
var clientContext = new SP.ClientContext(loc);
var oweb = clientContext.get_web();
oweb.deleteObject();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSubWebDeleted), Function.createDelegate(this, this.onQueryFailed));
}
function onSubWebDeleted(){
console.log("Web deleted successfully.");
}
ExecuteOrDelayUntilScriptLoaded(loadWebs, "sp.js");
</script>
<div>
<ul id="data">
</ul>
</div>
No comments:
Post a Comment