Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

Wednesday, 15 May 2013

manage show hide site actions sharepoint sp2010

How to manage visibility ( show/hide ) of Site Actions by user in Sharepoint

 

If you want to show site actions menu by user rights easy way of to do that using SPSecurityTrimmedControl .
Conditionally renders the contents of the control to the current user only if the current user has permissions defined in the PermissionString
<SharePoint:SPSecurityTrimmedControl runat=”server” PermissionsString=”ManageWeb”>
<div class=”ms-siteaction”>
….
</div>
</SharePoint:SPSecurityTrimmedControl>
Parameters and attributes:
  • PermissionString:



EmptyMask Has no permissions on the Web site. Not available through the user interface.

ViewListItems View items in lists, documents in document libraries, and view Web discussion comments.

AddListItems Add items to lists, add documents to document libraries, and add Web discussion comments.

EditListItems Edit items in lists, edit documents in document libraries, edit Web discussion comments in documents, and customize Web Part Pages in document libraries.

DeleteListItems Delete items from a list, documents from a document library, and Web discussion comments in documents.

ApproveItems Approve a minor version of a list item or document.

OpenItems View the source of documents with server-side file handlers.

ViewVersions View past versions of a list item or document.

DeleteVersions Delete past versions of a list item or document.

CancelCheckout Discard or check in a document which is checked out to another user.

ManagePersonalViews Create, change, and delete personal views of lists.

ManageLists Create and delete lists, add or remove columns in a list, and add or remove public views of a list.

ViewFormPages View forms, views, and application pages, and enumerate lists.

Open Allow users to open a Web site, list, or folder to access items inside that container.

ViewPages View pages in a Web site.

AddAndCustomizePages Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a SharePoint Foundation–compatible editor.

ApplyThemeAndBorder Apply a theme or borders to the entire Web site.

ApplyStyleSheets Apply a style sheet (.css file) to the Web site.

ViewUsageData View reports on Web site usage.

CreateSSCSite Create a Web site using Self-Service Site Creation.

ManageSubwebs Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.

CreateGroups Create a group of users that can be used anywhere within the site collection.

ManagePermissions Create and change permission levels on the Web site and assign permissions to users and groups.

BrowseDirectories Enumerate files and folders in a Web site using Microsoft Office SharePoint Designer 2007 and WebDAV interfaces.

BrowseUserInfo View information about users of the Web site.

AddDelPrivateWebParts Add or remove personal Web Parts on a Web Part Page.

UpdatePersonalWebParts Update Web Parts to display personalized information.

ManageWeb Grant the ability to perform all administration tasks for the Web site as well as manage content. Activate, deactivate, or edit properties of Web site scoped Features through the object model or through the user interface (UI). When granted on the root Web site of a site collection, activate, deactivate, or edit properties of site collection scoped Features through the object model. To browse to the Site Collection Features page and activate or deactivate site collection scoped Features through the UI, you must be a site collection administrator.

UseClientIntegration Use features that launch client applications; otherwise, users must work on documents locally and upload changes.

UseRemoteAPIs Use SOAP, WebDAV, or Microsoft Office SharePoint Designer 2007 interfaces to access the Web site.

ManageAlerts Manage alerts for all users of the Web site.

CreateAlerts Create e-mail alerts.

EditMyUserInfo Allows a user to change his or her user information, such as adding a picture.

EnumeratePermissions Enumerate permissions on the Web site, list, folder, document, or list item.

FullMask Has all permissions on the Web site. Not available through the user interface.
  • PermissionContext:



CurrentSite Apply a permission mask to the current site.

CurrentList Apply a permission mask to the current list.

CurrentItem Apply a permission mask to the current list or document library item.

RootSite Apply a permission mask to the root site of the site collection.

CurrentFolder Apply a permission mask to the current folder.
  • PermissionMode

All The user must have all of the rights specified in the permission mask to view a link.

Any The user must have only one of the rights specified in the permission mask to view a link.
Happy Codding…

 

Wednesday, 20 February 2013

How to get username from JQuery

 
Use below Jquery to get the Current User name
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "Title",
                debug: false
});
Use below code to get the ID for Current User
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "ID",
                debug: false
});
Use below code to get the LoginName for Current User
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "Name",
                debug: false
});

