Friday, February 28, 2014

Sharepoint 2013 Visio web access webpart scripts (3. Script to set active to perticular page name(Visio sheet name)

function setPage(callingNode) {
    try {
   

var vwaControl;
vwaControl= new Vwa.VwaControl(getVWAWebPartID1());
   


        // Get id from calling DOM node and set the corresponding page.
        vwaControl.setActivePage(callingNode);
    }
    catch(err) {
        alert(err);
    }
}



// Search the SharePoint page to get the WebPartID# for the Visio Web Access Web Part.
function getVWAWebPartID1() {
   
    // Get a NodesList of all the div tags on the page.
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
   
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
       
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

Note: Now when ever we want to set particular page name as active, we will just pass the name of the page(visio page) to that script.
Ex:
onclick= "javascript:setPage('visio page sheet name')");

Monday, February 24, 2014

Sharepoint 2013 Visio web access webpart scripts (2. Script to find list of page names(Visio Sheets names)

<script language="javascript">

// Add a button to display or dismiss the custom message.
document.write("<input type='button' value='Show Message' onclick='onDiagramComplete()' />");

// Hook into the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

// Declare global variables.
var vwaControl;
var vwaPage;
var vwaShapes;

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad() {
    try{
        vwaControl= new Vwa.VwaControl(getVWAWebPartID());
        vwaControl.addHandler("diagramcomplete", onDiagramComplete);
    }
    catch(err){
        alert(err);

    }
}

// Search SharePoint page to get WebPartID# for Visio Web Access Web Part.
function getVWAWebPartID() {
   
    // Get a NodesList of all the div tags on the page.
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
   
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
       
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

// Capture references to global variables and display message in the Web Part after rendering is complete.
function onDiagramComplete() {
    try{

        // Get references to the current Visio page displayed in the Web Part and the shapes on the page.


 vwaPages = vwaControl.getAllPageIds();
        var pageCount = vwaPages.length;
        var vwaPage = vwaControl.getActivePage();
 for (var i = 0; i < pageCount; i++){
            // Get page ID from array of pages IDs.
            vwaPageId = vwaPages[i];
     
alert(vwaPageId);


//This code returns all the page names
// var vwaPage = vwaControl.getActivePage();
// var vwaPageName = vwaPage.getId();

// alert(vwaPageName);


}




    
    }
    catch(err){
        alert(err);
    }
}

</script>

Sharepoint 2013 Visio web access webpart scripts (1. Script to find active page name(Visio sheet name)




<script language="javascript">

// Add a button to display or dismiss the custom message.
document.write("<input type='button' value='Show Message' onclick='onDiagramComplete()' />");

// Hook into the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

// Declare global variables.
var vwaControl;
var vwaPage;
var vwaShapes;

// Capture a reference to the current session of the Visio Web Access Web Part.
function onApplicationLoad() {
    try{
        vwaControl= new Vwa.VwaControl(getVWAWebPartID());
        vwaControl.addHandler("diagramcomplete", onDiagramComplete);
    }
    catch(err){
        alert(err);

    }
}

// Search SharePoint page to get WebPartID# for Visio Web Access Web Part.
function getVWAWebPartID() {
   
    // Get a NodesList of all the div tags on the page.
    var divArray = document.getElementsByTagName("div");
    var webPartElementID;
   
    // Iterate through the NodesList to get the node with the class attribute "VisioWebAccess."
    for (var i = 0; i < divArray.length; i++) {
        var node = divArray[i];
       
        // Return the first instance of the Visio Web Access Web Part.
        if (node.className == "VisioWebAccess") {
            webPartElementID = node.parentNode.parentNode.id;
            break;
        }
    }
    return webPartElementID;
}

// Capture references to global variables and display message in the Web Part after rendering is complete.
function onDiagramComplete() {
    try{

      
        var vwaPage = vwaControl.getActivePage();
        var vwaPageName = vwaPage.getId();

alert(vwaPageName);

    
    }
    catch(err){
        alert(err);
    }
}

</script>

script to get current page URL and query string parameters





function getQueryStringParameter(paramToRetrieve) {

var currentPageUrl = "";
if (typeof this.href === "undefined") {
    currentPageUrl = document.location.toString().toLowerCase();
}
else {
    currentPageUrl = this.href.toString().toLowerCase();
}

if (currentPageUrl != null) {
        var params =
       document.URL.split("?")[1].split("&");
        var strParams = "";
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split("=");
            if (singleParam[0] == paramToRetrieve)
                return singleParam[1];
        }
    }
    else {
        return "";
    }
  
}

var pagename=getQueryStringParameter('PageName');