102 "instance": __sp_messaging_instance |
102 "instance": __sp_messaging_instance |
103 }] |
103 }] |
104 }; |
104 }; |
105 |
105 |
106 |
106 |
107 |
|
108 /* |
|
109 Copyright © 2009 Nokia. All rights reserved. |
|
110 Code licensed under the BSD License: |
|
111 Software License Agreement (BSD License) Copyright © 2009 Nokia. |
|
112 All rights reserved. |
|
113 Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
114 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
115 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
116 Neither the name of Nokia Corporation. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Nokia Corporation. |
|
117 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
118 version: 1.0 |
|
119 */ |
|
120 // S60 sp-based messaging provider |
107 // S60 sp-based messaging provider |
121 var FILE_SCHEME = 'file://'; |
108 var FILE_SCHEME = 'file://'; |
122 //Constant values as per the CJSE Spec |
109 |
123 //var INVALID_URI_ERR = 108; |
110 |
124 |
|
125 /* |
|
126 * Global object for Async utility functions: |
|
127 * 1)addToGlobalArray |
|
128 * 2)getFromArray |
|
129 * 3)removeFromArray |
|
130 */ |
|
131 |
|
132 //var error = new DeviceError(0, 'dummy'); |
|
133 /* |
|
134 if(undefined == com.nokia.device.messaging) |
|
135 { |
|
136 com.nokia.device.messaging={}; |
|
137 } |
|
138 nokia.device.messaging.SORT_ASCENDING = 0; |
|
139 nokia.device.messaging.SORT_DESCENDING = 1; |
|
140 nokia.device.messaging.SORT_BY_DATE = 0; |
|
141 nokia.device.messaging.SORT_BY_SENDER = 1; |
|
142 nokia.device.messaging.STATUS_READ = 0; |
|
143 nokia.device.messaging.STATUS_UNREAD = 1;*/ |
|
144 function __sp_messaging_descriptor(){ |
111 function __sp_messaging_descriptor(){ |
145 //Read-only properties |
112 //Read-only properties |
146 this.interfaceName = "messaging"; |
113 this.interfaceName = "messaging"; |
147 if (window.__Service_Interface_Ver) |
114 if (window.__Service_Interface_Ver) |
148 this.version = __Service_Interface_Ver; |
115 this.version = __Service_Interface_Ver; |
207 if (typeof attachment.uri != "string") { |
174 if (typeof attachment.uri != "string") { |
208 throw new DeviceException(this.error.INVALID_ARG_ERR, "uri is invalid"); |
175 throw new DeviceException(this.error.INVALID_ARG_ERR, "uri is invalid"); |
209 } |
176 } |
210 //device1.0: added this statement.. with out this the script will crib..also checking for proper URI |
177 //device1.0: added this statement.. with out this the script will crib..also checking for proper URI |
211 if (attachment.uri.slice(0, 7) == FILE_SCHEME) { |
178 if (attachment.uri.slice(0, 7) == FILE_SCHEME) { |
|
179 |
212 if (attachment.uri.charAt(7) == "/") { |
180 if (attachment.uri.charAt(7) == "/") { |
|
181 |
213 if (attachment.uri.charAt(9) != ":") { |
182 if (attachment.uri.charAt(9) != ":") { |
214 throw new DeviceException(this.error.URI_NOT_FOUND_ERR, "specified uri not found"); |
183 throw new DeviceException(this.error.URI_NOT_FOUND_ERR, "specified uri not found"); |
215 } |
184 } |
216 sp_attachment.FileName = attachment.uri.slice(8).replace(/\057/g, "\\"); |
185 sp_attachment.FileName = attachment.uri.slice(8).replace(/\057/g, "\\"); |
217 if (sp_attachment.FileName.length > 256) { |
186 if (sp_attachment.FileName.length > 256) { |
247 var sp_message = {}; |
216 var sp_message = {}; |
248 modifyObjectBaseProp(sp_message); |
217 modifyObjectBaseProp(sp_message); |
249 var attachFlag = 0; |
218 var attachFlag = 0; |
250 sp_message.MessageParam = {}; |
219 sp_message.MessageParam = {}; |
251 modifyObjectBaseProp(sp_message.MessageParam); |
220 modifyObjectBaseProp(sp_message.MessageParam); |
252 sp_message.MessageParam.LaunchEditor = false; //Defaults to no editor |
221 sp_message.MessageParam.LaunchEditor = false; //Defaults to no editor |
253 sp_message.MessageType = (message.type == undefined || message.type == null) ? "SMS" : message.type; |
222 sp_message.MessageType = (message.type == undefined || message.type == null || message.type == "") ? "SMS" : message.type; |
254 //alert(message.to[0]+" "+message.type) |
223 //alert(message.to[0]+" "+message.type) |
255 if (message.to) { |
224 if (message.to) { |
256 if (typeof(message.to) == "string") { |
225 if (typeof(message.to) == "string") { |
257 sp_message.To = message.to; |
226 sp_message.To = message.to; |
258 } |
227 } |
498 } |
467 } |
499 else |
468 else |
500 if (typeof msg_cb != "function") { |
469 if (typeof msg_cb != "function") { |
501 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:callback is not a function"); //BadArgumentType error |
470 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:callback is not a function"); //BadArgumentType error |
502 } |
471 } |
|
472 |
|
473 if (ErrorCallback!=null && typeof ErrorCallback!="undefined") { |
|
474 if (typeof(ErrorCallback) != 'function') { |
|
475 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging: startEditor: ErrorCallback is invalid"); |
|
476 } |
|
477 } |
|
478 |
503 if (match != null && match != undefined && typeof match != "object") { |
479 if (match != null && match != undefined && typeof match != "object") { |
504 // a("match not object") |
480 // a("match not object") |
505 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:match is invalid"); //BadArgumentType error |
481 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:match is invalid"); //BadArgumentType error |
506 } |
482 } |
507 |
483 |
512 if (sortorder != null && sortorder != undefined && typeof sortorder != "number") { |
488 if (sortorder != null && sortorder != undefined && typeof sortorder != "number") { |
513 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortorder is invalid"); //BadArgumentType error |
489 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortorder is invalid"); //BadArgumentType error |
514 } |
490 } |
515 |
491 |
516 if (sortkey != null && sortkey != undefined && typeof sortkey == "number") { |
492 if (sortkey != null && sortkey != undefined && typeof sortkey == "number") { |
517 if ((sortkey != 0) && (sortkey != 1)) |
493 if ((sortkey != 0) && (sortkey != 1)) { |
518 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortkey is invalid"); //BadArgumentType error |
494 //alert("sortkey_2"); |
519 } |
495 //throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortkey is invalid"); //BadArgumentType error |
|
496 ErrorCallback( new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:getList:sortkey is out of range")); //BadArgumentType error |
|
497 return; |
|
498 } |
|
499 } |
520 |
500 |
521 if (sortorder != null && sortorder != undefined && typeof sortorder == "number") { |
501 if (sortorder != null && sortorder != undefined && typeof sortorder == "number") { |
522 // a(sortorder+" "+typeof sortorder) |
502 //alert(sortorder+" "+typeof sortorder) |
523 if ((sortorder != 0) && (sortorder != 1)) |
503 if ((sortorder != 0) && (sortorder != 1)) { |
524 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:getList:sortorder is invalid"); //BadArgumentType error |
504 ErrorCallback(new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:getList:sortorder is out of range")); //BadArgumentType error |
525 } |
505 return; |
526 |
506 } |
527 if (ErrorCallback) { |
507 } |
528 if (typeof(ErrorCallback) != 'function') { |
508 |
529 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging: startEditor: ErrorCallback is invalid"); |
|
530 } |
|
531 } |
|
532 |
509 |
533 |
510 |
534 var criteria = {}; |
511 var criteria = {}; |
535 modifyObjectBaseProp(criteria); |
512 modifyObjectBaseProp(criteria); |
536 criteria.Type = "Inbox"; |
513 criteria.Type = "Inbox"; |
1126 __device_handle_exception(e, '__sp_messaging_getMessage: ' + e); |
1103 __device_handle_exception(e, '__sp_messaging_getMessage: ' + e); |
1127 } |
1104 } |
1128 } |
1105 } |
1129 |
1106 |
1130 function __sp_messaging_delete(id){ |
1107 function __sp_messaging_delete(id){ |
1131 a("messageId" + typeof id); |
1108 //a("messageId" + typeof id); |
1132 if (!id) { |
1109 if (!id) { |
1133 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:delete:id is missing");//SErrMissingArgument = 1003 |
1110 throw new DeviceException(this.error.MISSING_ARG_ERR, "Messaging:delete:id is missing");//SErrMissingArgument = 1003 |
1134 } |
1111 } |
1135 else |
1112 else |
1136 if ((typeof id) != "string") |
1113 if ((typeof id) != "string") |
1151 criteria.MessageId = id; |
1128 criteria.MessageId = id; |
1152 |
1129 |
1153 try { |
1130 try { |
1154 // a("criteria.MessageId" + criteria.MessageId); |
1131 // a("criteria.MessageId" + criteria.MessageId); |
1155 var result = this.so.IMessaging.Delete(criteria); |
1132 var result = this.so.IMessaging.Delete(criteria); |
1156 a("MapErrorCode[ result.ErrorCode ]" + MapErrorCode[result.ErrorCode]); |
1133 //a("MapErrorCode[ result.ErrorCode ]" + MapErrorCode[result.ErrorCode]); |
1157 if (criteria) { |
1134 if (criteria) { |
1158 delete criteria.MessageId; |
1135 delete criteria.MessageId; |
1159 } |
1136 } |
1160 // a("result.ErrorCode" + result.ErrorCode); |
1137 // a("result.ErrorCode" + result.ErrorCode); |
1161 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
1138 if (result.ErrorCode != 0)//device1.0:Modified to throw exceptions |
1192 if (typeof status != "number") { |
1169 if (typeof status != "number") { |
1193 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setStatus:status is invalid"); //BadArgumentType error |
1170 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setStatus:status is invalid"); //BadArgumentType error |
1194 } |
1171 } |
1195 |
1172 |
1196 if (typeof status == "number" && status != 0 && status != 1) { |
1173 if (typeof status == "number" && status != 0 && status != 1) { |
1197 throw new DeviceException(this.error.INVALID_ARG_ERR, "Messaging:setStatus:status is invalid"); //BadArgumentType error |
1174 throw new DeviceException(this.error.DATA_OUT_OF_RANGE_ERR, "Messaging:setStatus:status is out of range"); //BadArgumentType error |
1198 } |
1175 } |
1199 |
1176 |
1200 if ((typeof id == "string") && !(isNaN(id))) { |
1177 if ((typeof id == "string") && !(isNaN(id))) { |
1201 id = Number(id); |
1178 id = Number(id); |
1202 if (id == 0) { |
1179 if (id == 0) { |