Thursday, 30 August 2012

How do check if file or image url exists using jQuery or Javascript json js ajax


Approach 1: (If its any file with any extension) :

To check whether files exist in file system, the best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they’re much faster than POST or GET requests. Perfect for a simple file check.
It’s also returns the content length and last modified date and that jQuery has an “ifModified” option for the .ajax function that returns a Boolean value.
This jquery / javascript /js will be useful to check the image / file existence by providing source complete URL path  or relative URL path

Sample Demo Code

$.ajax({
    url:images/header.jpg',
    type:'HEAD',
    error:
        function(){
            alert(‘no File exist);
        },
    success:
        function(){
            alert(‘File exist’);        }
});

Approach 2 : (If its Image File with its related extension.)

The above approach is most recommended since this approach is not that much reliable and performance when compared to it to check existence.

HTML Source:
<img id=”image_id” src=” images/header.jpg” alt=”” />

JQuery:

This Jquery js will get call automatically when image is not available / loaded 
from file system or repository or directory.
 
$('#image_id').error(function() {

  alert('Image does not exist !!');

});
 

Monday, 30 July 2012

Call or acess wcf webservice using ajax jquery code in asp.net c# javascript js

This code sample demonstrate how to pass with or without parameters to WCF service / web service method from client side code ajax jquery json js.
Unlike Javascript, Jquery provides rich access to service method in asp.net c#
 
With Parameters Sample

Client side code with dynamic and static text parameter to web service method from ajax json js With Parameters:-
 
