Home Reference Source Repository

Function

Static Public Summary
public

Adds an executeQuery function to the SP ClientContext that calls the executeQueryAsync function and returns a promise.

public

Deletes an item from a list.

public

deleteListItemFile(list: string, id: string, filename: string): Promise

Delete file from list item attachments.

public

Get the currently logged in user.

public
public

getItem(list: string, id: string, options: Object, attachments: boolean): Promise<Object>

Fetches an item by id from list.

public

getList(list: string, options: Object): Promise<Object[]>

Fetches a list.

public

readFileToString(file: File): string

Get the content of a File object.

public

respToJson(response: Object): Objcet

Convert fetch result to json

public

saveItem(list: string, item: Object, assigner: function(sp_item: Object)): Promise<Object>

Save or update an item.

public

searchPerson(searchText: string, options: Object): Promise<Object[]>

Search for persons in SP using clientPeoplePickerSearchUser.

public

shallowEqual(objA: *, objB: *): boolean

public

uploadFile(file: File, filename: string): Promise

Upload file to project Documents

public

Upload list for files to project Documents

public

uploadListItemFile(list: string, id: string, file: File): Promise

Upload file as attachment to a list item.

public

Upload list of files as attachment to a list item.

Static Public

public addExecuteQuery() source

import addExecuteQuery from 'ntnu-react/util/sp/addExecuteQuery.js'

Adds an executeQuery function to the SP ClientContext that calls the executeQueryAsync function and returns a promise.

Example:

const ctx = window.SP.ClientContext.get_current();
const item = ctx.get_web().getList(list).getItemById(id);
addExecuteQuery();
ctx.executeQuery()
.then(() => {})
.catch(() => {});

public deleteItem(list: string, id: string): Promise<number> source

import deleteItem from 'ntnu-react/util/sp/deleteItem.js'

Deletes an item from a list.

Params:

NameTypeAttributeDescription
list string

Name of the list to delete from

id string

Id of the item to delete

Return:

Promise<number>

id of deleted item.

public deleteListItemFile(list: string, id: string, filename: string): Promise source

import deleteListItemFile from 'ntnu-react/util/sp/deleteListItemFile.js'

Delete file from list item attachments.

Params:

NameTypeAttributeDescription
list string

Name of list.

id string

Id of item.

filename string

Name of file to delete.

Return:

Promise

public fetchViewer(prefix: string): Promise<Object> source

import fetchViewer from 'ntnu-react/util/sp/fetchViewer.js'

Get the currently logged in user.

Params:

NameTypeAttributeDescription
prefix string
  • optional
  • default:

Return:

Promise<Object>

object of user data.

public getAvatarUrlByEmail(email: string): string source

import {getAvatarUrlByEmail} from 'ntnu-react/util/sp/index.js'

Params:

NameTypeAttributeDescription
email string

Return:

string

url

public getItem(list: string, id: string, options: Object, attachments: boolean): Promise<Object> source

import getItem from 'ntnu-react/util/sp/getItem.js'

Fetches an item by id from list.

Params:

NameTypeAttributeDescription
list string

Name of list

id string

Id of item

options Object
options.fields string[]

List of fields to get

options.mapper function(item: Object): Object

Mapper function

attachments boolean

Also fetch attachments

Return:

Promise<Object>

object of item data.

Example:

getItem('List', '2', {
    fields: [ 'Id', 'Title' ],
    mapper: function(item) {
        return {
            id: item.get_id(),
            title: item.get_item('Title')
        };
    }
})
.then((item) => {})
.catch((sender, args) => {});

public getList(list: string, options: Object): Promise<Object[]> source

import getList from 'ntnu-react/util/sp/getList.js'

Fetches a list.

Params:

NameTypeAttributeDescription
list string

Name of the list

options Object
options.fields string[]

List of fields to get

options.mapper function(item: Object): Object

Mapper function

Return:

Promise<Object[]>

a list of items.

Example:

getList('List', {
    fields: [ 'Id', 'Title' ],
    mapper: function(item) {
        return {
            id: item.get_id(),
            title: item.get_item('Title')
        };
    }
})
.then((items) => {})
.catch((sender, args) => {});

public readFileToString(file: File): string source

import readFileToString from 'ntnu-react/util/readFileToString.js'

Get the content of a File object.

Params:

NameTypeAttributeDescription
file File

Return:

string

public respToJson(response: Object): Objcet source

import respToJson from 'ntnu-react/util/respToJson.js'

Convert fetch result to json

Params:

NameTypeAttributeDescription
response Object

fetch response object

Return:

Objcet

json data.

public saveItem(list: string, item: Object, assigner: function(sp_item: Object)): Promise<Object> source

import saveItem from 'ntnu-react/util/sp/saveItem.js'

Save or update an item.

Params:

NameTypeAttributeDescription
list string

Name of list

item Object

Object to save. Object.Id is used to fetch existing when updating

assigner function(sp_item: Object)

Function for assigning data to the SP list item

Return:

Promise<Object>

saved object.

Example:

const obj = { id: 21, title: 'Mr.Beet' };
saveItem('List', obj, (item) => {
    item.set_item('Id', obj.id);
    item.set_item('Title', obj.title);
});

public searchPerson(searchText: string, options: Object): Promise<Object[]> source

import searchPerson from 'ntnu-react/util/sp/searchPerson.js'

Search for persons in SP using clientPeoplePickerSearchUser.

Params:

NameTypeAttributeDescription
searchText string

part of name

options Object
options.maximumEntitySuggestions number

default 10

options.principalType number

default 1

options.principalSource number

default 15

options.searchPrefix string

default ''

options.searchSuffix string

default ''

Return:

Promise<Object[]>

list of items with person data.

public shallowEqual(objA: *, objB: *): boolean source

import shallowEqual from 'ntnu-react/util/shallowEqual.js'

Params:

NameTypeAttributeDescription
objA *
objB *

Return:

boolean

public uploadFile(file: File, filename: string): Promise source

import uploadFile from 'ntnu-react/util/sp/uploadFile.js'

Upload file to project Documents

Params:

NameTypeAttributeDescription
file File

File object from upload.

filename string

Wanted file name. Default file.name.

Return:

Promise

public uploadFiles(files: Object[]): Promise source

import uploadFiles from 'ntnu-react/util/sp/uploadFiles.js'

Upload list for files to project Documents

Params:

NameTypeAttributeDescription
files Object[]

{file: string, name: string}[]

Return:

Promise

public uploadListItemFile(list: string, id: string, file: File): Promise source

import uploadListItemFile from 'ntnu-react/util/sp/uploadListItemFile.js'

Upload file as attachment to a list item.

Params:

NameTypeAttributeDescription
list string

Name of list.

id string

Id of item.

file File

File object from upload.

Return:

Promise

public uploadListItemFiles(list: string, id: string, files: Object[]): Promise source

import uploadListItemFiles from 'ntnu-react/util/sp/uploadListItemFiles.js'

Upload list of files as attachment to a list item.

Params:

NameTypeAttributeDescription
list string

Name of list.

id string

Id of item.

files Object[]

{file: string, name: string}[]

Return:

Promise