2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/Converter.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <Tizen/Common/JSTizenException.h>
24 #include <Tizen/Common/JSTizenExceptionFactory.h>
25 #include <Tizen/TimeUtil/TimeUtilConverter.h>
26 #include <Tizen/TimeUtil/JSTZDate.h>
27 #include <API/Calendar/EventAlarm.h>
28 #include <API/Calendar/EventId.h>
29 #include "JSCalendarItemProperties.h"
30 #include "CalendarConverter.h"
31 #include "JSCategoryArray.h"
32 #include "JSEventId.h"
33 #include "JSEventAlarm.h"
34 #include "JSRecurrenceRule.h"
35 #include "JSAttendee.h"
37 using namespace TizenApis::Api::Calendar;
38 using namespace WrtDeviceApis::Commons;
39 using namespace WrtDeviceApis::CommonsJavaScript;
45 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
47 #define TIZEN_CALENDAR_ITEM_DESCRIPTION "description"
48 #define TIZEN_CALENDAR_ITEM_SUMMARY "summary"
49 #define TIZEN_CALENDAR_ITEM_STARTTIME "startDate"
50 #define TIZEN_CALENDAR_ITEM_LOCATION "location"
51 #define TIZEN_CALENDAR_ITEM_LATITUDE "latitude"
52 #define TIZEN_CALENDAR_ITEM_LONGITUDE "longitude"
53 #define TIZEN_CALENDAR_ITEM_ORGANIZER "organizer"
54 #define TIZEN_CALENDAR_ITEM_VISIBILITY "visibility"
55 #define TIZEN_CALENDAR_ITEM_STATUS "status"
56 #define TIZEN_CALENDAR_ITEM_ALARMS "alarms"
57 #define TIZEN_CALENDAR_ITEM_CATEGORIES "categories"
59 #define TIZEN_CALENDAR_EVENT_DURATION "duration"
60 #define TIZEN_CALENDAR_EVENT_IS_ALL_DAY "isAllDay"
61 #define TIZEN_CALENDAR_EVENT_ATTENDEES "attendees"
62 #define TIZEN_CALENDAR_EVENT_RECURRENCE_RULE "recurrenceRule"
63 #define TIZEN_CALENDAR_EVENT_AVAILABILITY "availability"
65 #define TIZEN_CALENDAR_TASK_DUEDATE "dueDate"
66 #define TIZEN_CALENDAR_TASK_PRIORITY "priority"
68 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
70 kJSClassAttributeNone,
71 TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
80 NULL, //DeleteProperty,
81 NULL, //GetPropertyNames,
82 NULL, //CallAsFunction,
83 NULL, //CallAsConstructor,
88 JSStaticValue JSCalendarItemProperties::m_property[] = {
90 { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription,
91 setPropertyDescription, kJSPropertyAttributeNone },
92 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary,
93 setPropertySummary, kJSPropertyAttributeNone },
94 { TIZEN_CALENDAR_ITEM_STARTTIME, getPropertyStartTime,
95 setPropertyStartTime, kJSPropertyAttributeNone },
96 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation,
97 setPropertyLocation, kJSPropertyAttributeNone },
98 { TIZEN_CALENDAR_ITEM_LATITUDE, getPropertyLatitude,
99 setPropertyLatitude, kJSPropertyAttributeNone },
100 { TIZEN_CALENDAR_ITEM_LONGITUDE, getPropertyLongitude,
101 setPropertyLongitude, kJSPropertyAttributeNone },
102 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer,
103 setPropertyOrganizer, kJSPropertyAttributeNone },
104 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility,
105 setPropertyVisibility, kJSPropertyAttributeNone },
106 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus,
107 setPropertyStatus, kJSPropertyAttributeNone },
108 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms,
109 setPropertyAlarms, kJSPropertyAttributeNone },
110 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories,
111 setPropertyCategories, kJSPropertyAttributeNone },
113 { TIZEN_CALENDAR_EVENT_DURATION, getPropertyDuration,
114 setPropertyDuration, kJSPropertyAttributeNone },
115 { TIZEN_CALENDAR_EVENT_IS_ALL_DAY, getPropertyIsAllDay,
116 setPropertyIsAllDay, kJSPropertyAttributeNone },
117 { TIZEN_CALENDAR_EVENT_ATTENDEES, getPropertyAttendees,
118 setPropertyAttendees, kJSPropertyAttributeNone },
119 { TIZEN_CALENDAR_EVENT_RECURRENCE_RULE, getPropertyRecurrenceRule,
120 setPropertyRecurrenceRule, kJSPropertyAttributeNone },
121 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability,
122 setPropertyAvailability, kJSPropertyAttributeNone },
124 { TIZEN_CALENDAR_TASK_DUEDATE, getPropertyDueDate,
125 setPropertyDueDate, kJSPropertyAttributeNone },
126 { TIZEN_CALENDAR_TASK_PRIORITY, getPropertyPriority,
127 setPropertyPriority, kJSPropertyAttributeNone },
132 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
134 void JSCalendarItemProperties::initialize(JSContextRef context,
138 CalendarItemPropertiesPrivObject *priv =
139 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
141 CalendarEventPtr privateData(new CalendarEvent());
142 priv = new CalendarItemPropertiesPrivObject(context, privateData);
143 JSObjectSetPrivate(object, static_cast<void*>(priv));
144 LogDebug("New CalendarItemPropertiesPrivObject is created.");
146 LogDebug("CalendarItemPropertiesPrivObject already exists.");
150 void JSCalendarItemProperties::finalize(JSObjectRef object)
153 CalendarItemPropertiesPrivObject *priv =
154 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
158 const JSClassRef JSCalendarItemProperties::getClassRef()
161 m_jsClassRef = JSClassCreate(&m_classInfo);
166 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
171 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
174 CalendarItemPropertiesPrivObject *priv =
175 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
177 ThrowMsg(NullPointerException, "Private object is null");
179 CalendarEventPtr result = priv->getObject();
181 ThrowMsg(NullPointerException, "Private object is null");
186 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
188 const JSObjectRef object)
193 CalendarItemPropertiesPrivObject *priv =
194 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
196 priv = new CalendarItemPropertiesPrivObject(ctx, event);
197 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
203 LogError("Error during replacing event object");
207 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
209 JSStringRef propertyName,
210 JSValueRef* exception)
215 Converter converter(context);
216 CalendarEventPtr event = getPrivateObject(object);
217 return converter.toJSValueRef(event->getDescription());
221 LogWarning("trying to get incorrect value");
223 return JSValueMakeUndefined(context);
226 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
228 JSStringRef propertyName,
230 JSValueRef* exception)
235 Converter converter(context);
236 CalendarEventPtr event = getPrivateObject(object);
237 std::string description = converter.toString(value);
238 event->setDescription(description);
243 LogWarning("trying to set incorrect value");
245 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
249 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
251 JSStringRef propertyName,
252 JSValueRef* exception)
257 Converter converter(context);
258 CalendarEventPtr event = getPrivateObject(object);
259 return converter.toJSValueRef(event->getSubject());
263 LogWarning("trying to get incorrect value");
265 return JSValueMakeUndefined(context);
268 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
270 JSStringRef propertyName,
272 JSValueRef* exception)
277 Converter converter(context);
278 CalendarEventPtr event = getPrivateObject(object);
279 std::string subject = converter.toString(value);
280 event->setSubject(subject);
285 LogWarning("trying to set incorrect value");
287 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
291 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
293 JSStringRef propertyName,
294 JSValueRef* exception)
299 CalendarItemPropertiesPrivObject *privateObject =
300 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
301 Converter converter(context);
302 CalendarEventPtr event = privateObject->getObject();
304 // Use the global context saved in the event struct.
305 return JSTZDate::createJSObject(privateObject->getContext(), event->getStartTime(), event->getTimeZone());
309 LogWarning("trying to get incorrect value");
311 return JSValueMakeUndefined(context);
314 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
316 JSStringRef propertyName,
318 JSValueRef* exception)
323 CalendarEventPtr event = getPrivateObject(object);
324 TimeUtilConverter converter(context);
325 std::time_t startTime = converter.toTZDateTimeT(value);
326 std::time_t duration = 0;
327 duration = (event->getEndTime() - event->getStartTime());
329 duration = 3600; // default 1 hour.
330 event->setEndTime(startTime + duration);
331 event->setStartTime(startTime);
333 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
334 event->setTimeZone(timeZone);
339 LogWarning("trying to set incorrect value");
341 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
345 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
347 JSStringRef propertyName,
348 JSValueRef* exception)
353 Converter converter(context);
354 CalendarEventPtr event = getPrivateObject(object);
355 return converter.toJSValueRef(event->getLocation());
359 LogWarning("trying to get incorrect value");
361 return JSValueMakeUndefined(context);
364 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
366 JSStringRef propertyName,
368 JSValueRef* exception)
373 Converter converter(context);
374 CalendarEventPtr event = getPrivateObject(object);
375 std::string location = converter.toString(value);
376 event->setLocation(location);
381 LogWarning("trying to set incorrect value");
383 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
387 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
389 JSStringRef propertyName,
390 JSValueRef* exception)
395 CalendarEventPtr event = getPrivateObject(object);
396 CategoryListPtr categories = event->getCategories();
398 return JSCategoryArray::createArray(context, categories);
403 LogWarning("trying to get incorrect value");
405 return JSValueMakeUndefined(context);
408 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
410 JSStringRef propertyName,
412 JSValueRef* exception)
417 CalendarEventPtr event = getPrivateObject(object);
418 CalendarConverterFactory::ConverterType converter =
419 CalendarConverterFactory::getConverter(context);
420 event->setCategories(converter->toCategories(value));
425 LogWarning("trying to set incorrect value");
427 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
431 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
433 JSStringRef propertyName,
434 JSValueRef* exception)
439 CalendarConverterFactory::ConverterType converter =
440 CalendarConverterFactory::getConverter(context);
441 CalendarEventPtr event = getPrivateObject(object);
442 std::string status = converter->toTizenValue(event->getStatus());
443 return converter->toJSValueRef(status);
447 LogWarning("trying to get incorrect value");
449 return JSValueMakeUndefined(context);
452 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
454 JSStringRef propertyName,
456 JSValueRef* exception)
459 CalendarEventPtr event(NULL);
462 if (!JSValueIsNumber(context, value)) {
463 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
466 event = getPrivateObject(object);
467 CalendarConverterFactory::ConverterType converter =
468 CalendarConverterFactory::getConverter(context);
469 CalendarEvent::EventStatus status =
470 converter->toEventStatus(converter->toString(value));
471 event->setStatus(status);
474 Catch(ConversionException)
476 LogWarning("trying to set incorrect value");
477 event->setStatus(CalendarEvent::INVALID_STATUS);
480 Catch(InvalidArgumentException)
482 LogWarning("trying to set incorrect value");
483 event->setStatus(CalendarEvent::INVALID_STATUS);
488 LogWarning("trying to set incorrect value");
490 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
494 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
496 JSStringRef propertyName,
497 JSValueRef* exception)
502 CalendarConverterFactory::ConverterType converter =
503 CalendarConverterFactory::getConverter(context);
504 CalendarEventPtr event = getPrivateObject(object);
506 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
507 if (NULL == jsResult) {
508 ThrowMsg(NullPointerException, "Could not create js array object");
510 for( unsigned int i=0; i<event->getAlarmsTick().size(); i++) {
511 EventAlarmPtr alarm(new EventAlarm());
512 alarm->setMinutes( event->getAlarmsTick().at(i) ); // Default unit is minute.
514 std::vector<int> methodVector;
515 methodVector.push_back(event->getAlarmsType().at(i)); // Only one alarm type is saved.
516 alarm->setMethods(methodVector);
517 alarm->setTimeZone(event->getTimeZone());
519 if (!JSSetArrayElement(context, jsResult, i, JSEventAlarm::createJSObject(context, alarm))) {
520 ThrowMsg(UnknownException, "Could not insert value into js array");
527 LogWarning("trying to get incorrect value");
529 return JSValueMakeUndefined(context);
532 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
534 JSStringRef propertyName,
536 JSValueRef* exception)
539 CalendarEventPtr event(NULL);
542 event = getPrivateObject(object);
543 CalendarConverterFactory::ConverterType converter =
544 CalendarConverterFactory::getConverter(context);
546 EventAlarmListPtr alarms = converter->toVectorOfEventAlarms(value);
547 std::vector<CalendarEvent::EventAlarmType> alarmsType;
548 std::vector<long> alarmsTick;
549 // Set the multiple alarms.
550 for( unsigned int i=0; i<alarms->size(); i++) {
551 EventAlarmPtr theAlarm = alarms->at(i);
552 alarmsType.push_back(converter->toEventAlarmType(theAlarm->getMethods().at(0)));
553 if( 0 < theAlarm->getAbsoluteDate() ) {
554 alarmsTick.push_back(theAlarm->getAbsoluteDate()/60); //
556 alarmsTick.push_back(theAlarm->getMinutes() + theAlarm->getDays()*24*60);
559 event->setAlarmsType(alarmsType);
560 event->setAlarmsTick(alarmsTick);
563 Catch(ConversionException)
565 LogWarning("trying to set incorrect value");
568 Catch(InvalidArgumentException)
570 LogWarning("trying to set incorrect value");
575 LogError("Error during setting a value");
577 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
581 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
583 JSStringRef propertyName,
584 JSValueRef* exception)
589 Converter converter(context);
590 CalendarEventPtr event = getPrivateObject(object);
591 return converter.toJSValueRef(event->getOrganizer());
595 LogWarning("trying to get incorrect value");
597 return JSValueMakeUndefined(context);
600 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
602 JSStringRef propertyName,
604 JSValueRef* exception)
609 Converter converter(context);
610 CalendarEventPtr event = getPrivateObject(object);
611 std::string organizer = converter.toString(value);
612 event->setOrganizer(organizer);
617 LogWarning("trying to set incorrect value");
619 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
623 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
625 JSStringRef propertyName,
626 JSValueRef* exception)
631 CalendarConverterFactory::ConverterType converter =
632 CalendarConverterFactory::getConverter(context);
633 CalendarEventPtr event = getPrivateObject(object);
634 std::string visibility = converter->toTizenValue(event->getVisibility());
635 return converter->toJSValueRef(visibility);
639 LogWarning("trying to get incorrect value");
641 return JSValueMakeUndefined(context);
644 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
646 JSStringRef propertyName,
648 JSValueRef* exception)
651 CalendarEventPtr event(NULL);
654 if (!JSValueIsNumber(context, value)) {
655 Throw(InvalidArgumentException);
658 event = getPrivateObject(object);
659 CalendarConverterFactory::ConverterType converter =
660 CalendarConverterFactory::getConverter(context);
661 CalendarEvent::EventVisibility visibility =
662 converter->toEventVisibility(converter->toString(value));
663 event->setVisibility(visibility);
666 Catch(ConversionException)
668 LogWarning("trying to set incorrect value");
669 event->setVisibility(CalendarEvent::INVALID_VISIBILITY);
672 Catch(InvalidArgumentException)
674 LogWarning("trying to set incorrect value");
675 event->setVisibility(CalendarEvent::INVALID_VISIBILITY);
680 LogError("Error during setting a value");
682 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
686 JSValueRef JSCalendarItemProperties::getPropertyLatitude(JSContextRef context,
688 JSStringRef propertyName,
689 JSValueRef* exception)
694 Converter converter(context);
695 CalendarEventPtr event = getPrivateObject(object);
696 double latitude = event->getLatitude();
697 return converter.toJSValueRef(latitude);
701 LogWarning("trying to get incorrect value");
703 return JSValueMakeUndefined(context);
707 bool JSCalendarItemProperties::setPropertyLatitude(JSContextRef context,
709 JSStringRef propertyName,
711 JSValueRef* exception)
716 Converter converter(context);
717 CalendarEventPtr event = getPrivateObject(object);
718 double latitude = converter.toDouble(value);
719 event->setLatitude(latitude);
724 LogWarning("trying to set incorrect value");
726 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
730 JSValueRef JSCalendarItemProperties::getPropertyLongitude(JSContextRef context,
732 JSStringRef propertyName,
733 JSValueRef* exception)
738 Converter converter(context);
739 CalendarEventPtr event = getPrivateObject(object);
740 double longitude = event->getLongitude();
741 return converter.toJSValueRef(longitude);
745 LogWarning("trying to get incorrect value");
747 return JSValueMakeUndefined(context);
751 bool JSCalendarItemProperties::setPropertyLongitude(JSContextRef context,
753 JSStringRef propertyName,
755 JSValueRef* exception)
760 Converter converter(context);
761 CalendarEventPtr event = getPrivateObject(object);
762 double longitude = converter.toDouble(value);
763 event->setLongitude(longitude);
768 LogWarning("trying to set incorrect value");
770 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
775 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
777 JSStringRef propertyName,
778 JSValueRef* exception)
783 CalendarEventPtr event = getPrivateObject(object);
784 CalendarItemPropertiesPrivObject *priv =
785 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
787 // Use the global context saved in the event struct.
788 TimeUtilConverter converter(priv->getContext());
789 long length = event->getEndTime() - event->getStartTime(); // in seconds only
790 LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
791 JSValueRef temp = converter.makeMillisecondDurationObject( length*1000 );
793 LogDebug("temp : " << temp);
794 return converter.makeMillisecondDurationObject( length*1000 );
798 LogWarning("trying to get incorrect value");
800 return JSValueMakeUndefined(context);
803 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
805 JSStringRef propertyName,
807 JSValueRef* exception)
812 CalendarEventPtr event = getPrivateObject(object);
813 TimeUtilConverter converter(context);
814 long length = converter.getDurationLength(value, exception);
815 int unit = converter.getDurationUnit(value, exception);
817 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
820 if( SECONDS_UNIT==unit ) {
821 event->setEndTime(event->getStartTime() + length);
822 } else if ( MINUTES_UNIT==unit ) {
823 event->setEndTime(event->getStartTime() + length*60);
824 } else if ( HOURS_UNIT==unit ) {
825 event->setEndTime(event->getStartTime() + length*60*60);
826 } else if ( DAYS_UNIT==unit ) {
827 event->setEndTime(event->getStartTime() + length*24*60*60);
828 } else if ( MSECS_UNIT==unit ) {
829 event->setEndTime(event->getStartTime() + length/1000);
831 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
839 LogWarning("trying to set incorrect value");
841 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
845 JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
847 JSStringRef propertyName,
848 JSValueRef* exception)
853 CalendarConverterFactory::ConverterType converter =
854 CalendarConverterFactory::getConverter(context);
855 CalendarEventPtr event = getPrivateObject(object);
856 EventRecurrenceRulePtr rrule = event->getRecurrenceRule();
859 return JSRecurrenceRule::createJSRecurrenceRule(context, rrule);
864 LogWarning("trying to get incorrect value");
866 return JSValueMakeUndefined(context);
869 bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
871 JSStringRef propertyName,
873 JSValueRef* exception)
876 CalendarEventPtr event(NULL);
879 event = getPrivateObject(object);
880 CalendarConverterFactory::ConverterType converter =
881 CalendarConverterFactory::getConverter(context);
882 event->setRecurrenceRule(converter->toEventRecurrenceRule(value));
887 LogWarning("trying to set incorrect value");
890 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
894 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
896 JSStringRef propertyName,
897 JSValueRef* exception)
902 CalendarConverterFactory::ConverterType converter =
903 CalendarConverterFactory::getConverter(context);
904 CalendarEventPtr event = getPrivateObject(object);
905 return converter->toJSValueRef(event->getIsAllDay());
909 LogWarning("trying to get incorrect value");
911 return JSValueMakeUndefined(context);
914 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
916 JSStringRef propertyName,
918 JSValueRef* exception)
922 CalendarEventPtr event = getPrivateObject(object);
923 Converter converter(context);
924 event->setIsAllDay(converter.toBool(value));
929 LogWarning("trying to get incorrect value");
934 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
936 JSStringRef propertyName,
937 JSValueRef* exception)
942 CalendarConverterFactory::ConverterType converter =
943 CalendarConverterFactory::getConverter(context);
944 CalendarEventPtr event = getPrivateObject(object);
945 std::string availability = converter->toTizenValue(event->getAvailability());
946 return converter->toJSValueRef(availability);
950 LogWarning("trying to get incorrect value");
952 return JSValueMakeUndefined(context);
955 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
957 JSStringRef propertyName,
959 JSValueRef* exception)
962 CalendarEventPtr event(NULL);
965 if (!JSValueIsNumber(context, value)) {
966 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
969 event = getPrivateObject(object);
970 CalendarConverterFactory::ConverterType converter =
971 CalendarConverterFactory::getConverter(context);
972 CalendarEvent::EventAvailability availability =
973 converter->toEventAvailability(converter->toString(value));
974 event->setAvailability(availability);
977 Catch(ConversionException)
979 LogWarning("trying to set incorrect value");
980 event->setAvailability(CalendarEvent::INVALID_AVAILABILITY);
983 Catch(InvalidArgumentException)
985 LogWarning("trying to set incorrect value");
986 event->setAvailability(CalendarEvent::INVALID_AVAILABILITY);
991 LogError("Error during setting a value");
993 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
997 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
999 JSStringRef propertyName,
1000 JSValueRef* exception)
1002 LogDebug("entered");
1005 CalendarEventPtr event = getPrivateObject(object);
1006 EventAttendeeListPtr attendees = event->getAttendees();
1008 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
1009 if (NULL == jsResult) {
1010 ThrowMsg(NullPointerException, "Could not create js array object");
1012 for(unsigned int i=0; i<attendees->size(); i++) {
1013 if (!JSSetArrayElement(context, jsResult, i, JSAttendee::createJSAttendee(context, attendees->at(i)))) {
1014 ThrowMsg(UnknownException, "Could not insert value into js array");
1022 LogWarning("trying to get incorrect value");
1024 return JSValueMakeUndefined(context);
1027 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
1029 JSStringRef propertyName,
1031 JSValueRef* exception)
1033 LogDebug("entered");
1036 CalendarEventPtr event = getPrivateObject(object);
1037 CalendarConverterFactory::ConverterType converter =
1038 CalendarConverterFactory::getConverter(context);
1039 event->setAttendees(converter->toVectorOfAttendees(value));
1044 LogWarning("trying to set incorrect value");
1046 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1051 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1053 JSStringRef propertyName,
1054 JSValueRef* exception)
1056 LogDebug("entered");
1059 CalendarItemPropertiesPrivObject *privateObject =
1060 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1061 CalendarEventPtr task = privateObject->getObject();
1062 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1063 return JSValueMakeUndefined(context);
1067 Throw(NullPointerException);
1069 if (task->getEndTime() != 0) {
1070 // Use the global context saved in the event struct.
1071 return JSTZDate::createJSObject(privateObject->getContext(), task->getEndTime(), task->getTimeZone());
1073 return JSValueMakeUndefined(context);
1078 LogWarning("trying to get incorrect value");
1080 return JSValueMakeUndefined(context);
1083 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1085 JSStringRef propertyName,
1087 JSValueRef* exception)
1089 LogDebug("entered");
1090 CalendarEventPtr task = getPrivateObject(object);
1094 Throw(NullPointerException);
1097 TimeUtilConverter converter(context);
1098 std::time_t dueDate = converter.toTZDateTimeT(value);
1100 task->setEndTime(dueDate);
1102 if( task->getTimeZone().empty() ) {
1103 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1104 task->setTimeZone(timeZone);
1110 LogWarning("trying to set incorrect value");
1112 task->setEndTime(0);
1118 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1120 JSStringRef propertyName,
1121 JSValueRef* exception)
1123 LogDebug("entered");
1126 CalendarConverterFactory::ConverterType converter =
1127 CalendarConverterFactory::getConverter(context);
1128 CalendarEventPtr task = getPrivateObject(object);
1130 Throw(NullPointerException);
1132 if(CalendarEvent::LOW_PRIORITY <= task->getPriority() ||
1133 CalendarEvent::HIGH_PRIORITY >= task->getPriority()) {
1134 return JSValueMakeUndefined(context);
1137 std::string priority = converter->toTizenValue(task->getPriority());
1138 return converter->toJSValueRef(priority);
1142 LogWarning("trying to get incorrect value");
1144 return JSValueMakeUndefined(context);
1147 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1149 JSStringRef propertyName,
1151 JSValueRef* exception)
1153 LogDebug("entered");
1154 CalendarEventPtr task = getPrivateObject(object);
1157 CalendarConverterFactory::ConverterType converter =
1158 CalendarConverterFactory::getConverter(context);
1160 Throw(NullPointerException);
1162 CalendarEvent::TaskPriority priority =
1163 converter->toTaskPriority(converter->toString(value));
1164 task->setPriority(priority);
1169 LogWarning("trying to set incorrect value");
1171 task->setPriority(CalendarEvent::INVALID_PRIORITY);
1177 bool JSCalendarItemProperties::validate(JSContextRef ctx,
1178 const JSObjectRef object,
1179 JSValueRef* exception)
1181 LogDebug("entered");
1182 CalendarItemPropertiesPrivObject *priv =
1183 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1187 CalendarEventPtr event = priv->getObject();
1191 return event->validate();