1 /**
  2  * @fileOverview JavaScript representation of the Finesse Users collection
  3  * object which contains a list of Users objects.
  4  *
  5  * @name finesse.restservices.Users
  6  * @requires finesse.clientservices.ClientServices
  7  * @requires Class
  8  * @requires finesse.FinesseBase
  9  * @requires finesse.restservices.RestBase
 10  * @requires finesse.restservices.RestCollectionBase
 11  * @requires finesse.restservices.User
 12  */
 13 
 14 var finesse = finesse || {};
 15 finesse.restservices = finesse.restservices || {};
 16 
 17 /** @private */
 18 finesse.restservices.Users = finesse.restservices.RestCollectionBase.extend(/** @lends finesse.restservices.Users.prototype */{
 19 
 20     /**
 21      * @class
 22      * JavaScript representation of the Finesse Users collection
 23      * object which contains a list of Users objects.
 24      *
 25 	 * @param {Object} options
 26 	 *     An object with the following properties:<ul>
 27      *         <li><b>id:</b> The id of the object being constructed</li>
 28      *         <li><b>onLoad(this): (optional)</b> when the object is successfully loaded from the server</li>
 29      *         <li><b>onChange(this): (optional)</b> when an update notification of the object is received</li>
 30      *         <li><b>onAdd(this): (optional)</b> when a notification that the object is created is received</li>
 31      *         <li><b>onDelete(this): (optional)</b> when a notification that the object is deleted is received</li>
 32      *         <li><b>onError(rsp): (optional)</b> if loading of the object fails, invoked with the error response object:<ul>
 33      *             <li><b>status:</b> {Number} The HTTP status code returned</li>
 34      *             <li><b>content:</b> {String} Raw string of response</li>
 35      *             <li><b>object:</b> {Object} Parsed object of response</li>
 36      *             <li><b>error:</b> {Object} Wrapped exception that was caught:<ul>
 37      *                 <li><b>errorType:</b> {String} Type of error that was caught</li>
 38      *                 <li><b>errorMessage:</b> {String} Message associated with error</li>
 39      *             </ul></li>
 40      *         </ul></li>
 41      *         <li><b>parentObj: (optional)</b> The parent object</li></ul>
 42      * @constructs finesse.restservices.Users
 43      **/
 44 	init: function (options) {
 45 		this._super(options);
 46 	},
 47 
 48 	/**
 49      * @private
 50 	 * Gets the REST class for the current object - this is the Users class.
 51 	 */
 52 	getRestClass: function () {
 53 	    return finesse.restservices.Users;
 54 	},
 55 
 56 	/**
 57      * @private
 58 	 * Gets the REST class for the objects that make up the collection. - this
 59 	 * is the User class.
 60 	 */
 61 	getRestItemClass: function () {
 62 		return finesse.restservices.User;
 63 	},
 64 
 65 	/**
 66      * @private
 67 	 * Gets the REST type for the current object - this is a "Users".
 68 	 */
 69 	getRestType: function () {
 70 	    return "Users";
 71 	},
 72 
 73 	/**
 74      * @private
 75 	 * Gets the REST type for the objects that make up the collection - this is "User".
 76 	 */
 77 	getRestItemType: function () {
 78 	    return "User";
 79 	},
 80 
 81 	/**
 82      * @private
 83      * Gets the node path for the current object - this is the team Users node
 84      * @returns {String} The node path
 85      */
 86     getXMPPNodePath: function () {
 87         return this.getRestUrl();
 88     },
 89 
 90     /**
 91      * @private
 92      * Overloading _doGET to reroute the GET to /Team/id from /Team/id/Users
 93      * This needs to be done because the GET /Team/id/Users API is missing
 94      * @returns {Users} This Users (collection) object to allow cascading
 95      */
 96     _doGET: function (handlers) {
 97         var _this = this;
 98         handlers = handlers || {};
 99         // Only do this for /Team/id/Users
100         if (this._restObj && this._restObj.getRestType() === "Team") {
101             this._restObj._doGET({
102                 success: function (rspObj) {
103                     // Making sure the response was a valid Team
104                     if (_this._restObj._validate(rspObj.object)) {
105                         // Shimmying the response to look like a Users collection by extracting it from the Team response
106                         rspObj.object[_this.getRestType()] = rspObj.object[_this._restObj.getRestType()][_this.getRestType().toLowerCase()];
107                         handlers.success(rspObj);
108                     } else {
109                         handlers.error(rspObj);
110                     }
111                 },
112                 error: handlers.error
113             });
114             return this; // Allow cascading
115         } else {
116             return this._super(handlers);
117         }
118     },
119 
120     /**
121      * @private
122      * Override default to indicates that the collection doesn't support making
123      * requests.
124      */
125     supportsRequests: false,
126 
127     /**
128      * @private
129      * Indicates that this collection handles the subscription for its items
130      */
131     handlesItemSubscription: true,
132     
133     /**
134      * @private
135      * Override default to indicate that we need to subscribe explicitly
136      */
137     explicitSubscription: true
138     
139 });