Tuesday, April 30, 2013

Remove hyperlink from lookup column in Dataview webpart in Sharepoint 2010

When you used lookup column in the list and implemented it in custom dataview webpart, the hyperlink appears on the lookup field value.

To remove the link from lookup field used the following tag:-

Just you have to replace with

<xsl:value-of disable-output-escaping="yes" select="@Teams"/>

By:

<xsl:value-of disable-output-escaping="yes"
select="substring-after(substring-before(substring-after(@Teams, 'ID='), '&lt;'), '&gt;')"/>


If you have added multiple selection lookup value in your list, and you want to remove hyperlink from field, the above trick will not work. For that we required to more customise the XSLT and used the following code:-

In multiple selection lookup value shows in data view web part:-

Team1; Team2; Team3; Team4

We will format it to:-

Team1
Team2
Team3
Team4

Using the following code:-

Add the below template to your data view web part:-

<!—Semicolon delimit start -- >
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />                
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!—Semicolon delimit End -- >

<!—Remove Hyperlink start-- >

<xsl:template name="deleteAnchorTags">
<xsl:param name="Anchor"/>
<xsl:choose>
<xsl:when test="contains($Anchor, '&lt;')">                                    
<xsl:value-of select="substring-before($Anchor, '&lt;')"/>
<xsl:call-template name="deleteAnchorTags">
<xsl:with-param name="Anchor" select="substring-after($Anchor, '&gt;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Anchor"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!—Remove Hyperlink End-- >


And replace your tag with:-

<xsl:value-of disable-output-escaping="yes" select="@Teams"/>

By:-

<xsl:variable name="onlyText">
<xsl:call-template name="deleteAnchorTags">
<xsl:with-param name="Anchor" select="@Teams" />
</xsl:call-template>
</xsl:variable>
 <xsl:variable name="thisRow">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$onlyText" />
<xsl:with-param name="replace" select="';'" />
<xsl:with-param name="by" select="'&lt;br/&gt;'" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$thisRow" disable-output-escaping="yes"/>


Happy coding..... :-) :-) :-)

Thursday, January 17, 2013

Ribbon menu missing on page load after customisation


After  Customisation in sharepoint pages ribbon menu missing on page load for perticular webpart.

            In sharepoint 2010, if you have more than one webpart on webpart page, the ribbon disappears because SharePoint doesn't know which web part to display ribbon for. This is by design because if you have a document library web part and list web part on the same page, the ribbons are obviously differ for the two and sharepoint needs to know which webpart to display the ribbon for.

To avoid the above problem use the following javascript.

<Script>
setTimeout(function()
{

var obj = document.getElementById("MSOZoneCell_WebPartWPQ3");
if(obj != null)
{

var obj1 = new Array()

obj1["target"] = obj

obj1 ["srcElement"] = obj

WpClick(obj1)
}
},2000)

</Script>

Overlay calendar items open in new window instead in Modal Popup

When you create overlay calendar view for combined 2 or 3 views especially for colour coded calendar, if you create event with category and click on it, it will open in popup which is by default function of SharePoint.
If you create event without category column value and click on it, it will open in new window. To remove the above problem use the below javascript.

<script src="/sites/CUEDemo/Code%20Library/jquery-1.8.3.min.js" type="text/javascript"></script>

<script type="text/javascript">
// load our function to the delayed load list
                _spBodyOnLoadFunctionNames.push('calendarEventLinkIntercept');

                // hook into the existing SharePoint calendar load function.
                function calendarEventLinkIntercept()
                {
                                if (SP.UI.ApplicationPages.CalendarNotify.$4a)
                                                {
                                                var OldCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4a;
                                                SP.UI.ApplicationPages.CalendarNotify.$4a = function ()
                                                {
                                                OldCalendarNotify();
                                                bindEventClickHandler();
                                                }
                                                }
                                if (SP.UI.ApplicationPages.CalendarNotify.$4b)
                                                {
                                                var OldCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4b;
                                                SP.UI.ApplicationPages.CalendarNotify.$4b =  function ()
                                                {
                                                OldCalendarNotify();
                                                bindEventClickHandler();

                                                } 
                                }
                  // future service pack change may go here!
                  // if (SP.UI.ApplicationPages.CalendarNotify.???)
                }

                function bindEventClickHandler()             {
                                $('.ms-acal-rootdiv a').click(function(){EditLink2(this,'WPQ2');return false;});
                }



</script>

Avoid Contributor user to edit home page in sharepoint 2012 Team site

This is contributor permission issue(sharepoint 2012 bug). Normally when you create Sharepoint 2012 team site, the home page by default create under "SitePages" library.

The contributor users on site can easily modify home page and change setting of webpart and layouts.
The key to that issue is in the description "customize Web Part Pages in document libraries ", and it's the "in document libraries " that's the problem. When a page is in a library, it is treated as a file or document. If the user has "contribute" or Edit permissions to the library storing the page then they have the right to edit the page.
In 2007 the home page (default.aspx) was stored outside of a library, so "contributors" did not have edit rights by default. In 2010 Team Sites the home page is stored in the SitePages library that inherits permissions from the site, and therefore contributors have edit rights.
The solution is to set custom permissions in the pages library. Just break inheritance and grant your team members View only rights and the Site Owners full control.

Happy Coding.......... :-)

Thursday, August 9, 2012

SharePoint 2010 Webpart page not showing Quick Launch

Some times SharePoint 2010 site newly created webpart page, publishing page does not show Quick launch bar(Left navigation panel) on page. It might be hide by some css available on page or some content place holder override by master page.

To solve the above issue, follow the following steps:-
1) Open your site in sharepoint designer.
2) Open your webpart page in advanced mode.
3) Remove the below content place holder.
   
<asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server">
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server">
</asp:Content>
 
4)Save the page, it will show the Quick launch bar on page. If it is not showing on page, then remove the below CSS available on page:-
 
<style type="text/css">
body #s4-leftpanel {
    display:none;
}
.s4-ca {
    margin-left:0px;
}
</style>

5) Save the page, quick launch bar appear on page.

Thursday, March 8, 2012

Disabled print option for SharePoint page


If you want to prevent user from printing SharePoint site page, you can use the below script in CEWB on your SharePoint site.


//Disabled File print and ctrl + P
<style type="text/css" media="print">
body { visibility: hidden; display: none }
</style>

The above JavaScript is not totally disabled the CTRL + P or Print option from browser File option. It tells the browser that if this Web page is set to print, switches the body to display nothing. Then, all that will print will be the standard header and/or footer that the browser appends to printed pages.  The user always get printed page with heading and blank page.

Disabled Right click, CTRL + A, C, V using JavaScript in SharePoint


You want user to avoid copy, Paste data from SharePoint site, use the below script in CEWB. It will prevent user to right click, and Copy, Paste data from SharePoint page

<script type="text/javascript">
    var message="Sorry, you do not have permission to right click.";

    function clickIE4(){
    if (event.button==2){
        alert(message);
        return false;
        }
    }

    function clickNS4(e){
        if (document.layers||document.getElementById&&!document.all){
            if (e.which==2||e.which==3){
                alert(message);
                return false;
                }
            }
        }
        if (document.layers){
            document.captureEvents(Event.MOUSEDOWN);
            document.onmousedown=clickNS4;
            }
        else if (document.all&&!document.getElementById){
            document.onmousedown=clickIE4;
        }
        document.oncontextmenu=new Function("alert(message);return false")
</script>

<script language="JavaScript1.2">

function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>