Eric’s adventures in Sharepoint, technology, and life.
Email icon Home icon
  • Modifying Employee Training template

    Posted on April 8th, 2009 Eric 2 comments

    In my last blog post, I mentioned I was starting to dislike the fab 40 templates. This post describes how we (myself and my colleague Tony Miller) fixed an inherent issue with one of these templates. This post goes into steps done after following these three blog posts:

    Here is some background on the template if you aren’t familiar. The site is designed so that an instructor can add courses they wish to teach to a list. Users come into the site and see the courses available and click a link to go to the Dispform to register. However there is a glaring security issue here. The navigational bar is present for users to delete a course! If a permission level is created to stop them from deleting items, then they can’t unregister for a course. This bar also contains a function to export the item to Outlook.

    ms-toolbar

    ms-toolbar

    So what do we do to fix it? I hope that’s why you’re reading.

    The first thing I did was to create a calculated column in the course list that creates an iCal hyperlink. I created the function as =CONCATENATE(”https://MyDomain/sites/cferegistration/_vti_bin/owssvr.dll?CS=109&Cmd=Display&List=%7B242652E5%2D0492%2D4C2F%2D8B37%2D06C9A59B0020%7D&CacheControl=1&ID=”,ID,”&Using=event.ics”). Easy enough. I then used a little of Paul Grenier’s jQuery magic to clean that up. Functionality restored for the users. Now to get it on the Dispform.

    Here I opened Sharepoint Designer and opened the Dispform associated with the Courses list. I added @iCal, iCal to the XSL data fields at the top of the transform. Then I added

    <tr style="display: none">
    	<td width="190px" valign="top" class="ms-formlabel">
    		<H3 class="ms-standardheader">
    			<nobr>Export to Outlook</nobr>
    		</H3>
    	</td>
    	<td width="400px" valign="top" class="ms-formbody">
    		<xsl:value-of select="@iCal/>
    	</td>
    </tr>

    an thought I’d be golden. well, I was wrong. It created a nightmare of a URL and needed a way to make a nice hyperlink so users could just click it and save the item. After about an hour of trying all sorts of things, Tony realized that Sharepoint was using XSL version 1.0. With this in hand we were able to utilize a replacement function to clean out the amp; values and create a nice hyperlink.

    We added

    <xsl:template name="replace-substring">
      <xsl:param name="original"/>
      <xsl:param name="substring"/>
      <xsl:param name="replacement" select="''"/>
      <xsl:variable name="first">
        <xsl:choose>
          <xsl:when test="contains($original, $substring)">
            <xsl:value-of select="substring-before($original, $substring)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$original"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="middle">
        <xsl:choose>
          <xsl:when test="contains($original, $substring)">
            <xsl:value-of select="$replacement"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text></xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="last">
        <xsl:choose>
          <xsl:when test="contains($original, $substring)">
            <xsl:choose>
              <xsl:when test="contains(substring-after($original, $substring), 
                                       $substring)">
                <xsl:call-template name="replace-substring">
                  <xsl:with-param name="original">
                    <xsl:value-of select="substring-after($original, $substring)"/>
                  </xsl:with-param>
                  <xsl:with-param name="substring">
                    <xsl:value-of select="$substring"/>
                  </xsl:with-param>
                  <xsl:with-param name="replacement">
                    <xsl:value-of select="$replacement"/>
                  </xsl:with-param>
                </xsl:call-template>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="substring-after($original, $substring)"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text></xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:value-of select="concat($first, $middle, $last)"/>
    </xsl:template>

    to the top of the transform after the following code.

    <xsl:variable name="dvt_1_automode">0</xsl:variable>

    Then we changed the values being displayed by altering the output code to:

    <tr>
    	<td width="190px" valign="top" class="ms-formlabel">
    		<H3 class="ms-standardheader">
    			<nobr>Export to iCal</nobr>
    		</H3>
    	</td>
    	<td width="400px" valign="top" class="ms-formbody">
    		<xsl:variable name="iCalLink">
    		<xsl:call-template name="replace-substring">
    		<xsl:with-param name="original" select="@iCal"/>
    		<xsl:with-param name="substring" select="string('amp;')"/>
    		<xsl:with-param name="replacement" select="string('')"/>
    		</xsl:call-template>
    		</xsl:variable>
    		<a href="{$iCalLink}">Export to iCal</a>
    	</td>
    </tr>

    Now we had a working hyperlink in our item details.

    Whew, almost done! Last cleanup item is to remove the toolbar so users cannot delete items. We cranked up Firefox and Firebug and found the toolbar easily enough. A few console trial and errors and we had removed it. Instead of putting it into a CEWP like I normally would, I just added it to the page head on the dispform. That code is:

    <script type="text/javascript">
     
    $(function() {
    	$('table[@id$=toolBarTbl].ms-toolbar').remove();
    });
    </script>

    Save, refresh and viola! the dispform now looks like the below image. This might not have been the easiest method to do this, and I’d be happy to hear other ways of doing it.

    dispform.aspx

    dispform.aspx

    Post to Twitter Post to Plurk Plurk This Post Post to Yahoo Buzz Buzz This Post Post to Delicious Delicious Post to Digg Digg This Post Stumble This Post