1 /** 2 * @fileOverview JavaScript representation of the TeamSignOutReasonCodes collection 3 * object which contains a list of TeamSignOutReasonCode objects. 4 * 5 * @name finesse.restservices.TeamSignOutReasonCodes 6 * @requires finesse.clientservices.ClientServices 7 * @requires Class 8 * @requires finesse.FinesseBase 9 * @requires finesse.restservices.RestBase 10 * @requires finesse.restservices.Dialog 11 * @requires finesse.restservices.RestCollectionBase 12 */ 13 14 var finesse = finesse || {}; 15 finesse.restservices = finesse.restservices || {}; 16 17 /** @private */ 18 finesse.restservices.TeamSignOutReasonCodes = finesse.restservices.RestCollectionBase.extend({/** @lends finesse.restservices.TeamSignOutReasonCodes.prototype */ 19 /** 20 * @class 21 * JavaScript representation of a TeamSignOutReasonCodes collection object. Also exposes 22 * methods to operate on the object against the server. 23 * 24 * @param {Object} options 25 * An object with the following properties:<ul> 26 * <li><b>id:</b> The id of the object being constructed</li> 27 * <li><b>onLoad(this): (optional)</b> when the object is successfully loaded from the server</li> 28 * <li><b>onChange(this): (optional)</b> when an update notification of the object is received</li> 29 * <li><b>onAdd(this): (optional)</b> when a notification that the object is created is received</li> 30 * <li><b>onDelete(this): (optional)</b> when a notification that the object is deleted is received</li> 31 * <li><b>onError(rsp): (optional)</b> if loading of the object fails, invoked with the error response object:<ul> 32 * <li><b>status:</b> {Number} The HTTP status code returned</li> 33 * <li><b>content:</b> {String} Raw string of response</li> 34 * <li><b>object:</b> {Object} Parsed object of response</li> 35 * <li><b>error:</b> {Object} Wrapped exception that was caught:<ul> 36 * <li><b>errorType:</b> {String} Type of error that was caught</li> 37 * <li><b>errorMessage:</b> {String} Message associated with error</li> 38 * </ul></li> 39 * </ul></li> 40 * <li><b>parentObj: (optional)</b> The parent object</li></ul> 41 * @constructs finesse.restservices.TeamSignOutReasonCodes 42 **/ 43 init: function (options) { 44 this._super(options); 45 }, 46 47 /** 48 * @private 49 * Gets the REST class for the current object - this is the TeamSignOutReasonCodes class. 50 */ 51 getRestClass: function () { 52 return finesse.restservices.TeamSignOutReasonCodes; 53 }, 54 55 /** 56 * @private 57 * Gets the REST class for the objects that make up the collection. - this 58 * is the TeamSignOutReasonCode class. 59 */ 60 getRestItemClass: function () { 61 return finesse.restservices.TeamSignOutReasonCode; 62 }, 63 64 /** 65 * @private 66 * Gets the REST type for the current object - this is a "ReasonCodes". 67 */ 68 getRestType: function () { 69 return "ReasonCodes"; 70 }, 71 72 /** 73 * Overrides the parent class. Returns the url for the SignOutReasonCodes resource 74 */ 75 getRestUrl: function () { 76 var restObj = this._restObj, restUrl = ""; 77 78 //Prepend the base REST object if one was provided. 79 //Otherwise prepend with the default webapp name. 80 if (restObj instanceof finesse.restservices.RestBase) { 81 restUrl += restObj.getRestUrl(); 82 } else { 83 restUrl += "/finesse/api"; 84 } 85 //Append the REST type. 86 restUrl += "/ReasonCodes?category=LOGOUT"; 87 //Append ID if it is not undefined, null, or empty. 88 if (this._id) { 89 restUrl += "/" + this._id; 90 } 91 return restUrl; 92 }, 93 94 /** 95 * @private 96 * Gets the REST type for the objects that make up the collection - this is "ReasonCode". 97 */ 98 getRestItemType: function () { 99 return "ReasonCode"; 100 }, 101 102 /** 103 * @private 104 * Override default to indicates that the collection supports making requests. 105 */ 106 supportsRequests: true, 107 108 /** 109 * @private 110 * Override default to indicates that the collection does not subscribe to its objects. 111 */ 112 supportsRestItemSubscriptions: false, 113 114 /** 115 * Retrieve the Sign Out Reason Codes. 116 * 117 * @returns {finesse.restservices.TeamSignOutReasonCodes} 118 * This TeamSignOutReasonCodes object to allow cascading. 119 */ 120 get: function () { 121 // set loaded to false so it will rebuild the collection after the get 122 this._loaded = false; 123 // reset collection 124 this._collection = {}; 125 // perform get 126 this._synchronize(); 127 return this; 128 }, 129 130 /* We only use PUT and GET on Reason Code team assignments 131 * @param {Object} contact 132 * @param {Object} contentBody 133 * @param {Function} successHandler 134 */ 135 createPutSuccessHandler: function (contact, contentBody, successHandler) { 136 return function (rsp) { 137 // Update internal structure based on response. Here we 138 // inject the contentBody from the PUT request into the 139 // rsp.object element to mimic a GET as a way to take 140 // advantage of the existing _processResponse method. 141 rsp.object = contentBody; 142 contact._processResponse(rsp); 143 144 //Remove the injected contentBody object before cascading response 145 rsp.object = {}; 146 147 //cascade response back to consumer's response handler 148 successHandler(rsp); 149 }; 150 }, 151 152 /** 153 * Update - This should be all that is needed. 154 * @param {Object} newValues 155 * @param {Object} handlers 156 * @returns {finesse.restservices.TeamSignOutReasonCodes} 157 * This TeamSignOutReasonCodes object to allow cascading. 158 */ 159 update: function (newValues, handlers) { 160 this.isLoaded(); 161 var contentBody = {}, contentBodyInner = [], i, innerObject = {}; 162 163 contentBody[this.getRestType()] = { 164 }; 165 166 for (i in newValues) { 167 if (newValues.hasOwnProperty(i)) { 168 innerObject = { 169 "uri": newValues[i] 170 }; 171 contentBodyInner.push(innerObject); 172 } 173 } 174 175 contentBody[this.getRestType()] = { 176 "ReasonCode" : contentBodyInner 177 }; 178 179 // Protect against null dereferencing of options allowing its (nonexistant) keys to be read as undefined 180 handlers = handlers || {}; 181 182 this.restRequest(this.getRestUrl(), { 183 method: 'PUT', 184 success: this.createPutSuccessHandler(this, contentBody, handlers.success), 185 error: handlers.error, 186 content: contentBody 187 }); 188 189 return this; // Allow cascading 190 } 191 192 });