Get a link in a CQWP to edit an item

Hi everyone!

I hope this could be of some use for you¬†ūüôā

I want:

An audiense filtered list of links where by clicking the link, I should end up being able to edit the item, not open the page it points to. After I have finished editing I should return to the page with links targeted to me (or any other page for that matter).

Ok this is what we have:

A links list called OrgLinks where we have activated Audience targeting settings. This list also has a custom column called Box that is of the type Managed metadata which is connected to a Term store called Linkboxes.
So each item is tagged with which box it should belong to and which part of the organization that should see it.

I have a page that consists of a number of CQWP that is querying this links list. Audience targeting is activated on these web parts and they are filtered on the values of the Term store Linkboxes.

On the same page, I have added a couple of buttons (targeted to editors) to make it easier to create new¬†items in this list and navigate to a page where you could edit items already created. This is actually the list that this blog is all about ūüôā

The thing is that even if you enable Audience targeting for a list, you can’t OOTB filter a lists view on audiences.

This is where the template I came up with for ItemStyles.xsl comes in. It could be that I am crossing the brook for water in my template but it gives me the result I want ūüôā

It was actually this template from Marc’s blog that got me in the right direction.

What it does is that it concatenate the link to the edit form of the item, the Item-ID and the URL to the page the user should go to after he or she is finished.

<xsl:template name="LinkListEdit" match="Row[@Style='LinkListEdit']" mode="itemstyle">
     <xsl:variable name="SafeLinkUrl">
         <xsl:call-template name="OuterTemplate.GetSafeLink">
             <xsl:with-param name="UrlColumnName" select="@URL"/>
         </xsl:call-template>
     </xsl:variable>
     <xsl:variable name="DisplayTitle">
         <xsl:call-template name="OuterTemplate.GetTitle">
             <xsl:with-param name="Title" select="@URL"/>
             <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
         </xsl:call-template>
     </xsl:variable>
     <xsl:variable name="TheList">
     <xsl:text disable-output-escaping="yes"> /alltomoss/_layouts/listform.aspx?PageType=6&amp;ListId={675357B2-D33C-4626-A61B-0FC978C0C09C}&amp;ID=</xsl:text>
     </xsl:variable>
     <xsl:variable name="Source">
     <xsl:text disable-output-escaping="yes">&amp;Source=/alltomoss/sidor/aoolankar.aspx</xsl:text>
     </xsl:variable>
          <xsl:variable name="TheLink">
          <xsl:value-of select="concat($TheList, @ID, $Source)" />
          </xsl:variable>
     <div id="linkitem">
         <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
         <a href="{$TheLink}" title="Redigera länken">
         <xsl:value-of select="substring-after($DisplayTitle,',')"/>
         </a>
     </div>
 </xsl:template>

Before we actually could use this template and use it it in our CQWP we need to export the webpart and add a couple of things to it. Change CommonViewFields to look like this:

 <property name="CommonViewFields" type="string">URL,Text; </property> 

Then as “usual” import it again and add it to the page.

CU!

/Niax

Advertisements

Working with the Visio Web Part

Hi everyone!

Ok, so a client had these requests:

1. We want to be able to navigate to different processes in an easy manner

2. We want to be able to bring up information about a process step

2b.Without loosing focus from the process we are currently at

3. Reuse instructions that we already have about the steps in our processes

This is what we will be working with:

  • A Visio file for the master process file that will be used to navigate to the different processes.
  • A Visio file for the process Customer Complaints, this process will contain two steps.
  • A PDF-file that will contain information about each step.
  • Two pages that will show the Visio-files.

First I would like to add that I am no expert in Visio so there might be better or different ways to attack this ūüôā

As a¬†matter of fact, I wonder if there is something that I am an expert in…

But anyway, this is how I did.

First of all I have these settings for Adobe Reader.

  • Set Adobe Reader to open PDF-files in the¬†browser
  • Uncheck to open in Read mode as default

To accommodate request 1 (navigate to different processes)

A main process is created in Visio with links to the pages that holds a Visio web part for each process like Sales and Customer complaints and so on.

Main process

The link for the Customer complaints object looks like this:

http://server/site/pages/customerc.aspx

This Visio-file is uploaded to http://server/site/processdiagrams as MainProcess.vdw

