quarta-feira, Julho 30, 2014

How to create Custom Ribbon Button to Move Documents in Library with Metadata/versions

This article is follow up from my last article "OneNote Custom Actions to support Create/Move Pages and Sections and conversion to Folder in SharePointwith a new feature "Move document in Library" Ribbon Action.

This Feature gives to users the ability to manage documents in a very easy way using a tree Dialog of folders from the Document Library and maintain the Metadata/versions associated.

Here the final output of the solution,


One thing i didn't like in my last article was the ability to manage documents. The "Drag and Drop" feature from SharePoint 2013 is a GREAT feature, but users aren't that skillful about managing documents in folders and they get confused very easily.  
Like i show in my last video you can count a loot of steps to move documents from one folder to another even using the drag and drop option and this is what i am trying to avoid.

There is another Out of Box tool call "Site Content and Structure Feature" that does this and a lot more but i don't want to use a cannon to kill a fly.... 

Site Content and Structure Feature

This great Out of the Box feature from SharePoint already exist for some years and gives users the ability to manage items or Document across the Site Collection, but this option just exist when Web Content Management is activated and with SharePoint Standard license, no to SharePoint Foundation and this is the reason why i created this feature, is more limited (Only move documents in current Document Library folders to preserve the Metadata) but responds my needs without to much clicks. 

Pre-Conditions:
You need to have SharePoint Standard license then you should activate the following feature:

  • Site collection features
    • Activate "SharePoint Server Publishing Infrastructure"
  • Manage site features
    • Activate "SharePoint Server Publishing"

After activated you can access in the foloowing path

Site Settings > Site Administration > Content and structure



To support this option, was used the SharePoint Out of the Box Method "LaunchPickerTreeDialogSelectUrl" already discuss in early articles.

Here are some links that support me in this article:
OneNote Custom Actions to support Create/Move Pages and Sections and conversion to Folder in SharePoint
http://aaclage.blogspot.ch/2014/07/onenote-custom-actions-to-support.html
SharePoint 2013: Manage Site/Web/Lists/Folder Filter using Picker Tree Dialog (LaunchPickerTreeDialogSelectUrl )

http://aaclage.blogspot.ch/2014/02/sharepoint-2013-manage-siteweb-lists.html
SharePoint 2013 App - Manage List Threshold (Moving Multiple Documents in Folders) Office365/ On-premise
http://aaclage.blogspot.ch/2014/02/sharepoint-2013-app-manage-list.html
SharePoint App Processlynx Custom Action and Ribbon Manager Launch
http://aaclage.blogspot.ch/2014/06/sharepoint-app-processlynx-custom.html

How solution "Move document in Library" Works

This solution creates a new Ribbon call "Move document in Library" in all templates of Document Libraries and is enabled when a document is selected.


When the Ribbon "Move document in Library" is enabled you are able to select the option.
This option opens a dialog box of the Library and his folders and sub folder "same behavior when users uploads documents to a specific folder".
This dialog box give the ability to select the folder where the document will be moved.


After select OK in the dialog box the document will be moved to the selected Subfolder as shown in the image without losing Metadata or versions.

How was configured(Implementation)

To configured this funcionalities i used the Processlynx Custom Action & Ribbon Manager for the customizations of the Ribbon and Actions associated and everything was made using Javascript and JSOM.
But you can also use Visual Studio declarative XML, JSOM or REST Custom Actions from SharePoint.

This code was tested in Office 365 Enviroment and Internet Explorer Browser 11.

With Processlynx Custom Action & Ribbon Manager

This SharePoint App Manage the CustomActions in the HostWeb in a very eficient and user friendly way.
For more info about the tool here a link


This options was configured in my last article OneNote Custom Actions to support Create/Move Pages and Sections and conversion to Folder in SharePoint and was given a new option in the Custom Action "OneNote Ribbon Support".


Configure "Move document in Library" Ribbon

LocationRibbon.Documents.Manage

Enable Script Code:

javascript: var EnableDisableItem = function() {
 this.clientContext = SP.ClientContext.get_current();
 this.selectedItems = SP.ListOperation.Selection.getSelectedItems(this.clientContext);
 if (selectedItems.length==1)
 {
if (selectedItems[0].fsObjType == 0)
{return true;}
else 
{return false;}
 }
 if (selectedItems.length!=1)
 {return false;}
 };
 EnableDisableItem();

