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

Tuesday, August 16, 2011

Calling List webservice using Jquery

Most of the times we generally use object model to query SharePoint List.But not all development environments gives you an option of custom code.So JQuery along with Content Editor WebPart.
Here is the scenario I had a case of using dataview webpart which needs to be filtered basing on criteria, as we can create a parameter based on query string.In this case I am intrested in the filter rather than how to create DVWP.So coming to the coding part
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<getlistitems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
<listname>AppStatusList</listName> \
<viewfields> \
<viewfields> \
<fieldref Name='Title' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";

$.ajax({
url: "http://balaapd004/dept/cs/test/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});

$('#ddlSelect').change(function() {
//var selectedValue=
$('#txtResult').val($('#ddlSelect option:selected').text());
});
});

function processResult(xData, status) {
var listItems="";

$(xData.responseXML).find("z\\:row").each(function() {
listItems+= "<option value='" + $(this).attr("ows_ID") + "'>" + $(this).attr("ows_Title") + "</option>";
$("#ddlSelect").html(listItems);

});
}
</script>

<select id="ddlSelect">
</select>
<input type="text" id="txtResult" />

Friday, June 24, 2011

To Find if the Page in MOSS is in Design Mode

Some Times we have to make the Jquery/JavaScript run when its not in the design mode.
I don't know how many of us has noted this tag "MSOLayout_InDesignMode" .This is a hidden HTML field present on the page. So using that its simple.

The HTML looks like this:
<input type="hidden" name="MSOLayout_InDesignMode" id="MSOLayout_InDesignMode" value="" />
if (document.getElementById("MSOLayout_InDesignMode").value != "1")
{
//do something
}
else
{
//do something
}

Thursday, June 23, 2011

URL Encoding using JQuery

Ever came across a scenario where you have to encode using JavaScript/JQuery other than using C# especially in SharePoint.One of my experience User required a link when clicked to be passed as filter value to the Document Library/List.If the value is simple Text its easy but if the value contains Ex: Harrison & Thomas there is the problem .If you pass in the mentioned value as a  Query string parameter it understands as two arguments and hence the Library is not filtered .Here comes the encoding part as we can extended the Jquery Library function.

$.extend({URLEncode:function(c){var o='';var x=0;c=c.toString();
var r=/(^[a-zA-Z0-9_.]*)/;
  while(x
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){
  b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});

Now you can call this  function as
$.URLEncode($(this).attr("title"));

Hint: Place this script below the List in Content Editor WebPart