10000 GitHub - inedu/spyreqs: SharePoint Requests
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

inedu/spyreqs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

InEdu SPyReqs.js

(SharePoint-Y not use this lib forREQuestS!)

Spyreqs is a library that contains general purpose methods useful for interacting with the sharepoint lists and files. It is dependent on the jQuery. It will work with a Sharepoint auto-hosted app even without the hostUrl & appUrl URLquery properties!

Welcome!

With spyreqs, you can manage:
  • Web, (Host/App web)
  • Lists,
  • List items,
  • Inheritance,
  • Users,
  • Permissions,
  • 'Recent' elements node,
  • Recycle Bin
  • Files

A few words

The spyreqs library exposes to the window the spyreqs object which has three properties:
  1. The rest property which is an object that contains rest methods
  2. The jsom property which is an object that contains jsom methods
  3. The utils property which is an object that contains general purpose methods

Both spyreqs.rest and spyreqs.jsom contains methods that refers either to the Application scope or to the Host Site scope. If the method is for use in the App scope then it contains 'App' in its name otherwise it contains 'Host'. Because description, parameters and results of both app methods and host methods are identical for each case there will be documentation for one of them. All spyreqs.rest and spyreqs.jsom methods return jQuery promises which are compatible with Q promises library and the subset of Q contained in Angular Framework.

Methods dictionary

rest.
getHostLists, getAppLists
getHostListByTitle, getAppListByTitle
getHostListItems, getAppListItems
getHostListFields, getAppListFields
createHostList, createAppList
addHostListItem, addAppListItem
addAppFolder, addHostFolder
deleteHostListItem, deleteAppListItem
updateHostListItem, updateAppListItem
updateHostListField, updateAppListField
addHostListField, addAppListField
breakRoleInheritanceOfHostList, breakRoleInheritanceOfAppList
resetRoleInheritanceOfHostList, resetRoleInheritanceOfAppList
breakRoleInheritanceOfHostWeb, breakRoleInheritanceOfAppWeb
resetRoleInheritanceOfHostWeb, resetRoleInheritanceOfAppWeb
addHostFile, addAppFile
addHostBinaryFile, addAppBinaryFile
getHostFolderFiles
getHostFolderFolders
addHostFolder
getHostListItemAttachments, addHostListItemAttachment
getSiteUsers, getCurrentUser
updateHostList
givePermissionToGroupToAppList
getHostListRoleAssigmnent, deleteAppFolder
postAsynq, getAsynq

jsom.
checkHostList, checkAppList
getHostList, getAppList
deleteHostList, deleteAppList
recycleHostList, recycleAppList
recycleHostListItem, recycleAppListItem
getHostListItems, getAppListItems
addHostListItem, addAppListItem
updateAppListItem, updateHostListItem
getAppListItemsPaginated, getHostListItemsPaginated
updateHostListItemsPaginated, recycleHostListItemsPaginated
deleteHostListItemsPaginated, deleteAppListItemsPaginated
removeHostRecentElemByTitle, removeAppRecentElemByTitle
createHostList, createAppList
getAppListPermissions
getHostListItemHasUniquePerms, getAppListItemHasUniquePerms
getAllHostListsHasUniquePerms, getAllAppListsHasUniquePerms
getHostProperty, getAppProperty
setHostProperty, setAppProperty

spyreqs.rest methods

For all the Rest methods the query argument is optional and compliant with the OData query operators.
You can use $filter,$select and so on. Full documentation

spyreqs.rest.getHostLists

description: gets all the Lists from the Host Site that the App was installed.
parameters:

  • string query (optional): the query to execute
returns: a promise which when resolved contains an object with an array of lists.

spyreqs.rest.getHostLists(query).then(function(data){
		var lists = data.d.results;
		//do something with the lists
});

spyreqs.rest.getAppLists

**description:** gets all the app Lists. Parameters and return value same as spyreqs.rest.getHostLists.

spyreqs.rest.getHostListByTitle

**description:** gets a List from the Host Site.
**parameters:**
  • string listTitle (required) : the title of the list to get
  • string query (optional): the query to execute

returns: a promise which when resolved contains an object the list.

spyreqs.rest.getHostListByTitle(listTitle,query).then(function(data){
		var list = data.d;
		//do something with the list
});

spyreqs.rest.getAppListByTitle

**description:** gets a List from the Host Site. Parameters and return value same as spyreqs.rest.getHostListByTitle.

spyreqs.rest.getHostListItems

**description:** gets the Items of a List from the Host Site.
**parameters:**
  • string listTitle (required): the title of the list
  • string query (optional): the query to execute on items