Action Script Code:

javascript:
function loadScript(url, callback){
    var script = document.createElement("script");
    script.type = "text/javascript";
    if (script.readyState){
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" || script.readyState == "complete"){
                script.onreadystatechange = null;callback();
            }};
    } else {
        script.onload = function(){callback();};
    }
    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
getWebProperties();
}
function LaunchTargetPicker(WebId,ListId,RootFolderList) {
var values = SP.ListOperation.Selection.getSelectedItems();
    var callback = function (dest) {
        if (dest != null && dest != undefined && dest[3] != null) {MoveItems(dest[3],values,ListId,RootFolderList);}
    };
ListId.replace("{", "");
ListId.replace("}", "");
    var iconUrl = "/_layouts/15/images/smt_icon.gif?rev=32";
SP.SOD.executeFunc('pickertreedialog.js', 'LaunchPickerTreeDialogSelectUrl', function () {
        LaunchPickerTreeDialogSelectUrl('CbqPickerSelectListTitle', 'CbqPickerSelectListText', 'websListsFolders', 'SPList:'+ListId+'?SPWeb:'+WebId+':', _spPageContextInfo.siteAbsoluteUrl, '', '', '', iconUrl, '', callback, 'true', '');
    });
}
function getWebProperties() {
        var ctx = new SP.ClientContext.get_current();
        var web = ctx.get_web();
        ctx.load(web,'Id');
        ctx.executeQueryAsync(function(){getListRootUrl(web.get_id(),'{ListId}')},Function.createDelegate(this, this.error));
    }
function getListRootUrl(WebID,ListId){
ListId.replace("{", "");
ListId.replace("}", "");
var ctx = new SP.ClientContext.get_current();
        var targetList = ctx.get_web().get_lists().getById(ListId);
var RootFolderList = targetList.get_rootFolder();
        ctx.load(RootFolderList, 'ServerRelativeUrl'); ctx.executeQueryAsync(function(){LaunchTargetPicker(WebID,ListId,RootFolderList)},Function.createDelegate(this, this.error));
}

function MoveItems(SelectedFolder,SelectedItem,ListId,RootFolderList) {
    Items = SelectedItem;
ListId.replace("{", "");
ListId.replace("}", "");
    var ctx = new SP.ClientContext.get_current();  
var targetList = ctx.get_web().get_lists().getById(ListId);    
    var currentItem = targetList.getItemById(Items[0].id);
    var file = currentItem.get_file();
    ctx.load(file, 'Name');
    ctx.executeQueryAsync(function(){
try {
if (file != null) {
var _destinationlibUrl;
if (SelectedFolder == "/")
{ _destinationlibUrl = RootFolderList.get_serverRelativeUrl()+ SelectedFolder + file.get_name(); }
else {
_destinationlibUrl = RootFolderList.get_serverRelativeUrl()+ SelectedFolder +"/"+ file.get_name();
}
file.moveTo(_destinationlibUrl, SP.MoveOperations.allowBrokenThickets);
ctx.executeQueryAsync(function(){SP.UI.Notify.addNotification('File moved', false);SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);}, Function.createDelegate(this, this.error));
}
} catch (e) {
alert(e.message);
}
}, Function.createDelegate(this, this.error));
}
function MoveFileHandler(SelectedFolder,file,RootFolderList) {
 }
 function error(sender,args){
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
 }
loadScript(_spPageContextInfo.webAbsoluteUrl+"/_layouts/15/pickertreedialog.js", function(){}); 

Here a simple Form of the configuration:


Configure with SharePoint REST/JSOM or Declarative XML

For the Custom Ribbon/Actions you can include the Custom Ribbon Action with the following XML Structure example:

<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIDefinitions>
<CommandUIDefinition Location="<Add Location>.Controls._children">
<Button Id="My Custom Button" LabelText="<Add LabelText>" Image32by32="/_layouts/15/1033/images/formatmap32x32.png?rev=33" Image32by32Left="-305" Image32by32Top="-169" ToolTipTitle="<Add TooltipTile>" Command="<Add ID>.Command" TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="<Add ID>.Command" CommandAction="<Add action Code here>" EnabledScript="<Add validation Code here>" />
</CommandUIHandlers>
</CommandUIExtension>

For the REST call you can use the following link
For SharePoint JSOM call you can use the following link

Video


