mardi 8 mai 2012

Sharepoint 2010: Add New Item Button In AssetPortalBrowser

Hi,
Adding new item from AssetPickerBrowser was possible in Sharepoint 2007 but in sharepoint 2010 Microsoft has disabled this functionnality due to placing this action in the Ribbon.
Here i post a customized version of assetpickerbrowser with this functionnality unabled.
It's simple, i just had to add a simple script in the head.
First of all Edit C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\AssetPortalBrowser.aspx as Administrator
and copy/paste this script in the PlaceHolderDialogBodyHeaderSection placeholder

<!-- Custom code start here-->
<!-- Customized By Safouene, safouenehaj@gmail.com for support or if you can optimize this version--> 
<script type="text/ecmascript">

    var options;
    function openModalDialog(pageToCall) {
        options = SP.UI.$create_DialogOptions();
        options.width = 700;
        options.height =500;
        options.url = SP.Utilities.Utility.getLayoutsPageUrl(pageToCall );
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
        SP.UI.ModalDialog.showModalDialog(options);

    }

    function CloseCallback(result, target) {
        location.reload(true);
    }

</script>
<script>
function querySt(ji) {
            hu = window.location.search.substring(1);
            gy = hu.split("&");
            for (i = 0; i < gy.length; i++) {
                ft = gy[i].split("=");
                if (ft[0] == ji) {
                    return ft[1];
                }
            }
        }
function insertBtnCustomUpload()
{
var queryListId = querySt('List');
var queryRoot = querySt('RootFolder');
if(typeof(queryRoot) == 'undefined')
{
queryRoot = '';
}
if (queryListId != null && queryListId.length > 0) {
var goToUploadUrl = "Upload.aspx?"+ "List="+queryListId+"&RootFolder="+queryRoot +"&IsDlg=1";
document.getElementById('DeveloperDashboard').innerHTML = "<a href=\"javascript:openModalDialog('"+goToUploadUrl+"');\" style='float:right;color:#3966BF;margin-right: 10px;margin-top: -20px;'>Add New Item</a>";
        }
}
</script>
<!-- Custom code ends here -->
in the code of the javascript function_spBodyOnLoad() add this line as last line
insertBtnCustomUpload();

save.
Now try it and you will see an 'Add New Item' link appear when you open a document Library.
Clicking in this link, an upload popup will open like the open that we have in the document library, i am very satisfied of what i've done, it's like it was given by microsoft by default. Enjoy :)
In this version also, using Chrome or firefox, the popup will do an auto-postback after the upload and then you will see the new document added (IE not, because in IE the popup doesn't do a postback).
This version is very useful for urlpicker, it works like a charm
copy and paste it in.

Aucun commentaire:

Enregistrer un commentaire