function CallService()  
 { 
      var msg = ‘test message’;
     $.ajax( 
     { 
         Type: "POST", 
         contentType: "application/json; charset=utf-8",
         url: "ServiceName.asmx/WebMethodName", 
         data: "{ 'message': '"+msg+"' , ‘name’: 'test name' }",
         success: function (msg) { 
         alert(msg.d); 
         } 
     });

Server Side webservice / WCF method code :
 
[WebMethod()]
public static string WebMethodName(string message, string name)
{
return message + “--” + name;
}

Without Parameters Sample

Client side code without parameter to web service method from ajax json js With Parameters:-
 
function CallService()  
 { 
     $.ajax( 
     { 
         Type: "POST", 
         contentType: "application/json; charset=utf-8",
         url: "ServiceName.asmx/WebMethodName", 
         data: "{  }",
         success: function (msg) { 
         alert(msg.d); 
         } 
     });

Server Side webservice / WCF method code :

[WebMethod()]
public static string WebMethodName()
{
return “success”;
}

Monday, 7 May 2012

Listbox move updown rightleft jquery


Listbox Move Up Down Right Left Delete Item value show / select all check list items in asp.net controls using jquery js sample demo code:


This jquery/js will perform the following function (not by using javascript method)...

1. Move list items between two listbox with multiple move option
2. Delete List Item / multiple list items.
3. Move list items up and down (multiple)
4. Seletet / read all list items. (option to show selected list items is commented in jquery js code)



Script sample demo code
<script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function() {
            $("#MoveRight,#MoveLeft").click(function(event) {
                var id = $(event.target).attr("id");
                var selectFrom = id == "MoveRight" ? "#from" : "#to";
                var moveTo = id == "MoveRight" ? "#to" : "#from";

                var selectedItems = $(selectFrom + " :selected").toArray();
                $(moveTo).append(selectedItems);
                selectedItems.remove;
            });
        });
    //function moveUp() {
    $(function() {
    $("#MoveUp").click(function(event) {
  
    $('#to :selected').each(function(i, selected) {
        if (!$(this).prev().length) return false;
        $(this).insertBefore($(this).prev());
    });
    $('#to select').focus().blur();
  
});
});

//function moveDown() {
$(function() {
$("#MoveDown").click(function(event) {
    $($('#to :selected').get().reverse()).each(function(i, selected) {
        if (!$(this).next().length) return false;
        $(this).insertAfter($(this).next());
    });
    $('#to select').focus().blur();
  
});
});
$(function() {
$("#ReadAll").click(function(event) {
$('#to option').each(function(index) {
//  if ( ($(this).is(':selected')) {
//    // do stuff if selected
//  }
//  else {
//   // this one isn't selected, do other stuff
//  }
alert($(this).val()+'--' + $(this).text());
});
});
});
$(function() {

$("#Delete").click(function(event) {
    $('#to :selected').each(function(i, selected) {
      
        $(this).remove();
        alert('Selected item deleted');
       $('#to').focus().blur();
  
});
});
});

    </script>
 
 
 
HTML APSX Source code 

<div>
    <asp:ListBox ID="from" runat="server" SelectionMode="Multiple">
    <asp:ListItem Value="f1">frm list 1</asp:ListItem>
    <asp:ListItem Value="f2">frm list 2</asp:ListItem>
    <asp:ListItem Value="f3">frm list 3</asp:ListItem>
    <asp:ListItem Value="f4">frm list 4</asp:ListItem>
    <asp:ListItem Value="f5">frm list 5</asp:ListItem>
    </asp:ListBox>
 
   
    <input id="MoveRight" type="button" value=" >> " />
    <input id="MoveLeft" type="button" value=" << " />
    <input id="MoveUp" type="button" value=" UP " />
    <input id="MoveDown" type="button" value=" Down " />
    <input id="Delete" type="button" value=" Delete Item " />
    <input id="ReadAll" type="button" value=" Read All " />
     
    <asp:ListBox ID="to" runat="server" SelectionMode="Multiple">
    <asp:ListItem Value="to1">to list 1</asp:ListItem>
    <asp:ListItem Value="to2">to list 2</asp:ListItem>
    <asp:ListItem Value="to3">to list 3</asp:ListItem>
    <asp:ListItem Value="to4">to list 4</asp:ListItem>
    <asp:ListItem Value="to5">to list 5</asp:ListItem>
    </asp:ListBox>
    </div>

Thursday, 19 April 2012

textbox watermark javascript jquery

How to add watermark to single/multiple textbox control using javascript/jquery js in Asp.net C# code:

The below sample has two approach by using jquery as well as javascript js.


Sample ASPX source code sample:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>

    <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">

/* js on load method*/  

$(document).ready(function() {
     var watermark = 'Enter your text';
     $('#txtBox').blur(function(){
      if ($(this).val().length == 0)
        $(this).val(watermark).addClass('watermark');
     }).focus(function(){
      if ($(this).val() == watermark)
        $(this).val('').removeClass('watermark');
     }).val(watermark).addClass('watermark');
    });

/* javascript function*/   
    function watermark(inputId,text){
      var inputBox = document.getElementById(inputId);
        if (inputBox.value.length > 0){
          if (inputBox.value == text)
            inputBox.value = '';
        }
        else
          inputBox.value = text;
    }
    </script>
  
    <style type="text/css">
    #txtBox.watermark { color: #999; } /*Gray color*/
    </style>
  
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="txtBox" runat="server"></asp:TextBox>
  
    <asp:TextBox ID="txtName" runat="server" Text="Enter your name" onfocus="watermark(this.id,'Enter your name');" onblur="watermark(this.id,'Enter your name');"></asp:TextBox>
    <asp:TextBox ID="txtAddress" runat="server" Text="Enter your Address" onfocus="watermark(this.id,'Enter your Address');" onblur="watermark(this.id,'Enter your Address');"></asp:TextBox>
    </div>
    </form>
</body>
</html>

calling server side function/method jquery-ajax


How to Call server side C# asp.net code behind method/ function from client side code using ajax jquery/json js:

The below sample demonstrate how to call server side web method/function using jquery js not by javascript.

This sample code also shows how to call web method from asp.net button control (server side control) and HTML hyperlink anchor tag (client side control)

Sample ASPX source code:
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
   
    <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
   
     <script type ="text/javascript">
         $(document).ready(function () {
            $('#<%=Button1.ClientID %>').click(function () {
                $.ajax({
                    type: "POST",
                    url: "serversidecallfromjs.aspx/callServerMethod",
                    data: "{}", /*indicates no parametre is passed to web method/function*/
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    cache: false,
                    success: function (msg) {
                      $('#msgDiv').text(msg.d);
                   }
                })
               return false;
             });
       });

function callm()
{

 $.ajax({
                    type: "POST",
                    url: "serversidecallfromjs.aspx/callServerMethod1",
                    data: "{'parname': 100}" /*if any parametre is there means {'parname': 1}*/,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    cache: false,
                    success: function (msg) {
                      $('#msgDiv').text(msg.d);
                   }
                })
                return false;
}

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" Text="Click" />
    <br />
    <a href="#" onclick="callm();">Click 2 clock</a>
    <br />
    <div id="msgDiv"></div>
    </div>
    </form>
</body>
</html>

Code behind:
 
using System.Web.Services;

namespace MyWebApps
{
    public partial class serversidecallfromjs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod]
        public static string callServerMethod()
        {
            return "Response from server.";
        }
        [WebMethod]
        public static string callServerMethod1(string parname)
        {
            return "Response from server" + parname + ".";
        }
      
    }
}
 

