locked
Links in Calendar WebPart View RRS feed

  • Question

  • Is is possible to change the links in the calendar webpart view to redirect to a different version of the DispForm.aspx page.  I am currently using the Employee Training template for a site, which works ok, except for the fact that in order for the site workflows to execute, the user has to be in the contributor role.  The only problem with this is that this role allows them to modify the Class list data or even to delete a class.  What I did was make a copy of the DispForm.aspx page and removed all ability to get to the EditForm.aspx page (yes, I know that if they know the URL, they can still get to it, but I am trying to prevent the casual user from messing things up).  However, for this to work, I need to have the links in the Calendar view point to DispForm2.aspx... can anyone point out how to make changes to the source using SPD to accomplish my goal.
    • Moved by Mike Walsh FIN Wednesday, August 19, 2009 3:49 PM cust q (From:SharePoint - Development and Programming)
    Wednesday, August 19, 2009 1:55 PM

Answers

  • Thanks Mike... using your code and some other code I found on the internet I was able to cobble together a solution. It's not very elegent, but it seems to work fine. 

    I created a content editor web part in the calendar.aspx page
    Change the chrome type to none to hide the toolbar

    Then added the following code to the webpart source Editor dialog
    <script>
    
    function RedirectLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x(i).href.indexOf("DispForm.aspx")>-1)
      {
       var hrefLocation = x(i).href;
        //alert(hrefLocation);
        var myParm = gup('ID',hrefLocation );
        //alert(myParm);
        var redirectPage = "/sites/training/firstaid/Lists/courses/ViewForm.aspx?ID=" + myParm
        //alert(redirectPage);
        x(i).href=redirectPage
        
      }
     }
    }
    
    function gup( name,hrefLocation )
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( hrefLocation );
      if( results == null )
        return "";
      else
        return results[1];
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("RedirectLinks"); 
    
    </script>
    • Marked as answer by Miriv365 Thursday, August 20, 2009 2:31 PM
    Wednesday, August 19, 2009 4:56 PM
  • Just move the Content Editor Web Part after the calendar web part, remove _spBodyOnLoadFunctionNames and the wrapper function "function RedirectLinks()"

    Why is the function call commented out?


    Mike Smith TechTrainingNotes.blogspot.com
    • Proposed as answer by lalov1 Friday, August 28, 2009 4:55 PM
    • Marked as answer by Mike Walsh FIN Wednesday, July 27, 2011 4:33 AM
    Friday, August 28, 2009 4:31 PM

All replies

  • In SharePoint designer, right click the list name in the folder list and select properties. Then switch to the supporting files tab. This allows you to change the default file used for edit/new display etc.

    Paul.
    Overweight SharePoint addict!
    Wednesday, August 19, 2009 2:01 PM
  • Is there anything else I need to do?  I went in as you said, and I made the change.  I double checked, but when I view the calendar.aspx page, it still has links pointing to the DispForm.aspx page... same thing goes if I go into the AllItems.aspx view --- it continues to point to the Dispform.aspx page. 
    Wednesday, August 19, 2009 2:54 PM
  • Moving to customization - not a programming question,,
    WSS FAQ sites: http://wssv2faq.mindsharp.com and http://wssv3faq.mindsharp.com
    Total list of WSS 3.0 / MOSS 2007 Books (including foreign language) http://wssv3faq.mindsharp.com/Lists/v3%20WSS%20FAQ/V%20Books.aspx
    Wednesday, August 19, 2009 3:48 PM
  • Paul's comments will work for the normal list views, but I think the calendar view is a bit more "hard coded". In a recent post there was a discussion of disabling the links in a calendar view. It has some JavaScript that may give you an idea on creating your own custom links.

      http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/498b171a-b00a-4dd9-8bee-2348bc4ccbd8
    Mike Smith TechTrainingNotes.blogspot.com
    Wednesday, August 19, 2009 4:04 PM
  • Thanks Mike... using your code and some other code I found on the internet I was able to cobble together a solution. It's not very elegent, but it seems to work fine. 

    I created a content editor web part in the calendar.aspx page
    Change the chrome type to none to hide the toolbar

    Then added the following code to the webpart source Editor dialog
    <script>
    
    function RedirectLinks()
    {
     var x = document.getElementsByTagName("A");
     for (var i=0;i<x.length;i++)
     {
      if (x(i).href.indexOf("DispForm.aspx")>-1)
      {
       var hrefLocation = x(i).href;
        //alert(hrefLocation);
        var myParm = gup('ID',hrefLocation );
        //alert(myParm);
        var redirectPage = "/sites/training/firstaid/Lists/courses/ViewForm.aspx?ID=" + myParm
        //alert(redirectPage);
        x(i).href=redirectPage
        
      }
     }
    }
    
    function gup( name,hrefLocation )
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( hrefLocation );
      if( results == null )
        return "";
      else
        return results[1];
    }
    
    // add our function to the SharePoint OnLoad event
    _spBodyOnLoadFunctionNames.push("RedirectLinks"); 
    
    </script>
    • Marked as answer by Miriv365 Thursday, August 20, 2009 2:31 PM
    Wednesday, August 19, 2009 4:56 PM
  • I'm having a similar problem:
    http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/6e9096be-0930-463f-9e97-e5dc49e8eadc

    I can't get the code to work is it because I have this code commented out in my master page:
    //_spBodyOnLoadWrapper();
    Friday, August 28, 2009 4:20 PM
  • Just move the Content Editor Web Part after the calendar web part, remove _spBodyOnLoadFunctionNames and the wrapper function "function RedirectLinks()"

    Why is the function call commented out?


    Mike Smith TechTrainingNotes.blogspot.com
    • Proposed as answer by lalov1 Friday, August 28, 2009 4:55 PM
    • Marked as answer by Mike Walsh FIN Wednesday, July 27, 2011 4:33 AM
    Friday, August 28, 2009 4:31 PM
  • That looks like it works! Thanks! I had it commented out because it conflicts with some of my other JavaScript. Is that bad?
    Friday, August 28, 2009 4:54 PM
  • Other SharePoint JavaScript routines may use it to register themselves. So look to see if there is anything that no longer works.

    If you removed it to add your own <BODY> onload code, then I would put it back, and then call your code as follows:

    function doOnLoadStuff()
    {
      // your onload code here
    }
    
    _spBodyOnLoadFunctionNames.push("doOnLoadStuff"); 
    

    Mike Smith TechTrainingNotes.blogspot.com
    Friday, August 28, 2009 6:48 PM