Support Links:
OneNote Custom Actions to support Create/Move Pages and Sections and conversion to Folder in SharePoint
http://aaclage.blogspot.ch/2014/07/onenote-custom-actions-to-support.html
SharePoint 2013: Manage Site/Web/Lists/Folder Filter using Picker Tree Dialog (LaunchPickerTreeDialogSelectUrl )

http://aaclage.blogspot.ch/2014/02/sharepoint-2013-manage-siteweb-lists.html
SharePoint 2013 App - Manage List Threshold (Moving Multiple Documents in Folders) Office365/ On-premise
http://aaclage.blogspot.ch/2014/02/sharepoint-2013-app-manage-list.html
SharePoint App Processlynx Custom Action and Ribbon Manager Launch
http://aaclage.blogspot.ch/2014/06/sharepoint-app-processlynx-custom.html

Hope you like this article,
Kind regards,
André Lage

quarta-feira, Julho 23, 2014

OneNote Custom Actions to support Create/Move Pages and Sections and conversion to Folder in SharePoint

This simple article is about OneNote documents and SharePoint integrations and what can be done to created, support and manage OneNote Document in SharePoint enviroment, in this case Document Library types.
This solution create custom Ribbons action and Custom Menu Item to create OneNote Document and manipulate the content of the OneNote and move to other OneNote documents.

This solution has 2 Ribbon Actions "New OneNote Document" to generate new OneNote Documents and "Convert to OneNote/Folder" where is made the manipulation of OneNote document to move their content.

This article has the following topics
  • Description of the Solution (Business case)
  • Implementation of the Solution in SharePoint Enviroment (Developers or IT Administrators).

PS:yep everything (code, video and article) was made in 1 hour, then is a simple article....

Here some links talking about this and some code associated:
http://modery.net/creating-onenote-notebooks-in-sharepoint-via-jsom/ 
http://aaronsaikovski.wordpress.com/2013/12/06/create-a-folder-and-set-the-progid-programmatically-using-the-sharepoint-2013-csom/
http://aaclage.blogspot.ch/2014/04/how-to-use-progid-in-sharepoint-custom.html

Here is the Custom Actions to manage OneNote Documents:



Here a little description of the Custom Actions and what are doing.

New OneNote Document

This Ribbon option give the option to create a New OneNote Document using the Out of the Box Ribbon Area associated with Document Library.



After the name of the document is selected the file is included in the Document Library.





Convert to OneNote/Folder

This option give the option to user to manipulate the content of OneNote Document, since OneNote is a folder with multiple other documents like ".one" documents, this option gives the option to users to grab the content of the OneNote Document and move to other OneNote Documents as shown in the Video bellow.

PS: For this example i rename the OneNote Document to "OneExample"



You can use the custom Menu item option called "Convert to OneNote/Folder", both will do the same task 
PS:the image bellow has different name because was used for other example purpose to show the option in the Menu item. 



After selecte the option the OneNote Document is converted to Folder and are able to see the support documents for the OneNote.

With the Folder option activated, users are able to access to content of OneNote and can move Sections/Pages (.one files) aggregated in the OneNote document to another folder or other OneNote document as shown in the video bellow in the article.
After make the change and move of content you can convert Convert to OneNote Document again using 


After you select the option the convertion of the documet is done and returns to the old format "" 



How was configured(Implementation)

To configured this funcionalities i used the Processlynx Custom Action & Ribbon Manager for the customizations of the Ribbon and Actions associated.
But you can also use Visual Studio declarative XML or REST Custom Actions from SharePoint.

With Processlynx Custom Action & Ribbon Manager

This SharePoint App Manage the CustomActions in the HostWeb in a very eficient and user friendly way.
For more info about the tool here a link



 Include CommandUI.Ribbon for Custom Ribbon Actions

Was created 2 Ribbon Actions called "New OneNote Document" and "Convert to OneNote/Folder".
This Custom Action will create new OneNote Document and Convert the OneNote Document to Folder.




Configure "New OneNote Document"

This option will open a prompt option where you can add the name of the OneNote documet, after this a folder is created and ProgId is changed to "OneNote.Notebook".

Location: Ribbon.Documents.New

Action Script Code:

