serviceproviders/jsapi/platformservices/src/calendar.js
changeset 27 02682e02e51f
child 34 5dae2c62e9b6
equal deleted inserted replaced
26:5d0ec8b709be 27:02682e02e51f
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Defination of class CCalendarInterface
       
    15 *
       
    16 */
       
    17 
       
    18 function __device_calendar_descriptor(provider){
       
    19 	//alert(("provider");
       
    20   this.interfaceName = provider.interfaceName;
       
    21   //alert(("provider interfaceName" + this.interfaceName);
       
    22   this.version = provider.version;
       
    23   //alert(("provider version" + this.version);
       
    24 }
       
    25 
       
    26 function __device_calendar_startEditor(callback, entry, ErrorCallback){
       
    27   this.provider.startEditor(callback, entry, ErrorCallback);
       
    28 }
       
    29 
       
    30 function __device_calendar_getList(callback, match, ErrorCallback){
       
    31   //alert(("__device_calendar_getList(callback, match)");
       
    32   return this.provider.getList(callback, match, ErrorCallback);
       
    33   //alert(("return from device_calendar_getList");
       
    34 
       
    35 }
       
    36 
       
    37 function __device_calendar_add(entry){
       
    38   return this.provider.addEntry(entry);
       
    39 }
       
    40 
       
    41 function __device_calendar_update(entry){
       
    42   return this.provider.updateEntry(entry);
       
    43 }
       
    44 
       
    45 function __device_calendar_delete(data){
       
    46   this.provider.deleteEntry(data);
       
    47 }
       
    48 
       
    49 function __device_calendar_cancel(transactionId){
       
    50   this.provider.cancel(transactionId);
       
    51 }
       
    52 
       
    53 // Private location prototype: called from service factory
       
    54 function __device_calendar(provider){
       
    55   //Private properties
       
    56   this.provider = provider;
       
    57   //Read-only properties
       
    58   this.interfaceName = provider.descriptor.interfaceName;
       
    59   this.version = provider.descriptor.version;
       
    60   //Core methods
       
    61   this.startEditor = __device_calendar_startEditor;
       
    62   //Extended methods
       
    63   this.getList = __device_calendar_getList;
       
    64   this.addEntry = __device_calendar_add;
       
    65   this.updateEntry = __device_calendar_update;
       
    66   this.deleteEntry = __device_calendar_delete;
       
    67   this.cancel = __device_calendar_cancel;
       
    68 }
       
    69 
       
    70 // calendar service interface
       
    71 
       
    72 // Namepace: com.nokia.device.service
       
    73 //alert(("before com.nokia.device.service");
       
    74 var __device_calendar_service_entry = {"name": null,
       
    75 					  "version": null,
       
    76 					  "proto": __device_calendar,
       
    77 					  "descriptor": __device_calendar_descriptor,
       
    78 					  "providers": [{"descriptor": __sp_calendar_descriptor, "instance": __sp_calendar_instance}]
       
    79 					 };
       
    80 		   
       
    81 //alert(("after com.nokia.device.service");
       
    82 
       
    83 
       
    84 
       
    85 /*
       
    86 Copyright � 2009 Nokia. All rights reserved.
       
    87 Code licensed under the BSD License:
       
    88 Software License Agreement (BSD License) Copyright � 2009 Nokia.
       
    89 All rights reserved.
       
    90 Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
       
    91 
       
    92 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
       
    93 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. 
       
    94 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. 
       
    95 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.
       
    96 
       
    97 version: 1.0
       
    98 */
       
    99 
       
   100 var dataGetList = 0;
       
   101 var isUpdate = 0;
       
   102 // S60 sp-based calendar provider
       
   103 
       
   104 function __sp_calendar_descriptor(){
       
   105   //Read-only properties
       
   106   this.interfaceName = "calendar";
       
   107   if(window.__Service_Interface_Ver)
       
   108 	this.version =__Service_Interface_Ver;
       
   109   else
       
   110 	this.version =1.0;
       
   111   //Class-static properties 
       
   112 }
       
   113 
       
   114 function __sp_calendar_entry_time(start, end, alarm){
       
   115    //////alert( start + " __sp_calendar_entry_time ");
       
   116   if (start) {
       
   117     //////alert("if start");
       
   118 	//////alert(start +"start");
       
   119 	var st = new Date(start);
       
   120   	this.begin = st;
       
   121 //	////alert("begin" + typeof this.begin);
       
   122   }
       
   123   if (end) {
       
   124   //	////alert("in end");
       
   125   	var en = new Date(end);
       
   126 	this.end = en;
       
   127   }
       
   128   if (alarm) {
       
   129     var al = new Date(alarm);
       
   130   	this.alarm = al;
       
   131   }
       
   132 }
       
   133 
       
   134 function __sp_calendar_isInputValid(match){
       
   135 //	////alert("Inside input validation");
       
   136 	
       
   137 		if (match) {
       
   138 			if (match.id) {
       
   139 				if (typeof(match.id) != "string") {
       
   140 					return false;
       
   141 				}
       
   142 			}
       
   143 			if (match.type) {
       
   144 				if ((typeof(match.type) != "string") || !__sp_calendar_entry_types.match(match.type)) {
       
   145 					return false;
       
   146 				}
       
   147 			}
       
   148 			if (match.text) {
       
   149 				if (typeof(match.text) != "string") {
       
   150 					return false;
       
   151 				}
       
   152 			}
       
   153 			if (match.range) {
       
   154 				if (typeof(match.range) != "object") {
       
   155 					return false;
       
   156 				}
       
   157 				if (match.range.begin) {
       
   158 					if (typeof(match.range.begin) != "object") {
       
   159 						return false;
       
   160 					}
       
   161 				}
       
   162 				if (match.range.end) {
       
   163 					if (typeof(match.range.end) != "object") {
       
   164 						return false;
       
   165 					}
       
   166 				}
       
   167 			}
       
   168 			
       
   169 			/******************************************************
       
   170 			 * addEntry/updateEntry input ,  id and type checked above
       
   171 			 **********************************************************/
       
   172 		
       
   173 				if (match.summary) {
       
   174 					
       
   175 					if (typeof(match.summary) != "string") {
       
   176 						return false;
       
   177 					}
       
   178 				}
       
   179 				if (match.description) {
       
   180 					if (typeof(match.description) != "string") {
       
   181 						return false;
       
   182 					}
       
   183 				}
       
   184 				if (match.status) {
       
   185 					if (typeof(match.status) != "string") {
       
   186 						return false;
       
   187 					}
       
   188 					
       
   189 				}
       
   190 				if (match.location) {
       
   191 					if (typeof(match.location) != "string") {
       
   192 						return false;
       
   193 					}
       
   194 				}
       
   195 				if (match.priority) {
       
   196 					if (typeof(match.priority) != "number") {
       
   197 						return false;
       
   198 					}
       
   199 				}
       
   200 				if (match.instanceStartTime) {
       
   201 					if (typeof(match.instanceStartTime) != "object") {
       
   202 						return false;
       
   203 					}
       
   204 				}
       
   205 				if (match.exceptionDates) {
       
   206 					if (typeof(match.exceptionDates) != "object") {
       
   207 						return false;
       
   208 					}
       
   209 				}
       
   210 				if (match.time) {
       
   211 					if (typeof match.time != 'object') {
       
   212 						return false;
       
   213 					}
       
   214 					if (match.time.begin) {
       
   215 						if (typeof(match.time.begin) != "object") {
       
   216 							return false;
       
   217 						}
       
   218 						if(match.time.begin == "Invalid Date" )
       
   219 						{
       
   220 							return false;
       
   221 						}
       
   222 						try{
       
   223 							(match.time.begin).getTime();
       
   224 						}
       
   225 						catch(e){
       
   226 							return false;
       
   227 						}
       
   228 					}
       
   229 					
       
   230 					if (match.time.end) {
       
   231 						if (typeof(match.time.end) != "object") {
       
   232 							return false;
       
   233 						}
       
   234 						if(match.time.end == "Invalid Date")
       
   235 						{
       
   236 							return false;
       
   237 						}
       
   238 						try{
       
   239 							(match.time.end).getTime();
       
   240 						}
       
   241 						catch(e){
       
   242 							return false;
       
   243 						}
       
   244 					}
       
   245 					if(match.time.begin && match.time.end)
       
   246 					{
       
   247 						if(match.time.begin > match.time.end)
       
   248 						{
       
   249 							return false;
       
   250 						}
       
   251 					}
       
   252 					if (match.time.alarm) {
       
   253 						
       
   254 						if (typeof(match.time.alarm) != "object") {
       
   255 							return false;
       
   256 						}
       
   257 						try{
       
   258 							(match.time.alarm).getTime();
       
   259 						}
       
   260 						catch(e){
       
   261 							return false;
       
   262 						}
       
   263 					}
       
   264 					
       
   265 				}
       
   266 				/*if(match.time && match.repeatRule){
       
   267 					if(match.time.end && match.repeatRule.untilDate){
       
   268 						if((match.time.end > match.repeatRule.untilDate)){
       
   269 							return false
       
   270 						}
       
   271 					}
       
   272 				}*/
       
   273 				if (match.repeatRule) {
       
   274 					if (typeof match.repeatRule != 'object') {
       
   275 						return false;
       
   276 					}
       
   277 					if (match.repeatRule.frequency) {
       
   278 						if (typeof(match.repeatRule.frequency) != "string") {
       
   279 							return false;
       
   280 						}
       
   281 					}
       
   282 					if (match.repeatRule.startDate) {
       
   283 						if (typeof(match.repeatRule.startDate) != "object") {
       
   284 							return false;
       
   285 						}
       
   286 						if((match.repeatRule.startDate) == "Invalid Date")
       
   287 						{
       
   288 							return false;
       
   289 						}
       
   290 						try{
       
   291 							(match.repeatRule.startDate).getTime();
       
   292 						}
       
   293 						catch(e){
       
   294 							return false;
       
   295 						}
       
   296 					}
       
   297 					if (match.repeatRule.untilDate) {
       
   298 						if (typeof(match.repeatRule.untilDate) != "object") {
       
   299 							return false;
       
   300 						}
       
   301 						if((match.repeatRule.untilDate) == "Invalid Date")
       
   302 						{
       
   303 							return false;
       
   304 						}
       
   305 						try{
       
   306 							(match.repeatRule.untilDate).getTime();
       
   307 						}
       
   308 						catch(e){
       
   309 							return false;
       
   310 						}
       
   311 					}
       
   312 					if (match.repeatRule.startDate && match.repeatRule.untilDate)
       
   313 					{
       
   314 						if (match.repeatRule.startDate > match.repeatRule.untilDate)
       
   315 						{
       
   316 							return false;
       
   317 						}
       
   318 					}
       
   319 					if (match.repeatRule.interval) {
       
   320 						if (typeof(match.repeatRule.interval) != "number") {
       
   321 							return false;
       
   322 						}
       
   323 					}
       
   324 					if (match.repeatRule.month) {
       
   325 						if (typeof(match.repeatRule.month) != "number") {
       
   326 							return false;
       
   327 						}
       
   328 					}
       
   329 					if (match.repeatRule.weekDays) {
       
   330 						if (typeof(match.repeatRule.weekDays) != "object") {
       
   331 							return false;
       
   332 						}
       
   333 					}
       
   334 					if (match.repeatRule.daysOfMonth) {
       
   335 						if (typeof(match.repeatRule.daysOfMonth) != "object") {
       
   336 							return false;
       
   337 						}
       
   338 					}
       
   339 					if (match.repeatRule.monthDates) {
       
   340 						if (typeof(match.repeatRule.monthDates) != "object") {
       
   341 							return false;
       
   342 						}
       
   343 					}
       
   344 					
       
   345 				}
       
   346 			}
       
   347 	//	////alert("returning true from input validation");
       
   348 		return true;
       
   349 }
       
   350 
       
   351 function __sp_calendar_getList_repeatRule(sp_RepeatRule){
       
   352 	var string;
       
   353  //     ////alert("getlist repeatrule************");
       
   354 	switch(sp_RepeatRule.Type){
       
   355 		case 1:
       
   356 			string = "daily";
       
   357 			this.frequency = string.toString();
       
   358 			break;
       
   359 		case 2:
       
   360 			string = "weekly";
       
   361 			this.frequency = string.toString();
       
   362 			break;
       
   363 		case 3:
       
   364 			string = "monthly";
       
   365 		//	////alert("monthly");
       
   366 			this.frequency = string.toString();
       
   367 			break;
       
   368 		case 4:
       
   369 			string = "yearly";
       
   370 			this.frequency = string.toString();
       
   371 			break;
       
   372 		default:
       
   373 			throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: Repeat Rule Type is Invalid");
       
   374 	}
       
   375 	if (sp_RepeatRule.StartDate) {
       
   376 		this.startDate = new Date(sp_RepeatRule.StartDate);
       
   377 		//////alert("startdate");
       
   378 	}
       
   379 	if (sp_RepeatRule.UntilDate) {
       
   380 		this.untilDate = new Date(sp_RepeatRule.UntilDate);
       
   381 	}
       
   382 	if (sp_RepeatRule.Interval) {
       
   383 		this.interval = sp_RepeatRule.Interval;
       
   384 	}
       
   385 	if (sp_RepeatRule.DaysInWeek) {
       
   386 		//	this.weekDays = sp_RepeatRule.DaysInWeek;
       
   387 			this.weekDays = [];
       
   388 			//repeatRule.weekDays;
       
   389 			for(var a in sp_RepeatRule.DaysInWeek){
       
   390 				if(sp_RepeatRule.DaysInWeek[a] == 6){
       
   391 					sp_RepeatRule.DaysInWeek[a] = 0;
       
   392 				}
       
   393 				else{
       
   394 					sp_RepeatRule.DaysInWeek[a]=sp_RepeatRule.DaysInWeek[a]+ 1;
       
   395 				}
       
   396 				this.weekDays.push(sp_RepeatRule.DaysInWeek[a]);
       
   397 			}
       
   398 	}
       
   399 	
       
   400 	if (sp_RepeatRule.Month) {
       
   401 		this.month = sp_RepeatRule.Month;
       
   402 	}
       
   403 	if(sp_RepeatRule.DaysOfMonth){
       
   404 		if(sp_RepeatRule.DaysOfMonth.Day){
       
   405 			if(sp_RepeatRule.DaysOfMonth.Day == 6){
       
   406 				sp_RepeatRule.DaysOfMonth.Day = 0;
       
   407 			}
       
   408 			else{
       
   409 				sp_RepeatRule.DaysOfMonth.Day = sp_RepeatRule.DaysOfMonth.Day + 1;
       
   410 			}
       
   411 			this.daysOfMonth.day = sp_RepeatRule.DaysOfMonth.Day;
       
   412 		}
       
   413 		if(sp_RepeatRule.DaysOfMonth.WeekNum){
       
   414 			this.daysOfMonth.weekInMonth = sp_RepeatRule.DaysOfMonth.WeekNum;
       
   415 		}
       
   416 	}
       
   417 	
       
   418 	if (sp_RepeatRule.MonthDays) {
       
   419 		//	this.monthDates = sp_RepeatRule.MonthDays;
       
   420 			this.monthDates = [];
       
   421 			for( var i=0; i<sp_RepeatRule.MonthDays.length; i++){
       
   422 				this.monthDates.push(sp_RepeatRule.MonthDays[i]-1);
       
   423 			}
       
   424 	}
       
   425 }
       
   426 
       
   427 function __sp_device_calendar_entry(sp_entry){ 
       
   428  // ////alert("sp_entry");
       
   429   if (sp_entry.id) {
       
   430   //	////alert("sp_entry id" + sp_entry.id);
       
   431 	this.id = sp_entry.id;
       
   432 	}
       
   433 	if (sp_entry.type) {
       
   434 	//	////alert("sp_entry.Type" + sp_entry.type);
       
   435   this.type = sp_entry.Type;
       
   436 	}
       
   437   if (sp_entry.Summary) {
       
   438  // 	////alert("summary" + sp_entry.Summary);
       
   439   	this.summary = sp_entry.Summary;
       
   440   }
       
   441   if (sp_entry.Description) {
       
   442   	this.description = sp_entry.Description;
       
   443   }
       
   444   if (sp_entry.Location) {
       
   445   	this.location = sp_entry.Location;
       
   446   }
       
   447   if (sp_entry.InstanceStartTime) {
       
   448   	this.instanceStartTime = sp_entry.InstanceStartTime;
       
   449 //	////alert("startTimeInstacce" + sp_entry.InstanceStartTime);
       
   450   }
       
   451 //  ////alert("sp_entry.Priority" + sp_entry.Priority);
       
   452   if (sp_entry.Priority >= 0 || sp_entry.Priority<= 255) {
       
   453   	this.priority = sp_entry.Priority;
       
   454   }
       
   455   if (sp_entry.Status) {
       
   456   	this.status = sp_entry.Status;
       
   457   }
       
   458   if (sp_entry.ExDates) {
       
   459   	this.exceptionDates = sp_entry.ExDates;
       
   460   }
       
   461   if (sp_entry.RepeatRule) {
       
   462   	this.repeatRule = new __sp_calendar_getList_repeatRule(sp_entry.RepeatRule);
       
   463   }
       
   464  // ////alert("sp_entry.StartTime" + sp_entry.StartTime);
       
   465 	if (dataGetList == 0) {
       
   466 		this.time = new __sp_calendar_entry_time(sp_entry.InstanceStartTime, sp_entry.InstanceEndTime, sp_entry.AlarmTime);
       
   467 	}
       
   468 	else{
       
   469 		this.time = new __sp_calendar_entry_time(sp_entry.StartTime, sp_entry.EndTime, sp_entry.AlarmTime);
       
   470 	}
       
   471 
       
   472 }
       
   473 
       
   474 
       
   475 function __sp_daysOfMonth_build(daysOfMonth){
       
   476 	if (daysOfMonth.day) {
       
   477 		////alert(daysOfMonth.day);
       
   478 		if(daysOfMonth.day == 0){
       
   479 			daysOfMonth.day = 6;
       
   480 		}
       
   481 		else{
       
   482 			////alert("in else");
       
   483 			daysOfMonth.day = daysOfMonth.day-1;
       
   484 		}
       
   485 		////alert(daysOfMonth.day);
       
   486 		this.Day = daysOfMonth.day;
       
   487 			//alert("this.Day - "+ this.Day);
       
   488 	}
       
   489 	if (daysOfMonth.weekInMonth) {
       
   490 		this.WeekNum = daysOfMonth.weekInMonth;
       
   491 	//alert("this.WeekNum" + this.WeekNum);
       
   492 	}
       
   493 }
       
   494 
       
   495 
       
   496 function __sp_calendar_addEntry_repeatRule(repeatRule,str){
       
   497 	try{
       
   498 			if (!(repeatRule.frequency)) {
       
   499 				throw new DeviceException( this.error.MISSING_ARG_ERR, "Calendar: addEntry: frequency is missing");
       
   500 			}
       
   501 			else {
       
   502 				var frequency = repeatRule.frequency;
       
   503 					switch(frequency){
       
   504 						case "daily":
       
   505 								this.Type = 1;
       
   506 								break;
       
   507 						case "weekly":
       
   508 								this.Type = 2;
       
   509 							//	////alert("weekly" + this.Type );
       
   510 								break;
       
   511 						case "monthly":
       
   512 								this.Type = 3;
       
   513 							//	////alert("monthly" + this.Type );
       
   514 								break;
       
   515 						case "yearly":
       
   516 								this.Type = 4;
       
   517 								break;
       
   518 					default:
       
   519 						throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: "+str+" Repeat Rule Type is Invalid");
       
   520 					}
       
   521 				if (repeatRule.startDate) {
       
   522 					this.StartDate = repeatRule.startDate;
       
   523 				//	////alert("this.StartDate123" +  this.StartDate);
       
   524 				}
       
   525 				if (repeatRule.untilDate) {
       
   526 					this.UntilDate = repeatRule.untilDate;
       
   527 				//	////alert("this.untilDate123" +  this.UntilDate);
       
   528 				}
       
   529 				if (repeatRule.interval) {
       
   530 					this.Interval = repeatRule.interval;
       
   531 				//	////alert("repeatRule.interval" + typeof repeatRule.interval);
       
   532 				//	////alert("this.Interval" + typeof this.Interval);
       
   533 					
       
   534 				}
       
   535 					
       
   536 				if (repeatRule.weekDays){
       
   537 						this.DaysInWeek = [];
       
   538 						//repeatRule.weekDays;
       
   539 						for(var a in repeatRule.weekDays){
       
   540 							if(repeatRule.weekDays[a] == 0){
       
   541 								repeatRule.weekDays[a] = 6;
       
   542 							}
       
   543 							else{
       
   544 								repeatRule.weekDays[a]=repeatRule.weekDays[a]-1;
       
   545 							}
       
   546 							this.DaysInWeek.push(repeatRule.weekDays[a]);
       
   547 						}
       
   548 				//		////alert("this.DaysInWeek123" + typeof this.DaysInWeek);
       
   549 				} 
       
   550 			//	//alert(repeatRule.month);
       
   551 				if (repeatRule.month) {
       
   552 					this.Month = repeatRule.month;
       
   553 					////alert("this.Month " + typeof this.Month +"  " + this.Month);
       
   554 				}
       
   555 		//	//alert("before MonthDays");
       
   556 				if (repeatRule.monthDates) {
       
   557 						this.MonthDays = [];
       
   558 						//repeatRule.monthDates;
       
   559 						for( var i=0; i<repeatRule.monthDates.length; i++){
       
   560 							this.MonthDays.push(repeatRule.monthDates[i]-1);
       
   561 						}
       
   562 						////alert("repeatRule.monthDates" + repeatRule.monthDates + "this.MonthDays" + this.MonthDays);
       
   563 				}
       
   564 				
       
   565 				if (repeatRule.daysOfMonth) {
       
   566 					////alert("repeatRule.daysOfMonth = " + repeatRule.daysOfMonth[0].weekInMonth);
       
   567 					this.DaysOfMonth = new Array();
       
   568 					for (var a in repeatRule.daysOfMonth) {
       
   569 						var dayofmnt = new __sp_daysOfMonth_build(repeatRule.daysOfMonth[a]);
       
   570 						////alert(dayofmnt.Day);
       
   571 						////alert(dayofmnt.WeekNum);
       
   572 						(this.DaysOfMonth).push(dayofmnt);
       
   573 					}
       
   574 					
       
   575     			}
       
   576 				
       
   577 			}	
       
   578 	}
       
   579 	catch(e){
       
   580 	////alert("exception");	
       
   581 	 __device_handle_exception (e, "__sp_calendar_addEntry_repeatRule: " + e);	
       
   582 	}
       
   583 }
       
   584 
       
   585 function __sp_calendar_entry(entry,str){
       
   586   // //alert("entry.type" + entry.type);
       
   587   try {
       
   588   	if (entry.type) {
       
   589 		this.Type = entry.type;
       
   590 	}
       
   591 
       
   592   	if (entry.id) {
       
   593 		this.id = entry.id;
       
   594 		if(isUpdate)
       
   595 		{
       
   596 			if (entry.time) {
       
   597 				if (entry.time.begin) {
       
   598 					this.StartTime = entry.time.begin;
       
   599 				}
       
   600 				if (entry.time.end) {
       
   601 					this.EndTime = entry.time.end;
       
   602 				}
       
   603 			}
       
   604 		}
       
   605 	}
       
   606 	
       
   607 	if (entry.instanceStartTime) {
       
   608 		this.InstanceStartTime = entry.instanceStartTime;
       
   609 	}
       
   610 
       
   611   	if (entry.description ) {
       
   612 		this.Description = entry.description;
       
   613 	}
       
   614 	else if(isUpdate && (entry.description == null)){
       
   615 		this.Description = " ";
       
   616 	}
       
   617 	
       
   618   	if (entry.summary) {
       
   619 		this.Summary = entry.summary;
       
   620 	}
       
   621 	else if(isUpdate && (entry.summary == null)){
       
   622 		this.Summary = " ";
       
   623 	}
       
   624 	
       
   625   	if (entry.location) {
       
   626 		this.Location = entry.location;
       
   627 	}
       
   628 	else if(isUpdate && (entry.location == null))
       
   629 	{
       
   630 		this.Location = " ";
       
   631 	}
       
   632 	
       
   633 	if (entry.priority) {
       
   634 		if ((entry.priority < 0) || (entry.priority > 255)) {
       
   635 			throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: "+str+" Priority is Invalid");
       
   636 		}
       
   637 		else {
       
   638 			this.Priority = entry.priority;
       
   639 		}
       
   640 	}
       
   641 	else if(isUpdate && (entry.priority == null))
       
   642 	{
       
   643 		this.Priority = 0;
       
   644 	}
       
   645 	
       
   646 	if (entry.status) {
       
   647 		if (this.Type == "ToDo") {
       
   648 			this.Status = "Todo"+entry.status;
       
   649 		}
       
   650 		else {
       
   651 			this.Status = entry.status;
       
   652 		}
       
   653 	}
       
   654 	else if(isUpdate && (entry.status == null))
       
   655 	{
       
   656 		this.Status = "Tentative";
       
   657 		//////alert("status****" + this.Status);
       
   658 	}
       
   659 	
       
   660 	if (entry.exceptionDates) {
       
   661 		this.ExDates = entry.exceptionDates;
       
   662 	}
       
   663 	if(entry.repeatRule){
       
   664 			this.RepeatRule = new __sp_calendar_addEntry_repeatRule(entry.repeatRule,str);
       
   665 			
       
   666 		}
       
   667 	
       
   668 	if (entry.type != undefined && entry.type != null) {
       
   669 		////alert("7857465988");
       
   670 		if (typeof this.Type != "string") {
       
   671 			//	////alert("Type is not a string");
       
   672 			throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: " + str + " Type is not a string");
       
   673 		}
       
   674 		switch (this.Type) {
       
   675 			case "Meeting":
       
   676 				if (entry.time) {
       
   677 					if (entry.time.begin) {
       
   678 						this.StartTime = entry.time.begin;
       
   679 						////alert("this.StartTime" + this.StartTime);
       
   680 					}
       
   681 					if (entry.time.end) {
       
   682 						this.EndTime = entry.time.end;
       
   683 					}
       
   684 				}
       
   685 				break;
       
   686 			case "Reminder":
       
   687 			case "Anniversary":
       
   688 				if (entry.time) {
       
   689 					if (entry.time.begin) {
       
   690 						this.StartTime = entry.time.begin;
       
   691 					}
       
   692 				}
       
   693 				break;
       
   694 			case "ToDo":
       
   695 				if (entry.time) {
       
   696 					if (entry.time.end) {
       
   697 						this.EndTime = entry.time.end;
       
   698 					}
       
   699 				}
       
   700 				break;
       
   701 			case "DayEvent":
       
   702 				if (entry.time) {
       
   703 					if (entry.time.begin) {
       
   704 						this.StartTime = entry.time.begin;
       
   705 					}
       
   706 				}
       
   707 				break;
       
   708 			default:
       
   709 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: " + str + " Type is Invalid");
       
   710 		}
       
   711 	}
       
   712 	
       
   713 	if (entry.time) {
       
   714 		if (entry.time.alarm) {
       
   715 			this.AlarmTime = entry.time.alarm;
       
   716 		}
       
   717 	}
       
   718 	
       
   719 	
       
   720  }
       
   721   catch (e) {
       
   722   		//alert("*****out");
       
   723     __device_handle_exception (e, "__sp_calendar_entry: " + e);
       
   724 
       
   725   } 
       
   726 }
       
   727 
       
   728 /* ------ Wrap sp iterator ------- */
       
   729 
       
   730 function __sp_calendar_iterator_get_next(){
       
   731 	//////alert("in get next");
       
   732   var sp_entry = this.iter.getNext();
       
   733  // ////alert("after calling sapi getlist");
       
   734  // ////alert("output of get next"+sp_entry.StartTime);
       
   735  // ////alert("type of output of get next"+typeof sp_entry);
       
   736   if(typeof sp_entry == "undefined"){
       
   737   //	////alert("return null");
       
   738     return null;
       
   739   }
       
   740   var calEntry = new __sp_device_calendar_entry(sp_entry);
       
   741   sp_entry.close();
       
   742   //////alert("return cal entry");
       
   743   return calEntry;
       
   744 }
       
   745 
       
   746 function __sp_calendar_iterator(js_iterator){
       
   747  // ////alert("in iter");	
       
   748   this.iter = js_iterator;
       
   749   this.next = __sp_calendar_iterator_get_next;
       
   750   this.close = function(){
       
   751 		this.iter.close();
       
   752 	};
       
   753 }
       
   754 
       
   755 /* --------- Public methods ---------- */
       
   756 var /*const causes rhino to fail */ CALENDAR_APP_ID = 0x10005901;
       
   757 
       
   758 // Apps should take care that this is not reinvoked
       
   759 // while the editor is already running. 
       
   760 
       
   761 function __sp_calendar_startEditor(editor_cb, entry, err_cb){
       
   762   try {
       
   763   	if (!editor_cb) {
       
   764   		//MissingArgument error "callback not passed";
       
   765 		throw new DeviceException( this.error.MISSING_ARG_ERR, "Calendar: startEditor: callback is missing");
       
   766 	   }
       
   767 	else if (typeof editor_cb != "function") //here we check if the type of callback is function. This case is useful when arbitrary values are passed to callback
       
   768 		{
       
   769 		  //BadArgumentType error
       
   770 		  throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: startEditor: callback is invalid");
       
   771 		}
       
   772 	if(err_cb)
       
   773 	{ 
       
   774 		if(typeof err_cb != 'function')
       
   775 		{
       
   776 		   	throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: startEditor: error callback is invalid");
       
   777 		}
       
   778 	}
       
   779 	if(entry == null || entry == undefined)
       
   780 	{
       
   781 		throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: startEditor: entry is invalid");
       
   782 	}
       
   783 	var finished = function(arg1, arg2, arg3){
       
   784 	
       
   785 	
       
   786 	var iter = null;
       
   787 	editor_cb(iter);
       
   788 	if (arg2 != event_cancelled) {
       
   789 		var iter = null;
       
   790 		if (arg3.ReturnValue) {
       
   791 			iter = new __sp_calendar_iterator(arg3.ReturnValue);
       
   792 		}
       
   793 		editor_cb(iter);
       
   794 	}		
       
   795 	
       
   796 	if (arg3.ErrorCode != 0) {
       
   797 		switch( arg3.ErrorCode )
       
   798 			{
       
   799 			 case this.error.MISSING_ARG_ERR :
       
   800 			 case this.error.INVALID_ARG_ERR :
       
   801 			 case this.error.NOT_SUPPORTED_ERR :
       
   802 				if(arg3.ErrorMessage) 
       
   803 					{
       
   804 					var err_msg = splitErrorMessage(arg3.ErrorMessage); 	
       
   805 					throw new DeviceException( MapErrorCode[arg3.ErrorCode], "Calendar: startEditor: "+err_msg);
       
   806 					}
       
   807 				else
       
   808 					{
       
   809 					throw new DeviceException( MapErrorCode[arg3.ErrorCode], "Calendar: startEditor: Operation Failed");	
       
   810 					}
       
   811 				break;
       
   812 
       
   813 			default:
       
   814 				err_cb(new DeviceException( MapErrorCode[arg3.ErrorCode], "Calendar: startEditor: Operation Failed"));
       
   815 				 }
       
   816 	   }
       
   817 	
       
   818 	};
       
   819 	//For some reason, calendar is unable to parse command line
       
   820 	__s60_start_and_wait(CALENDAR_APP_ID, '', finished);
       
   821 	return 0;
       
   822 	}
       
   823    catch (e) {
       
   824     __device_handle_exception (e, "__sp_calendar_startEditor: " + e);
       
   825   } 
       
   826 }
       
   827 
       
   828 var /*const causes rhino to fail */ __sp_calendar_entry_types = "MeetingReminderToDoAnniversaryDayEvent";
       
   829 
       
   830 function __sp_calendar_getList_cb(arg1, arg2, arg3) {
       
   831 
       
   832 	var CbObj;
       
   833 	var calendar_cb;
       
   834 	var err_cb;
       
   835 	
       
   836 	CbObj = glob_obj.getFromArray(arg1);
       
   837 			
       
   838 	 
       
   839 	if (CbObj) {
       
   840 		calendar_cb = CbObj.success_cb;
       
   841 		err_cb = CbObj.error_cb;
       
   842 	}
       
   843 	 
       
   844 	else{
       
   845 		alert( "Calendar: __sp_calendar_getList_cb: Callback not found ");
       
   846 		return;
       
   847 	}
       
   848 	
       
   849 	
       
   850 	//arg3.ErrorCode = DATA_OUT_OF_RANGE_ERR;
       
   851 	//////alert("err"+arg3.ErrorCode);
       
   852 	if(arg3.ErrorCode != 0)
       
   853 	{
       
   854 	//	////alert("before calling errcbk" + arg3.ErrorCode);
       
   855 		err_cb(new DeviceException( arg3.ErrorCode, "Calendar: getList: Operation Failed"));
       
   856 		return;
       
   857 	}	
       
   858    //__device_debug("Calendar callback invoker");
       
   859    // arg1 --> transacation Id
       
   860    // arg2 --> Error code
       
   861    // iter --> return object as per the domain
       
   862    if (arg2 != event_cancelled) {
       
   863    	  
       
   864 	   	var iter = null;
       
   865 	   	if (arg3.ReturnValue) {
       
   866 	   		iter = new __sp_calendar_iterator(arg3.ReturnValue);
       
   867 			}
       
   868 		   	calendar_cb(iter);
       
   869 		}	
       
   870 	glob_obj.removeFromArray(arg1);
       
   871     }
       
   872 
       
   873 function __sp_calendar_getList(calendar_cb, match, err_cb){
       
   874 
       
   875 //	////alert("in getlist");
       
   876 	
       
   877     try {
       
   878   	if(match)
       
   879 	{
       
   880   		if(typeof match != "object")
       
   881 		{
       
   882 			throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   883 		}
       
   884 		if (match.id) {
       
   885 			dataGetList = 1;
       
   886 			if (typeof match.id != "string") {
       
   887 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   888 			}
       
   889 		}
       
   890 		else
       
   891 		{
       
   892 			dataGetList = 0;
       
   893 		}
       
   894 	}
       
   895  	
       
   896   	if(!calendar_cb)
       
   897   	{
       
   898   		//MissingArgument error "callback not passed";
       
   899 		throw new DeviceException( this.error.MISSING_ARG_ERR, "Calendar: getList: callback is missing");
       
   900   	}
       
   901   	else if(typeof calendar_cb != "function")	//here we check if the type of callback is function. This case is useful when arbitrary values are passed to callback
       
   902   	{
       
   903   		//BadArgumentType error
       
   904 		throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: getList: callback is invalid");
       
   905   	}
       
   906 	if(err_cb)
       
   907 	{ 
       
   908 		//////alert("(inside)type of err_cb" + typeof err_cb);
       
   909 		if(typeof err_cb != "function")
       
   910 		{
       
   911 	//		////alert("not func");
       
   912 		   	throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: getList: error callback is invalid");
       
   913 		}
       
   914 		if( err_cb == undefined || err_cb == null)
       
   915 		{	
       
   916 			//alert("333");
       
   917 			throw new DeviceException( this.error.MISSING_ARG_ERR, "Calendar: getList: error callback is missing");
       
   918 		}
       
   919 	}
       
   920 	
       
   921 
       
   922   
       
   923 
       
   924     // Note: sp bug requires filter values of some kind
       
   925     var filter = {}; 
       
   926 	modifyObjectBaseProp(filter);
       
   927     filter.Type = "IncludeAll";
       
   928     if(match)
       
   929 	{
       
   930 	  if(match.id){
       
   931 		filter.id = match.id;
       
   932       }
       
   933       if((match.type) && __sp_calendar_entry_types.match(match.type)){
       
   934 		filter.Type = match.type;
       
   935       }
       
   936 	  else if((match.type) && typeof match.type != "string")
       
   937 	  {
       
   938 	  	 throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   939 	  }
       
   940       if(match.range){
       
   941 		if(match.range.begin){
       
   942 			if (typeof(match.range.begin) != "object") {
       
   943 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   944 			}
       
   945 			else if((match.range.begin) == "Invalid Date"){
       
   946 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   947 			}
       
   948 			else{
       
   949 				filter.StartRange = match.range.begin;
       
   950 			}
       
   951 		}
       
   952         if(match.range.end){
       
   953 			if (typeof(match.range.end) != "object") {
       
   954 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   955 			}
       
   956 			else if((match.range.end) == "Invalid Date"){
       
   957 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   958 			}
       
   959 			else{
       
   960 				filter.EndRange = match.range.end;
       
   961 			}
       
   962 		}
       
   963 		if((match.range.begin) && (match.range.end)){
       
   964 			if((match.range.begin) > (match.range.end))
       
   965 			{
       
   966 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   967 			}
       
   968 		}
       
   969 			
       
   970       }
       
   971       if(match.text){
       
   972 	  	if (typeof(match.text) != "string") {
       
   973 			throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: getList: match is invalid");
       
   974 		}
       
   975 		else {
       
   976 			filter.SearchText = match.text;
       
   977 		}
       
   978       }
       
   979     }
       
   980 //	////alert("filter.StartRange" + filter.StartRange);
       
   981 //	////alert("filter.EndRange" + filter.EndRange);
       
   982     var criteria = {};
       
   983 	modifyObjectBaseProp(criteria);
       
   984     criteria.Type = "CalendarEntry";
       
   985     criteria.Filter = filter;
       
   986 	temp_scb = calendar_cb;
       
   987 	temp_ecb = err_cb;
       
   988 //	////alert("1111");
       
   989 	var rval = this.so.IDataSource.GetList(criteria , this.getListCb );
       
   990 	if(rval.TransactionID){
       
   991 			glob_obj.addToGlobalArray(rval.TransactionID,calendar_cb,err_cb);
       
   992 		}
       
   993 //	////alert("2222*******");
       
   994 	if (criteria) {
       
   995 		delete criteria.Type;
       
   996 		delete criteria.Filter;
       
   997 	}
       
   998 //	////alert("rval.ErrorCode getlist" + rval.ErrorCode);
       
   999     if(rval.ErrorCode != 0)
       
  1000 		{
       
  1001 			
       
  1002 		switch( rval.ErrorCode )
       
  1003 			{
       
  1004 			 case this.error.MISSING_ARG_ERR :
       
  1005 			 case this.error.INVALID_ARG_ERR :
       
  1006 			 case this.error.NOT_SUPPORTED_ERR :
       
  1007 			 	////alert("case NOT_SUPPORTED_ERR");
       
  1008 				if(rval.ErrorMessage) 
       
  1009 					{
       
  1010 					var err_msg = splitErrorMessage(rval.ErrorMessage); 
       
  1011 					//////alert("1111" + rval.ErrorMessage);	
       
  1012 					throw new DeviceException( MapErrorCode[rval.ErrorCode], "Calendar: getList: "+err_msg);
       
  1013 					
       
  1014 					}
       
  1015 				else
       
  1016 					{
       
  1017 					//////alert("2222" + rval.ErrorMessage);
       
  1018 					throw new DeviceException( MapErrorCode[rval.ErrorCode], "Calendar: getList: Operation Failed");	
       
  1019 					}
       
  1020 				break;
       
  1021 
       
  1022 			default:
       
  1023 			//	////alert("Calendar: getList: Operation Failed");
       
  1024 				err_cb(new DeviceException( MapErrorCode[rval.ErrorCode], "Calendar: getList: Operation Failed"));
       
  1025 				 }
       
  1026    		}
       
  1027 	 return rval.TransactionID;
       
  1028   }
       
  1029   catch (e) {
       
  1030   	 //  ////alert("out");
       
  1031     __device_handle_exception (e, "sp_calendar_getList: " + e);
       
  1032   }  
       
  1033 //////alert("out getlist");
       
  1034 }
       
  1035 
       
  1036 function __sp_calendar_add(entry){
       
  1037 	
       
  1038 	
       
  1039 	if(entry)
       
  1040 	{
       
  1041 		if(typeof entry != "object")
       
  1042 		{
       
  1043 			throw new DeviceException(this.error.INVALID_ARG_ERR, 'Calendar: addEntry: calendarEntry param is invalid');			
       
  1044 		}
       
  1045 	//	//alert("add entry1");
       
  1046 		if(entry.id)
       
  1047 		{
       
  1048 			entry.id = undefined;
       
  1049 		}
       
  1050 	//	//alert("add entry2");
       
  1051 		if(!entry.type || !entry.time)
       
  1052 		{
       
  1053 			throw new DeviceException(this.error.MISSING_ARG_ERR, "Calendar: addEntry: mandatory param missing");
       
  1054 		}
       
  1055 		else if(typeof entry.type != "string" || typeof entry.time != "object")
       
  1056 		{
       
  1057 			throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: addEntry: mandatory param missing");
       
  1058 		}
       
  1059 	//	//alert("add entry3");
       
  1060 		if((entry.type != "ToDo") && !entry.time.begin )
       
  1061 		{
       
  1062 			throw new DeviceException(this.error.MISSING_ARG_ERR, "Calendar: addEntry: mandatory param StartTime missing");
       
  1063 		}
       
  1064 	//	//alert("add entry4");
       
  1065 		if(!entry.time.end && (entry.type == "ToDo"  || entry.type == "Meeting"))
       
  1066 		{
       
  1067 			throw new DeviceException(this.error.MISSING_ARG_ERR, "Calendar: addEntry: mandatory param EndTime missing");
       
  1068 		}
       
  1069 	//	//alert("add entry5");
       
  1070 		if(entry.time.end && entry.time.alarm)
       
  1071 		{
       
  1072 			if(entry.time.end < entry.time.alarm)
       
  1073 			{
       
  1074 				throw new DeviceException(this.error.NOT_SUPPORTED_ERR, "Calendar: addEntry: alarm time greater than end time:Not supported");
       
  1075 			}
       
  1076 		}
       
  1077 		
       
  1078 		if(entry.type == "ToDo"){
       
  1079 			if(entry.status == 0) {
       
  1080 				if (typeof(entry.status) != "string") {
       
  1081 					throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: addEntry: mandatory param missing");
       
  1082 				}
       
  1083 			}
       
  1084 		}
       
  1085 		
       
  1086 	//	//alert("add entry7");
       
  1087 		if (entry.repeatRule) {
       
  1088 			if(typeof entry.repeatRule != 'object')
       
  1089 			{
       
  1090 				throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: addEntry: repeatRule param type is invalid");
       
  1091 			}
       
  1092 			
       
  1093 			if (!entry.repeatRule.frequency || entry.repeatRule.frequency == null) 
       
  1094 			{
       
  1095 				throw new DeviceException(this.error.MISSING_ARG_ERR, "Calendar: addEntry: mandatory param Frequency missing");
       
  1096 			}
       
  1097 		}
       
  1098 	
       
  1099 		var isValid = __sp_calendar_isInputValid(entry);
       
  1100 	//	//alert(isValid);
       
  1101 	    	    
       
  1102 	    if (!isValid) {	
       
  1103 		//	////alert("returned false");    
       
  1104 	        throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: addEntry: calendarEntry param is invalid");
       
  1105 	    }
       
  1106 	//	////alert("returned true");
       
  1107 	}
       
  1108 	else
       
  1109 	{
       
  1110 		throw new DeviceException(this.error.MISSING_ARG_ERR, "Calendar: addEntry: mandatory param missing");
       
  1111 	}
       
  1112 	
       
  1113   try{
       
  1114   	////alert("calendar_entry");
       
  1115   	var str = "addEntry:";
       
  1116     var criteria = {};
       
  1117 	modifyObjectBaseProp(criteria);
       
  1118     criteria.Type = "CalendarEntry";
       
  1119     criteria.Item = new __sp_calendar_entry(entry,str);
       
  1120 	
       
  1121  //   //alert("before add");
       
  1122 	var result = this.so.IDataSource.Add(criteria);
       
  1123 	//alert("result" + result.ErrorCode);
       
  1124 	if (criteria) {
       
  1125 		delete criteria.Type;
       
  1126 		delete criteria.Item;
       
  1127 	}
       
  1128 	var err_msg = "Operation Failed";
       
  1129 	if(result.ErrorMessage)
       
  1130 	{
       
  1131 	err_msg = splitErrorMessage(result.ErrorMessage); 	
       
  1132 	}
       
  1133 //	//alert(result.ErrorCode);
       
  1134     if (result.ErrorCode != 0) {
       
  1135 			//alert("throwdeviceexptn" +result.ErrorCode);
       
  1136 			throw new DeviceException( MapErrorCode[result.ErrorCode], "Calendar: addEntry: Operation Failed");	
       
  1137 			return;
       
  1138 		}
       
  1139 	else {
       
  1140 		var retVal = result.ReturnValue;
       
  1141 		return retVal;
       
  1142 	}
       
  1143 //	////alert("addEntry");
       
  1144   }
       
  1145   catch(e){
       
  1146  // 	////alert("exception");
       
  1147     __device_handle_exception (e, "__sp_calendar_add: " + e);
       
  1148   }
       
  1149 }
       
  1150 
       
  1151 function __sp_calendar_update(entry){
       
  1152 	isUpdate = 1;
       
  1153 	if(entry)
       
  1154 		{
       
  1155 			if(typeof entry != 'object')
       
  1156 			{				
       
  1157 				throw new DeviceException(this.error.INVALID_ARG_ERR, 'Calendar: updateEntry: calendarEntry param is invalid');			
       
  1158 			}
       
  1159 			if(!entry.id)
       
  1160 			{
       
  1161 				throw new DeviceException(this.error.MISSING_ARG_ERR, "Calendar: updateEntry: mandatory param - Id missing");
       
  1162 			}	
       
  1163 			if (entry.repeatRule) {
       
  1164 				
       
  1165 				if(typeof entry.repeatRule != 'object')
       
  1166 				{
       
  1167 					throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: updateEntry: repeatRule param type is invalid");
       
  1168 				}
       
  1169 				if(/*entry.repeatRule.frequency && */(entry.repeatRule.frequency == null || entry.repeatRule.frequency == undefined))
       
  1170 				{
       
  1171 					////alert("am here in repeatrule");
       
  1172 					throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: updateEntry: repeatRule param type is invalid");
       
  1173 				}
       
  1174 				if(entry.repeatRule.startDate && (entry.repeatRule.startDate == null || entry.repeatRule.startDate == undefined))
       
  1175 				{
       
  1176 					throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: updateEntry: repeatRule param type is invalid");
       
  1177 				}
       
  1178 				if(entry.repeatRule.untilDate && (entry.repeatRule.untilDate == null || entry.repeatRule.untilDate == undefined))
       
  1179 				{
       
  1180 					throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: updateEntry: repeatRule param type is invalid");
       
  1181 				}
       
  1182 			}
       
  1183 			if(entry.time)
       
  1184 			{
       
  1185 				if(entry.time.end && entry.time.alarm)
       
  1186 				{
       
  1187 					if(entry.time.alarm > entry.time.end)
       
  1188 					{
       
  1189 						throw new DeviceException(this.error.NOT_SUPPORTED_ERR, "Calendar: updateEntry: alarm time greater than end time is not supported");
       
  1190 					}
       
  1191 				}
       
  1192 			}
       
  1193 		    var isValid = __sp_calendar_isInputValid(entry);
       
  1194 		//    //alert("isValid" + isValid);		    
       
  1195 		    if (!isValid) {	    
       
  1196 		        throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: updateEntry: calendarEntry param is invalid");
       
  1197 		    }
       
  1198 		}
       
  1199 		
       
  1200 		else
       
  1201 		{
       
  1202 			////alert("missing argument");
       
  1203 			throw new DeviceException(this.error.MISSING_ARG_ERR, "Calendar: updateEntry: mandatory param missing");
       
  1204 		}
       
  1205   try{
       
  1206   	//alert("update");
       
  1207   	var str = "updateEntry:";
       
  1208     var criteria = {};
       
  1209 	modifyObjectBaseProp(criteria);
       
  1210     criteria.Type = "CalendarEntry";
       
  1211     criteria.Item = new __sp_calendar_entry(entry,str);
       
  1212 	isUpdate = 0;
       
  1213 //	//alert("am here in update entry");
       
  1214     var result = this.so.IDataSource.Add(criteria);
       
  1215 //	//alert("result.ErrorCode" + result.ErrorCode);
       
  1216 	if (criteria) {
       
  1217 		delete criteria.Type;
       
  1218 		delete criteria.Item;
       
  1219 	}
       
  1220 	var err_msg = "Operation Failed";
       
  1221 	if(result.ErrorMessage)
       
  1222 	{
       
  1223 	err_msg = splitErrorMessage(result.ErrorMessage); 	
       
  1224 	}
       
  1225     if (result.ErrorCode != 0) {
       
  1226 			////alert("throwdeviceexptn" +result.ErrorCode);
       
  1227 			throw new DeviceException( MapErrorCode[result.ErrorCode], "Calendar: addEntry: Operation Failed");	
       
  1228 			return;
       
  1229 		}
       
  1230 	else {
       
  1231 		var retVal = result.ReturnValue;
       
  1232 		return retVal;
       
  1233    		}
       
  1234   }
       
  1235   catch(e){
       
  1236  // 	////alert("update exception" + e.message);
       
  1237     __device_handle_exception (e, "__sp_calendar_add: " + e);
       
  1238   }
       
  1239 }
       
  1240 
       
  1241 function __sp_calendar_delete(data){
       
  1242 
       
  1243 //	////alert("in delete");
       
  1244   try{
       
  1245   	if(data)
       
  1246 	{
       
  1247 		if(typeof data != "object")
       
  1248 		{
       
  1249 			throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: deleteEntry: data is invalid");
       
  1250 		}
       
  1251 		if (!data.id) 
       
  1252 		{
       
  1253 			throw new DeviceException( this.error.MISSING_ARG_ERR, "Calendar: deleteEntry: id is missing");
       
  1254 		}
       
  1255 		var isValid = __sp_calendar_isInputValid(data);
       
  1256 	    
       
  1257 	    if (!isValid) {      
       
  1258 	        throw new DeviceException(this.error.INVALID_ARG_ERR, "Calendar: deleteEntry: delete data is invalid");
       
  1259 	    }
       
  1260 	}
       
  1261 	else
       
  1262 	{
       
  1263 		throw new DeviceException( this.error.MISSING_ARG_ERR, "Calendar: deleteEntry: data is missing");
       
  1264 	}
       
  1265 	
       
  1266   	
       
  1267 	
       
  1268     var criteria = {};
       
  1269 	modifyObjectBaseProp(criteria);
       
  1270     criteria.Type = "CalendarEntry";
       
  1271     criteria.Data = {};
       
  1272 	modifyObjectBaseProp(criteria.Data);
       
  1273     criteria.Data.IdList = [];
       
  1274 	var list = [data.id];
       
  1275 	//list  = data.id;       //new Array(data.id);
       
  1276 	criteria.Data.IdList = list;
       
  1277 	if (data.range) {
       
  1278 		if (data.range.begin) {
       
  1279 		criteria.Data.StartRange = data.range.begin;
       
  1280 		}
       
  1281 		if (data.range.end) {
       
  1282 		criteria.Data.EndRange = data.range.end;
       
  1283 		}
       
  1284 	}	
       
  1285    var rval = this.so.IDataSource.Delete(criteria);
       
  1286  //  ////alert("rval.ErrorCode" + rval.ErrorCode);
       
  1287    if (criteria) {
       
  1288    	delete criteria.Type;
       
  1289 	delete criteria.Data.IdList;
       
  1290 	delete criteria.Data.StartRange;
       
  1291 	delete criteria.Data.EndRange;
       
  1292    }
       
  1293    if (list) {
       
  1294    	delete list.id;
       
  1295    }
       
  1296    if(rval.ErrorCode != 0)
       
  1297 	{
       
  1298 		if(rval.ErrorMessage) 
       
  1299 			{
       
  1300 			var err_msg = splitErrorMessage(rval.ErrorMessage); 	
       
  1301 			throw new DeviceException( MapErrorCode[rval.ErrorCode], "Calendar: deleteEntry: "+err_msg);
       
  1302 			}
       
  1303 		else
       
  1304 			{
       
  1305 			throw new DeviceException( MapErrorCode[rval.ErrorCode], "Calendar: deleteEntry: Operation Failed");	
       
  1306 			}
       
  1307    	}
       
  1308   }
       
  1309   catch(e){
       
  1310  // 	////alert("exception");
       
  1311     __device_handle_exception (e, "__sp_calendar_delete: " + e);
       
  1312   }
       
  1313 }
       
  1314 
       
  1315 function __sp_calendar_cancel(transactionId)
       
  1316 {
       
  1317 	try{
       
  1318     if (!transactionId || transactionId == null || transactionId == undefined) {
       
  1319 		throw new DeviceException( this.error.MISSING_ARG_ERR, "Calendar: cancel: id is missing");//SErrMissingArgument = 1003  
       
  1320 	}
       
  1321 	if(transactionId)
       
  1322 	{
       
  1323 		if(typeof transactionId != "number" ){
       
  1324 			throw new DeviceException( this.error.INVALID_ARG_ERR, "Calendar: cancel: id is missing");//SErrMissingArgument = 1003  
       
  1325 		}
       
  1326 	}
       
  1327     var criteria = {};
       
  1328     modifyObjectBaseProp(criteria);
       
  1329 	criteria.TransactionID = transactionId;
       
  1330     var result = this.so.IDataSource.Cancel(criteria);
       
  1331 	if(criteria){
       
  1332 		delete criteria.TransactionID;
       
  1333 	}
       
  1334 	//alert("result.ErrorCode" + result.ErrorCode);
       
  1335    if(result.ErrorCode != 0)
       
  1336 		{
       
  1337 		if(result.ErrorMessage) 
       
  1338 			{
       
  1339 			var err_msg = splitErrorMessage(result.ErrorMessage); 	
       
  1340 			throw new DeviceException( MapErrorCode[result.ErrorCode], "Calendar: cancel: "+err_msg);
       
  1341 			}
       
  1342 		else
       
  1343 			{
       
  1344 			throw new DeviceException( MapErrorCode[result.ErrorCode], "Calendar: cancel: Operation Failed");	
       
  1345 			}
       
  1346    		}
       
  1347 	}
       
  1348 	catch(e){
       
  1349     __device_handle_exception (e, "__sp_calendar_cancel: " + e);		
       
  1350 	}
       
  1351 }
       
  1352 
       
  1353 function __sp_calendar_instance(){
       
  1354   //Descriptor
       
  1355   this.descriptor = new __sp_calendar_descriptor();
       
  1356   //Core methods
       
  1357   //////alert("startEditor");
       
  1358   this.startEditor = __sp_calendar_startEditor;
       
  1359   //Extended methods
       
  1360   this.getList = __sp_calendar_getList;
       
  1361   this.getListCb = __sp_calendar_getList_cb;
       
  1362     
       
  1363   this.addEntry = __sp_calendar_add;
       
  1364   this.updateEntry = __sp_calendar_update;
       
  1365   this.deleteEntry = __sp_calendar_delete;
       
  1366   this.cancel = __sp_calendar_cancel;
       
  1367   this.error = new DeviceException(0, "Dummy");
       
  1368   //Private data
       
  1369   this.so = null;
       
  1370   //Private methods
       
  1371   try {
       
  1372 	this.so = device.getServiceObject("Service.Calendar", "IDataSource");
       
  1373 	//////alert(so);
       
  1374     }
       
  1375   catch (e){
       
  1376     __device_handle_exception(e, "Calendar service not available");
       
  1377   }
       
  1378 }