1,804 articles and 14,699 comments as of Wednesday, March 23rd, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Wednesday, January 21, 2009

JQuery for Everyone: Force Checkout

With browsers other than IE, users often miss the “force checkout” dialogs when they open documents. Even with IE, if the user has an older version of Office, the document opens in Read Only mode while their computer stores a cached copy in the temp files.

Unwary users then edit the file and save it thinking it will save to SharePoint when it usually just gets lost in their temp files. This script removes document links (you can configure which document extensions) and alerts users to check the document out. Once a document is checked out to the current user, the links work normally (they still need to be careful where they save it).

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function initForceCheckout(){
	var elm = "a[href$='ppt'],"+ //configure file extensions
			  "a[href$='pptx'],"+
			  "a[href$='doc'],"+
			  "a[href$='docx'],"+
			  "a[href$='xls'],"+
			  "a[href$='xlsx']";
	$(elm).each(function(i,e) {
		var str = "_"+$(e).attr("onclick");
		var arr = str.split(",");
		if (arr[0].indexOf("DispEx")!=-1 && arr[10] != arr[11]) {
			$(e).attr("href","#")
				.removeAttr("onClick")
				.addClass("ForceCheckout")
				.bind("click", function() {
					alert("You much check out this document before editing");
			});
		}
	});
}
$(function (){ //initialize the script
	initForceCheckout();
});
function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {//re-write of WSS fn for groups
 var tbody=document.getElementById("tbod"+groupName+"_");
 var wrapDiv=document.createElement("DIV");
 wrapDiv.innerHTML="<TABLE><TBODY id=\"tbod"+ groupName+"_\" isLoaded=\""+isLoaded+ "\">"+htmlToRender+"</TBODY></TABLE>";
 tbody.parentNode.replaceChild(wrapDiv.firstChild.firstChild,tbody);
 initForceCheckout();
}
</script>
View all entries in this series: PaulGrenier-JQuery for Everyone»
Entries in this series:
  1. JQuery for Everyone: Accordion Left Nav
  2. JQuery for Everyone: Print (Any) Web Part
  3. JQuery for Everyone: HTML Calculated Column
  4. JQuery for Everyone: Dressing-up Links Pt1
  5. JQuery for Everyone: Dressing-up Links Pt2
  6. JQuery for Everyone: Dressing-up Links Pt3
  7. JQuery for Everyone: Cleaning Windows Pt1
  8. JQuery for Everyone: Cleaning Windows Pt2
  9. JQuery for Everyone: Fixing the Gantt View
  10. JQuery for Everyone: Dynamically Sizing Excel Web Parts
  11. JQuery for Everyone: Manually Resizing Web Parts
  12. JQuery for Everyone: Total Calculated Columns
  13. JQuery for Everyone: Total of Time Differences
  14. JQuery for Everyone: Fixing Configured Web Part Height
  15. JQuery for Everyone: Expand/Collapse All Groups
  16. JQuery for Everyone: Preview Pane for Multiple Lists
  17. JQuery for Everyone: Preview Pane for Calendar View
  18. JQuery for Everyone: Degrading Dynamic Script Loader
  19. JQuery for Everyone: Force Checkout
  20. JQuery for Everyone: Replacing [Today]
  21. JQuery for Everyone: Whether They Want It Or Not
  22. JQuery for Everyone: Linking the Attachment Icon
  23. JQuery for Everyone: Aspect-Oriented Programming with jQuery
  24. JQuery for Everyone: AOP in Action - loadTip Gone Wild
  25. JQuery for Everyone: Wiki Outbound Links
  26. JQuery for Everyone: Collapse Text in List View
  27. JQuery for Everyone: AOP in Action - Clone List Header
  28. JQuery for Everyone: $.grep and calcHTML Revisited
  29. JQuery for Everyone: Evolution of the Preview
  30. JQuery for Everyone: Create a Client-Side Object Model
  31. JQuery for Everyone: Print (Any) Web Part(s) Plugin
  32. JQuery for Everyone: Minimal AOP and Elegant Modularity
  33. JQuery for Everyone: Cookies and Plugins
  34. JQuery for Everyone: Live Events vs. AOP
  35. JQuery for Everyone: Live Preview Pane
  36. JQuery for Everyone: Pre-populate Form Fields
  37. JQuery for Everyone: Get XML List Data with OWSSVR.DLL (RPC)
  38. Use Firebug in IE
  39. JQuery for Everyone: Extending OWS API for Calculated Columns
  40. JQuery for Everyone: Accordion Left-nav with Cookies Speed Test
  41. JQuery for Everyone: Email a List of People with OWS
  42. JQuery for Everyone: Faster than Document.Ready
  43. jQuery for Everyone: Collapse or Prepopulate Form Fields
  44. jQuery for Everyone: Hourly Summary Web Part
  45. jQuery for Everyone: "Read More..." On a Blog Site
  46. jQuery for Everyone: Slick Speed Test
  47. jQuery for Everyone: The SharePoint Game Changer
  48. JQuery For Everyone: Live LoadTip
 