javascript: function AddOneNoteDocument() { 
var Doc = prompt("Name of OneNote Document", "");
var context=SP.ClientContext.get_current(); 
var web=context.get_web();
var lists=web.get_lists();
var list=lists.getById('{ListId}');

var itemCreationInfo=new SP.ListItemCreationInformation();
itemCreationInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
itemCreationInfo.set_leafName(Doc);

var onenoteNotebook=list.addItem(itemCreationInfo);
onenoteNotebook.set_item("HTML_x0020_File_x0020_Type" ,"OneNote.Notebook");
onenoteNotebook.update();

context.load(onenoteNotebook);
context.executeQueryAsync(function(){alert('One Note Created!');SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);},function(sender,args){ alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);});
};

AddOneNoteDocument();

Here a simple Form of the configuration:

Configure "Convert to OneNote/Folder"

This option will became enable when one folder or OneNote document is selected. When the option is selected Folder became a OneNote document or OneNote document became a Folder.

Location: Ribbon.Documents.Manage

Enable Script Code:

javascript: var EnableDisable = function() {
 this.clientContext = SP.ClientContext.get_current();
 this.selectedItems = SP.ListOperation.Selection.getSelectedItems(this.clientContext);
 if (selectedItems.length==1)
 {
if (selectedItems[0].fsObjType == 1)
{return true;}
else 
{return false;}
 }
 if (selectedItems.length!=1)
 {return false;}
 };

 EnableDisable();

Action Script Code:

javascript: function runCode(GetListid){  
var values = SP.ListOperation.Selection.getSelectedItems();   
var clientContext = new SP.ClientContext.get_current();  
var targetList = clientContext.get_web().get_lists().getById(GetListid);  
var targetListItem = targetList.getItemById(values[0].id);  
clientContext.load(targetListItem, 'HTML_x0020_File_x0020_Type');  
clientContext.executeQueryAsync(function(){
if (targetListItem.get_item('HTML_x0020_File_x0020_Type')=="OneNote.Notebook")
{
if (confirm("Do you want to convert OneNote document to Folder?") == true) {
       ConvertToFormat('{ListId}','');
    } 
}
else{if (confirm("Do you want to convert Folder to OneNote document?") == true) {
    ConvertToFormat('{ListId}','OneNote.Notebook');
} };
},function(sender,args){ alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());});
}
function ConvertToFormat(GetListid,Format){
var clientContext = new SP.ClientContext.get_current();  
var values = SP.ListOperation.Selection.getSelectedItems(); 
var oList = clientContext.get_web().get_lists().getById(GetListid);
    var oListItem = oList.getItemById(values[0].id);
    oListItem.set_item('HTML_x0020_File_x0020_Type', Format);
    oListItem.update();
clientContext.executeQueryAsync(function(){alert('Convertion finish!');SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
},function(sender,args){ alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());});

}runCode('{ListId}');

Here a simple Form of the configuration:



 Include EditControlBlock

This option will include a new Menu item Option where you are able to make the same action as  "Convert to OneNote/Folder".

Include in the URL Action the following Script:

javascript:var GetListID=' {ListId} ';function ConvertToFormat(n,t){var i=new SP.ClientContext.get_current,u=SP.ListOperation.Selection.getSelectedItems(),f=i.get_web().get_lists().getById(n.trim()),r=f.getItemById(u[0].id);r.set_item("HTML_x0020_File_x0020_Type",t);r.update();i.executeQueryAsync(function(){alert("Convertion finish!");SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK)},function(n,t){alert("Request failed. "+t.get_message()+"\n"+t.get_stackTrace())})}function runCode(n){var r=SP.ListOperation.Selection.getSelectedItems(),t=new SP.ClientContext.get_current,u=t.get_web().get_lists().getById(n.trim()),i=u.getItemById(r[0].id);t.load(i,"HTML_x0020_File_x0020_Type");t.executeQueryAsync(function(){i.get_item("HTML_x0020_File_x0020_Type")=="OneNote.Notebook"?confirm("Do you want to convert OneNote document to Folder?")==!0&&ConvertToFormat(GetListID,""):confirm("Do you want to convert Folder to OneNote document?")==!0&&ConvertToFormat(GetListID,"OneNote.Notebook")},function(n,t){alert("Request failed. "+t.get_message()+"\n"+t.get_stackTrace())})}runCode(GetListID.trim());

Here a simple Form of the configuration:



Configure with SharePoint REST/JSOM or Declarative XML

For the Custom Ribbon/Actions you can include the Custom Ribbon Action with the following XML Structure example:

<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIDefinitions>
<CommandUIDefinition Location="<Add Location>.Controls._children">
<Button Id="My Custom Button" LabelText="My Custom Button" Image32by32="/_layouts/15/1033/images/formatmap32x32.png?rev=33" Image32by32Left="-168" Image32by32Top="-68" ToolTipTitle="My Custom Button" Command="My Custom Button.Command" TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="My Custom Button.Command" CommandAction="<Add action Code here>" EnabledScript="<Add validation Code here>" />
</CommandUIHandlers>
</CommandUIExtension>

For the REST call you can use the following link
For SharePoint JSOM call you can use the following link


Video of the Configuration

Link references:


Hope you enjoy the simple article, 
Kind regards, 
Andre Lage

terça-feira, Julho 15, 2014

Processlynx Team Organization Chart launch in Office Store

After the launch of the SharePoint App Processlynx Ribbon Manager a new App was launch in Microsoft Office Store call Processlynx Team Organization Chart.

This app allows content managers to create an organization chart to visually display structures of e.g. teams or business units. The organization chart can include contact details of each member, is exportable to e.g. Microsoft Outlook.

The goal of the app is to create a simple Organization chart that try to focus  specific groups/team or projects that is not described in the organization of the company or in the UserProfiles of the company and they want to show who they are. 
This Organization chart app is for presentation purposes.

The App provides a App part where you can add in the SharePoint site to display the Organization Chart, also gives the ability to zoom the chart when a lots of nodes are display in the app Part.

This App is base in SharePoint-Hosted and uses REST and HTML5 to create the Organization chart.

The app "Processlynx Team Organization Chart" can be found in Microsoft Office Store in the following link:
http://office.microsoft.com/en-us/store/processlynx-team-organization-chart-WA104365892.aspx


Here are some screenshoots of the Processlynx Organization Chart App.







Here are some videos of the SharePoint App on how you can manage and configure the App.

This app show how we can configure the nodes and dependencies and include the App Part in the SharePoint Site to present the Organization Chart in the SharePoint Site.




This Video shows how the App interacts with the Look and feel of the SharePoint Site to maintain the integrity in Site as one.


Here a presentation of the "Processlynx Team Organization Chart"


Hope you like this article, 
Kind regards, 
André Lage

segunda-feira, Julho 07, 2014

How to Enable/Disable Ribbon Buttons by User using EnabledScript and REST Code

Hi all, 

This article is again an oldie but a nice one to remember about the Ribbons (since SP 2010) and how we can manage their visibility. I am not saying nothing new because there are a lot of content about this topic on internet that can be used in your solution also this one (there are really good stuff and yes i am lazy...) to include in my business case "Disable Ribbons to specific user using EnabledScript".


This example creates a Custom Ribbon that visibility should be define to a specific user.
The solution uses EnabledScript with REST calls to indentify current user and enable/disable the Ribbon. 

Since i use RibbonManager App interface to create/manage/deletion/recycleBin of Custom Actions and complex XML structure, this give more focus to developers response the real business needs with their code.
There the RibbonManager App is helper to reduce time in a very boring task of XML configuration (some XML take hours...) and if you can do it in 5 minutes your life can be more easy and you become more efficient....   :)
Another thing from the RibbonManager App SharePoint App, don't need Farm or Sandbox deployments, uses the SharePoint App Model to work with Office365 and SharePoint On-premise 2013, this can take out the time to create IQ documents and discussions with IT Managers for approval of your Solution. :)

Here is the final output:





About code related, 
There is a lot of documentation talking about this topic EnabledScript in Ribbons you should read about to support your developmenthere are a small list of articles :
CommandUIHandler Element
http://msdn.microsoft.com/en-us/library/office/ff458385(v=office.15).aspx
Asynchronously Checking if a Command is Available in the SharePoint Ribbon
http://www.andrewconnell.com/blog/Asynchronously-Checking-if-a-Command-is-Available-in-the-SharePoint-Ribbon
Code example for EnabledScript element in Ribbon XML
http://henrikfromsweden.blogspot.ch/2010/11/code-example-for-enabledscript-elemnt.html
Using RefreshCommandUI with the Server Ribbon (Dallas Tester, Fred Mameri)
http://blogs.msdn.com/b/sharepointdev/archive/2011/02/17/using-refreshcommandui-with-the-server-ribbon.aspx
Customizing the ribbon (part 1) – creating tabs, groups and controls
http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html
Sample code: Asynchronously checking if a Ribbon command is available
http://blog.mastykarz.nl/sample-code-asynchronously-checking-ribbon-command/
Enable or disable custom ribbon button in SharePoint 2010
http://tomaszrabinski.pl/wordpress/2012/02/25/enable-or-disable-custom-ribbon-button-in-sharepoint-2010/