**returns:** a promise which when resolved contains an object with an array of the list items.
spyreqs.rest.getHostListItems(listTitle,query).then(function(data){
		var items = data.d.results;
		//do something with the items
});

spyreqs.rest.getAppListItems

**description:** gets the Items from an App List. Parameters and return value same as spyreqs.rest.getHostListItems.

spyreqs.rest.getHostListFields

description: gets the Fields of a List from the Host Site.
parameters:

  • string listTitle (required): the title of the list
  • string query (optional) : the query to execute on Items
**returns:** a promise which when resolved contains an object with an array of the list fields.
spyreqs.rest.getHostListFields(listTitle,query).then(function(data){
		var fields = data.d.results;
		//do something with the fields
});

spyreqs.rest.getAppListFields

description: gets the Fields of an App List. Parameters and return value same as spyreqs.rest.getAppListFields.

spyreqs.rest.createHostList

**description:** creates a List to the Host Site.
**parameters:**
  • object list (required) : the list to create. the list object must have the properties
    • string Title : the list Title
    • number Template : the list Template number(for a generic SP List 100)
**returns:** A promise that is resolved when the list is succesfully created and contains the created list or rejected if an error occurs.
var list={Title:"Demo",Template:100};

spyreqs.rest.createHostList(list).then(function(data){
	var createdList = data.d;
},function(error){
	//handle the error
});

spyreqs.rest.createAppList

**description:** creates an App List. Parameters and return value same as spyreqs.rest.createHostList.

spyreqs.rest.addHostListItem

**description:** adds an Item to a Host List.
**parameters:**
  • string listTitle (required): the title of the List to which the item should be added
  • object item (required) : the item to add.The item object must have the properies
    • string Title : the Title of the item
    • objext __metadata: the metadata object must have the property
      • string type : the type of the item
**returns:** A promise that is resolved when the item is added and contains the added item or rejected if an error occurs ```javascript

var listTile="Demo", item = { Title:"DemoItem", __metadata:{ type:"SP.Data.DemoListItem" } };

spyreqs.rest.addHostListItem(listTitle,item).then(function(data){ var addedItem = data.d; },function(error){ //handle the error });


<h3>spyreqs.rest.addAppListItem</h3>
**description:** adds an App List Item. Parameters and return value same as spyreqs.rest.addAppListItem.

<h3>spyreqs.rest.deleteHostListItem</h3>
**description:** deletes an Item in a Host List. <br>
**parameters:**
<ul>
	<li>string listTitle (required) : the title of the List</li>
	<li>string itemId (required) : the id of the Item to delete</li>
	<li>string etag (optional) : the etag property of the item. if not provided defaults to "*"</li>
</ul>
**returns:**A promise that is resolved when the item is deleted or rejected if the deletion fails.
```javascript

spyreqs.rest.deleteHostListItem(listTitle,itemId,"*").then(function(){
	//successfully deleted
},function(error){
	//handle the error
});

spyreqs.rest.deleteAppListItem

**description:** deletes an Item in an App List. Parameters and return value same as spyreqs.rest.deleteHostListItem.

spyreqs.rest.updateHostListItem

**description:** updates an item in a Host List.
**parameters:**
  • string listTitle (required) : the title of the List
  • object item (required) : the item to update. Must have the properties
    • string Id : the guid of the item
    • any property of the item you want to change
    • object __metadata : the metadata object must have the properties
      • string type: the type of the object e.g. "SP.Data.DemoListItem"
      • string etag (optional) : defaults to "*"
**returns:** A promise that is resolved when the item is updated or rejected if the update fails ```javascript

spyreqs.rest.updateHostListItem(listTitle,item).then(function(){ //successfully updated },function(error){ //handle the error });

<h3>spyreqs.rest.updateAppListItem</h3>
**description:** updates an Item in an App List. Parameters and return value same as spyreqs.rest.updateHostListItem.

<h3>spyreqs.rest.updateHostListField</h3>
**description:** updates a Field to a Host List. <br>
**parameters:**
<ul>
	<li>string listTitle (required) : the Title of the List</li>
	<li>object field (required) : the field to update.The field object must have the properties
		<ul>
			<li>string Id:the guid of the field</li>
			<li>object __metadata: the metadata object must have the properties
				<ul>
					<li>string type (required): the type of the field e.g ""SP.Field""</li>
					<li>string etag (optional): defaults to "*"</li>
				</ul>
			</li>
		</ul>
	</li>
</ul>

<h3>spyreqs.rest.updateAppListField</h3>
**description:** updates a Field to an App List. Parameters and return value same as spyreqs.rest.updateHostListField.

<h3>spyreqs.rest.addHostListField</h3>
**description:** adds a Field to a Host List. <br>
**parameters:**
<ul>
	<li>string listGuid (required) : the guid of the list</li>
	<li>string fieldType (optional) : the type of the field, defaults to the generic "SP.Field"</li>
	<li>object field (required) : the field to add. The object must have the properties
		<ul>
			<li>string Title : the title of the field</li>
			<li>number FieldTypeKind : <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.fieldtype.aspx">documentation about FieldTypeKind</a></li>
			<li>boolean Required: if the field is required or not</li>
			<li>boolean EnforceUniqueValues</li>
			<li>string StaticName: the static name of the field</li>
		</ul>
	</li>
</ul>
**returns:** A promise that contains the added field

```javascript

