2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #include <CommonsJavaScript/PrivateObject.h>
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/JSUtils.h>
22 #include <JSWebAPIErrorFactory.h>
23 #include <SecurityExceptions.h>
24 #include <TimeUtilConverter.h>
25 #include <JSTimeDuration.h>
27 #include <JSSimpleCoordinates.h>
28 #include "EventAlarm.h"
30 #include "ICalendar.h"
31 #include "CalendarFactory.h"
32 #include <DurationProperties.h>
33 #include "JSCalendarItemProperties.h"
34 #include "CalendarConverter.h"
35 #include "JSCalendarEventId.h"
36 #include "JSCalendarAlarm.h"
37 #include "JSCalendarAttendee.h"
38 #include "JSCalendarEvent.h"
39 #include "JSCalendarTask.h"
40 #include "plugin_config.h"
41 #include <GlobalContextManager.h>
42 #include <TimeTracer.h>
45 using namespace WrtDeviceApis::Commons;
46 using namespace WrtDeviceApis::CommonsJavaScript;
47 using namespace DeviceAPI::Common;
48 using namespace DeviceAPI::Time;
53 using WrtDeviceApis::Commons::UnknownException;
54 using WrtDeviceApis::Commons::NotFoundException;
56 #define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
58 JSClassDefinition JSCalendarItemProperties::m_classInfo = {
60 kJSClassAttributeNone,
61 TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
70 NULL, //DeleteProperty,
71 NULL, //GetPropertyNames,
72 NULL, //CallAsFunction,
73 NULL, //CallAsConstructor,
78 JSStaticValue JSCalendarItemProperties::m_property[] = {
80 { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone },
81 { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary, setPropertySummary, kJSPropertyAttributeNone },
82 { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime, setPropertyStartTime, kJSPropertyAttributeNone },
83 { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation, setPropertyLocation, kJSPropertyAttributeNone },
84 { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation, setPropertyGeolocation, kJSPropertyAttributeNone },
85 { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer, setPropertyOrganizer, kJSPropertyAttributeNone },
86 { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility, setPropertyVisibility, kJSPropertyAttributeNone },
87 { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus, setPropertyStatus, kJSPropertyAttributeNone },
88 { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms, setPropertyAlarms, kJSPropertyAttributeNone },
89 { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories, setPropertyCategories, kJSPropertyAttributeNone },
90 { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration, setPropertyDuration, kJSPropertyAttributeNone },
91 { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay, setPropertyIsAllDay, kJSPropertyAttributeNone },
92 { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees, setPropertyAttendees, kJSPropertyAttributeNone },
93 { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability, setPropertyAvailability, kJSPropertyAttributeNone },
94 { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate, setPropertyDueDate, kJSPropertyAttributeNone },
95 { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate, setPropertyCompletedDate, kJSPropertyAttributeNone },
96 { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress, setPropertyProgress, kJSPropertyAttributeNone },
97 { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority, setPropertyPriority, kJSPropertyAttributeNone },
98 { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate, setPropertyEndDate, kJSPropertyAttributeNone },
99 { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
100 { TIZEN_CALENDAR_ITEM_CALENDAR_ID, getPropertyCalendarId, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
105 JSStaticFunction JSCalendarItemProperties::m_function[] = {
106 { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
107 { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
112 JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
114 void JSCalendarItemProperties::initialize(JSContextRef context,
117 if (!JSObjectGetPrivate(object)) {
118 LoggerD("Create calendar item private object.");
119 CalendarEventPtr item( new CalendarEvent() );
120 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
121 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
125 LoggerD("Private object already set.");
129 void JSCalendarItemProperties::finalize(JSObjectRef object)
131 CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
134 JSObjectSetPrivate(object, NULL);
138 const JSClassRef JSCalendarItemProperties::getClassRef()
141 m_jsClassRef = JSClassCreate(&m_classInfo);
146 const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
151 CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
153 CalendarItemPropertiesPrivObject *priv =
154 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
156 ThrowMsg(NullPointerException, "Private object is null");
158 CalendarEventPtr result = priv->getObject();
160 ThrowMsg(NullPointerException, "Private object is null");
165 void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
167 const JSObjectRef object)
171 CalendarItemPropertiesPrivObject *priv =
172 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
174 priv = new CalendarItemPropertiesPrivObject(ctx, event);
175 if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
181 LoggerE("Error during replacing event object");
185 JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
187 CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
188 return JSObjectMake(context, getClassRef(), priv);
191 JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
193 JSObjectRef thisObject,
194 size_t argumentCount,
195 const JSValueRef arguments[],
196 JSValueRef* exception)
198 TIME_TRACER_ITEM_BEGIN(__FUNCTION__, 0);
199 CalendarItemPropertiesPrivObject *privateObject =
200 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
202 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
204 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
208 if (!privateObject) {
209 ThrowMsg(ConversionException, "Object is null.");
212 CalendarEventPtr item = privateObject->getObject();
214 ThrowMsg(ConversionException, "Parameter conversion failed.");
217 CalendarConverter converter(context);
219 CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
220 if (argumentCount>=1) {
221 format = converter.toVObjectFormat(converter.toString(arguments[0]));
223 ThrowMsg(ConversionException, "Wrong parameter type.");
226 ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
227 calendar->setType(item->getCalendarType());
229 IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
230 dplEvent->setEvent(item);
231 dplEvent->setFormat(format);
232 dplEvent->setForSynchronousCall();
233 calendar->exportEventToString(dplEvent);
235 if (dplEvent->getResult()) {
236 TIME_TRACER_ITEM_END(__FUNCTION__, 0);
237 return converter.toJSValueRef(dplEvent->getEventString());
239 ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
242 Catch(UnsupportedException)
244 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
245 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
247 Catch(InvalidArgumentException)
249 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
250 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
252 Catch(ConversionException)
254 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
255 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
257 Catch (NotFoundException)
259 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
260 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
264 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
265 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
269 JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
271 JSObjectRef thisObject,
272 size_t argumentCount,
273 const JSValueRef arguments[],
274 JSValueRef* exception)
276 TIME_TRACER_ITEM_BEGIN("clone(TASK)", 0);
277 TIME_TRACER_ITEM_BEGIN("clone(EVENT)", 0);
278 CalendarItemPropertiesPrivObject *privateObject =
279 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
281 AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
283 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
287 if (!privateObject) {
288 ThrowMsg(ConversionException, "Object is null.");
291 CalendarEventPtr item = privateObject->getObject(); // item to copy
293 ThrowMsg(ConversionException, "Parameter conversion failed.");
295 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
297 // Call the copy constructor.
298 CalendarEventPtr clonedItem( new CalendarEvent(*item));
301 clonedItem->resetId();
302 clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
304 if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
305 TIME_TRACER_ITEM_END("clone(TASK)", 0);
306 return JSCalendarTask::createJSCalendarTask(context, clonedItem);
307 } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
308 TIME_TRACER_ITEM_END("clone(EVENT)", 0);
309 // Use global context for potential async api invocation.
310 return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
312 ThrowMsg(ConversionException, "Wrong object type.");
315 Catch(UnsupportedException)
317 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
318 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
320 Catch(InvalidArgumentException)
322 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
323 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
325 Catch(ConversionException)
327 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
328 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
330 Catch (NotFoundException)
332 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
333 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
337 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
338 return JSWebAPIErrorFactory::postException(context, exception, JSWebAPIErrorFactory::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
342 JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
344 JSStringRef propertyName,
345 JSValueRef* exception)
349 Converter converter(context);
350 CalendarEventPtr event = getPrivateObject(object);
351 return converter.toJSValueRef(event->getDescription());
355 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
357 return JSValueMakeUndefined(context);
360 bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
362 JSStringRef propertyName,
364 JSValueRef* exception)
368 Converter converter(context);
369 CalendarEventPtr event = getPrivateObject(object);
370 std::string description = converter.toString(value);
371 event->setDescription(description);
376 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
382 JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
384 JSStringRef propertyName,
385 JSValueRef* exception)
389 Converter converter(context);
390 CalendarEventPtr event = getPrivateObject(object);
391 return converter.toJSValueRef(event->getSubject());
395 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
397 return JSValueMakeUndefined(context);
400 bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
402 JSStringRef propertyName,
404 JSValueRef* exception)
408 Converter converter(context);
409 CalendarEventPtr event = getPrivateObject(object);
410 std::string subject = converter.toString(value);
411 event->setSubject(subject);
416 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
422 JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
424 JSStringRef propertyName,
425 JSValueRef* exception)
429 CalendarItemPropertiesPrivObject *privateObject =
430 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
431 TimeUtilConverter timeConverter(context);
432 CalendarEventPtr event = privateObject->getObject();
434 LoggerI("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
435 if (UNDEFINED_TIME==event->getStartTime()) {
436 return JSValueMakeUndefined(context);
438 return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
443 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
445 return JSValueMakeUndefined(context);
448 bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
450 JSStringRef propertyName,
452 JSValueRef* exception)
456 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
457 ThrowMsg(ConversionException, "Wrong parameter type.");
460 CalendarEventPtr event = getPrivateObject(object);
461 TimeUtilConverter converter(context);
462 std::time_t duration = event->getEndTime() - event->getStartTime();
467 long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
468 event->setStartTime(startTime);
469 event->setEndTime(startTime + duration);
471 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
472 event->setTimeZone(timeZone);
477 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
483 JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
485 JSStringRef propertyName,
486 JSValueRef* exception)
490 Converter converter(context);
491 CalendarEventPtr event = getPrivateObject(object);
492 return converter.toJSValueRef(event->getLocation());
496 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
498 return JSValueMakeUndefined(context);
501 bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
503 JSStringRef propertyName,
505 JSValueRef* exception)
509 Converter converter(context);
510 CalendarEventPtr event = getPrivateObject(object);
511 std::string location = converter.toString(value);
512 event->setLocation(location);
517 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
523 JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
525 JSStringRef propertyName,
526 JSValueRef* exception)
530 CalendarEventPtr item = getPrivateObject(object);
531 JSContextRef globalContext = GlobalContextManager::getInstance()->getGlobalContext(context);
533 CalendarConverter converter(globalContext);
535 if(item->getCategoriesJSRef()) {
536 return item->getCategoriesJSRef();
538 LoggerD("Create a JS object for categories.");
539 StringArrayPtr categories = item->getCategories();
540 JSValueRef jsCategories = converter.toJSValueRefStringArray(categories);
541 item->setCategoriesJSRef(converter.toJSObjectRef(jsCategories));
543 JSValueProtect(globalContext, jsCategories);
544 item->setContext(globalContext);
550 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
552 return JSValueMakeUndefined(context);
555 bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
557 JSStringRef propertyName,
559 JSValueRef* exception)
563 CalendarEventPtr event = getPrivateObject(object);
564 CalendarConverter converter(context);
565 event->setCategories(converter.toStringArray(value));
570 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
576 JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
578 JSStringRef propertyName,
579 JSValueRef* exception)
583 CalendarConverter converter(context);
584 CalendarEventPtr event = getPrivateObject(object);
585 std::string status = converter.toTizenValue(event->getStatus());
586 return converter.toJSValueRef(status);
590 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
592 return JSValueMakeUndefined(context);
595 bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
597 JSStringRef propertyName,
599 JSValueRef* exception)
601 CalendarEventPtr event(NULL);
604 event = getPrivateObject(object);
605 CalendarConverter converter(context);
606 CalendarEvent::EventStatus status =
607 converter.toEventStatus(converter.toString(value));
608 event->setStatus(status);
613 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
619 JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
621 JSStringRef propertyName,
622 JSValueRef* exception)
626 CalendarEventPtr event = getPrivateObject(object);
628 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
629 if (NULL == jsResult) {
630 ThrowMsg(NullPointerException, "Can not create array object.");
632 for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
633 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
634 ThrowMsg(UnknownException, "Can not insert value into array.");
641 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
643 return JSValueMakeUndefined(context);
646 bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
648 JSStringRef propertyName,
650 JSValueRef* exception)
652 CalendarEventPtr event(NULL);
655 event = getPrivateObject(object);
656 CalendarConverter converter(context);
658 EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
660 event->setAlarms(alarms);
665 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
671 JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
673 JSStringRef propertyName,
674 JSValueRef* exception)
678 Converter converter(context);
679 CalendarEventPtr event = getPrivateObject(object);
680 return converter.toJSValueRef(event->getOrganizer());
684 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
686 return JSValueMakeUndefined(context);
689 bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
691 JSStringRef propertyName,
693 JSValueRef* exception)
697 Converter converter(context);
698 CalendarEventPtr event = getPrivateObject(object);
699 std::string organizer = converter.toString(value);
700 event->setOrganizer(organizer);
705 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
711 JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
713 JSStringRef propertyName,
714 JSValueRef* exception)
718 CalendarConverter converter(context);
719 CalendarEventPtr event = getPrivateObject(object);
720 std::string visibility = converter.toTizenValue(event->getVisibility());
721 return converter.toJSValueRef(visibility);
725 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
727 return JSValueMakeUndefined(context);
730 bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
732 JSStringRef propertyName,
734 JSValueRef* exception)
736 CalendarEventPtr event(NULL);
739 event = getPrivateObject(object);
740 CalendarConverter converter(context);
741 CalendarEvent::EventVisibility visibility =
742 converter.toEventVisibility(converter.toString(value));
743 event->setVisibility(visibility);
748 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
754 JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
756 JSStringRef propertyName,
757 JSValueRef* exception)
761 CalendarEventPtr item = getPrivateObject(object);
762 if( UNDEFINED_GEO==item->getGeolocation()->getLatitude() ) {
763 return JSValueMakeUndefined(context);
765 return DeviceAPI::Tizen::JSSimpleCoordinates::createJSObject(context, item->getGeolocation());
770 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
773 return JSValueMakeUndefined(context);
776 bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
778 JSStringRef propertyName,
780 JSValueRef* exception)
784 CalendarEventPtr item = getPrivateObject(object);
786 if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value)) {
787 item->getGeolocation()->setLatitude(UNDEFINED_GEO);
788 item->getGeolocation()->setLongitude(UNDEFINED_GEO);
790 DeviceAPI::Tizen::SimpleCoordinatesPtr geoLocation = DeviceAPI::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
792 item->setGeolocation(geoLocation);
798 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
804 JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
806 JSStringRef propertyName,
807 JSValueRef* exception)
811 CalendarEventPtr item = getPrivateObject(object);
813 if(UNDEFINED_TIME!=item->getDuration()->length) {
814 LoggerD("Duration length: "<<item->getDuration()->length<<", unit: "<<item->getDuration()->unit);
815 return JSTimeDuration::createJSObject(context, item->getDuration());
818 // Alternatively generate the duration object using start/end time.
819 if(UNDEFINED_TIME==item->getStartTime() || UNDEFINED_TIME==item->getEndTime()) {
820 LoggerD("Start or end time is not defined.");
821 return JSValueMakeUndefined(context);
824 long long length = item->getEndTime() - item->getStartTime(); // in seconds only
825 LoggerD("item->getStartTime():"<< item->getStartTime() << ", length:" << length);
827 DurationPropertiesPtr durationPtr(new DurationProperties());
828 durationPtr->length = length;
829 durationPtr->unit = SECONDS_UNIT;
830 item->setDuration(durationPtr);
832 return JSTimeDuration::createJSObject(context, durationPtr);
836 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
838 return JSValueMakeUndefined(context);
841 bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
843 JSStringRef propertyName,
845 JSValueRef* exception)
849 CalendarEventPtr event = getPrivateObject(object);
850 TimeUtilConverter timeUtilConverter(context);
852 DurationPropertiesPtr duration = timeUtilConverter.getDuration(value);
853 long long length = duration->length;
854 int unit = duration->unit;
856 DeviceAPI::Common::JSWebAPIErrorFactory::postException(context, exception, DeviceAPI::Common::JSWebAPIErrorFactory::INVALID_VALUES_ERROR);
860 LoggerD("length: "<<length<< ", unit:" <<unit);
861 event->setDuration(duration);
867 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
873 JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
875 JSStringRef propertyName,
876 JSValueRef* exception)
880 CalendarConverter converter(context);
881 CalendarEventPtr event = getPrivateObject(object);
882 return converter.toJSValueRef(event->getIsAllDay());
886 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
888 return JSValueMakeUndefined(context);
891 bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
893 JSStringRef propertyName,
895 JSValueRef* exception)
899 CalendarEventPtr event = getPrivateObject(object);
900 Converter converter(context);
901 event->setIsAllDay(converter.toBool(value));
906 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
912 JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
914 JSStringRef propertyName,
915 JSValueRef* exception)
919 CalendarConverter converter(context);
920 CalendarEventPtr event = getPrivateObject(object);
921 std::string availability = converter.toTizenValue(event->getAvailability());
922 return converter.toJSValueRef(availability);
926 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
928 return JSValueMakeUndefined(context);
931 bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
933 JSStringRef propertyName,
935 JSValueRef* exception)
937 CalendarEventPtr event(NULL);
940 event = getPrivateObject(object);
941 CalendarConverter converter(context);
942 CalendarEvent::EventAvailability availability =
943 converter.toEventAvailability(converter.toString(value));
944 event->setAvailability(availability);
949 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
955 JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
957 JSStringRef propertyName,
958 JSValueRef* exception)
962 CalendarEventPtr event = getPrivateObject(object);
963 EventAttendeeListPtr attendees = event->getAttendees();
965 JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
966 if (NULL == jsResult) {
967 ThrowMsg(NullPointerException, "Can not create array object.");
969 for(unsigned int i=0; i<attendees->size(); i++) {
970 if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
971 ThrowMsg(UnknownException, "Can not insert value into array.");
979 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
981 return JSValueMakeUndefined(context);
984 bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
986 JSStringRef propertyName,
988 JSValueRef* exception)
992 CalendarEventPtr event = getPrivateObject(object);
993 CalendarConverter converter(context);
994 event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
999 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1005 JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
1007 JSStringRef propertyName,
1008 JSValueRef* exception)
1012 CalendarItemPropertiesPrivObject *privateObject =
1013 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1014 CalendarEventPtr task = privateObject->getObject();
1015 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1016 return JSValueMakeUndefined(context);
1019 ThrowMsg(NullPointerException, "Task object is NULL.");
1022 if (UNDEFINED_TIME==task->getEndTime()) {
1023 return JSValueMakeUndefined(context);
1025 TimeUtilConverter timeConverter(context);
1026 return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
1031 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1033 return JSValueMakeUndefined(context);
1036 bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
1038 JSStringRef propertyName,
1040 JSValueRef* exception)
1044 CalendarEventPtr task = getPrivateObject(object);
1046 ThrowMsg(NullPointerException, "Task object is NULL.");
1048 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1049 ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
1051 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1052 ThrowMsg(ConversionException, "Wrong parameter type.");
1055 TimeUtilConverter converter(context);
1056 long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1058 task->setEndTime(dueDate);
1060 if( task->getTimeZone().empty() ) {
1061 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1062 task->setTimeZone(timeZone);
1068 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1074 JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
1076 JSStringRef propertyName,
1077 JSValueRef* exception)
1081 CalendarItemPropertiesPrivObject *privateObject =
1082 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1083 CalendarEventPtr task = privateObject->getObject();
1084 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1085 return JSValueMakeUndefined(context);
1088 ThrowMsg(NullPointerException, "Task object is NULL.");
1091 if (UNDEFINED_TIME==task->getCompletedDate()) {
1092 return JSValueMakeUndefined(context);
1094 TimeUtilConverter timeConverter(context);
1095 return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
1100 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1102 return JSValueMakeUndefined(context);
1105 bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
1107 JSStringRef propertyName,
1109 JSValueRef* exception)
1113 CalendarEventPtr task = getPrivateObject(object);
1115 ThrowMsg(NullPointerException, "Task object is NULL.");
1117 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1118 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1120 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1121 ThrowMsg(ConversionException, "Wrong parameter type.");
1124 TimeUtilConverter converter(context);
1125 long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1127 task->setCompletedDate(completedDate);
1129 if( task->getTimeZone().empty() ) {
1130 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1131 task->setTimeZone(timeZone);
1137 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1143 JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
1145 JSStringRef propertyName,
1146 JSValueRef* exception)
1150 CalendarEventPtr task = getPrivateObject(object);
1151 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1152 return JSValueMakeUndefined(context);
1155 Converter converter(context);
1156 return converter.toJSValueRef(task->getProgress());
1160 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1162 return JSValueMakeUndefined(context);
1165 bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
1167 JSStringRef propertyName,
1169 JSValueRef* exception)
1173 CalendarEventPtr task = getPrivateObject(object);
1174 if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
1175 return JSValueMakeUndefined(context);
1178 Converter converter(context);
1179 int progress = converter.toInt(value);
1180 task->setProgress(progress);
1185 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1191 JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
1193 JSStringRef propertyName,
1194 JSValueRef* exception)
1198 CalendarConverter converter(context);
1199 CalendarEventPtr item = getPrivateObject(object);
1201 ThrowMsg(NullPointerException, "Item object is NULL.");
1204 std::string priority = converter.toTizenValue(item->getPriority());
1205 return converter.toJSValueRef(priority);
1209 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1211 return JSValueMakeUndefined(context);
1214 bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
1216 JSStringRef propertyName,
1218 JSValueRef* exception)
1220 CalendarEventPtr item = getPrivateObject(object);
1223 CalendarConverter converter(context);
1224 CalendarEvent::TaskPriority priority =
1225 converter.toTaskPriority(converter.toString(value));
1226 item->setPriority(priority);
1231 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1237 JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
1239 JSStringRef propertyName,
1240 JSValueRef* exception)
1244 CalendarItemPropertiesPrivObject *privateObject =
1245 static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
1246 CalendarEventPtr event = privateObject->getObject();
1247 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1248 return JSValueMakeUndefined(context);
1251 ThrowMsg(NullPointerException, "Event object is NULL.");
1254 if (UNDEFINED_TIME==event->getEndTime()) {
1255 return JSValueMakeUndefined(context);
1257 TimeUtilConverter timeConverter(context);
1258 return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
1263 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1265 return JSValueMakeUndefined(context);
1268 bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
1270 JSStringRef propertyName,
1272 JSValueRef* exception)
1276 CalendarEventPtr event = getPrivateObject(object);
1278 ThrowMsg(NullPointerException, "Event object is NULL.");
1280 if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
1281 ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
1283 if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
1284 ThrowMsg(ConversionException, "Wrong parameter type.");
1287 TimeUtilConverter converter(context);
1288 long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
1290 event->setEndTime(endDate);
1292 if( event->getTimeZone().empty() ) {
1293 std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
1294 event->setTimeZone(timeZone);
1300 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1306 JSValueRef JSCalendarItemProperties::getPropertyLastModificationDate(JSContextRef context,
1308 JSStringRef propertyName,
1309 JSValueRef* exception)
1313 CalendarEventPtr item = getPrivateObject(object);
1315 ThrowMsg(NullPointerException, "Item object is NULL.");
1318 if (UNDEFINED_TIME==item->getLastModifiedDate()) {
1319 return JSValueMakeNull(context);
1321 TimeUtilConverter timeConverter(context);
1322 return timeConverter.toJSValueRefTZDate((double)(item->getLastModifiedDate()*1000.0), item->getTimeZone());
1327 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1329 return JSValueMakeUndefined(context);
1332 JSValueRef JSCalendarItemProperties::getPropertyCalendarId(JSContextRef context,
1334 JSStringRef propertyName,
1335 JSValueRef* exception)
1339 CalendarEventPtr item = getPrivateObject(object);
1341 if (UNDEFINED_CALENDAR_ID==item->getCalendarId()) {
1342 return JSValueMakeNull(context);
1344 CalendarConverter converter(context);
1345 std::stringstream ss;
1346 ss<<item->getCalendarId();
1347 return converter.toJSValueRef(ss.str());
1353 LoggerW("Exception: "<<_rethrown_exception.GetMessage());
1355 return JSValueMakeUndefined(context);