February 8, 2012 - 17:38, by Steven Van de Craen
Categories: SharePoint 2010, Sandbox Solutions, Ribbon, jQuery/JavaScript
A SharePoint 2010 Sandboxed Solution that adds a Ribbon Button that recycles all items in a Document Library with a single mouse click.
I' have created this miniproject more as an academic exercise in creating a Ribbon Button than for real business value. It can come in handy for development environments sometimes.
Installation and activation
Download from here (Ventigrate Codeplex Repository)
Upload the WSP (sandbox solution) to the Site Collection Solution Gallery and activate it
Activate the Site Collection Feature
Final note
Some lessons learned and things worth noting:
- Use a Module to deploy resource files to a folder or library like the Style Library (Sandbox cannot access the Layouts folder)
- The Module will overwrite the existing resource files with a newer version, but will not delete them
- Working with ECMAScript seems to have no effect on resource or resource quota
- Use InPrivate Browsing for testing Ribbon development, this avoids caching of Ribbon resources
-
CustomAction.ScriptSrc points to the Layouts folder when using relative URLs. Use ~SiteCollection if you want to reference a resource in the Site Collection
December 27, 2011 - 10:43, by Steven Van de Craen
Categories: jQuery/JavaScript, SharePoint 2010
Here’s a small fix for which I didn’t have time to investigate more properly:
Issue
The User Profile Page of another user shows a link “Add as colleague” when that user isn’t already a colleague:
It seems however that the link behind “Add as colleague” directs to the Default AAM URL rather than the current URL you’re using.
Example:
Zone: Default |
http://internalserver
|
Zone: Intranet |
http://intranet
|
When browsing to the page using http://intranet the link will refer to http://internalserver. This is not the desired behaviour (think mixed authentication or extranet scenario’s).
Quick fix using jQuery
<script type="text/javascript" src="/my/Style Library/js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(function() { var el = $('.ms-my-addcolleague'); if (el.attr('onclick') != undefined) { el.attr('onclick', el.attr('onclick').replace('http:\\u002f\\u002finternalserver:80', '')); } }); </script>
I’m referencing jQuery in the Style Library of the My Site Host, which you need to add or modify the link. I’ve hardcoded the internal URL (default zone public URL), might be better to look that up dynamically but as said this is a quick fix.
You can view the source of your own User Profile Page to find the internal URL for your environment.
You can add this in a Content Editor Web Part to the User Profile page and it should work just fine making the link relative.
Applies to
I’m seeing this issue in a SharePoint 2010 + Service Pack 1 + August 2011 Cumulative Update (14.0.6109.5002). Might be fixed in a later CU or SP.
June 4, 2010 - 13:46, by Steven Van de Craen
Categories: jQuery/JavaScript, MOSS 2007, SharePoint 2007
November 9, 2009 - 14:43, by Steven Van de Craen
Categories: jQuery/JavaScript
We’re doing quite some jQuery improvements to our SharePoint developments such as inserting navigation for document libraries, reordering elements, hiding menu actions, etc. and one of the big issues is that the jQuery action occurs “on document ready” and the end user might see the manipulation happening if the javascript execution is just a bit delayed.
One of the solutions we’re using is to set the body hidden using CSS on load and then in our jQuery show it again as follows:
Works like a treat btw, but maybe any of you have a better way ?
October 26, 2009 - 21:54, by Steven Van de Craen
Categories: jQuery/JavaScript, MOSS 2007, Search Server 2008, SharePoint 2007, WSS 3.0
Still one of my most popular posts ever is the extension I wrote on the Rooms and Equipment Reservations template for SharePoint 2007 which allows you to manage reservations for meeting resources.
The idea behind RER is simple, but the architecture Microsoft chose (and unfortunately me too) is flawed. For each resource there are two types of reservation items; “Available” and “Reserved”. When making a reservation the “Available” item is shrunk, split or replaced with a “Reserved item”. The list of reservation items for a certain resource should thus be continuous based on their respective start and end times.
Since quite a few people from the community and also some customers are using the RERv2, I get a lot of feedback on these flaws, which I tend to ‘consistency issues’. These issues can’t really be traced back to bugs in code but seem to happen at random. For every 100 reservations are made I typically see 3 consistency issues. They don’t all have a great impact; some are not even noticed, others are blocking future reservations for that resource.
Ideally the mechanism would have to be rewritten to just use “Reserved” items. This would make the fault ratio significantly smaller. However that project has been put in the fridge until further notice I’m afraid.
There is a sparkle of light at the end of the tunnel however ! I am releasing a Web Part that allows you to quickly correct consistency issues. And it’s even free ! ;)
Downloadables
-
I want to use it on my server
-
I want the code (Visual Studio 2008 + WSPBuilderExtensions)
Installation Instructions
1) WSP
The installation package (above) contains a SharePoint Solution (.wsp) to deploy using STSADM:
STSADM -o addsolution -filename RER.v2.ConsistencyCheckWebPart.wsp
STSADM -o deploysolution -name RER.v2.ConsistencyCheckWebPart.wsp -immediate -allowgacdeployment
2) Web Parts
Next in SharePoint create a Document Library (e.g. Pages) in the RER site where you upload the jQuery.js and RERAdmin.txt files from the install package. These make up the formatting and collapsing behaviour of the resources and reservations.
Also create a Web Part Page in this library called RERAdmin.aspx .
Add the ConsistencyCheckWebPart and RERAdmin_CSS_and_JS Web Parts on the RERAdmin page. You can import these Web Part directly if you go through Add Web Part > Advanced Web Part gallery and options > Import
It is best to break permissions and tighten security on the Web Part page so that users don’t inadvertently access the Consistency Check Web Part !
Usage Instructions
The Web Part must be placed in a site based on RERv2. It will automatically load the list of resources and corresponding reservations. If the CSS and JavaScript are in place the reservations are collapsed by default and the items will either have a green (good) or red (bad) icon. If it’s red that means there are consistency issues in the stream of reservation items for that resource.
The editor on the bottom of the Web Part will allow you to make changes directly to reservations.
NOTE: The number between square brackets is the item ID of either the resource or reservation item. You will need this to Modify or Delete a reservation !
Possible causes:
ISSUE |
EXPLANATION |
FIX |
There are no reservations |
The workflow on the Resource hasn’t run (yet). |
Add an “Available” reservation for the resource with no specified end time, or recreate the resource to trigger the workflow. |
There are two adjacent “Available” reservations |
They should be merged into a single “Available” item. |
Delete one of the items and Modify the remaining item to become ‘continuous’. |
There are overlapping reservations |
A resource was booked twice. Normally this is prohibited but could occur in some rare conditions. |
Remove on of the items or Modify the start and/or end times to resolve this. |
Reservations are not continuous |
All items should form a ‘continuous stream’ based on their start and end times. |
Modify the timings so that they become ‘continuous’. |
October 1, 2009 - 22:35, by Steven Van de Craen
Categories: Custom Field Types, jQuery/JavaScript, MOSS 2007, Search Server 2008, SharePoint 2007, WSS 3.0, Advanced Computed Field
A common question to receive is on list items with a long body (eg. Announcements) and then show only X characters and optionally a ‘read more’ link. Many ways to solve this but I went for the following: a Custom Field Type that renders the short text with ellipsis using jQuery.
This is another example using the Advanced Computed Field in a creative way. The ACF allows you to create computed fields referencing other fields or data in your list and manipulating them through CAML or JavaScript. It has the advantage that this can be done from within the browser, however I admit CAML isn’t the easiest of things to comprehend in the SharePoint technology stack.
Ellipsis sample
This ellipsis displays the first 20 characters of the plain text version of the Announcement Body
<span style="display:none;" id="el_
_
">
</span>
<script type="text/javascript">
$(function()
{ var mySpan = $('#el_
_
');
var myShortText = $(mySpan).text().substring(0, 20);
if ($(mySpan).text().length > 20)
myShortText += '...';
$(mySpan).show().html(myShortText); });
</script>
Notes
- If you prefer to not escape the brackets you can use CDATA tags: hello]]>
- GetVar ‘WPQ’ returns the unique Web Part ID. This takes care of multiple List View Web Parts on the same page
- You could optimize the output by extracting most of the script and placing it in an externally referenced JavaScript file
- My JavaScript/jQuery skills aren’t the best. I’ll have to ask Jan for some jQuery pointers next time :)