Please Join the Discussion

15 Responses to “JQuery for Everyone: Force Checkout”
  1. erugalatha says:

    IMHO this is going to help out a lot of people.
    Cheers for making it happen Paul. :)

  2. erugalatha says:

    Suggestion/Addition:

    Is there a way to modify the buttons produced on the message box instead of OK?

    i.e. have a Check Out button and Cancel button. Clicking Check Out automatically performs the Check Out and opens in the appropriate application.

  3. SevenOfNine says:

    Worth to note that it will fail on grouped views.

  4. AutoSponge says:

    @SevenOfNine,

    Actually, this was tested with groups.

    I rewrote the ExpGroupRenderData function on the page which renders grouped data to fire the initialization again.

    Are you seeing something different? Which browser?

  5. SevenOfNine says:

    You’re right. I missed the part with the rewritten ExpGroupRenderData function completely. Well, well, it was late last night ;-)

    Thanks for enlighting me…

  6. custardcrumble says:

    This looks perfect!
    Please forgive my ignorance but where should I put this code?
    CC

  7. AutoSponge says:

    @Custard,

    For a single library, use Site Actions > Edit to put the page in edit mode. Then ‘Add a web part’ to one of the zones. Add a Content Editor Web Part. In the settings for that CEWP, open the Source Editor and paste the code there.

    If you like that, start with my series on JavaScript: http://www.endusersharepoint.com/?p=929

  8. Adam Davidson says:

    Paul,

    Looks like a great trick. I’ve got a WSS 2.0 site that I’d like to use this on, but I can’t get it to work. I suspect it needs to be on MOSS 2007/WSS 3.0 to work. Any way it can be made to work for WSS 2.0?

    Thanks,
    Adam

  9. AutoSponge says:

    @Adam

    Thanks for the compliment. I’ve never used WSS2 so I can’t really help you. To create this, I studied the rendered source of the document library looking for a pattern near the document’s link.

    The javascript call has a bunch of arguments which included the current user and the user the document is checked out to (null if not checked out).

    Therefore, my logic just says arr[10] != arr[11] (if argument 10 does not equal argument 11…)

  10. Frank says:

    Do you have a ‘Screencast’ or ‘Screenshots’ for this? I’m still new at SharePoint and we are using WSS 3.0 for our hospital.
    Thanks

  11. Frank says:

    Two questions:
    1. Can this work with PDFs?
    2. Not all the documents and PPT slides have the ‘POPUP’. How can I fix this. We are using WSS 3.0
    Thanks

  12. AutoSponge says:

    I don’t think it’s going to work with PDFs because there’s no expected client integration.

    I intended for there to NOT be a popup if the document does not require checkout or you already have it checked out. Is that the case?

  13. AutoSponge says:

    @Frank,

    BTW, I’m terrible at screencasts. It takes me 2 hours to produce 10 minutes of video. It’s not something I do often but I’m trying to get better. I’ll keep this request in mind.

  14. sharepoint4endusers says:

    How and where to use this script?????

Trackbacks

Check out what others are saying about this post...
  1. OneOfSix says:

    Add Links to SharePoint Wiki Toolbar using jQuery…




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!