spyreqs.rest.addHostListField(listGuid, field, fieldType).then(function(data){
	var field = data.d;
},function(error){
	//handle the error
});

spyreqs.rest.addAppListField

**description:** adds a Field to a Host List. Parameters and return value same as spyreqs.rest.addHostListField.

spyreqs.rest.getCurrentUser

**description:** gets the current user.
**parameters:** empty
**returns:** A promise that contains an object with info about the current user, like Email and Id ```javascript

spyreqs.rest.getCurrentUser().then(function(data){ var currentUser = data.d; },function(error){ //handle the error });


<h3>spyreqs.rest.getHostFile</h3>
**description:** gets a File from the Host Site.(not tested on binary files)<br>
**parameters:**
<ul>
	<li>string fileUrl: the relative file url</li>
</ul>
**returns:** A promise that contains the file.
```javascript

spyreqs.rest.getHostFile(fileUrl).then(function(data){
	var file = data;
},function(error){
	//handle the error
});

spyreqs.rest.getAppFile

**description:** gets a File from the App Site.(not tested on binary files)
Parameters and return value same as spyreqs.rest.getHostFile.

spyreqs.rest.addHostFile

**description:** adds a File to the Host Site.(not tested on binary files)
**parameters:**
  • string folderPath: the relative url of the folder to which the file should be added
  • string fileName
  • file: the file to add
**returns:** A promise that contains the added file. ```javascript

spyreqs.rest.addHostFile(fileUrl).then(function(data){ var file = data; },function(error){ //handle the error });


<h3>spyreqs.rest.addAppFile</h3>
**description:** adds a File to the App Site.(not tested on binary files)<br>
Parameters and return value same as spyreqs.rest.addHostFile.

<h3>spyreqs.rest.getSiteUsers</h3>
**description:** gets all the users of the host Site<br>
**parameters:** empty <br>
**returns:** A promise that contains an array with the users of the site.
```javascript

spyreqs.rest.getSiteUsers(fileUrl).then(function(data){
	var siteUsers = data.d.results;
},function(error){
	//handle the error
});

spyreqs.jsom methods

spyreqs.jsom.checkHostList

**description:** checks wether a Host list exists or not.
**parameters:**
  • string listTitle:the list Title
**returns:** A promise that resolves to true if the list exists otherwise to false ```javascript spyreqs.jsom.checkHostList(listTitle).then(function(data){ var listExists = data; }); ```

spyreqs.jsom.checkAppList

**description:** checks wether an App list exists or not. Parameters and return value same as spyreqs.jsom.checkHostList.

spyreqs.jsom.getHostListItems

**description:** gets the items of a Host List.
**parameters:**
  • string listTitle:the list Title
  • string query : the query to execute
**returns:** A promise that contains a collection of the items ```javascript var query = "";

spyreqs.jsom.getHostListItems(listTitle,query).then(function(resultCollection) { var listItemEnumerator = resultCollection.getEnumerator(), out=" ";

while (listItemEnumerator.moveNext()) {
	var oListItem = listItemEnumerator.get_current();
	out += oListItem.get_item('ClassStudentGroupID');
}
alert(out);

}, function(error) { alert('getAppListItems request failed. ' + error.args.get_message() + '\n' + error.args.get_stackTrace()); });


<h3>spyreqs.jsom.getAppListItems</h3>
**description:** gets the items of an App List. Parameters and return value same as spyreqs.jsom.getHostListItems.<br>

<h3>spyreqs.jsom.addHostListItem</h3>
**description:** adds an item to a Host List.<br>
**parameters:**
<ul>
	<li>string listTitle:the list Title</li>
	<li>object itemObj : the item to add</li>
</ul>
**returns:** A promise that contains the id of the created item
```javascript
spyreqs.jsom.addHostListItem("My List", {"Title":"my item", "Score":90})
	.then(function(itemId) {
		alert("item was added, id:"+itemId);
	},
    function(error) {
    	alert('addHostListItem request failed. ' +  error.args.get_message() + '\n' + error.args.get_stackTrace());
    });

