[Calendar] JavaScript files refactoring
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Wed, 17 Dec 2014 08:11:36 +0000 (09:11 +0100)
committerRafal Galka <r.galka@samsung.com>
Wed, 17 Dec 2014 10:16:59 +0000 (19:16 +0900)
Change-Id: I5a7a930956ba5f0c3a316c27cdf20995df984a79
Signed-off-by: Pawel Kaczmarek <p.kaczmarek3@samsung.com>
src/calendar/js/tizen.calendar.Calendar.js
src/calendar/js/tizen.calendar.CalendarAlarm.js
src/calendar/js/tizen.calendar.CalendarAttendee.js
src/calendar/js/tizen.calendar.CalendarItem.js
src/calendar/js/tizen.calendar.CalendarManager.js
src/calendar/js/tizen.calendar.CalendarRecurrenceRule.js
src/calendar/js/tizen.calendar.Common.js

index dd635a418a42f3471379fa157381f458d0c1cb3f..3e2adcf648b0ff68bb87f65cef973a11cdd7371f 100644 (file)
@@ -1,25 +1,12 @@
-/*
- * 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.
  */
@@ -66,7 +53,7 @@ var InternalCalendar = function(data) {
 var Calendar = function(accountId, name, type) {
   var _data;
 
-  AV.validateConstructorCall(this, Calendar);
+  AV.isConstructorCall(this, Calendar);
 
   if (arguments[0] instanceof InternalCalendar) {
     _data = arguments[0];
@@ -125,32 +112,32 @@ Calendar.prototype.get = function(id) {
   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));
@@ -163,7 +150,7 @@ Calendar.prototype.get = function(id) {
 };
 
 Calendar.prototype.add = function() {
-  var args = AV.validateMethod(arguments, [
+  var args = AV.validateArgs(arguments, [
     {
       name: 'item',
       type: AV.Types.PLATFORM_OBJECT,
@@ -173,22 +160,23 @@ Calendar.prototype.add = function() {
 
   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;
@@ -205,7 +193,7 @@ Calendar.prototype.add = function() {
 };
 
 Calendar.prototype.addBatch = function() {
-  var args = AV.validateMethod(arguments, [
+  var args = AV.validateArgs(arguments, [
     {
       name: 'items',
       type: AV.Types.ARRAY,
@@ -225,11 +213,11 @@ Calendar.prototype.addBatch = function() {
   ]);
 
   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) {
@@ -242,7 +230,7 @@ Calendar.prototype.addBatch = function() {
         }
       }
       _edit.disallow();
-      C.callIfPossible(args.successCallback, args.items);
+      native_.callIfPossible(args.successCallback, args.items);
     }
   }.bind(this);
 
@@ -251,25 +239,26 @@ Calendar.prototype.addBatch = function() {
   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,
@@ -285,13 +274,14 @@ Calendar.prototype.update = function() {
 
   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)
@@ -299,11 +289,11 @@ Calendar.prototype.update = function() {
             : 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)) {
@@ -315,7 +305,7 @@ Calendar.prototype.update = function() {
 };
 
 Calendar.prototype.updateBatch = function() {
-  var args = AV.validateMethod(arguments, [
+  var args = AV.validateArgs(arguments, [
     {
       name: 'items',
       type: AV.Types.ARRAY,
@@ -345,12 +335,12 @@ Calendar.prototype.updateBatch = 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));
       return;
     }
 
-    C.callIfPossible(args.successCallback);
+    native_.callIfPossible(args.successCallback);
   }.bind(this);
 
   var tmp = [];
@@ -358,13 +348,14 @@ Calendar.prototype.updateBatch = function() {
   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)
@@ -372,8 +363,8 @@ Calendar.prototype.updateBatch = function() {
             : true
   }, callback);
 
-  if (C.isFailure(result)) {
-    throw C.getErrorObject(result);
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
   }
 };
 
@@ -381,32 +372,32 @@ Calendar.prototype.remove = function(id) {
   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,
@@ -428,25 +419,25 @@ Calendar.prototype.removeBatch = function() {
   ]);
 
   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
@@ -476,10 +467,10 @@ Calendar.prototype.find = function(successCallback, errorCallback, filter, sortM
   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) {
@@ -498,14 +489,14 @@ Calendar.prototype.find = function(successCallback, errorCallback, filter, sortM
     }
   };
 
-  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);
   }
 
 };
@@ -549,7 +540,7 @@ function _CalendarChangeCallback(type, event) {
 
     for (var watchId in listeners) {
       if (listeners.hasOwnProperty(watchId)) {
-        C.callIfPossible(listeners[watchId][callbackName], result);
+        native_.callIfPossible(listeners[watchId][callbackName], result);
       }
     }
   }.bind(this);
@@ -598,7 +589,7 @@ function _CalendarChangeCallback(type, event) {
 }
 
 Calendar.prototype.addChangeListener = function() {
-  var args = AV.validateMethod(arguments, [{
+  var args = AV.validateArgs(arguments, [{
     name: 'successCallback',
     type: AV.Types.LISTENER,
     values: ['onitemsadded', 'onitemsupdated', 'onitemsremoved']
@@ -607,15 +598,15 @@ Calendar.prototype.addChangeListener = function() {
   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;
@@ -634,7 +625,7 @@ Calendar.prototype.addChangeListener = function() {
 };
 
 Calendar.prototype.removeChangeListener = function() {
-  var args = AV.validateMethod(arguments, [
+  var args = AV.validateArgs(arguments, [
     {
       name: 'watchId',
       type: AV.Types.LONG
@@ -661,13 +652,13 @@ Calendar.prototype.removeChangeListener = function() {
     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);
 
index 5dbd00f3a5164115830a675d318a8a3b97e810da..67a5402c7f93145c3f2ffb493e66e5664d6221a2 100644 (file)
@@ -1,18 +1,6 @@
-/*
- * 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 AlarmMethod = {
   SOUND: 'SOUND',
@@ -20,7 +8,7 @@ var AlarmMethod = {
 };
 
 var CalendarAlarm = function(time, method, description) {
-  AV.validateConstructorCall(this, CalendarAlarm);
+  AV.isConstructorCall(this, CalendarAlarm);
 
   var _absoluteDate = time instanceof tizen.TZDate && !this.before ? time : null;
   var _before = time instanceof tizen.TimeDuration && !this.absoluteDate ? time : null;
index c5eecc46b7704c54f3186c0eb072de83db89f6bd..85757644d97318e610ab457f99522accb1338596 100644 (file)
@@ -1,18 +1,6 @@
-/*
- * 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 AttendeeType = {
   INDIVIDUAL: 'INDIVIDUAL',
@@ -153,7 +141,7 @@ var CalendarAttendeeInit = function(data) {
 };
 
 var CalendarAttendee = function(uri, attendeeInitDict) {
-  AV.validateConstructorCall(this, CalendarAttendee);
+  AV.isConstructorCall(this, CalendarAttendee);
 
   CalendarAttendeeInit.call(this, attendeeInitDict);
 
index 8fde51ccff6277787d9e283aeec1b92b1ca78f74..7205af504e3901b6e43a578d89bd40d141e78108 100644 (file)
@@ -1,18 +1,6 @@
-/*
- * 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',
@@ -46,7 +34,7 @@ var EventAvailability = {
 };
 
 var CalendarEventId = function(uid, rid) {
-  AV.validateConstructorCall(this, CalendarEventId);
+  AV.isConstructorCall(this, CalendarEventId);
 
   var _uid = null;
 
@@ -344,7 +332,7 @@ var CalendarItem = function(data) {
 };
 
 CalendarItem.prototype.convertToString = function() {
-  var args = AV.validateMethod(arguments, [
+  var args = AV.validateArgs(arguments, [
     {
       name: 'format',
       type: AV.Types.ENUM,
@@ -576,7 +564,7 @@ var CalendarTaskInit = function(data) {
 };
 
 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));
@@ -601,7 +589,8 @@ var CalendarEventInit = function(data) {
 
   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) {
@@ -667,7 +656,7 @@ var CalendarEventInit = function(data) {
 };
 
 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));
@@ -681,27 +670,28 @@ CalendarEvent.prototype.constructor = CalendarEvent;
 
 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,
index 75265f920deb81669b9a592ec6c9bc64a86a2ac0..1e7c94b2c7c89a215a4182c519f5f6695198d19d 100644 (file)
@@ -1,27 +1,10 @@
-/*
- * 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
@@ -29,7 +12,7 @@ var DefaultCalendarId = {
 };
 
 CalendarManager.prototype.getCalendars = function() {
-  var args = AV.validateMethod(arguments, [{
+  var args = AV.validateArgs(arguments, [{
     name: 'type',
     type: AV.Types.ENUM,
     values: Object.keys(CalendarType)
@@ -50,10 +33,10 @@ CalendarManager.prototype.getCalendars = function() {
   };
 
   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)));
@@ -62,16 +45,16 @@ CalendarManager.prototype.getCalendars = function() {
     }
   };
 
-  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)
@@ -85,7 +68,7 @@ CalendarManager.prototype.getUnifiedCalendar = function() {
 
 CalendarManager.prototype.getDefaultCalendar = function() {
 
-  var args = AV.validateMethod(arguments, [{
+  var args = AV.validateArgs(arguments, [{
     name: 'type',
     type: AV.Types.ENUM,
     values: Object.keys(CalendarType)
@@ -97,7 +80,7 @@ CalendarManager.prototype.getDefaultCalendar = function() {
 
 CalendarManager.prototype.getCalendar = function() {
 
-  var args = AV.validateMethod(arguments, [{
+  var args = AV.validateArgs(arguments, [{
     name: 'type',
     type: AV.Types.ENUM,
     values: Object.keys(CalendarType)
@@ -113,18 +96,18 @@ CalendarManager.prototype.getCalendar = function() {
     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
@@ -134,20 +117,20 @@ CalendarManager.prototype.addCalendar = function() {
     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)
@@ -163,10 +146,10 @@ CalendarManager.prototype.removeCalendar = function() {
     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);
   }
 };
 
index b3ddcc85bffe9f9864d39b182b51e847d751d5f7..7e6950a4757c9e3052794b8a5ffab287a77ae58c 100644 (file)
@@ -1,18 +1,6 @@
-/*
- * 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 RecurrenceRuleFrequency = {
   DAILY: 'DAILY',
@@ -153,7 +141,7 @@ var CalendarRecurrenceRuleInit = function(data) {
 };
 
 var CalendarRecurrenceRule = function(frequency, ruleInitDict) {
-  AV.validateConstructorCall(this, CalendarRecurrenceRule);
+  AV.isConstructorCall(this, CalendarRecurrenceRule);
 
   CalendarRecurrenceRuleInit.call(this, ruleInitDict);
 
index 176bea22ad57ceeb4821d15f260a17410ff9f606..66dde084641cbf790dc3720c9b33dd005196874c 100644 (file)
@@ -1,36 +1,13 @@
-/*
- * 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 _common = xwalk.utils;
 var T = _common.type;
 var Converter = _common.converter;
 var AV = _common.validator;
-var C = _common.Common;
-var _call = function() {}; //@TODO C.getCall('calendar');
-//var _callSync = C.getCallSync('calendar');
-
-function _callSync(cmd, msg) {
-  var msg = msg || {};
-  msg.cmd = cmd;
-  var ret = extension.internal.sendSyncMessage(JSON.stringify(msg));
-  var obj = JSON.parse(ret);
-  if (obj.error)
-    throwException_(obj.error);
-  return obj.result;
-}
+var native_ = new xwalk.utils.NativeManager(extension);
+
 
 var EditManager = function() {
   this.canEdit = false;