Порой бывают случаи, когда у ряда элементов нужно запустить определенный
РП.
Руками такой процесс может занять продолжительное время и
как всегда на помощь приходит PowerShell
SP.UI.Discussions.SortFilterItem.onPivotControlMenuOptionClick('SortItem1')
function getColor(login)
{
var color;
login = login.replace("i:0#.w|domain\\","");
switch(login){
case "Kaplin Vladimir" : color = "red"; break;
case "P Michael" : color = "green"; break;
case "F Pavel" : color = "rgba(254, 164, 0, 1)"; break;
default: color = "rgb(78, 142, 227)"
}
return color;
}
function postRender()
{
data = jQuery("a[href*='.aspx?ID=']");
//обработка ссылок на элементы
var arrayID = []
for (var i=0; i < data.length; i++)
{
var str = data[i].toString();
var start = str.indexOf('?ID=');
var end = str.indexOf('"',start);
if (end == -1){
var id = str.slice(start+4);
}
else{
var id = str.slice(start+4, end+1);
}
arrayID.push("Id eq " + id);
}
//работа с объектами элементов
if (arrayID.length > 0)
{
var getItems = getListItem(arrayID.join(" or "));
getItems.done(function (data, status, xhr) {
var items = data.d.results;
for(var i=0; i < items.length; i++ )
{
var url = String.format("a[href*='.aspx?ID={0}']", items[i].ID)
if(items[i].Editor.Title)
{
console.log(items[i].Editor.Title)
var color = getColor(items[i].Editor.Title)
jQuery(url).closest(".ms-acal-item").css("background-color", color)
};
}
})
getItems.fail(onError)
}
}
function onError(error) {
console.log(error.responseText);
}
function getListItem(itemId) {
var listTitle = "Заявки" // название списка
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var selectFields = ["Id","Title","Editor/Id","Editor/Title"]; // получаемые поля
var expandFields = ["Editor/Id","Editor/Title"]; // поля подстановки
var listItemUri = webUrl + "/_api/web/lists/GetByTitle('"+ listTitle + "')/Items?$filter=" + itemId+ "&$select="+selectFields.join()+"&$expand="+expandFields.join();
request = jQuery.ajax({
url: listItemUri,
type: "GET",
headers: { "accept": "application/json;odata=verbose" }
});
request.done(function (data){console.log('данные REST полученны, объектов - ' + data.d.results.length );});
request.fail(function (){console.log('Ошибка при вылнении запроса REST')});
return request;
}
/* =======================================================================
блок для вызова функции обработки при изменении представления месяц - день
======================================================================*/
function onCalendarGridsRendered(){
setTimeout(function () {
postRender()
}, 100);
}
function onCalendarResized(){
setTimeout(function () {
//Add your functionality here
postRender()
}, 100);
}
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
//Week or Day Calendar View
SP.UI.ApplicationPages.DetailCalendarView.prototype.renderGrids_Old =
SP.UI.ApplicationPages.DetailCalendarView.prototype.renderGrids;
SP.UI.ApplicationPages.DetailCalendarView.prototype.renderGrids =
function SP_UI_ApplicationPages_DetailCalendarView$renderGrids($p0) {
this.renderGrids_Old($p0);
onCalendarGridsRendered();
};
//Month Calendar View
SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids_Old =
SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids;
SP.UI.ApplicationPages.SummaryCalendarView.prototype.renderGrids =
function SP_UI_ApplicationPages_SummaryCalendarView$renderGrids($p0) {
this.renderGrids_Old($p0);
onCalendarGridsRendered();
};
//Resize Calendar
SP.UI.ApplicationPages.CalendarStateHandler.prototype.parentResized_Old =
SP.UI.ApplicationPages.CalendarStateHandler.prototype.parentResized;
SP.UI.ApplicationPages.CalendarStateHandler.prototype.parentResized =
function SP_UI_ApplicationPages_CalendarStateHandler$parentResized() {
this.parentResized_Old();
onCalendarResized();
};
}, "SP.UI.ApplicationPages.Calendar.js");
checkingExistenceFolder("Билеты", "Folder 10")
function checkingExistenceFolder(listTitle, folderTitle)
{
filter = "ContentTypeId eq '0x0120001EE026E991F8644A85A5F2888FADB06D' and Title eq '" + folderTitle +"'";
query = getRest(listTitle,"",filter,"","")
query.done(function (data, status, xhr) {
if(data.d.results.length > 0)
{
console.log(data.d.results.length);
console.log("папка '" + folderTitle + "' найдена ")
}
else{
console.log("папка '" + folderTitle + "' не найдена");
createFolder(listTitle,folderTitle)
}
});
query.fail(function (){
console.log("папка '" + folderTitle + "' не найдена");
});
}
function createFolder(listTitle,folderName)
{
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl + "/_api/web/lists/GetByTitle('"+listTitle+"')/Items/";
console.log(uri);
var getlistType = getListEntityTypeName(listTitle);
getlistType.done(function (data, status, xhr) {
console.log(data.d.EntityTypeName)
var listType = data.d.EntityTypeName
var body = "{ '__metadata': { 'type': 'SP.Data." + listType + "Item' }, 'Title': '" + folderName + "', 'FileLeafRef': '" + folderName + "', 'ContentTypeId': '0x0120001EE026E991F8644A85A5F2888FADB06D'}"
var newItem = addListItem(listTitle, body);
newItem.done (function (data, status, xhr) {
console.log(data)
var newItemId = data.d.Id;
var body = "{ '__metadata': { 'type': 'SP.Data." + listType + "Item' }, 'FileLeafRef': '" + folderName + "' }";
updateListItem(listTitle, newItemId, body);
});
});
}
function addListItem(listTitle,body)
{
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl + "/_api/web/lists/GetByTitle('"+listTitle+"')/Items/";
var query = jQuery.ajax({
url: uri,
type: "POST",
data: body,
contentLength: body.length,
headers: { "accept": "application/json; odata=verbose",
"content-type" : "application/json; odata=verbose",
"X-RequestDigest" : jQuery("#__REQUESTDIGEST").val() }
});
query.done(function (data){ console.log('элемент создан'); console.log(data)
});
query.fail(function (error){console.log('Ошибка при создании элемента'); console.log(error)});
return query;
}
moveListItem( "Билеты", "Folder 10", 26)
function moveListItem( listTitle, folderTitle, itemId)
{
var getlistType = getListEntityTypeName(listTitle);
getlistType.done(function (data, status, xhr) {
console.log(data.d.EntityTypeName)
var listType = data.d.EntityTypeName;
var listInternalName = listType.substring(0, listType.length - 4 )
console.log(listInternalName)
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl+ "/_api/web/getfilebyserverrelativeurl('/Lists/"+ listInternalName + "/" + itemId+ "_.000')/moveto(newurl='/Lists/"+ listInternalName + "/" + folderTitle + "/" + itemId+ "_.000',flags=1)";
var query = jQuery.ajax({
url: uri,
type: "POST",
headers: { "accept": "application/json; odata=verbose",
"content-type" : "application/json; odata=verbose",
"X-RequestDigest" : jQuery("#__REQUESTDIGEST").val()}
});
query.done(function (data){ console.log('элемент создан'); console.log(data) });
query.fail(function (error){console.log('Ошибка при создании элемента'); console.log(error)});
});
}
function getListEntityTypeName(listTitle)
{
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl + "/_api/web/lists/GetByTitle('"+listTitle+"')/EntityTypeName";
var queryAjax = jQuery.ajax({
url: uri,
type: "GET",
headers: { "accept": "application/json; odata=verbose",
"content-type" : "application/json; odata=verbose",
"X-RequestDigest" : jQuery("#__REQUESTDIGEST").val() }
});
queryAjax.done(function (data){ console.log('EntityTypeName полученны'); console.log(data)});
queryAjax.fail(function (){console.log('Ошибка при вылнении запроса EntityTypeName')});
return queryAjax;
}
Если заметили, то мне пришлось еще использовать доп функцию которая возвращает EntityTypeName. в первом случае я его использую для создания папки, а второй раз при перемещении элемента, т.к. нужно указывать путь (Url)
function checkingExistenceFolder(listTitle, folderTitle)
{
filter = "ContentTypeId eq '0x0120001EE026E991F8644A85A5F2888FADB06D' and Title eq '" + folderTitle +"'";
query = getRest(listTitle,"",filter,"","")
query.done(function (data, status, xhr) {
if(data.d.results.length > 0)
{
console.log(data.d.results.length);
console.log("папка '" + folderTitle + "' найдена ")
}
else{
console.log("папка '" + folderTitle + "' не найдена");
createFolder(listTitle,folderTitle)
}
});
query.fail(function (){
console.log("папка '" + folderTitle + "' не найдена");
});
}
function createFolder(listTitle,folderName)
{
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl + "/_api/web/lists/GetByTitle('"+listTitle+"')/Items/";
console.log(uri);
var getlistType = getListEntityTypeName(listTitle);
getlistType.done(function (data, status, xhr) {
console.log(data.d.EntityTypeName)
var listType = data.d.EntityTypeName
var body = "{ '__metadata': { 'type': 'SP.Data." + listType + "Item' }, 'Title': '" + folderName + "', 'FileLeafRef': '" + folderName + "', 'ContentTypeId': '0x0120001EE026E991F8644A85A5F2888FADB06D'}"
var newItem = addListItem(listTitle, body);
newItem.done (function (data, status, xhr) {
console.log(data)
var newItemId = data.d.Id;
var body = "{ '__metadata': { 'type': 'SP.Data." + listType + "Item' }, 'FileLeafRef': '" + folderName + "' }";
updateListItem(listTitle, newItemId, body);
});
});
}
function addListItem(listTitle,body)
{
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl + "/_api/web/lists/GetByTitle('"+listTitle+"')/Items/";
var query = jQuery.ajax({
url: uri,
type: "POST",
data: body,
contentLength: body.length,
headers: { "accept": "application/json; odata=verbose",
"content-type" : "application/json; odata=verbose",
"X-RequestDigest" : jQuery("#__REQUESTDIGEST").val() }
});
query.done(function (data){ console.log('элемент создан'); console.log(data)
});
query.fail(function (error){console.log('Ошибка при создании элемента'); console.log(error)});
return query;
}
function moveListItem( listTitle, folderTitle, itemId)
{
var getlistType = getListEntityTypeName(listTitle);
getlistType.done(function (data, status, xhr) {
console.log(data.d.EntityTypeName)
var listType = data.d.EntityTypeName;
var listInternalName = listType.substring(0, listType.length - 4 )
console.log(listInternalName)
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl+ "/_api/web/getfilebyserverrelativeurl('/Lists/"+ listInternalName + "/" + itemId+ "_.000')/moveto(newurl='/Lists/"+ listInternalName + "/" + folderTitle + "/" + itemId+ "_.000',flags=1)";
var query = jQuery.ajax({
url: uri,
type: "POST",
headers: { "accept": "application/json; odata=verbose",
"content-type" : "application/json; odata=verbose",
"X-RequestDigest" : jQuery("#__REQUESTDIGEST").val()}
});
query.done(function (data){ console.log('элемент создан'); console.log(data) });
query.fail(function (error){console.log('Ошибка при создании элемента'); console.log(error)});
});
}
function updateListItem(listTitle, itemId, body)
{
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl + "/_api/web/lists/GetByTitle('"+listTitle+"')/Items("+ itemId +")";
var query = jQuery.ajax({
url: uri,
type: "POST",
data: body,
contentLength: body.length,
headers: { "accept": "application/json; odata=verbose",
"content-type" : "application/json; odata=verbose",
"X-HTTP-Method":"MERGE",
"IF-MATCH": "*",
"X-RequestDigest" : jQuery("#__REQUESTDIGEST").val() }
});
query.done(function (data){ console.log('элемент обновлен'); console.log(data)
});
query.fail(function (error){console.log('Ошибка при обновлении элемента'); console.log(error)});
return query;
}
function getListEntityTypeName(listTitle)
{
var webUrl = _spPageContextInfo.webAbsoluteUrl;
var uri = webUrl + "/_api/web/lists/GetByTitle('"+listTitle+"')/EntityTypeName";
var queryAjax = jQuery.ajax({
url: uri,
type: "GET",
headers: { "accept": "application/json; odata=verbose",
"content-type" : "application/json; odata=verbose",
"X-RequestDigest" : jQuery("#__REQUESTDIGEST").val() }
});
queryAjax.done(function (data){ console.log('EntityTypeName полученны'); console.log(data)});
queryAjax.fail(function (){console.log('Ошибка при вылнении запроса EntityTypeName')});
return queryAjax;
}
cls
$login = 'i:0#.w|doman\user'
$app = Get-SPWebApplication http://url-app
foreach ($sites in $app.Sites)
{
$collSite = $sites.AllWebs
foreach ($web in $sites.AllWebs)
{
# удаляем из всех групп
foreach($group in $web.Groups)
{
foreach($user in $group.Users )
{
if($user.UserLogin -eq $login)
{
$web.Url
$userRemove = $web.AllUsers.Item($login)
$group.RemoveUser( $userRemove)
Write-Host "Сайт -" $web.Title " / удален из группы -" $group.Name -foregroundcolor Yellow
}
}
}
# удаляем из администраторов сайта
$admins = $web.SiteAdministrators
for ($i = 0 ; $i -le $admins.Count; $i++)
{
if( $admins[$i].UserLogin -eq $login)
{
$web.Url
$userRemove = $web.AllUsers.Item($login)
$admins.RemoveByID( $userRemove.ID)
Write-Host "Сайт -" $web.Title " / удален из администраторов сайта" -foregroundcolor blue
}
}
$web.Dispose();
}
}