spyreqs.jsom.addAppListItem

**description:** adds an item to an App List.Parameters and return value same as spyreqs.jsom.addHostListItem.

spyreqs.jsom.updateHostListItem

**description:** updates an item to a Host List.
**parameters:**
  • string listTitle:the list Title
  • object itemObj : the item contents to update
  • number itemId : the item id
**returns:** A promise that contains the id of the created item ```javascript spyreqs.jsom.updateHostListItem("My List", {"Title":"my item", "Score":90}, 9) .then(function(itemId) { alert("item was updated, id:"+itemId); }, function(error) { alert('updateHostListItem request failed. ' + error.args.get_message() + '\n' + error.args.get_stackTrace()); }); ```

spyreqs.jsom.updateAppListItem

**description:** updates an item to an App List. Parameters and return value same as spyreqs.jsom.updateHostListItem.

spyreqs.jsom.createHostList

**description:** creates a List to the Host Site.
**parameters:**
  • object listObj:the list to create
**returns:** A promise that contains the created List ```javascript var listObj = { "title":"app_MainListName", "url":"app_MainListName", "template" : "genericList", "description" : "this is a list", fields : [ {"Name":"userId", "Type":"Text", "Required":"true"}, {"Name":"score", "Type":"Number"}, {"Name":"scoreFinal", "Type":"Number", "hidden":"true"}, {"Name":"assginedTo", "Type":"User", "Required":"true"}, {"Name":"dateAssgined", "Type":"DateTime"}, {"Name":"state", "Type":"Choice", "choices" : ["rejected", "approved", "passed", "proggress"]}, {"Name":"comments", "Type":"Note"}, {"Name":"testLink", "Type":"URL"} ] };

spyreqs.jsom.createHostList(listObj) .then(function(data){ //success },function(error){ //error });


<h3>spyreqs.jsom.createAppList</h3>
**description:** creates a List to the App Site.Parameters and return value same as spyreqs.jsom.createHostList.<br>


<h3>spyreqs.jsom.getTestHostContext</h3>
**description:** When you need spyreqs to have a job done with spyreqs, but there is not a method for what you need, you can use getTestHostContext and getTestAppContext for quick jsom init.<br>
**returns:** An objects that contains jsom appContextSite and context objects
```javascript

var file, item, c, oWeb, oList;

function renameHostFile(listTitle, fileItemID, newName) {
	c = spyreqs.jsom.getTestHostContext();
	oWeb = c.appContextSite.get_web();
	 oList = oWeb.get_lists().getByTitle(listTitle);
	item = oList.getItemById(fileItemID);
	file = item.get_file();

	file.checkOut();
	c.context.load(item);
	c.context.load(file);
	c.context.executeQueryAsync(  OnLoadSuccess, fail );
}

function OnLoadSuccess(sender, args) {
	console.log(file.get_name() + " ok");

	item.set_item("Title","oktitleokefd");
	file.set_item("Name","okefd");
	item.update();
	file.checkIn();

	c.context.load(item);
	c.context.load(file);
	c.context.executeQueryAsync(  OnLoadSuccess2, fail );
}

function fail(sender, args) {
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

renameHostFile("GP_iSprings", 33, "renamed-ok.txt");

spyreqs.utils methods

spyreqs.utils.urlParamsObj

**description:** gets the url parameters.
**parameters:** empty.
**returns:** an object with the url parameters as key, value ```javascript //for example if the url is http://www.example.com?user=adam&email=adam@gmail.cmom //then var params = spyreqs.utils.urlParamsObj(); //params = {user:adam,email:adam@gmail.com} ```

spyreqs.utils.buildQueryString

**description:** builds a query string
**parameters:**
  • string str : the string to which the query string is added
  • string param : the parameter to add to the query string
  • string or number or boolean val : the value of the parameter to add to the query string
**returns:** a query string

spyreqs.utils.say

**description:** a safe way to log to the console, because it checks first if there is the console
and if it has the log method
**parameters:**
  • anything you want to log
**returns:** nothing

spyreqs.utils.getRegionalSettings

**description:** gets the Regional settings like DateFormat,localeId etc.
**parameters:**
  • string query:the query to execute
**returns:** A promise that contains an object with the regionalSettings ```javascript spyreqs.utils.getRegionalSettings(query).then(function(data){ var regionalSettings = data.d; }); ```

About

SharePoint Requests

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%
0