This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
/
usergrid.appSDK.js
2008 lines (1864 loc) · 54.1 KB
/
usergrid.appSDK.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* App SDK is a collection of classes designed to make working with
* the Appigee App Services API as easy as possible.
* Learn more at http://apigee.com/docs
*
* Copyright 2012 Apigee Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//define the console.log for IE
window.console = window.console || {};
window.console.log = window.console.log || function() {};
//Usergrid namespace encapsulates this SDK
window.Usergrid = window.Usergrid || {};
Usergrid = Usergrid || {};
Usergrid.SDK_VERSION = '0.9.6';
/**
* Usergrid.Query is a class for holding all query information and paging state
*
* @class Query
* @author Rod Simpson (rod@apigee.com)
*/
(function () {
/**
* @constructor
* @param {string} method
* @param {string} path
* @param {object} jsonObj
* @param {object} paramsObj
* @param {function} successCallback
* @param {function} failureCallback
*/
Usergrid.Query = function(method, resource, jsonObj, paramsObj, successCallback, failureCallback) {
//query vars
this._method = method;
this._resource = resource;
this._jsonObj = jsonObj;
this._paramsObj = paramsObj;
this._successCallback = successCallback;
this._failureCallback = failureCallback;
//curl command - will be populated by runQuery function
this._curl = '';
this._token = false;
//paging vars
this._cursor = null;
this._next = null
this._previous = [];
this._start = 0;
this._end = 0;
};
Usergrid.Query.prototype = {
setQueryStartTime: function() {
this._start = new Date().getTime();
},
setQueryEndTime: function() {
this._end = new Date().getTime();
},
getQueryTotalTime: function() {
var seconds = 0;
var time = this._end - this._start;
try {
seconds = ((time/10) / 60).toFixed(2);
} catch(e){ return 0; }
return this.getMethod() + " " + this.getResource() + " - " + seconds + " seconds";
},
/**
* A method to set all settable parameters of the Query at one time
*
* @public
* @method validateUsername
* @param {string} method
* @param {string} path
* @param {object} jsonObj
* @param {object} paramsObj
* @param {function} successCallback
* @param {function} failureCallback
* @return none
*/
setAllQueryParams: function(method, resource, jsonObj, paramsObj, successCallback, failureCallback) {
this._method = method;
this._resource = resource;
this._jsonObj = jsonObj;
this._paramsObj = paramsObj;
this._successCallback = successCallback;
this._failureCallback = failureCallback;
},
/**
* A method to reset all the parameters in one call
*
* @public
* @return none
*/
clearAll: function() {
this._method = null;
this._resource = null;
this._jsonObj = {};
this._paramsObj = {};
this._successCallback = null;
this._failureCallback = null;
},
/**
* Returns the method
*
* @public
* @method getMethod
* @return {string} Returns method
*/
getMethod: function() {
return this._method;
},
/**
* sets the method (POST, PUT, DELETE, GET)
*
* @public
* @method setMethod
* @return none
*/
setMethod: function(method) {
this._method = method;
},
/**
* Returns the resource
*
* @public
* @method getResource
* @return {string} the resource
*/
getResource: function() {
return this._resource;
},
/**
* sets the resource
*
* @public
* @method setResource
* @return none
*/
setResource: function(resource) {
this._resource = resource;
},
/**
* Returns the json Object
*
* @public
* @method getJsonObj
* @return {object} Returns the json Object
*/
getJsonObj: function() {
return this._jsonObj;
},
/**
* sets the json object
*
* @public
* @method setJsonObj
* @return none
*/
setJsonObj: function(jsonObj) {
this._jsonObj = jsonObj;
},
/**
* Returns the Query Parameters object
*
* @public
* @method getQueryParams
* @return {object} Returns Query Parameters object
*/
getQueryParams: function() {
return this._paramsObj;
},
/**
* sets the query parameter object
*
* @public
* @method setQueryParams
* @return none
*/
setQueryParams: function(paramsObj) {
this._paramsObj = paramsObj;
},
/**
* Returns the success callback function
*
* @public
* @method getSuccessCallback
* @return {function} Returns the successCallback
*/
getSuccessCallback: function() {
return this._successCallback;
},
/**
* sets the success callback function
*
* @public
* @method setSuccessCallback
* @return none
*/
setSuccessCallback: function(successCallback) {
this._successCallback = successCallback;
},
/**
* Calls the success callback function
*
* @public
* @method callSuccessCallback
* @return {boolean} Returns true or false based on if there was a callback to call
*/
callSuccessCallback: function(response) {
if (this._successCallback && typeof(this._successCallback ) == "function") {
this._successCallback(response);
return true;
} else {
return false;
}
},
/**
* Returns the failure callback function
*
* @public
* @method getFailureCallback
* @return {function} Returns the failureCallback
*/
getFailureCallback: function() {
return this._failureCallback;
},
/**
* sets the failure callback function
*
* @public
* @method setFailureCallback
* @return none
*/
setFailureCallback: function(failureCallback) {
this._failureCallback = failureCallback;
},
/**
* Calls the failure callback function
*
* @public
* @method callFailureCallback
* @return {boolean} Returns true or false based on if there was a callback to call
*/
callFailureCallback: function(response) {
if (this._failureCallback && typeof(this._failureCallback) == "function") {
this._failureCallback(response);
return true;
} else {
return false;
}
},
/**
* Returns the curl call
*
* @public
* @method getCurl
* @return {function} Returns the curl call
*/
getCurl: function() {
return this._curl;
},
/**
* sets the curl call
*
* @public
* @method setCurl
* @return none
*/
setCurl: function(curl) {
this._curl = curl;
},
/**
* Returns the Token
*
* @public
* @method getToken
* @return {function} Returns the Token
*/
getToken: function() {
return this._token;
},
/**
* Method to set
*
* @public
* @method setToken
* @return none
*/
setToken: function(token) {
this._token = token;
},
/**
* Resets the paging pointer (back to original page)
*
* @public
* @method resetPaging
* @return none
*/
resetPaging: function() {
this._previous = [];
this._next = null;
this._cursor = null;
},
/**
* Method to determine if there is a previous page of data
*
* @public
* @method hasPrevious
* @return {boolean} true or false based on if there is a previous page
*/
hasPrevious: function() {
return (this._previous.length > 0);
},
/**
* Method to set the paging object to get the previous page of data
*
* @public
* @method getPrevious
* @return none
*/
getPrevious: function() {
this._next=null; //clear out next so the comparison will find the next item
this._cursor = this._previous.pop();
},
/**
* Method to determine if there is a next page of data
*
* @public
* @method hasNext
* @return {boolean} true or false based on if there is a next page
*/
hasNext: function(){
return (this._next);
},
/**
* Method to set the paging object to get the next page of data
*
* @public
* @method getNext
* @return none
*/
getNext: function() {
this._previous.push(this._cursor);
this._cursor = this._next;
},
/**
* Method to save off the cursor just returned by the last API call
*
* @public
* @method saveCursor
* @return none
*/
saveCursor: function(cursor) {
//if current cursor is different, grab it for next cursor
if (this._next != cursor) {
this._next = cursor;
}
},
/**
* Method to determine if there is a next page of data
*
* @public
* @method getCursor
* @return {string} the current cursor
*/
getCursor: function() {
return this._cursor;
}
};
})(Usergrid);
/**
* A class to Model a Usergrid Entity.
*
* @class Entity
* @author Rod Simpson (rod@apigee.com)
*/
(function () {
/**
* Constructor for initializing an entity
*
* @constructor
* @param {string} collectionType - the type of collection to model
* @param {uuid} uuid - (optional), the UUID of the collection if it is known
*/
Usergrid.Entity = function(collectionType, uuid) {
this._collectionType = collectionType;
this._data = {};
this._uuid = uuid;
};
//inherit prototype from Query
Usergrid.Entity.prototype = new Usergrid.Query();
/**
* gets the current Entity type
*
* @method getCollectionType
* @return {string} collection type
*/
Usergrid.Entity.prototype.getCollectionType = function (){
return this._collectionType;
}
/**
* sets the current Entity type
*
* @method setCollectionType
* @param {string} collectionType
* @return none
*/
Usergrid.Entity.prototype.setCollectionType = function (collectionType){
this._collectionType = collectionType;
}
/**
* gets a specific field or the entire data object. If null or no argument
* passed, will return all data, else, will return a specific field
*
* @method get
* @param {string} field
* @return {string} || {object} data
*/
Usergrid.Entity.prototype.get = function (field){
if (field) {
return this._data[field];
} else {
return this._data;
}
},
/**
* adds a specific field or object to the Entity's data
*
* @method set
* @param {string} item || {object}
* @param {string} value
* @return none
*/
Usergrid.Entity.prototype.set = function (item, value){
if (typeof item == 'object') {
for(field in item) {
this._data[field] = item[field];
}
} else if (typeof item == 'string') {
this._data[item] = value;
} else {
this._data = null;
}
}
/**
* Saves the entity back to the database
*
* @method save
* @public
* @param {function} successCallback
* @param {function} errorCallback
* @return none
*/
Usergrid.Entity.prototype.save = function (successCallback, errorCallback){
var path = this.getCollectionType();
//TODO: API will be changed soon to accomodate PUTs via name which create new entities
// This function should be changed to PUT only at that time, and updated to use
// either uuid or name
var method = 'POST';
if (this.get('uuid')) {
method = 'PUT';
if (Usergrid.validation.isUUID(this.get('uuid'))) {
path += "/" + this.get('uuid');
}
}
//if this is a user, update the password if it has been specified
var data = {};
if (path == 'users') {
data = this.get();
var pwdata = {};
//Note: we have a ticket in to change PUT calls to /users to accept the password change
// once that is done, we will remove this call and merge it all into one
if (data.oldpassword && data.newpassword) {
pwdata.oldpassword = data.oldpassword;
pwdata.newpassword = data.newpassword;
this.runAppQuery(new Usergrid.Query('PUT', 'users/'+uuid+'/password', pwdata, null,
function (response) {
//not calling any callbacks - this section will be merged as soon as API supports
// updating passwords in general PUT call
},
function (response) {
}
));
}
//remove old and new password fields so they don't end up as part of the entity object
delete data.oldpassword;
delete data.newpassword;
}
//update the entity
var self = this;
data = {};
var entityData = this.get();
//remove system specific properties
for (var item in entityData) {
if (item == 'metadata' || item == 'created' || item == 'modified' ||
item == 'type' || item == 'activatted' ) { continue; }
data[item] = entityData[item];
}
this.setAllQueryParams(method, path, data, null,
function(response) {
try {
var entity = response.entities[0];
self.set(entity);
if (typeof(successCallback) == "function"){
successCallback(response);
}
} catch (e) {
if (typeof(errorCallback) == "function"){
errorCallback(response);
}
}
},
function(response) {
if (typeof(errorCallback) == "function"){
errorCallback(response);
}
}
);
Usergrid.ApiClient.runAppQuery(this);
}
/**
* refreshes the entity by making a GET call back to the database
*
* @method fetch
* @public
* @param {function} successCallback
* @param {function} errorCallback
* @return none
*/
Usergrid.Entity.prototype.fetch = function (successCallback, errorCallback){
var path = this.getCollectionType();
//if a uuid is available, use that, otherwise, use the name
if (this.get('uuid')) {
path += "/" + this.get('uuid');
} else {
if (path == "users") {
if (this.get("username")) {
path += "/" + this.get("username");
} else {
console.log('no username specified');
if (typeof(errorCallback) == "function"){
console.log('no username specified');
}
}
} else {
if (this.get()) {
path += "/" + this.get();
} else {
console.log('no entity identifier specified');
if (typeof(errorCallback) == "function"){
console.log('no entity identifier specified');
}
}
}
}
var self = this;
this.setAllQueryParams('GET', path, null, null,
function(response) {
try {
if (response.user) {
self.set(response.user);
}
var entity = response.entities[0];
self.set(entity);
if (typeof(successCallback) == "function"){
successCallback(response);
}
} catch (e) {
if (typeof(errorCallback) == "function"){
errorCallback(response);
}
}
},
function(response) {
if (typeof(errorCallback) == "function"){
errorCallback(response);
}
}
);
Usergrid.ApiClient.runAppQuery(this);
}
/**
* deletes the entity from the database - will only delete
* if the object has a valid uuid
*
* @method destroy
* @public
* @param {function} successCallback
* @param {function} errorCallback
* @return none
*
*/
Usergrid.Entity.prototype.destroy = function (successCallback, errorCallback){
var path = this.getCollectionType();
if (this.get('uuid')) {
path += "/" + this.get('uuid');
} else {
console.log('Error trying to delete object - no uuid specified.');
if (typeof(errorCallback) == "function"){
errorCallback('Error trying to delete object - no uuid specified.');
}
}
var self = this;
this.setAllQueryParams('DELETE', path, null, null,
function(response) {
//clear out this object
self.set(null);
if (typeof(successCallback) == "function"){
successCallback(response);
}
},
function(response) {
if (typeof(errorCallback) == "function"){
errorCallback(response);
}
}
);
Usergrid.ApiClient.runAppQuery(this);
}
})(Usergrid);
/**
* The Collection class models Usergrid Collections. It essentially
* acts as a container for holding Entity objects, while providing
* additional funcitonality such as paging, and saving
*
* @class Collection
* @author Rod Simpson (rod@apigee.com)
*/
(function () {
/**
* Collection is a container class for holding entities
*
* @constructor
* @param {string} collectionPath - the type of collection to model
* @param {uuid} uuid - (optional), the UUID of the collection if it is known
*/
Usergrid.Collection = function(path, uuid) {
this._path = path;
this._uuid = uuid;
this._list = [];
this._Query = new Usergrid.Query();
this._iterator = -1; //first thing we do is increment, so set to -1
};
Usergrid.Collection.prototype = new Usergrid.Query();
/**
* gets the current Collection path
*
* @method getPath
* @return {string} path
*/
Usergrid.Collection.prototype.getPath = function (){
return this._path;
}
/**
* sets the Collection path
*
* @method setPath
* @param {string} path
* @return none
*/
Usergrid.Collection.prototype.setPath = function (path){
this._path = path;
}
/**
* gets the current Collection UUID
*
* @method getUUID
* @return {string} the uuid
*/
Usergrid.Collection.prototype.getUUID = function (){
return this._uuid;
}
/**
* sets the current Collection UUID
* @method setUUID
* @param {string} uuid
* @return none
*/
Usergrid.Collection.prototype.setUUID = function (uuid){
this._uuid = uuid;
}
/**
* Adds an Entity to the collection (adds to the local object)
*
* @method addEntity
* @param {object} entity
* @param {function} successCallback
* @param {function} errorCallback
* @return none
*/
Usergrid.Collection.prototype.addEntity = function (entity){
//then add it to the list
var count = this._list.length;
this._list[count] = entity;
}
/**
* Adds a new Entity to the collection (saves, then adds to the local object)
*
* @method addNewEntity
* @param {object} entity
* @return none
*/
Usergrid.Collection.prototype.addNewEntity = function (entity,successCallback, errorCallback) {
//add the entity to the list
this.addEntity(entity);
//then save the entity
entity.save(successCallback, errorCallback);
}
Usergrid.Collection.prototype.destroyEntity = function (entity) {
//first get the entities uuid
var uuid = entity.get('uuid');
//if the entity has a uuid, delete it
if (Usergrid.validation.isUUID(uuid)) {
//then remove it from the list
var count = this._list.length;
var i=0;
var reorder = false;
for (i=0; i<count; i++) {
if(reorder) {
this._list[i-1] = this._list[i];
this._list[i] = null;
}
if (this._list[i].get('uuid') == uuid) {
this._list[i] = null;
reorder=true;
}
}
}
//first destroy the entity on the server
entity.destroy();
}
/**
* Looks up an Entity by a specific field - will return the first Entity that
* has a matching field
*
* @method getEntityByField
* @param {string} field
* @param {string} value
* @return {object} returns an entity object, or null if it is not found
*/
Usergrid.Collection.prototype.getEntityByField = function (field, value){
var count = this._list.length;
var i=0;
for (i=0; i<count; i++) {
if (this._list[i].getField(field) == value) {
return this._list[i];
}
}
return null;
}
/**
* Looks up an Entity by UUID
*
* @method getEntityByUUID
* @param {string} UUID
* @return {object} returns an entity object, or null if it is not found
*/
Usergrid.Collection.prototype.getEntityByUUID = function (UUID){
var count = this._list.length;
var i=0;
for (i=0; i<count; i++) {
if (this._list[i].get('uuid') == UUID) {
return this._list[i];
}
}
return null;
}
/**
* Returns the first Entity of the Entity list - does not affect the iterator
*
* @method getFirstEntity
* @return {object} returns an entity object
*/
Usergrid.Collection.prototype.getFirstEntity = function (){
var count = this._list.length;
if (count > 0) {
return this._list[0];
}
return null;
}
/**
* Returns the last Entity of the Entity list - does not affect the iterator
*
* @method getLastEntity
* @return {object} returns an entity object
*/
Usergrid.Collection.prototype.getLastEntity = function (){
var count = this._list.length;
if (count > 0) {
return this._list[count-1];
}
return null;
}
/**
* Entity iteration -Checks to see if there is a "next" entity
* in the list. The first time this method is called on an entity
* list, or after the resetEntityPointer method is called, it will
* return true referencing the first entity in the list
*
* @method hasNextEntity
* @return {boolean} true if there is a next entity, false if not
*/
Usergrid.Collection.prototype.hasNextEntity = function (){
var next = this._iterator + 1;
if(next >=0 && next < this._list.length) {
return true;
}
return false;
}
/**
* Entity iteration - Gets the "next" entity in the list. The first
* time this method is called on an entity list, or after the method
* resetEntityPointer is called, it will return the,
* first entity in the list
*
* @method hasNextEntity
* @return {object} entity
*/
Usergrid.Collection.prototype.getNextEntity = function (){
this._iterator++;
if(this._iterator >= 0 && this._iterator <= this._list.length) {
return this._list[this._iterator];
}
return false;
}
/**
* Entity iteration - Checks to see if there is a "previous"
* entity in the list.
*
* @method hasPreviousEntity
* @return {boolean} true if there is a previous entity, false if not
*/
Usergrid.Collection.prototype.hasPreviousEntity = function (){
var previous = this._iterator - 1;
if(previous >=0 && previous < this._list.length) {
return true;
}
return false;
}
/**
* Entity iteration - Gets the "previous" entity in the list.
*
* @method getPreviousEntity
* @return {object} entity
*/
Usergrid.Collection.prototype.getPreviousEntity = function (){
this._iterator--;
if(this._iterator >= 0 && this._iterator <= this._list.length) {
return this.list[this._iterator];
}
return false;
}
/**
* Entity iteration - Resets the iterator back to the beginning
* of the list
*
* @method resetEntityPointer
* @return none
*/
Usergrid.Collection.prototype.resetEntityPointer = function (){
this._iterator = -1;
}
/**
* gets and array of all entities currently in the colleciton object
*
* @method getEntityList
* @return {array} returns an array of entity objects
*/
Usergrid.Collection.prototype.getEntityList = function (){
return this._list;
}
/**
* sets the entity list
*
* @method setEntityList
* @param {array} list - an array of Entity objects
* @return none
*/
Usergrid.Collection.prototype.setEntityList = function (list){
this._list = list;
}
/**
* Paging - checks to see if there is a next page od data
*
* @method hasNextPage
* @return {boolean} returns true if there is a next page of data, false otherwise
*/
Usergrid.Collection.prototype.hasNextPage = function (){
return this.hasNext();
}
/**
* Paging - advances the cursor and gets the next
* page of data from the API. Stores returned entities
* in the Entity list.
*
* @method getNextPage
* @return none
*/
Usergrid.Collection.prototype.getNextPage = function (){
if (this.hasNext()) {
//set the cursor to the next page of data
this.getNext();
//empty the list
this.setEntityList([]);
Usergrid.ApiClient.runAppQuery(this);
}
}
/**
* Paging - checks to see if there is a previous page od data
*
* @method hasPreviousPage
* @return {boolean} returns true if there is a previous page of data, false otherwise
*/
Usergrid.Collection.prototype.hasPreviousPage = function (){
return this.hasPrevious();
}