About the creation of the Custom Ribbon structure was associated the Registration type Document Libraries ID -101 and associate to new Ribbon the Location "Ribbon.Library.Actions"



When the new Ribbon is created the validation Script should added in the field "Enabled" associated to EnabledScript in the XML structure.



Validation Code to Enable/Disable Ribbon Button

This code has to be included in the EnabledScript option of the XML Sctructure associated with the Ribbon described in point "Add Ribbon Custom Action and ScripLink to support solution in SharePoint Site" .

****************Code Example****************
javascript:var name;
//Get Current User Name and send welcome message
getCurrentUser(function(userData){
alert("Welcome back Mr. "+userData);
name=userData;
});
//Get User Name REST call
function getCurrentUser(success)
{$.ajax({    
url:  _spPageContextInfo.webServerRelativeUrl + ((_spPageContextInfo.webServerRelativeUrl.indexOf('/', _spPageContextInfo.webServerRelativeUrl.length - 1) !== -1) ? '' : '/') + "_api/web/currentUser?$select=Title",
method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },    
success: function (data) {success(data.d.Title);},  
async: false,
error: function (error){alert(error.status);}   
});
}
//This validation returns true ="Enable Option" or false="Disable Option"
if (name=='Andre Lage')
{true;}else{false;}


User Validated

Access the Library where the Custom Ribbon was created and should appear Enable.




User not Validated

If you change in the code the following line
"if (name=='Andre Lage')" to "if (name!='Andre Lage')
the next time you access the Library with Custom Ribbon should appear Disable.



Add Ribbon Custom Action and ScripLink to support solution in SharePoint Site

I use the RibbonManager App, to include the Scriplinks and Ribbons in the Host Web Site to became accessible in SharePoint Site (is faster and more efficient to create the interface and Developers should only focus in the business code).
If you like to use Visual Studio and Declarative code you can use the following XML.

For the Custom Ribbon you can include the Custom Ribbon Action with the following XML Structure:

<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Library.Actions.Controls._children">
<Button Id="My Custom Button" LabelText="My Custom Button" Image32by32="/_layouts/15/1033/images/formatmap32x32.png?rev=33" Image32by32Left="-168" Image32by32Top="-68" ToolTipTitle="My Custom Button" Command="My Custom Button.Command" TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="My Custom Button.Command" CommandAction="<Add action Code here>" EnabledScript="<Add validation Code here>" />
</CommandUIHandlers>
</CommandUIExtension>

For the Jquery you can use the following XML Structure:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="Global Jquery" Title="Global Jquery" Description="" Location="ScriptLink"ScriptSrc="~Site/SiteAssets/jquery-1.10.2.min.js" Sequence="1" > </CustomAction>
</Elements>

Here a video with all the steps to create this Action:




Support Links:
CommandUIHandler Element
http://msdn.microsoft.com/en-us/library/office/ff458385(v=office.15).aspx
Asynchronously Checking if a Command is Available in the SharePoint Ribbon

http://www.andrewconnell.com/blog/Asynchronously-Checking-if-a-Command-is-Available-in-the-SharePoint-Ribbon
Code example for EnabledScript element in Ribbon XML
http://henrikfromsweden.blogspot.ch/2010/11/code-example-for-enabledscript-elemnt.html
Using RefreshCommandUI with the Server Ribbon (Dallas Tester, Fred Mameri)
http://blogs.msdn.com/b/sharepointdev/archive/2011/02/17/using-refreshcommandui-with-the-server-ribbon.aspx
Customizing the ribbon (part 1) – creating tabs, groups and controls
http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html
Sample code: Asynchronously checking if a Ribbon command is available
http://blog.mastykarz.nl/sample-code-asynchronously-checking-ribbon-command/
Enable or disable custom ribbon button in SharePoint 2010
http://tomaszrabinski.pl/wordpress/2012/02/25/enable-or-disable-custom-ribbon-button-in-sharepoint-2010/

Hope you enjoy the Article, 
Kind regards,
André Lage