DFFS: Check out list items

Change log
December 14, 2015
Added a fix for an unintentional check-in when adding attachments on SP2007 with Internet Explorer 8/9. See code section below.

May 06, 2015
Changed the function “goToDispForm” to include “dffs_beforeunload = false;” to prevent check-in when a user was redirected to DispForm.

May 05, 2015
Updated code example to handle check in if the user cancels out of the EditForm without saving changes (and thus not being asked to check in the list item. Please adapt the code to suite your needs.

This post will describe a possible solution to handle check out of list items when editing. This will prevent others from making changes to the list item while another person has the same item already open in EditForm.

This solution is intended used in EditForm, and requires you to add one new field to the list: A yes/no column named (for example) “CheckedOut”.

Currently this requires four rules added to DFFS, but I might consider building in support for this so that this would just require a “tick in a box” to enable.

These are the rules required in DFFS


IMG


IMG


IMG

Please note that you must have DFFS frontend v4.267 or later to be able to “alert” the name of the Editor like in this example.


IMG

Please note a typo in “promptCheckin” – use lover case “i” to correspond with the function in the Custom JS below.

The code from the CSS and JS tab in DFFS backend
var dffs_beforeunload = true;

function goToDispForm(){
	dffs_beforeunload = false;
	$("#part1").hide();
	location.href = location.href.replace(/editform.aspx/i,"DispForm.aspx");
}

function mustCheckOut(){
	dffs_beforeunload = false;	
	if(confirm("You must check out this item to proceed.\n\nCheck out this item now?")){
		var res = spjs_updateItem({"listName":_spPageContextInfo.pageListId,"id":GetUrlKeyValue("ID"),"data":{"CheckedOut":"1"}});
		if(res.success){
			location.href = location.href;
		}else{
			alert(res.errorText);
		}
	}else{
		goToDispForm();
	}
}

function promptCheckin(){
	dffs_beforeunload = false;	
	if(getFieldValue("CheckedOut") === true){
		if(confirm("Do you want to check in this item to allow otheres to contribute?")){
			setFieldValue("CheckedOut",false);
		}
	}
}

$(window).bind("beforeunload",function(event) {
	if(dffs_beforeunload){
		var res = spjs_updateItem({"listName":_spPageContextInfo.pageListId,"id":GetUrlKeyValue("ID"),"data":{"CheckedOut":"0"}});
		if(res.success){
			alert("The list item was checked in.");
		}else{
			alert(res.errorText);
		}
	}
});

// Fix for add attachment in IE 8 / 9 on SharePoint 2007
$("a[href^='javascript:UploadAttachment()']").hover( 
	function(){
		dffs_beforeunload = false;
	},
	function(){
		dffs_beforeunload = true;
	}	
);

Please use the forum for any discussions

Alexander