Monday, 9 April 2012

jquery for each loop to read elements

How to read elements by using for each loop in jquery ?

function(index, Element) -- A function to execute for each matched element.

The .each() method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0. More importantly, the callback is fired in the context of the current DOM element, so the keyword this refers to the element.

Example  1: Iterates through the array displaying each value text:

<script type="text/javascript">

var arrvar = [ "sample javascript code1", "sample javascript code2", "sample javascript code1", "sample javascript code1", "sample javascript code1" ];


    jQuery.each(arrvar, function() {
         alert(this);
      });

</script>

Example 2:Iterates over div elements /controls

      <div id="div1">jquery call 1</div>
      <div id="div2">javascript alert 1</div>
      <div id="div3">jquery call 2</div>
      <div id="div4">javascript alert 2</div>
      <div id="div5">jquery call 3</div>

<script type="text/javascript"> 

//$(document).click(function() { // onclick of body content call $(document).ready(function() {
 
      $("div").each(function () {
        alert($(this).text());
      });
    });

</script>

 

 

 

Thursday, 15 March 2012

set css all style for hyper link or image tags inside the div or panel or any other control id using jquery

How to set css style for all hyper link or image  tags inside the div or panel or any other control id using jquery:


Jquery Tips:

Unlike the javascript, we can easily style for all hyper link or image  tags inside the div or panel or any other control id using jquery:

By using, we can avoid use of looping / for each conditions.

This will be used to set css styles to the element dynamically.

Sample Code:


For all hyper link inside the DIV element.

$('#divid').find('a').css({visibility : "visible", display : "none"});

For all image inside the DIV element.


$('#divid').find('img').css({visibility : "visible", display : "none"});

How to get element attribute by css class name or id using jquery

How to get element attribute by css class name or id jquery:

Jquery Tips:

Unlike the javascript, we can easily get the elements attribute easily.
By using, we can avoid use of looping / for each conditions

Sample Code:

/* to get class name attribute- find using by css class name*/
var className = $('.classname').attr('class');
or
var className = $('.classname[class]');

/* to get id attribute- find using by css class name*/
var className = $('.classname').attr('class');
or
var className = $('.classname[class]');


/* to get class name attribute - find using by ID*/
var className = $('#idname').attr('class');
or
var className = $('#idname[class]');

/* to get id attribute- find using by ID*/
var className = $('#idname').attr('class');
or
var className = $('#idname[id]');

how to select different element id with the repeated matched class name using jquery

How to select element id when it have common style CSS class  name using jquery:

Scenario:

I have the repeated class name with different element id. on click or on mouse over, how could i get matched element id using jquery not by javascript. 

No need to do for each loop condtion

To achieve this, we need a pretty basic regular expression, like so.
The following example will not validate the html code. It just check the matched css class and get the respect whatevee attribute we want from that element.

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FindClassJQuery.aspx.cs" Inherits="MyWebApps.FindClassJQuery" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>

    <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function($) {
    $("[class^=testcss]").click(function(Event) {
    var id = $(this).attr('id');
    alert(id);
});
});
</script>
<style type="text/css">
.testcss1, .testcss2, .testcss3
{
color:Red;
font-weight:bold;
/*background-image:url(images/aa1.jpg);*/
}

</style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div class="testcss1" id="div1">test1</div>
    <div class="testcss2" id="div2">test2</div>
    <div class="testcss3" id="div3">test3</div>
    </div>
    </form>
</body>
</html>