2016-05-16 3 views
0

Я получаю, что это сработает, если я выберу конкретный список, чтобы добавить действие. Есть ли простой способ включить это настраиваемое действие во все библиотеки документов во всем sitecollection?Список SharePoint UserCustomAction, В целом sitecollection

Пример кода:

function createUserCustomActionList() { 
    var cmd = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" + 
     "<Button Id=\"DiaryAction.Button\" TemplateAlias=\"o1\" Command=\"DiaryCommand\" CommandType=\"General\" LabelText=\"Dela flera\" Image32by32=\"https://eolusvind.sharepoint.com/sites/intranet/_layouts/15/1033/Images/formatmap32x32.png?rev=23\"" + 
    " Image32by32Top=\"-271\" Image32by32Left=\"-109\" />" + 
     "</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" + 
      "<CommandUIHandler Command =\"DiaryCommand\" CommandAction=\"javascript:alert('Hej');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 1;\" />" + 
    "</CommandUIHandlers></CommandUIExtension>"; 

    var ctx = new SP.ClientContext.get_current(); 
    var list = ctx.get_web().get_lists().getByTitle('Dokument'); 
    var uca = list.get_userCustomActions(); 

    var oUserCustomAction = uca.add(); 
    oUserCustomAction.set_location('CommandUI.Ribbon.ListView'); 
    oUserCustomAction.set_commandUIExtension(cmd); 
    oUserCustomAction.set_sequence(100); 
    oUserCustomAction.set_title('Dela flera'); 
    oUserCustomAction.update(); 

    ctx.load(list, 'Title' ,'UserCustomActions'); 

    ctx.executeQueryAsync(function() { 
     alert('Custom action created for ' + list.get_title()) 
    }, function (sender, args) { 
     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
    }); 
} 

ответ

0

Я хотел бы предложить следующий подход к регистрации пользовательской кнопки в библиотеках Документы по коллекции сайта:

  • использование RegistrationType комплект для 2 (ContentType) и RegistrationId набор до 0x0101 (для типа контента Document) для регистрации пользовательских действий по типу содержимого
  • использовать сайт области действия пользователя настраиваемое действие, чтобы применить изменения по всей площадке коллекции

Пример

var cmd = "<CommandUIExtension>" + 
"<CommandUIDefinitions>" + 
"<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" + 
"<Button Id=\"ClickAction.Button\" TemplateAlias=\"o1\" Command=\"ViewCustomPropertiesCommand\" CommandType=\"General\" LabelText=\"View Custom Properties\" Image32by32=\"/_layouts/15/1033/Images/formatmap32x32.png?rev=23\" Image32by32Top=\"-1\" Image32by32Left=\"-171\" />" + 
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" + 
"<CommandUIHandler Command =\"ViewCustomPropertiesCommand\" CommandAction=\"javascript:console.log('View Custom Properties');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 0;\" />" + 
"</CommandUIHandlers>" + 
"</CommandUIExtension>"; 

var ctx = new SP.ClientContext.get_current(); 
var customAction = ctx.get_site().get_userCustomActions().add(); //1. apply via site scope user custom action 
customAction.set_location('CommandUI.Ribbon.ListView'); 
customAction.set_commandUIExtension(cmd); 
customAction.set_sequence(112); 
customAction.set_registrationType(2); //2.set to ContentType 
customAction.set_registrationId("0x0101"); //2.set Document content type 
//customAction.set_title('Document custom button'); 
customAction.update(); 

ctx.executeQueryAsync(function() { 
    console.log('Button has been registered'); 
}, function (sender, args) { 
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
}); 
+1

Nice Вадим! Я пытался загрузить пользовательские свойства с объекта «Сайт», но я не использовал registertype или registrationID. Большое спасибо! – simon

Смежные вопросы