On the start page for http://server/site/start.apsx a Visio web part will be showing this Main process.

I also added a Go back button above this web part so that they in an easy manner could go back to the page that holds the Main process.

To accomodate request 3 (reusing information that we have)

First I made sure that the information about each process step started on a new page in the document. Then I saved the Word-file as a PDF letting Word create bookmarks in the PDF-file from the headings in the document while it was beeing published. That way we get a table of contents in the left navigation of the PDF.

(If you don’t get one, make sure that you have unchecked the default value to open PDF in Read mode.)

This PDF-file is uploaded to http://server/site/documents as CCsteps.pdf

To accomodate request 2 (bring up information on each step)

The Customer complaints visio-file (that is saved as a .vdw-file) holds two different steps ACC CC and Qualify CC.

Customer complaints

The link for ACC CC is configured like this:

URL: http://server/site/documents/ccsteps.pdf

The sub adress is “Page=2” (because the instructions¬†for the¬†ACC CC step starts at page 2)

Description is set to¬†ACC CC and I don’t use a relative path.

This Visio-file is uploaded to http://server/site/processdiagrams as CustomerC.vdw

To accomodate request 2b (navigate without loosing focus)

Ok, so this is something that I don’t like with the new vdw-type of file, you can not set a link for an object to open in a new window.

So to get around this I first got some help on MSDN forum here >> with some javaScript.

On the Visio web part you want to have this script active for edit the web part like this:

I did not get this to work OOTB, so I got some help from some collegues of mine, thanks guys ūüôā

This code you could simply copy and paste and put in a CEWP or FormWP on the page where you have your Visio web part, to try it out.

It ended up with a JavaScript looking like this:

<script type="text/javascript">

// Declare the global variables for the script, for the Visio Web Access Web Part, the active page in the Web Part,
// and the shapes on the active page.
var vwaControl;
var vwaPage;
var vwaShapes;
var newURL;

// Add a handler to the AJAX Sys.Application.load event.
Sys.Application.add_load(onApplicationLoad)

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

function getVWAWebPartID()
{
// Search all of the</pre>
<div>tags on the page to find the div tag with the ID of the VWA Web Part.</div>
<pre>
  var divArray = document.getElementsByTagName("div");
  var webPartElementID;
  for (var i = 0; i < divArray.length; i++) {
    var node = divArray[i];
    if (node.className == "VisioWebAccess")
    {
      webPartElementID = node.parentNode.parentNode.id;
      break;
    }
  }
  return webPartElementID;
}

function onDiagramComplete()
{
  try{
    // Set the vwaPage and vwaShapes variables to the active page and the shapes collection on that page, respectively.
    vwaPage = vwaControl.getActivePage();
    vwaShapes = vwaPage.getShapes();

    // Remove the handler from the shape selection changed event and then add it back to the event.
    vwaControl.removeHandler("shapeselectionchanged", onShapeSelectionChanged);
    vwaControl.addHandler("shapeselectionchanged", onShapeSelectionChanged);

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

function setNewPage(pageId) {
  // Set the active page in the drawing to the page ID passed in as argument.
  var indexOfAmp = pageId.indexOf("&");
  var page = pageId.slice(6, indexOfAmp);
 vwaControl.setActivePage(page);
}
onShapeSelectionChanged = function (source, args)
{
  try{
    // Get the array of hyperlinks from the selected shape.
    var vwaShape = vwaShapes.getItemById(args);
    var newURLArray = vwaShape.getHyperlinks();

    // Check to see whether the shape has any hyperlinks.
    if (newURLArray.length> 0)
    {
      newURL = newURLArray[0].value;

      // Check to see if the hyperlink goes to another page in the drawing.
      if (newURL.indexOf('vdw') < 0)
      {
        // Open the hyperlink in a new window.
           var newWindow = window.open(newURL, "", 'width=800,height=650')
      }
     else
      {
         //Set the active page to the new page.
        setNewPage(newURL);
      }
    }
  }
  catch(err)
  {
    alert(err);
  }
}
</script>

Now when you click on a process step, the actual page in the PDF-file should be brought up in a separate window and give you the instructions about that step. You should also have a table of contents in the left pane in AcrobatReader so that you could easily navigate between different instructions.

Well thats about it guys, I hope this will help you or give you some ideas.

CU

/Niax