Sunday, January 10, 2016

Download a Copy and Number of Likes

Hi,

We had a requirement for our customer i.e.

We had document library on the page through list view web part.

Instead of clicking ‘Download a copy’ option on the file once user hovers on the file.

There should be an option available to the user so that

Post clicking on the option respective file should be downloaded easily i.e. download to be intuitive.

Along with this user should be able to Like/Unlike the document.

First we have created a column of type Single line of text.

Number of Likes column has been added from through content type.

We have written the script in such a way that based upon root element of Likes Download a Copy icon is going to be populated.

Now we have added the below script
<script type="text/javascript">
$(function(){
setTimeout(function(){
$('.ms-vb-icon').each(function(){
      var gethref= $(this).closest('tr').find('.ms-vb a').attr('href');
      var downloadhref = "/sites/nucleus/_layouts/15/download.aspx?SourceUrl=" + gethref;
                                $(this).closest('tr').find('.ms-vb-lastCell').append('<a unselectable="on" href="'+ downloadhref +'" target="_blank" class="ms-cui-ctl-large downloadFileIcon" aria-describedby="Ribbon.Documents.Copies.Download_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.Documents.Copies.Download-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class="ms-cui-img-16by16 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/15/1033/images/formatmap16x16.png?rev=31" style="top: -181px; left: -181px;"></span></span></a>');
                                $('.ms-listviewtable').find('.ms-vb-icon a img').closest('tr').find('.ms-vb-lastCell').empty();
});
},1000);
});

</script>
               
Post this user is able to see the below icon for each row of respective file

File Check Out Restriction

Hi,

There was requirement from our customer to restrict check out from the user.

We have a document library on the page which was added through list view web part.

We have written the below script to restrict user to check out the document.

<script type="text/javascript">

var intervalId2 = setInterval("OverrideOpenFuncs2()", 1000);  

function OverrideOpenFuncs2()  
 {  
   CheckoutDocument = function (strhttpRoot, strDocument, strOpenControl)
{
alert('This Library does not support Checking Out documents. To modify the metadata on this document, please select "Edit Item"');
}

}

setTimeout("window.clearInterval(intervalId2);", 10000);  

</script>

Post clicking on the checkout option, user was getting the below dialog box