-
Notifications
You must be signed in to change notification settings - Fork 10
/
spcrud-demo.js
152 lines (137 loc) · 4.73 KB
/
spcrud-demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//demo AngularJS controller to test run CRUD operations
function spcrudCtl($scope, $http) {
//default data
var vm = $scope;
vm.status = 'OK';
vm.listName = 'Test';
vm.accTable = 'Employees';
vm.accSubweb = '/Timesheet';
//click events
vm.create = function () {
vm.status = ''
spcrud.create($http, vm.listName, {
'Title': 'Hello World'
}).then(function (resp) {
vm.itemId = resp.data.d.ID;
vm.done('CREATE Id=' + vm.itemId);
});
};
vm.read = function () {
spcrud.read($http, vm.listName).then(function (resp) {
vm.itemId = resp.data.d.results[0].ID;
vm.done('READ Id=' + vm.itemId);
});
};
vm.update = function () {
spcrud.update($http, vm.listName, vm.itemId, {
'Title': 'Hello Update'
}).then(function () {
vm.done('UPDATE Id=' + vm.itemId);
});
};
vm.del = function () {
spcrud.del($http, vm.listName, vm.itemId).then(function () {
vm.itemId = null;
vm.done('DELETE Id=' + vm.itemId);
});
};
//status display
vm.done = function (operation) {
vm.status = operation + ' complete ' + (new Date()).toTimeString();
};
//==========
//JSON blob read
vm.settingsRead = function () {
spcrud.jsonRead($http, 'Test').then(function (item) {
if (item) {
//success
console.log('settingsRead');
console.log(item);
vm.settings = item.JSON;
}
});
};
//JSON blob write
vm.settingsWrite = function () {
spcrud.jsonWrite($http, 'Test', vm.settings).then(function (response) {
//response
console.log('settingsWrite');
console.log(response);
});
};
//==========
//SendMail
vm.send = function () {
vm.mailResult = '';
spcrud.sendMail($http, vm.mailTo, vm.mailFrom, vm.mailSubject, vm.mailBody).then(function(resp) {
vm.mailResult = angular.toJson(resp);
});
};
//==========
//ACCDW
//CREATE
vm.accCreate = function() {
spcrud.setBaseUrl(_spPageContextInfo.webAbsoluteUrl + vm.accSubweb);
spcrud.refreshDigest($http).then(function() {
spcrud.accCreate($http, vm.accTable, [null, "222", "john smith"], ["ID","Employee Number","First Name"]).then(function (response) {
//response
console.log('accCreate');
console.log(response);
vm.accResult = JSON.stringify(response.data.d.Result.Values);
vm.accId = response.data.d.Result.Values[0][0];
});
});
};
//READ
vm.accRead = function() {
spcrud.setBaseUrl(_spPageContextInfo.webAbsoluteUrl + vm.accSubweb);
spcrud.refreshDigest($http).then(function() {
spcrud.accRead($http, vm.accTable).then(function (response) {
//response
console.log('accRead');
console.log(response);
vm.accResult = JSON.stringify(response.data.d.Result.Values);
vm.accId = response.data.d.Result.Values[0][0];
});
});
};
//READ
vm.accReadID = function() {
spcrud.setBaseUrl(_spPageContextInfo.webAbsoluteUrl + vm.accSubweb);
spcrud.refreshDigest($http).then(function() {
spcrud.accReadID($http, vm.accTable, vm.accId).then(function (response) {
//response
console.log('accReadID');
console.log(response);
vm.accResult = JSON.stringify(response.data.d.Result.Values);
vm.accId = response.data.d.Result.Values[0][0];
});
});
};
//UPDATE
vm.accUpdate = function() {
spcrud.setBaseUrl(_spPageContextInfo.webAbsoluteUrl + vm.accSubweb);
spcrud.refreshDigest($http).then(function() {
spcrud.accUpdate($http, vm.accTable, [vm.accId, "111","john update"], ["ID","Employee Number","First Name"]).then(function (response) {
//response
console.log('accUpdate');
console.log(response);
vm.accResult = JSON.stringify(response.data.d.Result.Values);
});
});
};
//DELETE
vm.accDelete = function() {
spcrud.setBaseUrl(_spPageContextInfo.webAbsoluteUrl + vm.accSubweb);
spcrud.refreshDigest($http).then(function() {
spcrud.accDelete($http, vm.accTable, vm.accId).then(function (response) {
//response
console.log('accDel');
console.log(response);
vm.accResult = JSON.stringify(response.data.d.Result.Values);
});
});
};
}
//load
angular.module('spcrudApp', []).controller('spcrudCtl', spcrudCtl);