Tuesday, February 26, 2013

Fetch document and list url dynamically and open in pop-up

 Below is the script to fetch the document or list and its root folder dynamically:

<script src="/SiteAssets/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script><script src="/_layouts/SP.UI.Dialog.js" type="text/javascript"></script><script src="/_layouts/SP.UI.Dialog.debug.js" type="text/javascript"></script><script type="text/javascript">

        $(document).ready(function () {
            SP.SOD.executeOrDelayUntilScriptLoaded(initialize, 'SP.js');
            SP.SOD.executeOrDelayUntilScriptLoaded(test, 'SP.js');
        });
        function getUrlVars() {
            var vars = {};
            var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
                vars[key] = value;
            });
            return vars;
        }

        var listID = getUrlVars()["List"]
        var rootFolder = getUrlVars()["RootFolder"];
               
               
        function openDiaForm() {
                       var diaOptions = SP.UI.$create_DialogOptions();
            diaOptions.url = '/_layouts/Upload.aspx?List='+listID+'&RootFolder='+rootFolder+'&IsDlg=1';
            diaOptions.width = 800;
            diaOptions.height = 600;
            diaOptions.title = "Upload Document Form";
            diaOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
            SP.UI.ModalDialog.showModalDialog(diaOptions);
        }
        //The function refreshes the content of the Document Set Welcome Page after the Upload Document modal dialog box has been closed 
        function CloseCallback(result, target) {
            location.reload(true);
        }
        function runCode() {
            var x = ExecuteOrDelayUntilScriptLoaded(openDiaForm, "sp.js");
        } 
    </script><a onclick="runCode();" href="#">Upload Proposal</a>

No comments:

Post a Comment