-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
var CalendarType = {
EVENT: 'EVENT',
TASK: 'TASK'
};
-
/**
* For internal use only.
*/
var Calendar = function(accountId, name, type) {
var _data;
- AV.validateConstructorCall(this, Calendar);
+ AV.isConstructorCall(this, Calendar);
if (arguments[0] instanceof InternalCalendar) {
_data = arguments[0];
var args;
if (this.type === CalendarType.TASK) {
if (!parseInt(id) || parseInt(id) <= 0) {
- throw C.throwNotFound();
+ throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
}
- args = AV.validateMethod(arguments, [{
+ args = AV.validateArgs(arguments, [{
name: 'id',
type: AV.Types.STRING
}]);
} else {
- args = AV.validateMethod(arguments, [{
+ args = AV.validateArgs(arguments, [{
name: 'id',
type: AV.Types.PLATFORM_OBJECT,
values: tizen.CalendarEventId
}]);
}
- var result = _callSync('Calendar_get', {
+ var result = native_.callSync('Calendar_get', {
calendarId: this.id,
id: args.id
});
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
_edit.allow();
var item;
- var _item = C.getResultObject(result);
+ var _item = native_.getResultObject(result);
if (this.type === CalendarType.TASK) {
item = new CalendarTask(_itemConverter.toTizenObject(_item, _item.isAllDay));
};
Calendar.prototype.add = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'item',
type: AV.Types.PLATFORM_OBJECT,
if ((this.type === CalendarType.EVENT && !(args.item instanceof CalendarEvent)) ||
(this.type === CalendarType.TASK && !(args.item instanceof CalendarTask))) {
- C.throwTypeMismatch('Invalid item type.');
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+ 'Invalid item type.');
}
var tmp = _itemConverter.fromTizenObject(args.item);
tmp.calendarId = this.id;
- var result = _callSync('Calendar_add', {
+ var result = native_.callSync('Calendar_add', {
item: tmp,
type: this.type
});
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
- var _id = C.getResultObject(result);
+ var _id = native_.getResultObject(result);
_edit.allow();
args.item.calendarId = this.id;
};
Calendar.prototype.addBatch = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'items',
type: AV.Types.ARRAY,
]);
var callback = function(result) {
- if (C.isFailure(result)) {
- C.callIfPossible(args.errorCallback, C.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
} else {
_edit.allow();
- var _ids = C.getResultObject(result);
+ var _ids = native_.getResultObject(result);
for (var i = 0; i < args.items.length; i++) {
args.items[i].calendarId = this.id;
switch (this.type) {
}
}
_edit.disallow();
- C.callIfPossible(args.successCallback, args.items);
+ native_.callIfPossible(args.successCallback, args.items);
}
}.bind(this);
for (var i = 0; i < args.items.length; i++) {
if ((this.type === CalendarType.EVENT && !(args.items[i] instanceof CalendarEvent)) ||
(this.type === CalendarType.TASK && !(args.items[i] instanceof CalendarTask))) {
- C.throwTypeMismatch('Invalid item type.');
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+ 'Invalid item type.');
}
tmpItem = _itemConverter.fromTizenObject(args.items[i]);
tmpItem.calendarId = this.id;
tmp.push(tmpItem);
}
- var result = _call('Calendar_addBatch', {
+ var result = native_.call('Calendar_addBatch', {
type: this.type,
items: tmp
}, callback);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
Calendar.prototype.update = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'item',
type: AV.Types.PLATFORM_OBJECT,
if ((this.type === CalendarType.EVENT && !(args.item instanceof CalendarEvent)) ||
(this.type === CalendarType.TASK && !(args.item instanceof CalendarTask))) {
- C.throwTypeMismatch('Invalid item type.');
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+ 'Invalid item type.');
}
var tmp = _itemConverter.fromTizenObject(args.item);
tmp.calendarId = this.id;
- var result = _callSync('Calendar_update', {
+ var result = native_.callSync('Calendar_update', {
item: tmp,
type: this.type,
updateAllInstances: (args.has.updateAllInstances)
: true
});
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
- var _item = C.getResultObject(result);
+ var _item = native_.getResultObject(result);
_edit.allow();
for (var prop in _item) {
if (args.item.hasOwnProperty(prop)) {
};
Calendar.prototype.updateBatch = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'items',
type: AV.Types.ARRAY,
var calendarType = this.type;
var callback = function(result) {
- if (C.isFailure(result)) {
- C.callIfPossible(args.errorCallback, C.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- C.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback);
}.bind(this);
var tmp = [];
for (var i = 0; i < args.items.length; i++) {
if ((calendarType === CalendarType.EVENT && !(args.items[i] instanceof CalendarEvent)) ||
(calendarType === CalendarType.TASK && !(args.items[i] instanceof CalendarTask))) {
- C.throwTypeMismatch('Invalid item type.');
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+ 'Invalid item type.');
}
tmpItem = _itemConverter.fromTizenObject(args.items[i]);
tmp.push(tmpItem);
}
- var result = _call('Calendar_updateBatch', {
+ var result = native_.call('Calendar_updateBatch', {
type: this.type,
items: tmp,
updateAllInstances: (args.has.updateAllInstances)
: true
}, callback);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
var args;
if (this.type === CalendarType.TASK) {
if (!parseInt(id) || parseInt(id) <= 0) {
- throw C.throwNotFound();
+ throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
}
- args = AV.validateMethod(arguments, [{
+ args = AV.validateArgs(arguments, [{
name: 'id',
type: AV.Types.STRING
}]);
} else {
- args = AV.validateMethod(arguments, [{
+ args = AV.validateArgs(arguments, [{
name: 'id',
type: AV.Types.PLATFORM_OBJECT,
values: tizen.CalendarEventId
}]);
}
- var result = _callSync('Calendar_remove', {
+ var result = native_.callSync('Calendar_remove', {
type: this.type,
id: args.id
});
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
Calendar.prototype.removeBatch = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'ids',
type: AV.Types.ARRAY,
]);
var callback = function(result) {
- if (C.isFailure(result)) {
- C.callIfPossible(args.errorCallback, C.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
} else {
- C.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback);
}
};
- var result = _call('Calendar_removeBatch', {
+ var result = native_.call('Calendar_removeBatch', {
type: this.type,
ids: args.ids
}, callback);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
Calendar.prototype.find = function(successCallback, errorCallback, filter, sortMode) {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'successCallback',
type: AV.Types.FUNCTION
var calendarType = this.type;
var callback = function(result) {
- if (C.isFailure(result)) {
- C.callIfPossible(args.errorCallback, C.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
} else {
- var _items = C.getResultObject(result);
+ var _items = native_.getResultObject(result);
var c = [];
_edit.allow();
_items.forEach(function(i) {
}
};
- var result = _call('Calendar_find', {
+ var result = native_.call('Calendar_find', {
calendarId: this.id,
filter: args.filter,
sortMode: args.sortMode
}, callback);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
for (var watchId in listeners) {
if (listeners.hasOwnProperty(watchId)) {
- C.callIfPossible(listeners[watchId][callbackName], result);
+ native_.callIfPossible(listeners[watchId][callbackName], result);
}
}
}.bind(this);
}
Calendar.prototype.addChangeListener = function() {
- var args = AV.validateMethod(arguments, [{
+ var args = AV.validateArgs(arguments, [{
name: 'successCallback',
type: AV.Types.LISTENER,
values: ['onitemsadded', 'onitemsupdated', 'onitemsremoved']
var listenerId = 'CalendarChangeCallback_' + this.type;
if (!_nativeListeners.hasOwnProperty(listenerId)) {
- var result = _callSync('Calendar_addChangeListener', {
+ var result = native_.callSync('Calendar_addChangeListener', {
type: this.type,
listenerId: listenerId
});
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
- native.addListener(listenerId, (this.type === 'EVENT')
+ native_.addListener(listenerId, (this.type === 'EVENT')
? _CalendarEventChangeCallback
: _CalendarTaskChangeCallback);
_nativeListeners[listenerId] = this.type;
};
Calendar.prototype.removeChangeListener = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'watchId',
type: AV.Types.LONG
var fail = false;
for (var listenerId in _nativeListeners) {
if (_nativeListeners.hasOwnProperty(listenerId)) {
- result = _callSync('Calendar_removeChangeListener', {
+ result = native_.callSync('Calendar_removeChangeListener', {
type: _nativeListeners[listenerId]
});
- if (C.isFailure(result)) {
- fail = C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ fail = native_.getErrorObject(result);
}
- native.removeListener(listenerId, (this.type === 'EVENT')
+ native_.removeListener(listenerId, (this.type === 'EVENT')
? _CalendarEventChangeCallback
: _CalendarTaskChangeCallback);
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
var CalendarTextFormat = {
ICALENDAR_20: 'ICALENDAR_20',
};
var CalendarEventId = function(uid, rid) {
- AV.validateConstructorCall(this, CalendarEventId);
+ AV.isConstructorCall(this, CalendarEventId);
var _uid = null;
};
CalendarItem.prototype.convertToString = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'format',
type: AV.Types.ENUM,
};
var CalendarTask = function(taskInitDict, format) {
- AV.validateConstructorCall(this, CalendarTask);
+ AV.isConstructorCall(this, CalendarTask);
if (T.isString(taskInitDict) && Object.keys(CalendarTextFormat).indexOf(format) > -1) {
CalendarTaskInit.call(this, _convertFromStringToItem(taskInitDict));
var _validateReccurence = function(v) {
if (_isDetached && v !== null) {
- C.throwNotSupported('Recurrence can\'t be set because event is detached');
+ throw new tizen.WebAPIException(tizen.WebAPIException.NOT_SUPPORTED_ERR,
+ 'Recurrence can\'t be set because event is detached');
}
if (v === null || v instanceof tizen.CalendarRecurrenceRule) {
};
var CalendarEvent = function(eventInitDict, format) {
- AV.validateConstructorCall(this, CalendarEvent);
+ AV.isConstructorCall(this, CalendarEvent);
if (T.isString(eventInitDict) && Object.keys(CalendarTextFormat).indexOf(format) > -1) {
CalendarEventInit.call(this, _convertFromStringToItem(eventInitDict));
CalendarEvent.prototype.expandRecurrence = function(startDate, endDate, successCallback, errorCallback) {
if (arguments.length < 3) {
- C.throwTypeMismatch();
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
}
if (!(startDate instanceof tizen.TZDate)) {
- C.throwTypeMismatch();
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
}
if (!(endDate instanceof tizen.TZDate)) {
- C.throwTypeMismatch();
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
}
if (typeof successCallback !== 'function') {
- C.throwTypeMismatch();
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
}
if (errorCallback) {
if (typeof errorCallback !== 'function') {
- C.throwTypeMismatch();
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
}
}
if (!(this.recurrenceRule instanceof tizen.CalendarRecurrenceRule)) {
- C.throwInvalidValues('The event is not recurring.');
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+ 'The event is not recurring.');
}
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'startDate',
type: AV.Types.PLATFORM_OBJECT,
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
// class CalendarManager
var CalendarManager = function() {};
-var CalendarType = {
- EVENT: 'EVENT',
- TASK: 'TASK'
-};
-
// IDs defined in C-API calendar_types2.h
var DefaultCalendarId = {
EVENT: 1, // DEFAULT_EVENT_CALENDAR_BOOK_ID
};
CalendarManager.prototype.getCalendars = function() {
- var args = AV.validateMethod(arguments, [{
+ var args = AV.validateArgs(arguments, [{
name: 'type',
type: AV.Types.ENUM,
values: Object.keys(CalendarType)
};
var callback = function(result) {
- if (C.isFailure(result)) {
- C.callIfPossible(args.errorCallback, C.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
} else {
- var calendars = C.getResultObject(result);
+ var calendars = native_.getResultObject(result);
var c = [];
calendars.forEach(function(i) {
c.push(new Calendar(new InternalCalendar(i)));
}
};
- var result = _call('CalendarManager_getCalendars', callArgs, callback);
+ var result = native_.call('CalendarManager_getCalendars', callArgs, callback);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
CalendarManager.prototype.getUnifiedCalendar = function() {
- var args = AV.validateMethod(arguments, [{
+ var args = AV.validateArgs(arguments, [{
name: 'type',
type: AV.Types.ENUM,
values: Object.keys(CalendarType)
CalendarManager.prototype.getDefaultCalendar = function() {
- var args = AV.validateMethod(arguments, [{
+ var args = AV.validateArgs(arguments, [{
name: 'type',
type: AV.Types.ENUM,
values: Object.keys(CalendarType)
CalendarManager.prototype.getCalendar = function() {
- var args = AV.validateMethod(arguments, [{
+ var args = AV.validateArgs(arguments, [{
name: 'type',
type: AV.Types.ENUM,
values: Object.keys(CalendarType)
id: args.id
};
- var result = _callSync('CalendarManager_getCalendar', callArgs);
+ var result = native_.callSync('CalendarManager_getCalendar', callArgs);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
- return new Calendar(new InternalCalendar(C.getResultObject(result)));
+ return new Calendar(new InternalCalendar(native_.getResultObject(result)));
};
CalendarManager.prototype.addCalendar = function() {
- var args = AV.validateMethod(arguments, [{
+ var args = AV.validateArgs(arguments, [{
name: 'calendar',
type: AV.Types.PLATFORM_OBJECT,
values: Calendar
calendar: args.calendar
};
- var result = _callSync('CalendarManager_addCalendar', callArgs);
+ var result = native_.callSync('CalendarManager_addCalendar', callArgs);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
args.calendar.id = new InternalCalendar({
- id: C.getResultObject(result)
+ id: native_.getResultObject(result)
});
};
CalendarManager.prototype.removeCalendar = function() {
- var args = AV.validateMethod(arguments, [{
+ var args = AV.validateArgs(arguments, [{
name: 'type',
type: AV.Types.ENUM,
values: Object.keys(CalendarType)
id: args.id
};
- var result = _callSync('CalendarManager_removeCalendar', callArgs);
+ var result = native_.callSync('CalendarManager_removeCalendar', callArgs);
- if (C.isFailure(result)) {
- throw C.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};