<!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>
<title>Simple SPS List Management Code</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style>
body
{
margin-left:1px;
}
</style>
<script type="text/javascript" src="/mysite/IS/mn/Files%20To%20Share/jquery-1.10.2.js"></script>
<script type="text/javascript" src="/mysite/IS/mn/Files%20To%20Share/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript" src="/mysite/IS/mn/Files%20To%20Share/jquery.SPServices-2014.02.js"></script>
<script type="text/javascript">
function addItem()
{
var strSubsiteName = document.getElementById("txtSubsiteName").value
var columnsForInsert = [];
columnsForInsert[0] = ["Title", document.getElementById("txtTitle").value];
columnsForInsert[1] = ["Country", document.getElementById("txtCountry").value];
columnsForInsert[2] = ["Code", document.getElementById("txtCode").value];
// Create New List Item
$(document).ready(function() {
$().SPServices({
operation: "UpdateListItems",
webURL: "/mysite/IS/"+strSubsiteName,
async: true,
batchCmd: "New",
listName: "SPS",
valuepairs: columnsForInsert,
completefunc: function (xData, Status) {
alert("List Item successfully created.");
}
}); // End of SPServices UpdateListItems
});
}
function updateItem()
{
var strSubsiteName = document.getElementById("txtSubsiteName").value
var nDeleteID = document.getElementById("txtID").value;
if (parseInt(nDeleteID, 10))
{
alert("Item with ID of " + nDeleteID + " will be updated.");
}
else
{
alert("Please enter a valid ID to update list data.");
return;
}
var columnsForUpdate = [];
columnsForUpdate [0] = ["Title", document.getElementById("txtTitle").value];
columnsForUpdate [1] = ["Country", document.getElementById("txtCountry").value];
columnsForUpdate [2] = ["Code", document.getElementById("txtCode").value];
// Update List Item
$(document).ready(function() {
$().SPServices({
operation: "UpdateListItems",
webURL: "/mysite/IS/"+strSubsiteName,
async: true,
batchCmd: "Update",
listName: "SPS",
ID: nDeleteID,
valuepairs: columnsForUpdate,
completefunc: function (xData, Status) {
alert("List Item has been updated");
}
});
});
}
function deleteItem()
{
var strSubsiteName = document.getElementById("txtSubsiteName").value
var nDeleteID = document.getElementById("txtID").value;
if (parseInt(nDeleteID, 10))
{
alert("Item with ID of " + nDeleteID + " will be deleted.");
}
else
{
alert("Please enter a valid ID to delete from list.");
return;
}
// Delete List Item
$(document).ready(function() {
$().SPServices({
operation: "UpdateListItems",
webURL: "/mysite/IS/"+strSubsiteName,
async: true,
batchCmd: "Delete",
listName: "SPS",
ID: nDeleteID,
completefunc: function (xData, Status) {
alert("List Item deleted");
}
});
});
}
function deleteFile()
{
var nDeleteID = document.getElementById("txtID").value;
var strFileRef = document.getElementById("txtFileRef").value;
if (strFileRef == "")
{
alert("Must enter a ref URL to the file in the library that you wish to delete. Eg : http://myserver/document/mydoc.docx");
return;
}
if (parseInt(nDeleteID, 10))
{
alert("Item with ID of " + nDeleteID + " will be deleted.");
}
else
{
alert("Please enter a valid ID to delete from list.");
return;
}
// This is the command needed to delete the specified file. It uses the ID and the URL of the file name. These values must be passed into this function when calling it.
var batchCmd = "<Batch OnError='Continue'><Method ID='1' Cmd='Delete'><Field Name='ID'>" + nDeleteID + "</Field><Field Name='FileRef'>" + strFileRef + "</Field></Method></Batch>";
// Use SPServices to delete the file.
$().SPServices({
operation: "UpdateListItems",
async: false,
listName: "SPS",
updates: batchCmd,
completefunc: function ( xData, Status ) {
// Check the error codes for the web service call.
$( xData.responseXML ).SPFilterNode( 'ErrorCode' ).each( function(){
responseError = $( this ).text();
// If the error codes indicate that the file was successfully deleted, inform the user.
if ( responseError === '0x00000000' ) {
alert( "The file has been successfully deleted." );
}
// If the error codes indicate that the file was NOT successfully deleted, inform the user.
else {
alert( "There was an error trying to delete the file." );
}
});
}
});
}
</script>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
// Test Concept functions trying to add OR to a AND CAML query
function getPMAFunds_And_Or()
{
var strDeptValue = "Equities";
var strRegionValue = "TW";
var strReportTypeValue = "Attribution";
var strReportFinderType = "Active";
$(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>Report Names</listName> \
<query><Query><Where><And><And><And><And><Contains><FieldRef Name='Asset_Type'/><Value Type='Text'>"+strDeptValue+"</Value></Contains> \
<Contains><FieldRef Name='Report_Type'/><Value Type='Text'>"+strReportTypeValue+"</Value></Contains> \
</And> \
<Contains><FieldRef Name='Region'/><Value Type='Text'>"+strRegionValue+"</Value></Contains> \
</And> \
<Contains><FieldRef Name='Live'/><Value Type='Text'>"+strReportFinderType+"</Value></Contains> \
</And><Or><Or><Or> \
<Contains> \
<FieldRef Name='Group1' /> \
<Value Type='Boolean'>0</Value> \
</Contains> \
<Contains> \
<FieldRef Name='Group2' /> \
<Value Type='Boolean'>0</Value> \
</Contains> \
</Or> \
<Contains> \
<FieldRef Name='Group3' /> \
<Value Type='Boolean'>0</Value> \
</Contains> \
</Or> \
<Contains> \
<FieldRef Name='Group4' /> \
<Value Type='Boolean'>1</Value> \
</Contains> \
</Or> \
</And> \
</Where> \
<OrderBy><FieldRef Name='Display_Code' Ascending='TRUE' /></OrderBy></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Display_Code' /> \
<FieldRef Name='Asset_Type' /> \
<FieldRef Name='Report_Code' /> \
<FieldRef Name='Region' /> \
<FieldRef Name='Live' /> \
<FieldRef Name='Report_Type' /> \
<FieldRef Name='Group1' /> \
<FieldRef Name='Group2' /> \
<FieldRef Name='Group3' /> \
<FieldRef Name='Group4' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/mysite/is/mn/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processPMAFunds,
contentType: "text/xml; charset=\"utf-8\""
});
});
}
function getPMAFunds_All_Ands()
{
var strDeptValue = "Equities";
var strRegionValue = "TW";
var strReportTypeValue = "Attribution";
var strReportFinderType = "Active";
$(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>Report Names</listName> \
<query><Query><Where><And><And><And><And><And><And><And><Contains><FieldRef Name='Asset_Type'/><Value Type='Text'>"+strDeptValue+"</Value></Contains> \
<Contains><FieldRef Name='Report_Type'/><Value Type='Text'>"+strReportTypeValue+"</Value></Contains> \
</And> \
<Contains><FieldRef Name='Region'/><Value Type='Text'>"+strRegionValue+"</Value></Contains> \
</And> \
<Contains><FieldRef Name='Live'/><Value Type='Text'>"+strReportFinderType+"</Value></Contains> \
</And> \
<Contains> \
<FieldRef Name='Group1' /> \
<Value Type='Boolean'>0</Value> \
</Contains> \
</And> \
<Contains> \
<FieldRef Name='Group2' /> \
<Value Type='Boolean'>0</Value> \
</Contains> \
</And> \
<Contains> \
<FieldRef Name='Group3' /> \
<Value Type='Boolean'>1</Value> \
</Contains> \
</And> \
<Contains> \
<FieldRef Name='Group4' /> \
<Value Type='Boolean'>1</Value> \
</Contains> \
</And> \
</Where> \
<OrderBy><FieldRef Name='Display_Code' Ascending='TRUE' /></OrderBy></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Display_Code' /> \
<FieldRef Name='Asset_Type' /> \
<FieldRef Name='Report_Code' /> \
<FieldRef Name='Region' /> \
<FieldRef Name='Live' /> \
<FieldRef Name='Report_Type' /> \
<FieldRef Name='Group1' /> \
<FieldRef Name='Group2' /> \
<FieldRef Name='Group3' /> \
<FieldRef Name='Group4' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/mysite/is/mn/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processPMAFunds,
contentType: "text/xml; charset=\"utf-8\""
});
});
}
// End of Test Functions
////////////////////////////////////////////////////////////////////////////////////////////////////
var strGroupsUserBelongsTo = "";
/* place code right before the matching closing tag </asp:Content> for <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">*/
$(document).ready(function() {
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function(xData, Status) {
// Code below to set what permission current user belongs to
if($(xData.responseXML).find("Group[Name='Group Owners']").length == 1) {
//alert("User is in the group");
// set the string for user's permission settings. If he is in a group it is 1 else 0.
// this string will be used later.
strGroupsUserBelongsTo = "1,0,0,0";
// Call main get funds function
getPMAFunds("0,1,0,0");
}
else
{
strGroupsUserBelongsTo = "1,0,0,1";
getPMAFunds("1,0,0,0");
}
}
}); /*close().SPServices({ */
}); /* close (document).ready(function() { */
function getPMAFunds(strGroupsUserIn)
{
var strDeptValue = "Equities";
var strRegionValue = "TW";
var strReportTypeValue = "Characteristics";
var strReportFinderType = "Active";
$(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>Report Names</listName> \
<query><Query><Where><And><And><And><Contains><FieldRef Name='Asset_Type'/><Value Type='Text'>"+strDeptValue+"</Value></Contains> \
<Contains><FieldRef Name='Report_Type'/><Value Type='Text'>"+strReportTypeValue+"</Value></Contains> \
</And> \
<Contains><FieldRef Name='Region'/><Value Type='Text'>"+strRegionValue+"</Value></Contains> \
</And> \
<Contains><FieldRef Name='Live'/><Value Type='Text'>"+strReportFinderType+"</Value></Contains> \
</And> \
</Where> \
<OrderBy><FieldRef Name='Display_Code' Ascending='TRUE' /></OrderBy></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Display_Code' /> \
<FieldRef Name='Asset_Type' /> \
<FieldRef Name='Report_Code' /> \
<FieldRef Name='Region' /> \
<FieldRef Name='Live' /> \
<FieldRef Name='Report_Type' /> \
<FieldRef Name='Group1' /> \
<FieldRef Name='Group2' /> \
<FieldRef Name='Group3' /> \
<FieldRef Name='Group4' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "/mysite/is/mn/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: function(jqXHR, textStatus)
{
processPMAFunds(jqXHR, textStatus, strGroupsUserIn)
},
contentType: "text/xml; charset=\"utf-8\""
});
});
}
function processPMAFunds(xData, status, strGroups)
{
var strForDropDown = "";
$(xData.responseXML).find("z\\:row, row").each(function() {
strForDropDown = strForDropDown + $(this).attr("ows_Display_Code") + "@" + $(this).attr("ows_Report_Code") + "@" + $(this).attr("ows_Group1") + "@" + $(this).attr("ows_Group2") + "@" + $(this).attr("ows_Group3") + "@" + $(this).attr("ows_Group4") + "@" +"\n";
});
// Now populate the department dropdown with our extracted data
alert(strGroups);
//alert(strForDropDown);
populateFunds(strForDropDown, strGroups);
}
// function that populates fund drop down
function populateFunds(strForDropDown, strGroupsForUser)
{
//Clear the dropdown if there is anything.
document.getElementById("cboFunds").options.length = 0;
document.getElementById("cboFunds").options[0] = new Option("(None)", "None");
if (strForDropDown != "")
{
var item_array = strForDropDown.split("\n");
for (var iCount = 0; iCount < (item_array.length-1); iCount++)
{
//alert(item_array[iCount].toString());
var items = item_array[iCount].split("@");
try
{
// Force "None" into all values because it needs this value to fool SharePoint into accepting it when saving
var bHasPermission = userHasPermission(items[2], items[3], items[4], items[5], strGroupsForUser)
if (bHasPermission == true)
{
document.getElementById("cboFunds").options[iCount+1] = new Option(items[0], items[1]);
}
}
catch(ex)
{
alert("Possible array out of bound error - populateFunds(strForDropDown)");
}
}
}
else
{
document.getElementById("cboFunds").options[0] = new Option("(None)", "None");
}
// Trim the select box of null items. The above insertions can result in some blank entries
for (var i = 0; i < document.getElementById("cboFunds").length; i++)
{
if (document.getElementById("cboFunds").options[i].value == "")
{
//alert("Null Item at " + i);
document.getElementById("cboFunds").remove(i);
i = i - 1;
}
}
}
// function to decide whether user has permission to see a fund
function userHasPermission(strGroup1, strGroup2, strGroup3, strGroup4, strGroupsUserBelongs)
{
var returnPermission = false;
//var userPermissions = strGroupsUserBelongsTo.split(",");
var userPermissions = strGroupsUserBelongs.split(",");
if (userPermissions[0] == 1 && strGroup1 == 1)
{
returnPermission = true;
}
if (userPermissions[1] == 1 && strGroup2 == 1)
{
returnPermission = true;
}
if (userPermissions[2] == 1 && strGroup3 == 1)
{
returnPermission = true;
}
if (userPermissions[3] == 1 && strGroup4 == 1)
{
returnPermission = true;
}
// If nothing been initialised and set, show it to users. Remove this section if you want to block access instead.
if (strGroup1 == "undefined" && strGroup2 == "undefined" && strGroup3 == "undefined" && strGroup4 == "undefined")
{
returnPermission = true;
}
return returnPermission;
}
getUserBU();
function getUserBU()
{
var strReportTypeValue = "Simon Chung";
$(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>GWMS_ContactList</listName> \
<query><Query><Where><Contains><FieldRef Name='Title'/><Value Type='Text'>"+strReportTypeValue+"</Value></Contains></Where> \
<OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy></Query></query> \
<viewFields> \
<ViewFields> \
<FieldRef Name='Title' /> \
<FieldRef Name='BusinessContactDept0' /> \
</ViewFields> \
</viewFields> \
</GetListItems> \
</soapenv:Body> \
</soapenv:Envelope>";
$.ajax({
url: "http://mfcgim.ap.manulife.com/mysite/IS/gwms/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processUserBUs,
contentType: "text/xml; charset=\"utf-8\""
});
});
}
function processUserBUs(xData, status)
{
var strForDropDown = "";
$(xData.responseXML).find("z\\:row").each(function() {
strForDropDown = strForDropDown + $(this).attr("ows_Title") + "@" + $(this).attr("ows_BusinessContactDept0") +"\n";
});
// Now populate the department dropdown with our extracted data
alert(strForDropDown);
}
alert($().SPServices.SPGetCurrentUser());
</script>
</head>
<BODY>
<div id="StatusMessages" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; margin-left:0px; font-family:Verdana; font-size:small">
<input type="button" onclick="addItem()" value="Add Item" style="font-family:inherit;font-size:small" />
<input type="button" onclick="updateItem()" value="Update Item" />
<input type="button" onclick="deleteItem()" value="Delete Item" />
<input type="button" onclick="deleteFile()" value="Delete Item - File" /><br><br>
ID: <input type="text" id="txtID" name="txtID"/> Title: <input type="text" id="txtTitle" name="txtTitle"/> Country: <input type="text" id="txtCountry" name="txtCountry"/> Code: <input type="text" id="txtCode" name="txtCode"/> Subsite URL Name: <input type="text" id="txtSubsiteName" name="txtSubsiteName"/><br><br>
File Ref : Must be added for Delete File <input type="text" id="txtFileRef" name="txtFileRef" size="100"/><br><br>
Funds to Select : <select name="cboFunds" id="cboFunds" style="WIDTH: 330px"><option></option></select>
</div>
<script type="text/javascript">
</script>
</BODY></html>
No comments:
Post a Comment