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.
19 #include <dpl/log/log.h>
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 "API/TimeUtil/DurationProperties.h"
30 #include "JSCalendarItemProperties.h"
31 #include "CalendarConverter.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 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
49 kJSClassAttributeNone,
50 TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
59 NULL, //DeleteProperty,
60 NULL, //GetPropertyNames,
61 NULL, //CallAsFunction,
62 NULL, //CallAsConstructor,
67 JSStaticValue JSCalendarItemProperties::m_property[] = {
69 { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription,
70 setPropertyDescription, kJSPropertyAttributeNone },
71 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary,
72 setPropertySummary, kJSPropertyAttributeNone },
73 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime,
74 setPropertyStartTime, kJSPropertyAttributeNone },
75 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation,
76 setPropertyLocation, kJSPropertyAttributeNone },
77 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation,
78 setPropertyGeolocation, kJSPropertyAttributeNone },
79 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer,
80 setPropertyOrganizer, kJSPropertyAttributeNone },
81 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility,
82 setPropertyVisibility, kJSPropertyAttributeNone },
83 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus,
84 setPropertyStatus, kJSPropertyAttributeNone },
85 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms,
86 setPropertyAlarms, kJSPropertyAttributeNone },
87 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories,
88 setPropertyCategories, kJSPropertyAttributeNone },
89 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration,
90 setPropertyDuration, kJSPropertyAttributeNone },
91 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay,
92 setPropertyIsAllDay, kJSPropertyAttributeNone },
93 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees,
94 setPropertyAttendees, kJSPropertyAttributeNone },
95 { TIZEN_CALENDAR_EVENT_RECURRENCE_RULE, getPropertyRecurrenceRule,
96 setPropertyRecurrenceRule, kJSPropertyAttributeNone },
97 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability,
98 setPropertyAvailability, kJSPropertyAttributeNone },
99 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate,
100 setPropertyDueDate, kJSPropertyAttributeNone },
101 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate,
102 setPropertyCompletedDate, kJSPropertyAttributeNone },
103 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress,
104 setPropertyProgress, kJSPropertyAttributeNone },
105 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority,
106 setPropertyPriority, kJSPropertyAttributeNone },
107 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate,
108 setPropertyEndDate, kJSPropertyAttributeNone },
113 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
115 void JSCalendarItemProperties::initialize(JSContextRef context,
119 CalendarItemPropertiesPrivObject *priv =
120 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
122 CalendarEventPtr privateData(new CalendarEvent());
123 priv = new CalendarItemPropertiesPrivObject(context, privateData);
124 JSObjectSetPrivate(object, static_cast<void*>(priv));
125 LogDebug("New CalendarItemPropertiesPrivObject is created.");
127 LogDebug("CalendarItemPropertiesPrivObject already exists.");
131 void JSCalendarItemProperties::finalize(JSObjectRef object)
134 CalendarItemPropertiesPrivObject *priv =
135 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
139 const JSClassRef JSCalendarItemProperties::getClassRef()
142 m_jsClassRef = JSClassCreate(&m_classInfo);
147 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
152 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
155 CalendarItemPropertiesPrivObject *priv =
156 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
158 ThrowMsg(NullPointerException, "Private object is null");
160 CalendarEventPtr result = priv->getObject();
162 ThrowMsg(NullPointerException, "Private object is null");
167 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
169 const JSObjectRef object)
174 CalendarItemPropertiesPrivObject *priv =
175 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
177 priv = new CalendarItemPropertiesPrivObject(ctx, event);
178 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
184 LogError("Error during replacing event object");
188 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
190 JSStringRef propertyName,
191 JSValueRef* exception)
196 Converter converter(context);
197 CalendarEventPtr event = getPrivateObject(object);
198 return converter.toJSValueRef(event->getDescription());
202 LogWarning("trying to get incorrect value");
204 return JSValueMakeUndefined(context);
207 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
209 JSStringRef propertyName,
211 JSValueRef* exception)
216 if (!JSValueIsString(context, value)) {
217 Throw(InvalidArgumentException);
220 Converter converter(context);
221 CalendarEventPtr event = getPrivateObject(object);
222 std::string description = converter.toString(value);
223 event->setDescription(description);
228 LogWarning("trying to set incorrect value");
229 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
235 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
237 JSStringRef propertyName,
238 JSValueRef* exception)
243 Converter converter(context);
244 CalendarEventPtr event = getPrivateObject(object);
245 return converter.toJSValueRef(event->getSubject());
249 LogWarning("trying to get incorrect value");
251 return JSValueMakeUndefined(context);
254 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
256 JSStringRef propertyName,
258 JSValueRef* exception)
263 if (!JSValueIsString(context, value)) {
264 Throw(InvalidArgumentException);
267 Converter converter(context);
268 CalendarEventPtr event = getPrivateObject(object);
269 std::string subject = converter.toString(value);
270 event->setSubject(subject);
275 LogWarning("trying to set incorrect value");
276 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
282 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
284 JSStringRef propertyName,
285 JSValueRef* exception)
290 CalendarItemPropertiesPrivObject *privateObject =
291 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
292 TimeUtilConverter timeConverter(privateObject->getContext());
293 CalendarEventPtr event = privateObject->getObject();
295 LogInfo("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
296 return timeConverter.FromUTCTimeTToTZDate(event->getStartTime(), event->getTimeZone());
300 LogWarning("trying to get incorrect value");
302 return JSValueMakeUndefined(context);
305 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
307 JSStringRef propertyName,
309 JSValueRef* exception)
314 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
315 Throw(InvalidArgumentException);
318 CalendarEventPtr event = getPrivateObject(object);
319 TimeUtilConverter converter(context);
320 std::time_t duration = event->getEndTime() - event->getStartTime();
325 std::time_t startTime = converter.toTZDateTimeT(value);
326 event->setStartTime(startTime);
327 event->setEndTime(startTime + duration);
329 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
330 event->setTimeZone(timeZone);
335 LogWarning("trying to set incorrect value");
336 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
342 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
344 JSStringRef propertyName,
345 JSValueRef* exception)
350 Converter converter(context);
351 CalendarEventPtr event = getPrivateObject(object);
352 return converter.toJSValueRef(event->getLocation());
356 LogWarning("trying to get incorrect value");
358 return JSValueMakeUndefined(context);
361 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
363 JSStringRef propertyName,
365 JSValueRef* exception)
370 if (!JSValueIsString(context, value)) {
371 Throw(InvalidArgumentException);
374 Converter converter(context);
375 CalendarEventPtr event = getPrivateObject(object);
376 std::string location = converter.toString(value);
377 event->setLocation(location);
382 LogWarning("trying to set incorrect value");
383 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
389 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
391 JSStringRef propertyName,
392 JSValueRef* exception)
397 Converter converter(context);
398 CalendarEventPtr event = getPrivateObject(object);
399 CategoryListPtr categories = event->getCategories();
401 return converter.toJSValueRef(*categories);
406 LogWarning("trying to get incorrect value");
408 return JSValueMakeUndefined(context);
411 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
413 JSStringRef propertyName,
415 JSValueRef* exception)
420 CalendarEventPtr event = getPrivateObject(object);
421 CalendarConverterFactory::ConverterType converter =
422 CalendarConverterFactory::getConverter(context);
423 event->setCategories(converter->toCategories(value));
428 LogWarning("trying to set incorrect value");
429 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
435 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
437 JSStringRef propertyName,
438 JSValueRef* exception)
443 CalendarConverterFactory::ConverterType converter =
444 CalendarConverterFactory::getConverter(context);
445 CalendarEventPtr event = getPrivateObject(object);
446 std::string status = converter->toTizenValue(event->getStatus());
447 return converter->toJSValueRef(status);
451 LogWarning("trying to get incorrect value");
453 return JSValueMakeUndefined(context);
456 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
458 JSStringRef propertyName,
460 JSValueRef* exception)
463 CalendarEventPtr event(NULL);
466 if (!JSValueIsString(context, value)) {
467 Throw(InvalidArgumentException);
470 event = getPrivateObject(object);
471 CalendarConverterFactory::ConverterType converter =
472 CalendarConverterFactory::getConverter(context);
473 CalendarEvent::EventStatus status =
474 converter->toEventStatus(converter->toString(value));
475 event->setStatus(status);
480 LogWarning("trying to set incorrect value");
481 event->setStatus(CalendarEvent::INVALID_STATUS);
482 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
488 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
490 JSStringRef propertyName,
491 JSValueRef* exception)
496 CalendarConverterFactory::ConverterType converter =
497 CalendarConverterFactory::getConverter(context);
498 CalendarEventPtr event = getPrivateObject(object);
500 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
501 if (NULL == jsResult) {
502 ThrowMsg(NullPointerException, "Could not create js array object");
504 for( unsigned int i=0; i<event->getAlarmsTick().size(); i++) {
505 EventAlarmPtr alarm(new EventAlarm());
506 TizenApis::Api::TimeUtil::DurationProperties duration;
507 duration.unit = TizenApis::Api::TimeUtil::MINUTES_UNIT;
508 duration.length = event->getAlarmsTick().at(i);
509 alarm->setDuration(duration); // Default unit is minute.
510 std::vector<CalendarEvent::EventAlarmType> methodVector;
511 methodVector.push_back(event->getAlarmsType().at(i)); // Only one alarm type is saved.
512 alarm->setMethods(methodVector);
513 alarm->setTimeZone(event->getTimeZone());
515 if (!JSSetArrayElement(context, jsResult, i, JSEventAlarm::createJSObject(context, alarm))) {
516 ThrowMsg(UnknownException, "Could not insert value into js array");
523 LogWarning("trying to get incorrect value");
525 return JSValueMakeUndefined(context);
528 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
530 JSStringRef propertyName,
532 JSValueRef* exception)
535 CalendarEventPtr event(NULL);
538 event = getPrivateObject(object);
539 CalendarConverterFactory::ConverterType converter =
540 CalendarConverterFactory::getConverter(context);
542 EventAlarmListPtr alarms = converter->toVectorOfEventAlarms(value);
543 std::vector<CalendarEvent::EventAlarmType> alarmsType;
544 std::vector<long> alarmsTick;
545 // Set the multiple alarms.
546 for( unsigned int i=0; i<alarms->size(); i++) {
547 EventAlarmPtr theAlarm = alarms->at(i);
548 alarmsType.push_back(theAlarm->getMethods().at(0));
549 if( 0 < theAlarm->getAbsoluteDate() ) {
550 alarmsTick.push_back(theAlarm->getAbsoluteDate()/60);
553 long length = theAlarm->getDuration().length;
554 switch(theAlarm->getDuration().unit) {
555 case TizenApis::Api::TimeUtil::MSECS_UNIT:
556 tick = length/(1000*60);
558 case TizenApis::Api::TimeUtil::SECONDS_UNIT:
561 case TizenApis::Api::TimeUtil::MINUTES_UNIT:
564 case TizenApis::Api::TimeUtil::HOURS_UNIT:
567 case TizenApis::Api::TimeUtil::DAYS_UNIT:
571 ThrowMsg(ConversionException, "Wrong alarm unit type.");
574 alarmsTick.push_back(tick);
577 event->setAlarmsType(alarmsType);
578 event->setAlarmsTick(alarmsTick);
583 LogWarning("trying to set incorrect value");
584 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
590 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
592 JSStringRef propertyName,
593 JSValueRef* exception)
598 Converter converter(context);
599 CalendarEventPtr event = getPrivateObject(object);
600 return converter.toJSValueRef(event->getOrganizer());
604 LogWarning("trying to get incorrect value");
606 return JSValueMakeUndefined(context);
609 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
611 JSStringRef propertyName,
613 JSValueRef* exception)
618 if (!JSValueIsString(context, value)) {
619 Throw(InvalidArgumentException);
622 Converter converter(context);
623 CalendarEventPtr event = getPrivateObject(object);
624 std::string organizer = converter.toString(value);
625 event->setOrganizer(organizer);
630 LogWarning("trying to set incorrect value");
631 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
637 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
639 JSStringRef propertyName,
640 JSValueRef* exception)
645 CalendarConverterFactory::ConverterType converter =
646 CalendarConverterFactory::getConverter(context);
647 CalendarEventPtr event = getPrivateObject(object);
648 std::string visibility = converter->toTizenValue(event->getVisibility());
649 return converter->toJSValueRef(visibility);
653 LogWarning("trying to get incorrect value");
655 return JSValueMakeUndefined(context);
658 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
660 JSStringRef propertyName,
662 JSValueRef* exception)
665 CalendarEventPtr event(NULL);
668 if (!JSValueIsString(context, value)) {
669 Throw(InvalidArgumentException);
672 event = getPrivateObject(object);
673 CalendarConverterFactory::ConverterType converter =
674 CalendarConverterFactory::getConverter(context);
675 CalendarEvent::EventVisibility visibility =
676 converter->toEventVisibility(converter->toString(value));
677 event->setVisibility(visibility);
682 LogError("Error during setting a value");
683 event->setVisibility(CalendarEvent::INVALID_VISIBILITY);
684 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
690 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
692 JSStringRef propertyName,
693 JSValueRef* exception)
698 CalendarConverter converter(context);
699 CalendarEventPtr event = getPrivateObject(object);
700 CalendarItemGeoPtr geoInfo = event->getGeolocation();
702 return converter.toJSValueRef(geoInfo);
706 LogWarning("trying to get incorrect value");
709 return JSValueMakeUndefined(context);
712 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
714 JSStringRef propertyName,
716 JSValueRef* exception)
719 CalendarEventPtr event(NULL);
722 event = getPrivateObject(object);
723 CalendarConverter converter(context);
724 event->setGeolocation(converter.toGeolocation(value));
729 LogWarning("trying to set incorrect value");
730 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
736 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
738 JSStringRef propertyName,
739 JSValueRef* exception)
744 CalendarEventPtr event = getPrivateObject(object);
745 CalendarItemPropertiesPrivObject *priv =
746 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
748 // Use the global context saved in the event struct.
749 TimeUtilConverter converter(priv->getContext());
750 long length = event->getEndTime() - event->getStartTime(); // in seconds only
751 LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
752 return converter.makeMillisecondDurationObject( length*1000 );
756 LogWarning("trying to get incorrect value");
758 return JSValueMakeUndefined(context);
761 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
763 JSStringRef propertyName,
765 JSValueRef* exception)
770 CalendarEventPtr event = getPrivateObject(object);
771 TimeUtilConverter converter(context);
772 long length = converter.getDurationLength(value);
773 int unit = converter.getDurationUnit(value);
775 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
778 if( SECONDS_UNIT==unit ) {
779 event->setEndTime(event->getStartTime() + length);
780 } else if ( MINUTES_UNIT==unit ) {
781 event->setEndTime(event->getStartTime() + length*60);
782 } else if ( HOURS_UNIT==unit ) {
783 event->setEndTime(event->getStartTime() + length*60*60);
784 } else if ( DAYS_UNIT==unit ) {
785 event->setEndTime(event->getStartTime() + length*24*60*60);
786 } else if ( MSECS_UNIT==unit ) {
787 event->setEndTime(event->getStartTime() + length/1000);
789 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
797 LogWarning("trying to set incorrect value");
798 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
804 JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
806 JSStringRef propertyName,
807 JSValueRef* exception)
812 CalendarConverterFactory::ConverterType converter =
813 CalendarConverterFactory::getConverter(context);
814 CalendarEventPtr event = getPrivateObject(object);
815 EventRecurrenceRulePtr rrule = event->getRecurrenceRule();
818 return JSRecurrenceRule::createJSRecurrenceRule(context, rrule);
823 LogWarning("trying to get incorrect value");
825 return JSValueMakeUndefined(context);
828 bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
830 JSStringRef propertyName,
832 JSValueRef* exception)
835 CalendarEventPtr event(NULL);
838 event = getPrivateObject(object);
839 CalendarConverterFactory::ConverterType converter =
840 CalendarConverterFactory::getConverter(context);
841 event->setRecurrenceRule(converter->toEventRecurrenceRule(value));
846 LogWarning("trying to set incorrect value");
847 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
853 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
855 JSStringRef propertyName,
856 JSValueRef* exception)
861 CalendarConverterFactory::ConverterType converter =
862 CalendarConverterFactory::getConverter(context);
863 CalendarEventPtr event = getPrivateObject(object);
864 return converter->toJSValueRef(event->getIsAllDay());
868 LogWarning("trying to get incorrect value");
870 return JSValueMakeUndefined(context);
873 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
875 JSStringRef propertyName,
877 JSValueRef* exception)
881 if (!JSValueIsBoolean(context, value)) {
882 Throw(InvalidArgumentException);
885 CalendarEventPtr event = getPrivateObject(object);
886 Converter converter(context);
887 event->setIsAllDay(converter.toBool(value));
892 LogWarning("trying to get incorrect value");
893 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
899 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
901 JSStringRef propertyName,
902 JSValueRef* exception)
907 CalendarConverterFactory::ConverterType converter =
908 CalendarConverterFactory::getConverter(context);
909 CalendarEventPtr event = getPrivateObject(object);
910 std::string availability = converter->toTizenValue(event->getAvailability());
911 return converter->toJSValueRef(availability);
915 LogWarning("trying to get incorrect value");
917 return JSValueMakeUndefined(context);
920 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
922 JSStringRef propertyName,
924 JSValueRef* exception)
927 CalendarEventPtr event(NULL);
930 if (!JSValueIsString(context, value)) {
931 Throw(InvalidArgumentException);
934 event = getPrivateObject(object);
935 CalendarConverterFactory::ConverterType converter =
936 CalendarConverterFactory::getConverter(context);
937 CalendarEvent::EventAvailability availability =
938 converter->toEventAvailability(converter->toString(value));
939 event->setAvailability(availability);
944 LogError("Error during setting a value");
945 event->setAvailability(CalendarEvent::INVALID_AVAILABILITY);
946 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
952 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
954 JSStringRef propertyName,
955 JSValueRef* exception)
960 CalendarEventPtr event = getPrivateObject(object);
961 EventAttendeeListPtr attendees = event->getAttendees();
963 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
964 if (NULL == jsResult) {
965 ThrowMsg(NullPointerException, "Could not create js array object");
967 for(unsigned int i=0; i<attendees->size(); i++) {
968 if (!JSSetArrayElement(context, jsResult, i, JSAttendee::createJSAttendee(context, attendees->at(i)))) {
969 ThrowMsg(UnknownException, "Could not insert value into js array");
977 LogWarning("trying to get incorrect value");
979 return JSValueMakeUndefined(context);
982 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
984 JSStringRef propertyName,
986 JSValueRef* exception)
991 CalendarEventPtr event = getPrivateObject(object);
992 CalendarConverterFactory::ConverterType converter =
993 CalendarConverterFactory::getConverter(context);
994 event->setAttendees(converter->toVectorOfAttendees(value));
999 LogWarning("trying to set incorrect attendee value");
1000 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1006 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1008 JSStringRef propertyName,
1009 JSValueRef* exception)
1011 LogDebug("entered");
1014 CalendarItemPropertiesPrivObject *privateObject =
1015 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1016 CalendarEventPtr task = privateObject->getObject();
1017 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1018 return JSValueMakeUndefined(context);
1021 Throw(NullPointerException);
1023 if (task->getEndTime() != 0) {
1024 // Use the global context saved in the event struct.
1025 return JSTZDate::createJSObject(privateObject->getContext(), task->getEndTime(), task->getTimeZone());
1027 return JSValueMakeUndefined(context);
1032 LogWarning("trying to get incorrect value");
1034 return JSValueMakeUndefined(context);
1037 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1039 JSStringRef propertyName,
1041 JSValueRef* exception)
1043 LogDebug("entered");
1046 CalendarEventPtr task = getPrivateObject(object);
1048 Throw(NullPointerException);
1050 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1051 Throw(InvalidArgumentException);
1053 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1054 Throw(InvalidArgumentException);
1057 TimeUtilConverter converter(context);
1058 std::time_t dueDate = converter.toTZDateTimeT(value);
1060 task->setEndTime(dueDate);
1062 if( task->getTimeZone().empty() ) {
1063 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1064 task->setTimeZone(timeZone);
1070 LogWarning("trying to set incorrect value");
1071 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1077 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1079 JSStringRef propertyName,
1080 JSValueRef* exception)
1082 LogDebug("entered");
1085 CalendarItemPropertiesPrivObject *privateObject =
1086 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1087 CalendarEventPtr task = privateObject->getObject();
1088 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1089 return JSValueMakeUndefined(context);
1092 Throw(NullPointerException);
1094 if (task->getEndTime() != 0) {
1095 // Use the global context saved in the event struct.
1096 return JSTZDate::createJSObject(privateObject->getContext(), task->getEndTime(), task->getTimeZone());
1098 return JSValueMakeUndefined(context);
1103 LogWarning("trying to get incorrect value");
1105 return JSValueMakeUndefined(context);
1108 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1110 JSStringRef propertyName,
1112 JSValueRef* exception)
1114 LogDebug("entered");
1117 CalendarEventPtr task = getPrivateObject(object);
1119 Throw(NullPointerException);
1121 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1122 Throw(InvalidArgumentException);
1124 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1125 Throw(InvalidArgumentException);
1128 TimeUtilConverter converter(context);
1129 std::time_t completedDate = converter.toTZDateTimeT(value);
1131 task->setEndTime(completedDate);
1133 if( task->getTimeZone().empty() ) {
1134 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1135 task->setTimeZone(timeZone);
1141 LogWarning("trying to set incorrect value");
1142 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1148 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1150 JSStringRef propertyName,
1151 JSValueRef* exception)
1153 LogDebug("entered");
1156 CalendarEventPtr task = getPrivateObject(object);
1157 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1158 return JSValueMakeUndefined(context);
1161 Converter converter(context);
1162 return converter.toJSValueRef(task->getProgress());
1166 LogWarning("trying to get incorrect value");
1168 return JSValueMakeUndefined(context);
1171 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1173 JSStringRef propertyName,
1175 JSValueRef* exception)
1177 LogDebug("entered");
1180 if (!JSValueIsNumber(context, value)) {
1181 Throw(InvalidArgumentException);
1184 CalendarEventPtr task = getPrivateObject(object);
1185 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1186 return JSValueMakeUndefined(context);
1189 Converter converter(context);
1190 int progress = converter.toInt(value);
1191 task->setProgress(progress);
1196 LogWarning("trying to set incorrect value");
1197 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1203 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1205 JSStringRef propertyName,
1206 JSValueRef* exception)
1208 LogDebug("entered");
1211 CalendarConverterFactory::ConverterType converter =
1212 CalendarConverterFactory::getConverter(context);
1213 CalendarEventPtr item = getPrivateObject(object);
1215 Throw(NullPointerException);
1217 if(CalendarEvent::LOW_PRIORITY <= item->getPriority() ||
1218 CalendarEvent::HIGH_PRIORITY >= item->getPriority()) {
1219 return JSValueMakeUndefined(context);
1222 std::string priority = converter->toTizenValue(item->getPriority());
1223 return converter->toJSValueRef(priority);
1227 LogWarning("trying to get incorrect value");
1229 return JSValueMakeUndefined(context);
1232 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1234 JSStringRef propertyName,
1236 JSValueRef* exception)
1238 LogDebug("entered");
1239 CalendarEventPtr item = getPrivateObject(object);
1243 if (!JSValueIsString(context, value)) {
1244 Throw(InvalidArgumentException);
1247 CalendarConverterFactory::ConverterType converter =
1248 CalendarConverterFactory::getConverter(context);
1249 CalendarEvent::TaskPriority priority =
1250 converter->toTaskPriority(converter->toString(value));
1251 item->setPriority(priority);
1256 LogWarning("trying to set incorrect value");
1258 item->setPriority(CalendarEvent::INVALID_PRIORITY);
1260 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1266 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1268 JSStringRef propertyName,
1269 JSValueRef* exception)
1271 LogDebug("entered");
1274 CalendarItemPropertiesPrivObject *privateObject =
1275 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1276 CalendarEventPtr event = privateObject->getObject();
1277 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1278 return JSValueMakeUndefined(context);
1281 Throw(NullPointerException);
1283 if (event->getEndTime() != 0) {
1284 // Use the global context saved in the event struct.
1285 return JSTZDate::createJSObject(privateObject->getContext(), event->getEndTime(), event->getTimeZone());
1287 return JSValueMakeUndefined(context);
1292 LogWarning("trying to get incorrect value");
1294 return JSValueMakeUndefined(context);
1297 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1299 JSStringRef propertyName,
1301 JSValueRef* exception)
1303 LogDebug("entered");
1306 CalendarEventPtr event = getPrivateObject(object);
1308 Throw(NullPointerException);
1310 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1311 Throw(InvalidArgumentException);
1313 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1314 Throw(InvalidArgumentException);
1317 TimeUtilConverter converter(context);
1318 std::time_t endDate = converter.toTZDateTimeT(value);
1320 event->setEndTime(endDate);
1322 if( event->getTimeZone().empty() ) {
1323 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1324 event->setTimeZone(timeZone);
1330 LogWarning("trying to set incorrect value");
1331 TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
1337 bool JSCalendarItemProperties::validate(JSContextRef ctx,
1338 const JSObjectRef object,
1339 JSValueRef* exception)
1341 LogDebug("entered");
1342 CalendarItemPropertiesPrivObject *priv =
1343 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1347 CalendarEventPtr event = priv->getObject();
1351 return event->validate();