This blog explain how to create your own ribbon for sharepoint.
2. Create "Scripts" and "Icons" sub folder in "Layouts" folder.Add Icon to Icons Folder(16x16 and 32x32). Add script to scripts folder.
function showAll() {
var ctx = SP.ClientContext.get_current();var ItemIds = "";
var listId = SP.ListOperation.Selection.getSelectedList();
var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
for (var i = 0; i < selectedItems.length; i++) {
ItemIds += selectedItems[i].id + ",";}
var pageUrl = SP.Utilities.Utility.getLayoutsPageUrl(
'/_layouts/ReportHandler.ashx?id=' + ItemIds + '&listid=' + listId);var options = SP.UI.$create_DialogOptions();
options.width = 520;
options.height = 380;
options.url = pageUrl;
options.dialogReturnValueCallback = Function.createDelegate(null, OnDialogClose);
SP.UI.ModalDialog.showModalDialog(options);
}
function enableAll() {
var ctx = SP.ClientContext.get_current();return SP.ListOperation.Selection.getSelectedItems(ctx).length > 1;
}
function showSingleControlReport() {
debugger;var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var ItemIds = "";
var listId = SP.ListOperation.Selection.getSelectedList();
var selectedItem = SP.ListOperation.Selection.getSelectedItems(ctx)[0];
var pageUrl = '/_layouts/ReportHandler.ashx?id=';
var options = SP.UI.$create_DialogOptions();
options.width = 520;options.height = 380;
options.url = pageUrl + selectedItem.id + '&listid=' + listId+'&rType=itk';
options.dialogReturnValueCallback = Function.createDelegate(null, OnDialogClose);
window.location.href = options.url;
}
function enableSingleControlReport() {
var ctx = SP.ClientContext.get_current();var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);
return selectedItems.length == 1;
}
function OnDialogClose(result, target) {
if (result == SP.UI.DialogResult.OK) {location.reload(true);
}
}
3.Right click your solution and select "new item" tab and then select "Empty Element" on sharepoint tab
4. Set your Element.xml file in "Empy Element" control like this...
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="COB.SharePoint.Ribbon.NewControlInExistingGroup2"
Location="CommandUI.Ribbon.ListView"
RegistrationType="ContentType"
RegistrationId="0x0100EDEEEBA3D546EC4D9C55CADF92A70381">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListItem.Workflow.Controls._children">
<Button Id="COB.SharePoint.Ribbon.NewControlInExistingGroup2.Notify"
Command="COB.Command.NewControlInExistingGroup2.Notify"
Sequence="21"
Image16by16="/_layouts/Icons/word16x16.png"
Image32by32="/_layouts/Icons/word32x32.png"
Description="Uses the notification area to display a message."
LabelText="Raporu İndir"
TemplateAlias="o1"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="COB.Command.NewControlInExistingGroup2.Notify"
EnabledScript="javascript:enableSingleControlReport();"
CommandAction="javascript:showSingleControlReport(); "/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<CustomAction
Id="COB.Command.NewControlInExistingGroup2.Notify.Script"
Location="ScriptLink"
ScriptSrc ="/_layouts/Scripts/CADownloadControlReport.js"/>
</Elements>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="COB.SharePoint.Ribbon.NewControlInExistingGroup2"
Location="CommandUI.Ribbon.ListView"
RegistrationType="ContentType"
RegistrationId="0x0100EDEEEBA3D546EC4D9C55CADF92A70381">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.ListItem.Workflow.Controls._children">
<Button Id="COB.SharePoint.Ribbon.NewControlInExistingGroup2.Notify"
Command="COB.Command.NewControlInExistingGroup2.Notify"
Sequence="21"
Image16by16="/_layouts/Icons/word16x16.png"
Image32by32="/_layouts/Icons/word32x32.png"
Description="Uses the notification area to display a message."
LabelText="Raporu İndir"
TemplateAlias="o1"/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="COB.Command.NewControlInExistingGroup2.Notify"
EnabledScript="javascript:enableSingleControlReport();"
CommandAction="javascript:showSingleControlReport(); "/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<CustomAction
Id="COB.Command.NewControlInExistingGroup2.Notify.Script"
Location="ScriptLink"
ScriptSrc ="/_layouts/Scripts/CADownloadControlReport.js"/>
</Elements>
5.Your custom ribbon is ready to use.You only set your ReportHandler.ashx (may be aspx) page and doing some thing in this page (or handler). You can get selected item id's in your page querystring and do something to listitems where selected in list. You can get selected item id with key of "id" from query string and you can get list id with key of "listid" from query string of page.
Hiç yorum yok:
Yorum Gönder