1 /**
  2  * @fileOverview JavaScript representation of the Finesse Dialogs collection
  3  * object which contains a list of Dialog objects.
  4  *
  5  * @name finesse.restservices.Dialogs
  6  * @requires finesse.clientservices.ClientServices
  7  * @requires Class
  8  * @requires finesse.FinesseBase
  9  * @requires finesse.restservices.RestBase
 10  * @requires finesse.restservices.Dialog
 11  */
 12 
 13 var finesse = finesse || {};
 14 finesse.restservices = finesse.restservices || {};
 15 
 16 /** @private */
 17 finesse.restservices.Dialogs = finesse.restservices.RestCollectionBase.extend(/** @lends finesse.restservices.Dialogs.prototype */{
 18 
 19     /**
 20      * @class
 21      * JavaScript representation of a Dialogs 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.Dialogs
 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 Dialogs class.
 50      */
 51     getRestClass: function () {
 52         return finesse.restservices.Dialogs;
 53     },
 54 
 55     /**
 56      * @private
 57      * Gets the REST class for the objects that make up the collection. - this
 58      * is the Dialog class.
 59      */
 60     getRestItemClass: function () {
 61         return finesse.restservices.Dialog;
 62     },
 63 
 64     /**
 65      * @private
 66      * Gets the REST type for the current object - this is a "Dialogs".
 67      */
 68     getRestType: function () {
 69         return "Dialogs";
 70     },
 71 
 72     /**
 73      * @private
 74      * Gets the REST type for the objects that make up the collection - this is "Dialogs".
 75      */
 76     getRestItemType: function () {
 77         return "Dialog";
 78     },
 79 
 80     /**
 81      * @private
 82      * Override default to indicates that the collection doesn't support making
 83      * requests.
 84      */
 85     supportsRequests: true,
 86 
 87     /**
 88      * @private
 89      * Override default to indicates that the collection subscribes to its objects.
 90      */
 91     supportsRestItemSubscriptions: true,
 92 
 93     /**
 94      * Create a new Dialog in this colleciton
 95      *
 96      * @param {String} toAddress
 97      *     The to address of the new Dialog
 98      * @param {String} fromAddress
 99      *     The from address of the new Dialog
100      * @param {Object} handlers
101      *     An object containing the following (optional) handlers for the request:<ul>
102      *         <li><b>success(rsp):</b> A callback function for a successful request to be invoked with the following
103      *         response object as its only parameter:<ul>
104      *             <li><b>status:</b> {Number} The HTTP status code returned</li>
105      *             <li><b>content:</b> {String} Raw string of response</li>
106      *             <li><b>object:</b> {Object} Parsed object of response</li></ul>
107      *         <li>A error callback function for an unsuccessful request to be invoked with the
108      *         error response object as its only parameter:<ul>
109      *             <li><b>status:</b> {Number} The HTTP status code returned</li>
110      *             <li><b>content:</b> {String} Raw string of response</li>
111      *             <li><b>object:</b> {Object} Parsed object of response (HTTP errors)</li>
112      *             <li><b>error:</b> {Object} Wrapped exception that was caught:<ul>
113      *                 <li><b>errorType:</b> {String} Type of error that was caught</li>
114      *                 <li><b>errorMessage:</b> {String} Message associated with error</li>
115      *             </ul></li>
116      *         </ul>
117      */
118     createNewCallDialog: function (toAddress, fromAddress, handlers)
119     {
120         var contentBody = {};
121         contentBody[this.getRestItemType()] = {
122             "requestedAction": "MAKE_CALL",
123             "toAddress": toAddress,
124             "fromAddress": fromAddress
125         };
126 
127         // Protect against null dereferencing of options allowing its (nonexistant) keys to be read as undefined
128         handlers = handlers || {};
129 
130         this.restRequest(this.getRestUrl(), {
131             method: 'POST',
132             success: handlers.success,
133             error: handlers.error,
134             content: contentBody
135         });
136         return this; // Allow cascading
137     },
138 
139     /**
140      * Create a new Dialog in this colleciton as a result of a requested action
141      *
142      * @param {String} toAddress
143      *     The to address of the new Dialog
144      * @param {String} fromAddress
145      *     The from address of the new Dialog
146      * @param {String} actionType
147      *     The associated action to request for creating this new dialog
148      * @param {Object} handlers
149      *     An object containing the following (optional) handlers for the request:<ul>
150      *         <li><b>success(rsp):</b> A callback function for a successful request to be invoked with the following
151      *         response object as its only parameter:<ul>
152      *             <li><b>status:</b> {Number} The HTTP status code returned</li>
153      *             <li><b>content:</b> {String} Raw string of response</li>
154      *             <li><b>object:</b> {Object} Parsed object of response</li></ul>
155      *         <li>A error callback function for an unsuccessful request to be invoked with the
156      *         error response object as its only parameter:<ul>
157      *             <li><b>status:</b> {Number} The HTTP status code returned</li>
158      *             <li><b>content:</b> {String} Raw string of response</li>
159      *             <li><b>object:</b> {Object} Parsed object of response (HTTP errors)</li>
160      *             <li><b>error:</b> {Object} Wrapped exception that was caught:<ul>
161      *                 <li><b>errorType:</b> {String} Type of error that was caught</li>
162      *                 <li><b>errorMessage:</b> {String} Message associated with error</li>
163      *             </ul></li>
164      *         </ul>
165      */
166     createNewSuperviseCallDialog: function (toAddress, fromAddress, actionType, handlers)
167     {
168         var contentBody = {};
169         this._isLoaded = true;
170 
171         contentBody[this.getRestItemType()] = {
172             "requestedAction": actionType,
173             "toAddress": toAddress,
174             "fromAddress": fromAddress
175         };
176 
177         // Protect against null dereferencing of options allowing its (nonexistant) keys to be read as undefined
178         handlers = handlers || {};
179 
180         this.restRequest(this.getRestUrl(), {
181             method: 'POST',
182             success: handlers.success,
183             error: handlers.error,
184             content: contentBody
185         });
186         return this; // Allow cascading
187     },
188     
189     /**
190      * Create a new Dialog in this collection as a result of a requested action
191      * @param {String} fromAddress
192      *     The from address of the new Dialog
193      * @param {String} toAddress
194      *     The to address of the new Dialog
195      * @param {String} actionType
196      *     The associated action to request for creating this new dialog
197      * @param {String} dialogUri
198      *     The associated uri of SUPERVISOR_MONITOR call
199      * @param {Object} handlers
200      *     An object containing the following (optional) handlers for the request:<ul>
201      *         <li><b>success(rsp):</b> A callback function for a successful request to be invoked with the following
202      *         response object as its only parameter:<ul>
203      *             <li><b>status:</b> {Number} The HTTP status code returned</li>
204      *             <li><b>content:</b> {String} Raw string of response</li>
205      *             <li><b>object:</b> {Object} Parsed object of response</li></ul>
206      *         <li>A error callback function for an unsuccessful request to be invoked with the
207      *         error response object as its only parameter:<ul>
208      *             <li><b>status:</b> {Number} The HTTP status code returned</li>
209      *             <li><b>content:</b> {String} Raw string of response</li>
210      *             <li><b>object:</b> {Object} Parsed object of response (HTTP errors)</li>
211      *             <li><b>error:</b> {Object} Wrapped exception that was caught:<ul>
212      *                 <li><b>errorType:</b> {String} Type of error that was caught</li>
213      *                 <li><b>errorMessage:</b> {String} Message associated with error</li>
214      *             </ul></li>
215      *         </ul>
216      */
217     createNewBargeCall: function (fromAddress, toAddress,actionType,dialogURI, handlers) {
218         this.isLoaded();
219      
220         var contentBody = {};
221         contentBody[this.getRestItemType()] = {
222             "fromAddress": fromAddress,
223             "toAddress": toAddress,
224             "requestedAction": actionType,
225             "associatedDialogUri": dialogURI
226             
227         };
228         // (nonexistant) keys to be read as undefined
229         handlers = handlers || {};	
230         this.restRequest(this.getRestUrl(), {
231             method: 'POST',
232             success: handlers.success,
233             error: handlers.error,
234             content: contentBody
235         });
236         return this; // Allow cascading
237     }
238 
239 });
240