|
7 | 7 | $scope.security = $rootScope.security; |
8 | 8 | $scope.UserVars = UserVars; |
9 | 9 | $scope.root = $rootScope.SiteVars.ApplicationRelativeWebRoot; |
| 10 | + $scope.customFields = []; |
10 | 11 |
|
11 | 12 | $scope.load = function () { |
12 | 13 | var lookupsUrl = '/api/lookups'; |
|
93 | 94 | $log.log(data); |
94 | 95 | if (data.Id) { |
95 | 96 | angular.copy(data, $scope.page); |
96 | | - var x = $scope.page.Id; |
| 97 | + $scope.updateCustom(); |
97 | 98 | } |
98 | 99 | $("#modal-form").modal('hide'); |
99 | 100 | spinOff(); |
|
195 | 196 | }); |
196 | 197 | } |
197 | 198 |
|
198 | | - $scope.saveCustom = function () { |
| 199 | + $scope.addCustom = function () { |
199 | 200 | var customField = { |
200 | 201 | "CustomType": "PAGE", |
201 | 202 | "ObjectId": $scope.page.Id, |
|
206 | 207 | toastr.error("Custom key is required"); |
207 | 208 | return false; |
208 | 209 | } |
209 | | - dataService.addItem("/api/customfields", customField) |
210 | | - .success(function (data) { |
211 | | - toastr.success('New item added'); |
212 | | - $scope.loadCustom(); |
213 | | - $("#modal-custom-fields").modal('hide'); |
214 | | - }) |
215 | | - .error(function () { |
216 | | - toastr.error($rootScope.lbl.updateFailed); |
217 | | - $("#modal-custom-fields").modal('hide'); |
| 210 | + $scope.customFields.push(customField); |
| 211 | + $("#modal-custom-fields").modal('hide'); |
| 212 | + } |
| 213 | + |
| 214 | + $scope.deleteCustom = function (key, objId) { |
| 215 | + $.each($scope.customFields, function (index, result) { |
| 216 | + if (result["Key"] == key && result["ObjectId"] == objId) { |
| 217 | + $scope.customFields.splice(index, 1); |
| 218 | + } |
218 | 219 | }); |
219 | 220 | } |
220 | 221 |
|
221 | 222 | $scope.updateCustom = function () { |
| 223 | + for (var i = 0; i < $scope.customFields.length; i++) { |
| 224 | + $scope.customFields[i].ObjectId = $scope.page.Id; |
| 225 | + } |
222 | 226 | dataService.updateItem("/api/customfields", $scope.customFields) |
223 | 227 | .success(function (data) { |
224 | 228 | spinOff(); |
|
229 | 233 | }); |
230 | 234 | } |
231 | 235 |
|
232 | | - $scope.deleteCustom = function (key, objId) { |
233 | | - var customField = { |
234 | | - "CustomType": "PAGE", |
235 | | - "Key": key, |
236 | | - "ObjectId": objId |
237 | | - }; |
238 | | - spinOn(); |
239 | | - dataService.deleteItem("/api/customfields", customField) |
240 | | - .success(function (data) { |
241 | | - toastr.success("Item deleted"); |
242 | | - spinOff(); |
243 | | - $scope.loadCustom(); |
244 | | - }) |
245 | | - .error(function () { |
246 | | - toastr.error($rootScope.lbl.couldNotDeleteItem); |
247 | | - spinOff(); |
248 | | - }); |
249 | | - } |
250 | | - |
251 | | - function findCustomItem(key) { |
252 | | - var arr = $scope.profileCustomFields; |
253 | | - if (arr && arr.length > 0) { |
254 | | - for (var i = 0, len = arr.length; i < len; i++) { |
255 | | - if (arr[i].Key == key) { |
256 | | - return arr[i]; |
257 | | - } |
258 | | - }; |
259 | | - } |
260 | | - return null; |
261 | | - } |
262 | | - |
263 | 236 | /* end custom fields */ |
264 | 237 |
|
265 | 238 | }]); |
|
0 commit comments