[Calendar] JS files renamed to match common convention
authorRafal Galka <r.galka@samsung.com>
Tue, 13 Jan 2015 12:04:19 +0000 (13:04 +0100)
committerRafal Galka <r.galka@samsung.com>
Tue, 13 Jan 2015 12:04:19 +0000 (13:04 +0100)
Change-Id: I6d24a57e7e50004eb43b2ad2425de302facf839c
Signed-off-by: Rafal Galka <r.galka@samsung.com>
15 files changed:
src/calendar/calendar_api.js
src/calendar/js/calendar.js [new file with mode: 0644]
src/calendar/js/calendar_alarm.js [new file with mode: 0644]
src/calendar/js/calendar_attendee.js [new file with mode: 0644]
src/calendar/js/calendar_item.js [new file with mode: 0644]
src/calendar/js/calendar_manager.js [new file with mode: 0644]
src/calendar/js/calendar_recurrence_rule.js [new file with mode: 0644]
src/calendar/js/common.js [new file with mode: 0644]
src/calendar/js/tizen.calendar.Calendar.js [deleted file]
src/calendar/js/tizen.calendar.CalendarAlarm.js [deleted file]
src/calendar/js/tizen.calendar.CalendarAttendee.js [deleted file]
src/calendar/js/tizen.calendar.CalendarItem.js [deleted file]
src/calendar/js/tizen.calendar.CalendarManager.js [deleted file]
src/calendar/js/tizen.calendar.CalendarRecurrenceRule.js [deleted file]
src/calendar/js/tizen.calendar.Common.js [deleted file]

index 9173210b48ab716d46497aafd9f75ab351d788f8..2c866e49c17a573c4b22c1268c1e747325376f3d 100644 (file)
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-//= require('tizen.calendar.Common.js');
-//= require('tizen.calendar.CalendarItem.js');
-//= require('tizen.calendar.Calendar.js');
-//= require('tizen.calendar.CalendarManager.js');
-//= require('tizen.calendar.CalendarAttendee.js');
-//= require('tizen.calendar.CalendarAlarm.js');
-//= require('tizen.calendar.CalendarRecurrenceRule.js');
+//= require('common.js');
+//= require('calendar_item.js');
+//= require('calendar.js');
+//= require('calendar_manager.js');
+//= require('calendar_attendee.js');
+//= require('calendar_alarm.js');
+//= require('calendar_recurrence_rule.js');
diff --git a/src/calendar/js/calendar.js b/src/calendar/js/calendar.js
new file mode 100644 (file)
index 0000000..9833edc
--- /dev/null
@@ -0,0 +1,700 @@
+// 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 InternalCalendar = function(data) {
+  Object.defineProperties(this, {
+    accountId: {
+      value: -1,
+      writable: true,
+      enumerable: true
+    },
+    id: {
+      value: null,
+      writable: true,
+      enumerable: true
+    },
+    name: {
+      value: null,
+      writable: true,
+      enumerable: true
+    },
+    type: {
+      value: '',
+      writable: true,
+      enumerable: true
+    },
+    isUnified: {
+      value: false,
+      writable: true,
+      enumerable: true
+    }
+  });
+
+  if (data instanceof Object) {
+    for (var prop in data) {
+      if (this.hasOwnProperty(prop)) {
+        this[prop] = data[prop];
+      }
+    }
+  }
+};
+
+
+// class Calendar
+var Calendar = function(accountId, name, type) {
+  var _data;
+
+  AV.isConstructorCall(this, Calendar);
+
+  if (arguments[0] instanceof InternalCalendar) {
+    _data = arguments[0];
+  } else {
+    var _accountId = Converter.toLong(accountId);
+    var _name = Converter.toString(name);
+    var _type = Converter.toString(type);
+
+    if (arguments.length < 3) {
+      _data = new InternalCalendar();
+    } else {
+      _data = new InternalCalendar({
+                accountId: _accountId,
+                name: _name,
+                type: _type
+      });
+    }
+  }
+
+  Object.defineProperties(this, {
+    accountId: {
+      value: Converter.toLong(_data.accountId),
+      writable: false,
+      enumerable: true
+    },
+    id: {
+      get: function() {
+        return Converter.toString(_data.id, true);
+      },
+      set: function(v) {
+        if (v instanceof InternalCalendar) {
+          _data.id = v.id;
+        }
+      },
+      enumerable: true
+    },
+    name: {
+      value: _data.name,
+      writable: false,
+      enumerable: true
+    },
+    type: {
+      value: _data.type,
+      writable: false,
+      enumerable: false
+    },
+    isUnified: {
+      value: _data.isUnified,
+      writable: false,
+      enumerable: false
+    }
+  });
+};
+
+Calendar.prototype.get = function(id) {
+  var args;
+  if (this.type === CalendarType.TASK) {
+    if (!parseInt(id) || parseInt(id) <= 0) {
+      throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
+    }
+    args = AV.validateArgs(arguments, [{
+      name: 'id',
+      type: AV.Types.STRING
+    }]);
+  } else {
+    args = AV.validateArgs(arguments, [{
+      name: 'id',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: tizen.CalendarEventId
+    }]);
+  }
+
+  var result = native_.callSync('Calendar_get', {
+    calendarId: this.id,
+    id: args.id
+  });
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  _edit.allow();
+  var item;
+  var _item = native_.getResultObject(result);
+
+  if (this.type === CalendarType.TASK) {
+    item = new CalendarTask(_itemConverter.toTizenObject(_item, _item.isAllDay));
+  } else {
+    item = new CalendarEvent(_itemConverter.toTizenObject(_item, _item.isAllDay));
+  }
+  _edit.disallow();
+
+  return item;
+};
+
+Calendar.prototype.add = function() {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'item',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: [CalendarEvent, CalendarTask]
+    }
+  ]);
+
+  if ((this.type === CalendarType.EVENT && !(args.item instanceof CalendarEvent)) ||
+      (this.type === CalendarType.TASK && !(args.item instanceof CalendarTask))) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+        'Invalid item type.');
+  }
+
+  var tmp = _itemConverter.fromTizenObject(args.item);
+  tmp.calendarId = this.id;
+
+  var result = native_.callSync('Calendar_add', {
+    item: tmp,
+    type: this.type
+  });
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  var _id = native_.getResultObject(result);
+
+  _edit.allow();
+  args.item.calendarId = this.id;
+
+  switch (this.type) {
+    case CalendarType.EVENT:
+      args.item.id = new CalendarEventId(_id.uid, _id.rid);
+      break;
+    case CalendarType.TASK:
+      args.item.id = _id.uid;
+      break;
+  }
+  _edit.disallow();
+};
+
+Calendar.prototype.addBatch = function() {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'items',
+      type: AV.Types.ARRAY,
+      values: (this.type === CalendarType.EVENT)
+                ? tizen.CalendarEvent : tizen.CalendarTask
+    }, {
+      name: 'successCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    }, {
+      name: 'errorCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    }
+  ]);
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+    } else {
+      _edit.allow();
+      var _ids = native_.getResultObject(result);
+      for (var i = 0; i < args.items.length; i++) {
+        args.items[i].calendarId = this.id;
+        switch (this.type) {
+          case CalendarType.EVENT:
+            args.items[i].id = new CalendarEventId(_ids[i].uid, _ids[i].rid);
+            break;
+          case CalendarType.TASK:
+            args.items[i].id = _ids[i].uid;
+            break;
+        }
+      }
+      _edit.disallow();
+      native_.callIfPossible(args.successCallback, args.items);
+    }
+  }.bind(this);
+
+  var tmp = [];
+  var tmpItem;
+  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))) {
+      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);
+  }
+
+  native_.call('Calendar_addBatch', {
+    type: this.type,
+    items: tmp
+  }, callback);
+
+};
+
+Calendar.prototype.update = function() {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'item',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: [tizen.CalendarEvent, tizen.CalendarTask]
+    },
+    {
+      name: 'updateAllInstances',
+      type: AV.Types.BOOLEAN,
+      optional: true,
+      nullable: true
+    }
+  ]);
+
+  if ((this.type === CalendarType.EVENT && !(args.item instanceof CalendarEvent)) ||
+      (this.type === CalendarType.TASK && !(args.item instanceof CalendarTask))) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+      'Invalid item type.');
+  }
+
+  var tmp = _itemConverter.fromTizenObject(args.item);
+  tmp.calendarId = this.id;
+
+  var result = native_.callSync('Calendar_update', {
+    item: tmp,
+    type: this.type,
+    updateAllInstances: (args.has.updateAllInstances)
+            ? Converter.toBoolean(args.updateAllInstances, true)
+            : true
+  });
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  var _item = native_.getResultObject(result);
+  _edit.allow();
+  for (var prop in _item) {
+    if (args.item.hasOwnProperty(prop)) {
+      args.item[prop] = _item[prop];
+    }
+  }
+  _edit.disallow();
+
+};
+
+Calendar.prototype.updateBatch = function() {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'items',
+      type: AV.Types.ARRAY,
+      values: (this.type === CalendarType.EVENT)
+                ? tizen.CalendarEvent : tizen.CalendarTask
+    },
+    {
+      name: 'successCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    },
+    {
+      name: 'errorCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    },
+    {
+      name: 'updateAllInstances',
+      type: AV.Types.BOOLEAN,
+      optional: true,
+      nullable: true
+    }
+  ]);
+
+  var calendarType = this.type;
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+      return;
+    }
+
+    native_.callIfPossible(args.successCallback);
+  }.bind(this);
+
+  var tmp = [];
+  var tmpItem;
+  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))) {
+      throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+        'Invalid item type.');
+    }
+    tmpItem = _itemConverter.fromTizenObject(args.items[i]);
+    tmp.push(tmpItem);
+  }
+
+  native_.call('Calendar_updateBatch', {
+    type: this.type,
+    items: tmp,
+    updateAllInstances: (args.has.updateAllInstances)
+            ? Converter.toBoolean(args.updateAllInstances, true)
+            : true
+  }, callback);
+
+};
+
+Calendar.prototype.remove = function(id) {
+  var args;
+  if (this.type === CalendarType.TASK) {
+    if (!parseInt(id) || parseInt(id) <= 0) {
+      throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
+    }
+    args = AV.validateArgs(arguments, [{
+      name: 'id',
+      type: AV.Types.STRING
+    }]);
+  } else {
+    args = AV.validateArgs(arguments, [{
+      name: 'id',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: tizen.CalendarEventId
+    }]);
+  }
+
+  var result = native_.callSync('Calendar_remove', {
+    type: this.type,
+    id: args.id
+  });
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+Calendar.prototype.removeBatch = function() {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'ids',
+      type: AV.Types.ARRAY,
+      values: (this.type === CalendarType.EVENT)
+                ? tizen.CalendarEventId : undefined
+    },
+    {
+      name: 'successCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    },
+    {
+      name: 'errorCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    }
+  ]);
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+    } else {
+      native_.callIfPossible(args.successCallback);
+    }
+  };
+
+  native_.call('Calendar_removeBatch', {
+    type: this.type,
+    ids: args.ids
+  }, callback);
+
+};
+
+Calendar.prototype.find = function(successCallback, errorCallback, filter, sortMode) {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'successCallback',
+      type: AV.Types.FUNCTION
+    },
+    {
+      name: 'errorCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    },
+    {
+      name: 'filter',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: [tizen.AttributeFilter, tizen.AttributeRangeFilter, tizen.CompositeFilter],
+      optional: true,
+      nullable: true
+    },
+    {
+      name: 'sortMode',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: tizen.SortMode,
+      optional: true,
+      nullable: true
+    }
+  ]);
+  //TODO: Move sorting and filtering to native code
+  var C = {};
+  C.sort = function (arr, sortMode) {
+    var _getSortProperty = function (obj, props) {
+      for (var i = 0; i < props.length; ++i) {
+        if (!obj.hasOwnProperty(props[i])) {
+          return null;
+        }
+        obj = obj[props[i]];
+      }
+      return obj;
+    };
+
+    if (sortMode instanceof tizen.SortMode) {
+      var props = sortMode.attributeName.split('.');
+      arr.sort(function (a, b) {
+        var aValue = _getSortProperty(a, props);
+        var bValue = _getSortProperty(b, props);
+
+        if (sortMode.order === 'DESC') {
+          return aValue < bValue;
+        }
+        return bValue < aValue;
+      });
+    }
+    return arr;
+  };
+
+  C.filter = function (arr, filter) {
+    if (T.isNullOrUndefined(arr))
+      return arr;
+    if (filter instanceof tizen.AttributeFilter ||
+            filter instanceof tizen.AttributeRangeFilter ||
+            filter instanceof tizen.CompositeFilter) {
+      arr = arr.filter(function (element) {
+          return filter._filter(element);
+      });
+    }
+    return arr;
+  };
+
+  var calendarType = this.type;
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+    } else {
+      var _items = native_.getResultObject(result);
+      var c = [];
+      _edit.allow();
+      _items.forEach(function(i) {
+        if (calendarType === CalendarType.TASK) {
+          c.push(new CalendarTask(_itemConverter.toTizenObject(i, i.isAllDay)));
+        } else {
+          c.push(new CalendarEvent(_itemConverter.toTizenObject(i, i.isAllDay)));
+        }
+      });
+      _edit.disallow();
+      //TODO: Move sorting and filtering to native code
+      c = C.filter(c, args.filter); // NYA: due to commit dependency
+      c = C.sort(c, args.sortMode);
+      args.successCallback(c);
+
+    }
+  };
+  native_.call('Calendar_find', {
+    calendarId: this.id,
+    filter: args.filter,
+    sortMode: args.sortMode
+  }, callback);
+
+};
+
+var _listeners = {};
+// @todo this could be replaced by _taskListeners & _eventListeners
+var _nativeListeners = {};
+var _nextId = 0;
+
+function _CalendarEventChangeCallback(event) {
+  _CalendarChangeCallback('EVENT', event);
+}
+function _CalendarTaskChangeCallback(event) {
+  _CalendarChangeCallback('TASK', event);
+}
+function _CalendarChangeCallback(type, event) {
+  var invokeListeners = function(listeners, callbackName, items) {
+    var result = [];
+    _edit.allow();
+    for (var i = 0, length = items.length; i < length; i++) {
+      var item;
+
+      if (callbackName === 'onitemsremoved') {
+        if (type === 'EVENT') {
+          item = new CalendarEventId(items[i].id, null);
+        } else {
+          item = Converter.toString(items[i].id);
+        }
+      } else {
+        item = _itemConverter.toTizenObject(items[i], items[i].isAllDay);
+        if (type === 'EVENT') {
+          item = new CalendarEvent(item);
+        } else {
+          item = new CalendarTask(item);
+        }
+      }
+
+      result.push(item);
+    }
+    _edit.disallow();
+
+    for (var watchId in listeners) {
+      if (listeners.hasOwnProperty(watchId)) {
+        native_.callIfPossible(listeners[watchId][callbackName], result);
+      }
+    }
+  }.bind(this);
+
+  var groupItemsByCalendar = function(items) {
+    var grouped = {};
+
+    for (var i = 0, length = items.length; i < length; i++) {
+      var item = items[i];
+
+      // skip item if we are not listening on this calendarId
+      if (!_listeners.hasOwnProperty(item.calendarId)) {
+        continue;
+      }
+
+      if (!grouped.hasOwnProperty(item.calendarId)) {
+        grouped[item.calendarId] = [];
+      }
+      grouped[item.calendarId].push(item);
+    }
+
+    return grouped;
+  }.bind(this);
+
+  var actions = ['added', 'updated', 'removed'];
+  for (var i = 0; i < actions.length; i++) {
+    var action = actions[i];
+    var callback = 'onitems' + action;
+
+    if (event.hasOwnProperty(action) && T.isArray(event[action]) && event[action].length) {
+
+      // invoke listeners for unified calendars
+      if (_listeners.hasOwnProperty(type)) {
+        invokeListeners(_listeners[type], callback, event[action]);
+      }
+
+      var groupedItems = groupItemsByCalendar(event[action]);
+      for (var calendarId in groupedItems) {
+        if (groupedItems.hasOwnProperty(calendarId)) {
+          invokeListeners(_listeners[calendarId], callback, groupedItems[calendarId]);
+        }
+      }
+    }
+  }
+}
+
+Calendar.prototype.addChangeListener = function() {
+  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 = native_.callSync('Calendar_addChangeListener', {
+      type: this.type,
+      listenerId: listenerId
+    });
+    if (native_.isFailure(result)) {
+      throw native_.getErrorObject(result);
+    }
+
+    native_.addListener(listenerId, (this.type === 'EVENT')
+            ? _CalendarEventChangeCallback
+            : _CalendarTaskChangeCallback);
+    _nativeListeners[listenerId] = this.type;
+  }
+
+  // we can't use id in case of unified calendar - which is null for both calendar types
+  var calendarId = (this.isUnified) ? this.type : this.id;
+  if (!_listeners.hasOwnProperty(calendarId)) {
+    _listeners[calendarId] = {};
+  }
+
+  var watchId = ++_nextId;
+  _listeners[calendarId][watchId] = args.successCallback;
+
+  return watchId;
+};
+
+Calendar.prototype.removeChangeListener = function() {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'watchId',
+      type: AV.Types.LONG
+    }
+  ]);
+
+  var watchId = Converter.toString(args.watchId);
+  var calendarId = (this.isUnified) ? this.type : this.id;
+
+  if (!_listeners[calendarId] || !_listeners[calendarId][watchId]) {
+    return;
+  }
+
+  delete _listeners[calendarId][watchId];
+
+  if (T.isEmptyObject(_listeners[calendarId])) {
+    delete _listeners[calendarId];
+  }
+
+  if (T.isEmptyObject(_listeners)) {
+
+    var result;
+    // @todo consider listener unregister when we are not listening on this.type of calendar
+    var fail = false;
+    for (var listenerId in _nativeListeners) {
+      if (_nativeListeners.hasOwnProperty(listenerId)) {
+        result = native_.callSync('Calendar_removeChangeListener', {
+          type: _nativeListeners[listenerId]
+        });
+        if (native_.isFailure(result)) {
+          fail = native_.getErrorObject(result);
+        }
+        native_.removeListener(listenerId, (this.type === 'EVENT')
+                    ? _CalendarEventChangeCallback
+                    : _CalendarTaskChangeCallback);
+
+        delete _nativeListeners[listenerId];
+      }
+    }
+
+    if (fail) {
+      throw fail;
+    }
+  }
+};
+
+tizen.Calendar = Calendar;
diff --git a/src/calendar/js/calendar_alarm.js b/src/calendar/js/calendar_alarm.js
new file mode 100644 (file)
index 0000000..b9ac85d
--- /dev/null
@@ -0,0 +1,61 @@
+// 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',
+  DISPLAY: 'DISPLAY'
+};
+
+var CalendarAlarm = function(time, method, description) {
+  AV.isConstructorCall(this, CalendarAlarm);
+
+  var _absoluteDate = time instanceof tizen.TZDate && !this.before ? time : null;
+  var _before = time instanceof tizen.TimeDuration && !this.absoluteDate ? time : null;
+  var _method = Converter.toEnum(method, Object.keys(AlarmMethod), false);
+  var _description = (description) ? Converter.toString(description, true) : '';
+
+  Object.defineProperties(this, {
+    absoluteDate: {
+      get: function() {
+        return _absoluteDate;
+      },
+      set: function(v) {
+        _absoluteDate = v instanceof tizen.TZDate && !_before ? v : null;
+      },
+      enumerable: true
+    },
+    before: {
+      get: function() {
+        return _before;
+      },
+      set: function(v) {
+        _before = v instanceof tizen.TimeDuration && !_absoluteDate ? v : null;
+      },
+      enumerable: true
+    },
+    method: {
+      get: function() {
+        return _method;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _method = Converter.toEnum(v, Object.keys(AlarmMethod), false);
+      },
+      enumerable: true
+    },
+    description: {
+      get: function() {
+        return _description;
+      },
+      set: function(v) {
+        _description = Converter.toString(v, true);
+      },
+      enumerable: true
+    }
+  });
+};
+
+tizen.CalendarAlarm = CalendarAlarm;
diff --git a/src/calendar/js/calendar_attendee.js b/src/calendar/js/calendar_attendee.js
new file mode 100644 (file)
index 0000000..8575764
--- /dev/null
@@ -0,0 +1,171 @@
+// 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',
+  GROUP: 'GROUP',
+  RESOURCE: 'RESOURCE',
+  ROOM: 'ROOM',
+  UNKNOWN: 'UNKNOWN'
+};
+
+var AttendeeStatus = {
+  PENDING: 'PENDING',
+  ACCEPTED: 'ACCEPTED',
+  DECLINED: 'DECLINED',
+  TENTATIVE: 'TENTATIVE',
+  DELEGATED: 'DELEGATED',
+  COMPLETED: 'COMPLETED',
+  IN_PROCESS: 'IN_PROCESS'
+};
+
+var AttendeeRole = {
+  REQ_PARTICIPANT: 'REQ_PARTICIPANT',
+  OPT_PARTICIPANT: 'OPT_PARTICIPANT',
+  NON_PARTICIPANT: 'NON_PARTICIPANT',
+  CHAIR: 'CHAIR'
+};
+
+var CalendarAttendeeInit = function(data) {
+  var _name = null;
+  var _role = 'REQ_PARTICIPANT';
+  var _status = 'PENDING';
+  var _RSVP = false;
+  var _type = 'INDIVIDUAL';
+  var _group = null;
+  var _delegatorURI = null;
+  var _delegateURI = null;
+  var _contactRef = null;
+
+  Object.defineProperties(this, {
+    name: {
+      get: function() {
+        return _name;
+      },
+      set: function(v) {
+        _name = Converter.toString(v, true);
+      },
+      enumerable: true
+    },
+    role: {
+      get: function() {
+        return _role;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _role = Converter.toEnum(v, Object.keys(AttendeeRole), false);
+      },
+      enumerable: true
+    },
+    status: {
+      get: function() {
+        return _status;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _status = Converter.toEnum(v, Object.keys(AttendeeStatus), false);
+      },
+      enumerable: true
+    },
+    RSVP: {
+      get: function() {
+        return _RSVP;
+      },
+      set: function(v) {
+        _RSVP = Converter.toBoolean(v);
+      },
+      enumerable: true
+    },
+    type: {
+      get: function() {
+        return _type;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _type = Converter.toEnum(v, Object.keys(AttendeeType), false);
+      },
+      enumerable: true
+    },
+    group: {
+      get: function() {
+        return _group;
+      },
+      set: function(v) {
+        _group = Converter.toString(v, true);
+      },
+      enumerable: true
+    },
+    delegatorURI: {
+      get: function() {
+        return _delegatorURI;
+      },
+      set: function(v) {
+        _delegatorURI = Converter.toString(v, true);
+      },
+      enumerable: true
+    },
+    delegateURI: {
+      get: function() {
+        return _delegateURI;
+      },
+      set: function(v) {
+        _delegateURI = Converter.toString(v, true);
+      },
+      enumerable: true
+    },
+    contactRef: {
+      get: function() {
+        return _contactRef;
+      },
+      set: function(v) {
+        _contactRef = v instanceof tizen.ContactRef ? v : _contactRef;
+      },
+      enumerable: true
+    }
+  });
+
+  if (data instanceof Object) {
+    for (var prop in data) {
+      if (this.hasOwnProperty(prop)) {
+        this[prop] = data[prop];
+      }
+    }
+  }
+};
+
+var CalendarAttendee = function(uri, attendeeInitDict) {
+  AV.isConstructorCall(this, CalendarAttendee);
+
+  CalendarAttendeeInit.call(this, attendeeInitDict);
+
+  var _uri = null;
+
+  Object.defineProperties(this, {
+    uri: {
+      get: function() {
+        return _uri;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _uri = Converter.toString(v, true);
+      },
+      enumerable: true
+    }
+  });
+
+  this.uri = uri;
+};
+
+CalendarAttendee.prototype = new CalendarAttendeeInit();
+CalendarAttendee.prototype.constructor = CalendarAttendee;
+
+tizen.CalendarAttendee = CalendarAttendee;
diff --git a/src/calendar/js/calendar_item.js b/src/calendar/js/calendar_item.js
new file mode 100644 (file)
index 0000000..c7de25d
--- /dev/null
@@ -0,0 +1,733 @@
+// 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',
+  VCALENDAR_10: 'VCALENDAR_10'
+};
+
+var CalendarItemVisibility = {
+  PUBLIC: 'PUBLIC', //default
+  PRIVATE: 'PRIVATE',
+  CONFIDENTIAL: 'CONFIDENTIAL'
+};
+
+var CalendarItemPriority = {
+  HIGH: 'HIGH',
+  MEDIUM: 'MEDIUM',
+  LOW: 'LOW' //default
+};
+
+var CalendarItemStatus = {
+  TENTATIVE: 'TENTATIVE',
+  CONFIRMED: 'CONFIRMED', //default for CalendarEvent
+  CANCELLED: 'CANCELLED',
+  NEEDS_ACTION: 'NEEDS_ACTION', //default for CalendarTask
+  IN_PROCESS: 'IN_PROCESS',
+  COMPLETED: 'COMPLETED'
+};
+
+var EventAvailability = {
+  BUSY: 'BUSY', //default for CalendarEvent
+  FREE: 'FREE'
+};
+
+var CalendarEventId = function(uid, rid) {
+  AV.isConstructorCall(this, CalendarEventId);
+
+  var _uid = null;
+
+  Object.defineProperties(this, {
+    uid: {
+      get: function() {
+        return _uid;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _uid = Converter.toString(v, true);
+      },
+      enumerable: true
+    },
+    rid: {
+      value: (rid) ? Converter.toString(rid, true) : null,
+      writable: true,
+      enumerable: true
+    }
+  });
+
+  this.uid = uid;
+};
+
+// class CalendarItem
+var CalendarItem = function(data) {
+  var _id = null;
+  var _calendarId = null;
+  var _lastModificationDate = null;
+  var _description = '';
+  var _summary = '';
+  var _isAllDay = false;
+  var _startDate = null;
+  var _duration = null;
+  var _location = '';
+  var _geolocation = null;
+  var _organizer = '';
+  var _visibility = CalendarItemVisibility.PUBLIC;
+  var _status = CalendarItemStatus.CONFIRMED;
+  var _priority = CalendarItemPriority.LOW;
+  var _alarms = [];
+  var _categories = [];
+  var _attendees = [];
+
+  function _validateAlarms(v) {
+    var valid = false;
+
+    if (T.isArray(v)) {
+      for (var i = 0; i < v.length; i++) {
+        if (!(v[i] instanceof tizen.CalendarAlarm)) {
+          return false;
+        }
+      }
+      valid = true;
+    }
+    return valid;
+  }
+
+  function _validateAttendees(v) {
+    var valid = false;
+
+    if (T.isArray(v)) {
+      for (var i = 0; i < v.length; i++) {
+        if (!(v[i] instanceof tizen.CalendarAttendee)) {
+          return false;
+        }
+      }
+      valid = true;
+    }
+    return valid;
+  }
+
+  function _validateCategories(v) {
+    var valid = false;
+
+    if (T.isArray(v)) {
+      for (var i = 0; i < v.length; i++) {
+        if (!(T.isString(v[i]))) {
+          return false;
+        }
+      }
+      valid = true;
+    }
+    return valid;
+  }
+
+  Object.defineProperties(this, {
+    id: {
+      get: function() {
+        return _id;
+      },
+      set: function(v) {
+        if (_edit.canEdit) {
+          if (v instanceof Object) {
+            _id = new CalendarEventId(v.uid, v.rid);
+          } else {
+            _id = Converter.toString(v, true);
+          }
+        }
+      },
+      enumerable: true
+    },
+    calendarId: {
+      get: function() {
+        return _calendarId;
+      },
+      set: function(v) {
+        if (_edit.canEdit) {
+          _calendarId = v;
+        }
+      },
+      enumerable: true
+    },
+    lastModificationDate: {
+      get: function() {
+        return _lastModificationDate;
+      },
+      set: function(v) {
+        if (_edit.canEdit) {
+          _lastModificationDate = v instanceof tizen.TZDate ? v :
+              tizen.time.getCurrentDateTime();
+        }
+      },
+      enumerable: true
+    },
+    description: {
+      get: function() {
+        return _description;
+      },
+      set: function(v) {
+        _description = v ? Converter.toString(v, true) : _description;
+      },
+      enumerable: true
+    },
+    summary: {
+      get: function() {
+        return _summary;
+      },
+      set: function(v) {
+        _summary = v ? Converter.toString(v, true) : _summary;
+      },
+      enumerable: true
+    },
+    isAllDay: {
+      get: function() {
+        return _isAllDay;
+      },
+      set: function(v) {
+        _isAllDay = v ? Converter.toBoolean(v) : _isAllDay;
+      },
+      enumerable: true
+    },
+    startDate: {
+      get: function() {
+        return _startDate;
+      },
+      set: function(v) {
+        _startDate = v instanceof tizen.TZDate ? v : _startDate;
+        this.duration = _duration;
+      },
+      enumerable: true
+    },
+    duration: {
+      get: function() {
+        return _duration;
+      },
+      set: function(v) {
+        // set duration as dueDate or endDate
+        var _startDate = this.startDate ?
+            this.startDate : tizen.time.getCurrentDateTime();
+        if (this instanceof tizen.CalendarEvent) {
+          this.endDate = v instanceof tizen.TimeDuration ?
+              _startDate.addDuration(v) : this.endDate;
+        } else {
+          this.dueDate = v instanceof tizen.TimeDuration ?
+              _startDate.addDuration(v) : this.dueDate;
+        }
+        _duration = v instanceof tizen.TimeDuration ? v : null;
+        //@todo Fix UTC, UTC expect duration value but according to documentation:
+        // ... the implementation may not save the duration itself,
+        // rather convert it to the corresponding endDate/dueDate attribute and save it.
+        // For example, if you set the startDate and the duration attributes and save the item,
+        // you may see that the duration is null while endDate/dueDate is non-null
+        // after retrieving it because the implementation has calculated the endDate/dueDate
+        // based on the duration and the startDate then saved it, not the duration.
+      },
+      enumerable: true
+    },
+    location: {
+      get: function() {
+        return _location;
+      },
+      set: function(v) {
+        _location = v ? Converter.toString(v) : _location;
+      },
+      enumerable: true
+    },
+    geolocation: {
+      get: function() {
+        return _geolocation;
+      },
+      set: function(v) {
+        _geolocation = v instanceof tizen.SimpleCoordinates ? v : _geolocation;
+      },
+      enumerable: true
+    },
+    organizer: {
+      get: function() {
+        return _organizer;
+      },
+      set: function(v) {
+        _organizer = v ? Converter.toString(v) : _organizer;
+      },
+      enumerable: true
+    },
+    visibility: {
+      get: function() {
+        return _visibility;
+      },
+      set: function(v) {
+        _visibility = v ? Converter.toEnum(v, Object.keys(CalendarItemVisibility), false) :
+                _visibility;
+      },
+      enumerable: true
+    },
+    status: {
+      get: function() {
+        return _status;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        if (this instanceof tizen.CalendarEvent) {
+          _status = v ? Converter.toEnum(v, Object.keys(CalendarItemStatus).slice(0, 3), false) :
+                        CalendarItemStatus.CONFIRMED;
+        } else {
+          _status = v ? Converter.toEnum(v, Object.keys(CalendarItemStatus).slice(2), false) :
+                        CalendarItemStatus.NEEDS_ACTION;
+        }
+      },
+      enumerable: true
+    },
+    priority: {
+      get: function() {
+        return _priority;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _priority = v ? Converter.toEnum(v, Object.keys(CalendarItemPriority), false) :
+                    _status;
+      },
+      enumerable: true
+    },
+    alarms: {
+      get: function() {
+        return _alarms;
+      },
+      set: function(v) {
+        _alarms = _validateAlarms(v) ? v : _alarms;
+      },
+      enumerable: true
+    },
+    categories: {
+      get: function() {
+        return _categories;
+      },
+      set: function(v) {
+        _categories = _validateCategories(v) ? v : _categories;
+      },
+      enumerable: true
+    },
+    attendees: {
+      get: function() {
+        return _attendees;
+      },
+      set: function(v) {
+        _attendees = _validateAttendees(v) ? v : _attendees;
+      },
+      enumerable: true
+    }
+  });
+
+  if (data instanceof Object) {
+    for (var prop in data) {
+      if (this.hasOwnProperty(prop)) {
+        this[prop] = data[prop];
+      }
+    }
+  }
+
+};
+
+CalendarItem.prototype.convertToString = function() {
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'format',
+      type: AV.Types.ENUM,
+      values: Object.keys(CalendarTextFormat)
+    }
+  ]);
+
+  var _checkNumber = function(n) {
+    return n < 10 ? '0' + n : n;
+  };
+
+  var _timeFormat = function(d) {
+    return ';TZID=' + d.getTimezone() +
+        ':' + d.getFullYear() + _checkNumber(d.getMonth()) + _checkNumber(d.getDate()) +
+            'T' + _checkNumber(d.getHours()) + _checkNumber(d.getMinutes()) +
+            _checkNumber(d.getSeconds() + 'Z');
+  };
+
+  var _this = this;
+  var _dtStart = '';
+
+  if (_this.startDate) {
+    _dtStart = _timeFormat(_this.startDate);
+  } else {
+    _dtStart = _timeFormat(tizen.time.getCurrentDateTime());
+  }
+
+  var _dtEnd = _dtStart;
+
+  if (_this.endDate) {
+    _dtEnd = _timeFormat(_this.endDate);
+  } else if (_this.dueDate) {
+    _dtEnd = _timeFormat(_this.dueDate);
+  }
+
+  var _description = _this.description.length ? ':' + _this.description : '';
+  var _location = _this.location.length ? ':' + _this.location : '';
+  var _organizer = _this.organizer.length ? ';CN=' + _this.organizer : '';
+  var _priority = _this.priority.length ? ':' + _this.priority : '';
+  var _summary = _this.summary.length ? ':' + _this.summary : '';
+  var _categories = _this.categories.length ? ':' + _this.categories.join(', ') : '';
+  var _visibility = _this.visibility;
+  var _status = _this.status;
+  var _version = args.format === CalendarTextFormat.ICALENDAR_20 ? ':2.0' : ':1.0';
+
+  var vEven = [
+    'BEGIN:VCALENDAR',
+    'VERSION' + _version,
+    'BEGIN:VEVENT',
+    'CLASS:' + _visibility,
+    'TRANSP:OPAQUE',
+    'DTSTART' + _dtStart,
+    'DESCRIPTION' + _description,
+    'LOCATION' + _location,
+    'ORGANIZER' + _organizer,
+    'PRIORITY' + _priority,
+    'SUMMARY' + _summary,
+    'DTEND' + _dtEnd,
+    'CATEGORIES' + _categories,
+    'END:VEVENT',
+    'END:VCALENDAR'
+  ].join('\n');
+
+  var vTodo = [
+    'BEGIN:VCALENDAR',
+    'VERSION' + _version,
+    'BEGIN:VTODO',
+    'SUMMARY' + _summary,
+    'DUE' + _dtEnd,
+    'STATUS' + _status,
+    'END:VTODO',
+    'END:VCALENDAR'
+  ].join('\n');
+
+  if (this instanceof tizen.CalendarTask) {
+    return vTodo;
+  } else {
+    return vEven;
+  }
+
+};
+
+CalendarItem.prototype.clone = function() {
+  var tmp = _itemConverter.toTizenObject(_itemConverter.fromTizenObject(this));
+
+  tmp.id = null;
+
+  return this instanceof tizen.CalendarEvent ? new tizen.CalendarEvent(tmp) :
+      new tizen.CalendarTask(tmp);
+};
+
+function _convertFromStringToItem(str) {
+  if (str.indexOf('VCALENDAR') === -1) {
+    console.logd('Wrong format');
+    return;
+  }
+
+  var _startDate = null;
+  var _description = '';
+  var _location = null;
+  var _organizer = null;
+  var _priority = null;
+  var _summary = null;
+  var _categories = [];
+  var _visibility = null;
+  var _status = null;
+  var _endDate = null;
+  var _dueDate = null;
+  var sep;
+
+  if (str.indexOf('\r\n') > -1) {
+    sep = '\r\n';
+  } else if (str.indexOf('\n') > -1) {
+    sep = '\n';
+  } else {
+    console.logd('Wrong separator');
+    return;
+  }
+
+  function _convertTime(v) {
+    var y = parseInt(v.substring(0, 4) , 10);
+    var m = parseInt(v.substring(4, 6) , 10);
+    var d = parseInt(v.substring(6, 8) , 10);
+    var h = parseInt(v.substring(9, 11) , 10);
+    var n = parseInt(v.substring(11, 13) , 10);
+    var s = parseInt(v.substring(13, 15) , 10);
+
+    return new tizen.TZDate(y, m, d, h, n, s);
+  }
+
+  var arr = str.split(sep);
+
+  for (var i = 0; i < arr.length; i++) {
+    if (arr[i].indexOf('SUMMARY') > -1) {
+      _summary = arr[i].split(':')[1];
+    } else if (arr[i].indexOf('CATEGORIES') > -1) {
+      var c = arr[i].split(':')[1];
+      _categories = c.split(',');
+    } else if (arr[i].indexOf('ORGANIZER') > -1) {
+      _organizer = arr[i].split('=')[1];
+    } else if (arr[i].indexOf('DESCRIPTION') > -1) {
+      _description = arr[i].split(':')[1];
+    } else if (arr[i].indexOf('CLASS') > -1) {
+      _visibility = arr[i].split(':')[1];
+    } else if (arr[i].indexOf('LOCATION') > -1) {
+      _location = arr[i].split(':')[1];
+    } else if (arr[i].indexOf('PRIORITY') > -1) {
+      _priority = arr[i].split(':')[1];
+    } else if (arr[i].indexOf('STATUS') > -1) {
+      _status = arr[i].split(':')[1];
+    } else if (arr[i].indexOf('DTSTART') > -1) {
+      _startDate = _convertTime(arr[i].split(':')[1]);
+    } else if (arr[i].indexOf('DTEND') > -1) {
+      _endDate = _convertTime(arr[i].split(':')[1]);
+    } else if (arr[i].indexOf('DUE') > -1) {
+      _dueDate = _convertTime(arr[i].split(':')[1]);
+    }
+  }
+
+  return {
+    visibility: _visibility,
+    startDate: _startDate,
+    description: _description,
+    location: _location,
+    organizer: _organizer,
+    priority: _priority,
+    summary: _summary,
+    status: _status,
+    categories: _categories,
+    endDate: _endDate,
+    dueDate: _dueDate
+  };
+
+}
+
+var CalendarTaskInit = function(data) {
+  CalendarItem.call(this, {
+    status: CalendarItemStatus.NEEDS_ACTION
+  });
+
+  var _dueDate = null;
+  var _completedDate = null;
+  var _progress = 0;
+
+  Object.defineProperties(this, {
+    dueDate: {
+      get: function() {
+        return _dueDate;
+      },
+      set: function(v) {
+        if (!v instanceof tizen.TZDate && this.startDate) {
+          v = this.startDate;
+        }
+
+        _dueDate = v instanceof tizen.TZDate ? v : _dueDate;
+      },
+      enumerable: true
+    },
+    completedDate: {
+      get: function() {
+        return _completedDate;
+      },
+      set: function(v) {
+        _completedDate = v instanceof tizen.TZDate ? v : _completedDate;
+      },
+      enumerable: true
+    },
+    progress: {
+      get: function() {
+        return _progress;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _progress = (T.isNumber(v) && (v >= 0 || v <= 100)) ? v : _progress;
+      },
+      enumerable: true
+    }
+  });
+
+  if (data instanceof Object) {
+    for (var prop in data) {
+      if (this.hasOwnProperty(prop)) {
+        this[prop] = data[prop];
+      }
+    }
+  }
+};
+
+var CalendarTask = function(taskInitDict, format) {
+  AV.isConstructorCall(this, CalendarTask);
+
+  if (T.isString(taskInitDict) && Object.keys(CalendarTextFormat).indexOf(format) > -1) {
+    CalendarTaskInit.call(this, _convertFromStringToItem(taskInitDict));
+  } else {
+    CalendarTaskInit.call(this, taskInitDict);
+  }
+};
+
+CalendarTask.prototype = new CalendarItem();
+CalendarTask.prototype.constructor = CalendarTask;
+
+
+var CalendarEventInit = function(data) {
+  CalendarItem.call(this, {
+    status: CalendarItemStatus.CONFIRMED
+  });
+
+  var _isDetached = false;
+  var _endDate = null;
+  var _availability = EventAvailability.BUSY;
+  var _recurrenceRule = null;
+
+  var _validateReccurence = function(v) {
+    if (_isDetached && v !== null) {
+      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) {
+      return v;
+    } else {
+      return _recurrenceRule;
+    }
+  };
+
+  Object.defineProperties(this, {
+    isDetached: {
+      get: function() {
+        return _isDetached;
+      },
+      set: function(v) {
+        if (_edit.canEdit) {
+          _isDetached = v;
+        }
+      },
+      enumerable: true
+    },
+    endDate: {
+      get: function() {
+        return _endDate;
+      },
+      set: function(v) {
+        if (!v instanceof tizen.TZDate && this.startDate) {
+          v = this.startDate;
+        }
+
+        _endDate = v instanceof tizen.TZDate ? v : _endDate;
+      },
+      enumerable: true
+    },
+    availability: {
+      get: function() {
+        return _availability;
+      },
+      set: function(v) {
+        _availability = Object.keys(EventAvailability).indexOf(v) > -1 ? v :
+                _availability;
+      },
+      enumerable: true
+    },
+    recurrenceRule: {
+      get: function() {
+        return _recurrenceRule;
+      },
+      set: function(v) {
+        _recurrenceRule = _validateReccurence(v);
+      },
+      enumerable: true
+    }
+  });
+
+  if (data instanceof Object) {
+    for (var prop in data) {
+      if (this.hasOwnProperty(prop)) {
+        this[prop] = data[prop];
+      }
+    }
+  }
+};
+
+var CalendarEvent = function(eventInitDict, format) {
+  AV.isConstructorCall(this, CalendarEvent);
+
+  if (T.isString(eventInitDict) && Object.keys(CalendarTextFormat).indexOf(format) > -1) {
+    CalendarEventInit.call(this, _convertFromStringToItem(eventInitDict));
+  } else {
+    CalendarEventInit.call(this, eventInitDict);
+  }
+};
+
+CalendarEvent.prototype = new CalendarItem();
+CalendarEvent.prototype.constructor = CalendarEvent;
+
+CalendarEvent.prototype.expandRecurrence = function(startDate, endDate, successCallback, errorCallback) {
+  if (arguments.length < 3) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+  }
+  if (!(startDate instanceof tizen.TZDate)) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+  }
+  if (!(endDate instanceof tizen.TZDate)) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+  }
+  if (typeof successCallback !== 'function') {
+    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+  }
+  if (errorCallback) {
+    if (typeof errorCallback !== 'function') {
+      throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+    }
+  }
+  if (!(this.recurrenceRule instanceof tizen.CalendarRecurrenceRule)) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+      'The event is not recurring.');
+  }
+
+  var args = AV.validateArgs(arguments, [
+    {
+      name: 'startDate',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: tizen.TZDate
+    },
+    {
+      name: 'endDate',
+      type: AV.Types.PLATFORM_OBJECT,
+      values: tizen.TZDate
+    },
+    {
+      name: 'successCallback',
+      type: AV.Types.FUNCTION,
+      nullable: true
+    },
+    {
+      name: 'errorCallback',
+      type: AV.Types.FUNCTION,
+      optional: true,
+      nullable: true
+    }
+  ]);
+
+  // invoke callbacks in "next tick"
+  setTimeout(function() {
+    var result = _recurrenceManager.get(this, startDate, endDate);
+
+    if (result instanceof Array) {
+      args.successCallback(result);
+    } else if (args.errorCallback) {
+      args.errorCallback(result);
+    }
+  }.bind(this), 1);
+};
+
+tizen.CalendarEventId = CalendarEventId;
+tizen.CalendarEvent = CalendarEvent;
+tizen.CalendarTask = CalendarTask;
diff --git a/src/calendar/js/calendar_manager.js b/src/calendar/js/calendar_manager.js
new file mode 100644 (file)
index 0000000..b6e0f49
--- /dev/null
@@ -0,0 +1,152 @@
+// 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() {};
+
+// IDs defined in C-API calendar_types2.h
+var DefaultCalendarId = {
+  EVENT: 1, // DEFAULT_EVENT_CALENDAR_BOOK_ID
+  TASK: 2 // DEFAULT_TODO_CALENDAR_BOOK_ID
+};
+
+CalendarManager.prototype.getCalendars = function() {
+  var args = AV.validateArgs(arguments, [{
+    name: 'type',
+    type: AV.Types.ENUM,
+    values: Object.keys(CalendarType)
+  },
+  {
+    name: 'successCallback',
+    type: AV.Types.FUNCTION
+  },
+  {
+    name: 'errorCallback',
+    type: AV.Types.FUNCTION,
+    optional: true,
+    nullable: true
+  }]);
+
+  var callArgs = {
+    type: args.type
+  };
+
+  var callback = function(result) {
+    if (native_.isFailure(result)) {
+      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+    } else {
+      var calendars = native_.getResultObject(result);
+      var c = [];
+      calendars.forEach(function(i) {
+        c.push(new Calendar(new InternalCalendar(i)));
+      });
+      args.successCallback(c);
+    }
+  };
+
+  native_.call('CalendarManager_getCalendars', callArgs, callback);
+};
+
+CalendarManager.prototype.getUnifiedCalendar = function() {
+
+  var args = AV.validateArgs(arguments, [{
+    name: 'type',
+    type: AV.Types.ENUM,
+    values: Object.keys(CalendarType)
+  }]);
+
+  return new Calendar(new InternalCalendar({
+    type: args.type,
+    isUnified: true
+  }));
+};
+
+CalendarManager.prototype.getDefaultCalendar = function() {
+
+  var args = AV.validateArgs(arguments, [{
+    name: 'type',
+    type: AV.Types.ENUM,
+    values: Object.keys(CalendarType)
+  }
+  ]);
+
+  return this.getCalendar(args.type, DefaultCalendarId[args.type]);
+};
+
+CalendarManager.prototype.getCalendar = function() {
+
+  var args = AV.validateArgs(arguments, [{
+    name: 'type',
+    type: AV.Types.ENUM,
+    values: Object.keys(CalendarType)
+  },
+  {
+    name: 'id',
+    type: AV.Types.STRING
+  }
+  ]);
+
+  var callArgs = {
+    type: args.type,
+    id: args.id
+  };
+
+  var result = native_.callSync('CalendarManager_getCalendar', callArgs);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return new Calendar(new InternalCalendar(native_.getResultObject(result)));
+};
+
+CalendarManager.prototype.addCalendar = function() {
+
+  var args = AV.validateArgs(arguments, [{
+    name: 'calendar',
+    type: AV.Types.PLATFORM_OBJECT,
+    values: Calendar
+  }]);
+
+  var callArgs = {
+    calendar: args.calendar
+  };
+
+  var result = native_.callSync('CalendarManager_addCalendar', callArgs);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  args.calendar.id = new InternalCalendar({
+    id: native_.getResultObject(result)
+  });
+};
+
+CalendarManager.prototype.removeCalendar = function() {
+
+  var args = AV.validateArgs(arguments, [{
+    name: 'type',
+    type: AV.Types.ENUM,
+    values: Object.keys(CalendarType)
+  },
+  {
+    name: 'id',
+    type: AV.Types.STRING
+  }
+  ]);
+
+  var callArgs = {
+    type: args.type,
+    id: args.id
+  };
+
+  var result = native_.callSync('CalendarManager_removeCalendar', callArgs);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+};
+
+exports = new CalendarManager();
diff --git a/src/calendar/js/calendar_recurrence_rule.js b/src/calendar/js/calendar_recurrence_rule.js
new file mode 100644 (file)
index 0000000..7e6950a
--- /dev/null
@@ -0,0 +1,172 @@
+// 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',
+  WEEKLY: 'WEEKLY',
+  MONTHLY: 'MONTHLY',
+  YEARLY: 'YEARLY'
+};
+
+var ByDayValue = {
+  MO: 'MO',
+  TU: 'TU',
+  WE: 'WE',
+  TH: 'TH',
+  FR: 'FR',
+  SA: 'SA',
+  SU: 'SU'
+};
+
+var CalendarRecurrenceRuleInit = function(data) {
+  var _interval = 1;
+  var _untilDate = null;
+  var _daysOfTheWeek = [];
+  var _occurrenceCount = -1;
+  var _setPositions = [];
+  var _exceptions = [];
+
+  function _validateDaysOfTheWeek(v) {
+    if (T.isArray(v)) {
+      var allowedValues = Object.keys(ByDayValue);
+      for (var i = 0; i < v.length; ++i) {
+        if (allowedValues.indexOf(v[i]) < 0) {
+          return false;
+        }
+      }
+      return true;
+    }
+
+    return false;
+  }
+
+  function _validateSetPositions(v) {
+    var valid = false;
+
+    if (T.isArray(v)) {
+      for (var i = 0; i < v.length; i++) {
+        v[i] = parseInt(v[i]);
+        if (isNaN(v[i]) || (v[i] < -366 || v[i] > 366 || v[i] === 0)) {
+          return false;
+        }
+      }
+      valid = true;
+    }
+    return valid;
+  }
+
+  function _validateExceptions(v) {
+    var valid = false;
+
+    if (T.isArray(v)) {
+      for (var i = 0; i < v.length; i++) {
+        if (!(v[i] instanceof tizen.TZDate)) {
+          return false;
+        }
+      }
+      valid = true;
+    }
+    return valid;
+  }
+
+  Object.defineProperties(this, {
+    interval: {
+      get: function() {
+        return _interval;
+      },
+      set: function(v) {
+        _interval = (T.isNumber(v) && v > 0) ? v : _interval;
+      },
+      enumerable: true
+    },
+    untilDate: {
+      get: function() {
+        return _untilDate;
+      },
+      set: function(v) {
+        if (v instanceof tizen.TZDate) {
+          _untilDate = v;
+        }
+      },
+      enumerable: true
+    },
+    occurrenceCount: {
+      get: function() {
+        return _occurrenceCount;
+      },
+      set: function(v) {
+        if (T.isNumber(v) && v >= -1) {
+          _occurrenceCount = v;
+        }
+      },
+      enumerable: true
+    },
+    daysOfTheWeek: {
+      get: function() {
+        return _daysOfTheWeek;
+      },
+      set: function(v) {
+        _daysOfTheWeek = _validateDaysOfTheWeek(v) ? v : _daysOfTheWeek;
+      },
+      enumerable: true
+    },
+    setPositions: {
+      get: function() {
+        return _setPositions;
+      },
+      set: function(v) {
+        _setPositions = _validateSetPositions(v) ? v : _setPositions;
+      },
+      enumerable: true
+    },
+    exceptions: {
+      get: function() {
+        return _exceptions;
+      },
+      set: function(v) {
+        _exceptions = _validateExceptions(v) ? v : _exceptions;
+      },
+      enumerable: true
+    }
+  });
+
+  if (data instanceof Object) {
+    for (var prop in data) {
+      if (this.hasOwnProperty(prop)) {
+        this[prop] = data[prop];
+      }
+    }
+  }
+};
+
+var CalendarRecurrenceRule = function(frequency, ruleInitDict) {
+  AV.isConstructorCall(this, CalendarRecurrenceRule);
+
+  CalendarRecurrenceRuleInit.call(this, ruleInitDict);
+
+  var _frequency = null;
+
+  Object.defineProperties(this, {
+    frequency: {
+      get: function() {
+        return _frequency;
+      },
+      set: function(v) {
+        if (v === null) {
+          return;
+        }
+        _frequency = Converter.toEnum(v, Object.keys(RecurrenceRuleFrequency), false);
+      },
+      enumerable: true
+    }
+  });
+
+  // @todo fix UTC, according to documentation frequency is not optional
+  this.frequency = (!frequency) ? 'DAILY' : frequency;
+};
+
+CalendarRecurrenceRule.prototype = new CalendarRecurrenceRuleInit();
+CalendarRecurrenceRule.prototype.constructor = CalendarRecurrenceRule;
+
+tizen.CalendarRecurrenceRule = CalendarRecurrenceRule;
diff --git a/src/calendar/js/common.js b/src/calendar/js/common.js
new file mode 100644 (file)
index 0000000..66dde08
--- /dev/null
@@ -0,0 +1,292 @@
+// 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 native_ = new xwalk.utils.NativeManager(extension);
+
+
+var EditManager = function() {
+  this.canEdit = false;
+};
+
+EditManager.prototype.allow = function() {
+  this.canEdit = true;
+};
+
+EditManager.prototype.disallow = function() {
+  this.canEdit = false;
+};
+
+var _edit = new EditManager();
+
+var DateConverter = function() {};
+
+DateConverter.prototype.toTZDate = function(v, isAllDay) {
+  if (typeof v === 'number') {
+    v = {
+      UTCTimestamp: v
+        };
+    isAllDay = false;
+  }
+
+  if (!(v instanceof Object)) {
+    return v;
+  }
+
+  if (isAllDay) {
+    return new tizen.TZDate(v.year, v.month, v.day,
+        null, null, null, null, v.timezone || null);
+  } else {
+    return new tizen.TZDate(new Date(v.UTCTimestamp * 1000), 'UTC').toLocalTimezone();
+  }
+};
+
+DateConverter.prototype.fromTZDate = function(v) {
+  if (!(v instanceof tizen.TZDate)) {
+    return v;
+  }
+
+  var utc = v.toUTC();
+  var timestamp = new Date(utc.getFullYear(), utc.getMonth(), utc.getDate(), utc.getHours(),
+      utc.getMinutes(), utc.getSeconds()) / 1000;
+
+  return {
+    year: v.getFullYear(),
+    month: v.getMonth(),
+    day: v.getDate(),
+    timezone: v.getTimezone(),
+    UTCTimestamp: timestamp
+  };
+
+};
+
+var _dateConverter = new DateConverter();
+
+var ItemConverter = function() {};
+
+ItemConverter.prototype.toTizenObject = function(item) {
+  var tmp = {};
+  for (var prop in item) {
+    if (prop === 'startDate' ||
+            prop === 'endDate' ||
+            prop === 'dueDate' ||
+            prop === 'completedDate' ||
+            prop === 'lastModificationDate') {
+      tmp[prop] = _dateConverter.toTZDate(item[prop], item.isAllDay);
+    } else {
+      tmp[prop] = item[prop];
+    }
+  }
+
+  var alarms = [];
+  var alarm, time;
+  for (var i = 0; i < tmp.alarms.length; i++) {
+    alarm = tmp.alarms[i];
+    if (alarm.absoluteDate) {
+      time = _dateConverter.toTZDate(alarm.absoluteDate, tmp.isAllDay);
+    } else if (alarm.before) {
+      time = new tizen.TimeDuration(alarm.before.length, alarm.before.unit);
+    }
+    alarms.push(new tizen.CalendarAlarm(time, alarm.method, alarm.description));
+  }
+  tmp.alarms = alarms;
+
+  var attendees = [];
+  for (var i = 0; i < tmp.attendees.length; i++) {
+    if (tmp.attendees[i].contactRef) {
+      var contactRef = new tizen.ContactRef(tmp.attendees[i].contactRef.addressBookId,
+                                                  tmp.attendees[i].contactRef.contactId);
+      tmp.attendees[i].contactRef = contactRef;
+    }
+    if (tmp.attendees[i].uri) {
+      attendees.push(new tizen.CalendarAttendee(tmp.attendees[i].uri, tmp.attendees[i]));
+    }
+  }
+  tmp.attendees = attendees;
+
+  var untilDate;
+  var exceptions = [];
+  if (tmp.recurrenceRule) {
+    untilDate = _dateConverter.toTZDate(tmp.recurrenceRule.untilDate, tmp.isAllDay);
+    tmp.recurrenceRule.untilDate = untilDate;
+
+    for (var i = 0; i < tmp.recurrenceRule.exceptions.length; i++) {
+      exceptions.push(_dateConverter.toTZDate(tmp.recurrenceRule.exceptions[i], tmp.isAllDay));
+    }
+    tmp.recurrenceRule.exceptions = exceptions;
+
+    var recurrenceRule = new tizen.CalendarRecurrenceRule(tmp.recurrenceRule.frequency, tmp.recurrenceRule);
+    tmp.recurrenceRule = recurrenceRule;
+  }
+
+  if (tmp.duration) {
+    var duration = new tizen.TimeDuration(tmp.duration.length, tmp.duration.unit);
+    tmp.duration = duration;
+  }
+
+  if (tmp.geolocation) {
+    var geolocation = new tizen.SimpleCoordinates(tmp.geolocation.latitude, tmp.geolocation.longitude);
+    tmp.geolocation = geolocation;
+  }
+
+  return tmp;
+};
+
+ItemConverter.prototype.fromTizenObject = function(item) {
+  var tmp = {};
+  for (var prop in item) {
+    if (item[prop] instanceof tizen.TZDate) {
+      tmp[prop] = _dateConverter.fromTZDate(item[prop]);
+    } else if (item[prop] instanceof Array) {
+      tmp[prop] = [];
+      for (var i = 0, length = item[prop].length; i < length; i++) {
+        if (item[prop][i] instanceof Object) {
+          tmp[prop][i] = {};
+          for (var p in item[prop][i]) {
+            if (item[prop][i][p] instanceof tizen.TZDate) {
+              tmp[prop][i][p] = _dateConverter.fromTZDate(item[prop][i][p]);
+            } else {
+              tmp[prop][i][p] = item[prop][i][p];
+            }
+          }
+        } else {
+          tmp[prop] = item[prop];
+        }
+      }
+    } else if (item[prop] instanceof Object) {
+      tmp[prop] = {};
+      for (var p in item[prop]) {
+        if (item[prop][p] instanceof tizen.TZDate) {
+          tmp[prop][p] = _dateConverter.fromTZDate(item[prop][p]);
+        } else if (item[prop][p] instanceof Array) {
+          tmp[prop][p] = [];
+          for (var j = 0, l = item[prop][p].length; j < l; j++) {
+            tmp[prop][p].push(_dateConverter.fromTZDate(item[prop][p][j]));
+          }
+        } else {
+          tmp[prop][p] = item[prop][p];
+        }
+      }
+    } else {
+      tmp[prop] = item[prop];
+    }
+  }
+
+  return tmp;
+};
+
+var _itemConverter = new ItemConverter();
+
+function _daysInYear(y) {
+  if ((y % 4 === 0 && y % 100) || y % 400 === 0) {
+    return 366;
+  }
+  return 365;
+}
+
+function _daysInMonth(m, y) {
+  switch (m) {
+    case 1 :
+      return _daysInYear(y) === 366 ? 29 : 28;
+    case 3 :
+    case 5 :
+    case 8 :
+    case 10 :
+      return 30;
+    default :
+      return 31;
+  }
+}
+
+var RecurrenceManager = function() {};
+
+RecurrenceManager.prototype.get = function(event, startDate, endDate) {
+  var events = [];
+  var frequency = event.recurrenceRule.frequency;
+  var interval = event.recurrenceRule.interval;
+  var untilDate = event.recurrenceRule.untilDate;
+  var occurrenceCount = event.recurrenceRule.occurrenceCount;
+  var exceptions = event.recurrenceRule.exceptions;
+  var isDetached = event.isDetached;
+  var startEvent = event.startDate;
+  var startDate = startDate;
+  var endDate = endDate;
+
+  if (isDetached) {
+    return 'The event is detached.';
+  }
+
+  if (startEvent.laterThan(startDate)) {
+    startDate = startEvent;
+  }
+
+  if (untilDate) {
+    endDate = untilDate.laterThan(endDate) ? endDate : untilDate;
+  }
+
+  var timeDifference = endDate.difference(startDate);
+  var daysDifference = timeDifference.length;
+
+  function checkDays(date) {
+    switch (frequency) {
+      case 'DAILY' :
+        return 1;
+      case 'WEEKLY' :
+        return 7;
+      case 'MONTHLY' :
+        return _daysInMonth(date.getMonth(), date.getFullYear());
+      case 'YEARLY' :
+        return _daysInYear(date.getFullYear());
+    }
+  }
+
+  function checkException(date) {
+    for (var j = 0; j < exceptions.length; j++) {
+      if (exceptions[j].equalsTo(date)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  var dates = [];
+  var date = startDate;
+  var push = true;
+  var _interval = occurrenceCount >= 0 ? occurrenceCount :
+      (daysDifference + 1) / checkDays(startDate);
+
+  for (var i = 0; i < _interval; ++i) {
+    if (exceptions) {
+      checkException(date) ? push = false : null;
+    }
+
+    if (push) {
+      if (endDate.laterThan(date) || endDate.equalsTo(date)) {
+        dates.push(date);
+      }
+    }
+    date = date.addDuration(new tizen.TimeDuration((checkDays(date) * interval), 'DAYS'));
+  }
+
+  var tmp;
+  for (var i = 0; i < dates.length; i++) {
+    tmp = event.clone();
+    _edit.allow();
+    tmp.startDate = dates[i];
+    if (event.id instanceof tizen.CalendarEventId) {
+      tmp.id = new tizen.CalendarEventId(event.id.uid, +new Date());
+      tmp.isDetached = true;
+    }
+    _edit.disallow();
+
+    events.push(tmp);
+  }
+
+  return events;
+};
+
+var _recurrenceManager = new RecurrenceManager();
diff --git a/src/calendar/js/tizen.calendar.Calendar.js b/src/calendar/js/tizen.calendar.Calendar.js
deleted file mode 100644 (file)
index 9833edc..0000000
+++ /dev/null
@@ -1,700 +0,0 @@
-// 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 InternalCalendar = function(data) {
-  Object.defineProperties(this, {
-    accountId: {
-      value: -1,
-      writable: true,
-      enumerable: true
-    },
-    id: {
-      value: null,
-      writable: true,
-      enumerable: true
-    },
-    name: {
-      value: null,
-      writable: true,
-      enumerable: true
-    },
-    type: {
-      value: '',
-      writable: true,
-      enumerable: true
-    },
-    isUnified: {
-      value: false,
-      writable: true,
-      enumerable: true
-    }
-  });
-
-  if (data instanceof Object) {
-    for (var prop in data) {
-      if (this.hasOwnProperty(prop)) {
-        this[prop] = data[prop];
-      }
-    }
-  }
-};
-
-
-// class Calendar
-var Calendar = function(accountId, name, type) {
-  var _data;
-
-  AV.isConstructorCall(this, Calendar);
-
-  if (arguments[0] instanceof InternalCalendar) {
-    _data = arguments[0];
-  } else {
-    var _accountId = Converter.toLong(accountId);
-    var _name = Converter.toString(name);
-    var _type = Converter.toString(type);
-
-    if (arguments.length < 3) {
-      _data = new InternalCalendar();
-    } else {
-      _data = new InternalCalendar({
-                accountId: _accountId,
-                name: _name,
-                type: _type
-      });
-    }
-  }
-
-  Object.defineProperties(this, {
-    accountId: {
-      value: Converter.toLong(_data.accountId),
-      writable: false,
-      enumerable: true
-    },
-    id: {
-      get: function() {
-        return Converter.toString(_data.id, true);
-      },
-      set: function(v) {
-        if (v instanceof InternalCalendar) {
-          _data.id = v.id;
-        }
-      },
-      enumerable: true
-    },
-    name: {
-      value: _data.name,
-      writable: false,
-      enumerable: true
-    },
-    type: {
-      value: _data.type,
-      writable: false,
-      enumerable: false
-    },
-    isUnified: {
-      value: _data.isUnified,
-      writable: false,
-      enumerable: false
-    }
-  });
-};
-
-Calendar.prototype.get = function(id) {
-  var args;
-  if (this.type === CalendarType.TASK) {
-    if (!parseInt(id) || parseInt(id) <= 0) {
-      throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
-    }
-    args = AV.validateArgs(arguments, [{
-      name: 'id',
-      type: AV.Types.STRING
-    }]);
-  } else {
-    args = AV.validateArgs(arguments, [{
-      name: 'id',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: tizen.CalendarEventId
-    }]);
-  }
-
-  var result = native_.callSync('Calendar_get', {
-    calendarId: this.id,
-    id: args.id
-  });
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
-
-  _edit.allow();
-  var item;
-  var _item = native_.getResultObject(result);
-
-  if (this.type === CalendarType.TASK) {
-    item = new CalendarTask(_itemConverter.toTizenObject(_item, _item.isAllDay));
-  } else {
-    item = new CalendarEvent(_itemConverter.toTizenObject(_item, _item.isAllDay));
-  }
-  _edit.disallow();
-
-  return item;
-};
-
-Calendar.prototype.add = function() {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'item',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: [CalendarEvent, CalendarTask]
-    }
-  ]);
-
-  if ((this.type === CalendarType.EVENT && !(args.item instanceof CalendarEvent)) ||
-      (this.type === CalendarType.TASK && !(args.item instanceof CalendarTask))) {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
-        'Invalid item type.');
-  }
-
-  var tmp = _itemConverter.fromTizenObject(args.item);
-  tmp.calendarId = this.id;
-
-  var result = native_.callSync('Calendar_add', {
-    item: tmp,
-    type: this.type
-  });
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
-
-  var _id = native_.getResultObject(result);
-
-  _edit.allow();
-  args.item.calendarId = this.id;
-
-  switch (this.type) {
-    case CalendarType.EVENT:
-      args.item.id = new CalendarEventId(_id.uid, _id.rid);
-      break;
-    case CalendarType.TASK:
-      args.item.id = _id.uid;
-      break;
-  }
-  _edit.disallow();
-};
-
-Calendar.prototype.addBatch = function() {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'items',
-      type: AV.Types.ARRAY,
-      values: (this.type === CalendarType.EVENT)
-                ? tizen.CalendarEvent : tizen.CalendarTask
-    }, {
-      name: 'successCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    }, {
-      name: 'errorCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    }
-  ]);
-
-  var callback = function(result) {
-    if (native_.isFailure(result)) {
-      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
-    } else {
-      _edit.allow();
-      var _ids = native_.getResultObject(result);
-      for (var i = 0; i < args.items.length; i++) {
-        args.items[i].calendarId = this.id;
-        switch (this.type) {
-          case CalendarType.EVENT:
-            args.items[i].id = new CalendarEventId(_ids[i].uid, _ids[i].rid);
-            break;
-          case CalendarType.TASK:
-            args.items[i].id = _ids[i].uid;
-            break;
-        }
-      }
-      _edit.disallow();
-      native_.callIfPossible(args.successCallback, args.items);
-    }
-  }.bind(this);
-
-  var tmp = [];
-  var tmpItem;
-  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))) {
-      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);
-  }
-
-  native_.call('Calendar_addBatch', {
-    type: this.type,
-    items: tmp
-  }, callback);
-
-};
-
-Calendar.prototype.update = function() {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'item',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: [tizen.CalendarEvent, tizen.CalendarTask]
-    },
-    {
-      name: 'updateAllInstances',
-      type: AV.Types.BOOLEAN,
-      optional: true,
-      nullable: true
-    }
-  ]);
-
-  if ((this.type === CalendarType.EVENT && !(args.item instanceof CalendarEvent)) ||
-      (this.type === CalendarType.TASK && !(args.item instanceof CalendarTask))) {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
-      'Invalid item type.');
-  }
-
-  var tmp = _itemConverter.fromTizenObject(args.item);
-  tmp.calendarId = this.id;
-
-  var result = native_.callSync('Calendar_update', {
-    item: tmp,
-    type: this.type,
-    updateAllInstances: (args.has.updateAllInstances)
-            ? Converter.toBoolean(args.updateAllInstances, true)
-            : true
-  });
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
-
-  var _item = native_.getResultObject(result);
-  _edit.allow();
-  for (var prop in _item) {
-    if (args.item.hasOwnProperty(prop)) {
-      args.item[prop] = _item[prop];
-    }
-  }
-  _edit.disallow();
-
-};
-
-Calendar.prototype.updateBatch = function() {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'items',
-      type: AV.Types.ARRAY,
-      values: (this.type === CalendarType.EVENT)
-                ? tizen.CalendarEvent : tizen.CalendarTask
-    },
-    {
-      name: 'successCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    },
-    {
-      name: 'errorCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    },
-    {
-      name: 'updateAllInstances',
-      type: AV.Types.BOOLEAN,
-      optional: true,
-      nullable: true
-    }
-  ]);
-
-  var calendarType = this.type;
-
-  var callback = function(result) {
-    if (native_.isFailure(result)) {
-      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
-      return;
-    }
-
-    native_.callIfPossible(args.successCallback);
-  }.bind(this);
-
-  var tmp = [];
-  var tmpItem;
-  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))) {
-      throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
-        'Invalid item type.');
-    }
-    tmpItem = _itemConverter.fromTizenObject(args.items[i]);
-    tmp.push(tmpItem);
-  }
-
-  native_.call('Calendar_updateBatch', {
-    type: this.type,
-    items: tmp,
-    updateAllInstances: (args.has.updateAllInstances)
-            ? Converter.toBoolean(args.updateAllInstances, true)
-            : true
-  }, callback);
-
-};
-
-Calendar.prototype.remove = function(id) {
-  var args;
-  if (this.type === CalendarType.TASK) {
-    if (!parseInt(id) || parseInt(id) <= 0) {
-      throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR);
-    }
-    args = AV.validateArgs(arguments, [{
-      name: 'id',
-      type: AV.Types.STRING
-    }]);
-  } else {
-    args = AV.validateArgs(arguments, [{
-      name: 'id',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: tizen.CalendarEventId
-    }]);
-  }
-
-  var result = native_.callSync('Calendar_remove', {
-    type: this.type,
-    id: args.id
-  });
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
-};
-
-Calendar.prototype.removeBatch = function() {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'ids',
-      type: AV.Types.ARRAY,
-      values: (this.type === CalendarType.EVENT)
-                ? tizen.CalendarEventId : undefined
-    },
-    {
-      name: 'successCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    },
-    {
-      name: 'errorCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    }
-  ]);
-
-  var callback = function(result) {
-    if (native_.isFailure(result)) {
-      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
-    } else {
-      native_.callIfPossible(args.successCallback);
-    }
-  };
-
-  native_.call('Calendar_removeBatch', {
-    type: this.type,
-    ids: args.ids
-  }, callback);
-
-};
-
-Calendar.prototype.find = function(successCallback, errorCallback, filter, sortMode) {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'successCallback',
-      type: AV.Types.FUNCTION
-    },
-    {
-      name: 'errorCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    },
-    {
-      name: 'filter',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: [tizen.AttributeFilter, tizen.AttributeRangeFilter, tizen.CompositeFilter],
-      optional: true,
-      nullable: true
-    },
-    {
-      name: 'sortMode',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: tizen.SortMode,
-      optional: true,
-      nullable: true
-    }
-  ]);
-  //TODO: Move sorting and filtering to native code
-  var C = {};
-  C.sort = function (arr, sortMode) {
-    var _getSortProperty = function (obj, props) {
-      for (var i = 0; i < props.length; ++i) {
-        if (!obj.hasOwnProperty(props[i])) {
-          return null;
-        }
-        obj = obj[props[i]];
-      }
-      return obj;
-    };
-
-    if (sortMode instanceof tizen.SortMode) {
-      var props = sortMode.attributeName.split('.');
-      arr.sort(function (a, b) {
-        var aValue = _getSortProperty(a, props);
-        var bValue = _getSortProperty(b, props);
-
-        if (sortMode.order === 'DESC') {
-          return aValue < bValue;
-        }
-        return bValue < aValue;
-      });
-    }
-    return arr;
-  };
-
-  C.filter = function (arr, filter) {
-    if (T.isNullOrUndefined(arr))
-      return arr;
-    if (filter instanceof tizen.AttributeFilter ||
-            filter instanceof tizen.AttributeRangeFilter ||
-            filter instanceof tizen.CompositeFilter) {
-      arr = arr.filter(function (element) {
-          return filter._filter(element);
-      });
-    }
-    return arr;
-  };
-
-  var calendarType = this.type;
-
-  var callback = function(result) {
-    if (native_.isFailure(result)) {
-      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
-    } else {
-      var _items = native_.getResultObject(result);
-      var c = [];
-      _edit.allow();
-      _items.forEach(function(i) {
-        if (calendarType === CalendarType.TASK) {
-          c.push(new CalendarTask(_itemConverter.toTizenObject(i, i.isAllDay)));
-        } else {
-          c.push(new CalendarEvent(_itemConverter.toTizenObject(i, i.isAllDay)));
-        }
-      });
-      _edit.disallow();
-      //TODO: Move sorting and filtering to native code
-      c = C.filter(c, args.filter); // NYA: due to commit dependency
-      c = C.sort(c, args.sortMode);
-      args.successCallback(c);
-
-    }
-  };
-  native_.call('Calendar_find', {
-    calendarId: this.id,
-    filter: args.filter,
-    sortMode: args.sortMode
-  }, callback);
-
-};
-
-var _listeners = {};
-// @todo this could be replaced by _taskListeners & _eventListeners
-var _nativeListeners = {};
-var _nextId = 0;
-
-function _CalendarEventChangeCallback(event) {
-  _CalendarChangeCallback('EVENT', event);
-}
-function _CalendarTaskChangeCallback(event) {
-  _CalendarChangeCallback('TASK', event);
-}
-function _CalendarChangeCallback(type, event) {
-  var invokeListeners = function(listeners, callbackName, items) {
-    var result = [];
-    _edit.allow();
-    for (var i = 0, length = items.length; i < length; i++) {
-      var item;
-
-      if (callbackName === 'onitemsremoved') {
-        if (type === 'EVENT') {
-          item = new CalendarEventId(items[i].id, null);
-        } else {
-          item = Converter.toString(items[i].id);
-        }
-      } else {
-        item = _itemConverter.toTizenObject(items[i], items[i].isAllDay);
-        if (type === 'EVENT') {
-          item = new CalendarEvent(item);
-        } else {
-          item = new CalendarTask(item);
-        }
-      }
-
-      result.push(item);
-    }
-    _edit.disallow();
-
-    for (var watchId in listeners) {
-      if (listeners.hasOwnProperty(watchId)) {
-        native_.callIfPossible(listeners[watchId][callbackName], result);
-      }
-    }
-  }.bind(this);
-
-  var groupItemsByCalendar = function(items) {
-    var grouped = {};
-
-    for (var i = 0, length = items.length; i < length; i++) {
-      var item = items[i];
-
-      // skip item if we are not listening on this calendarId
-      if (!_listeners.hasOwnProperty(item.calendarId)) {
-        continue;
-      }
-
-      if (!grouped.hasOwnProperty(item.calendarId)) {
-        grouped[item.calendarId] = [];
-      }
-      grouped[item.calendarId].push(item);
-    }
-
-    return grouped;
-  }.bind(this);
-
-  var actions = ['added', 'updated', 'removed'];
-  for (var i = 0; i < actions.length; i++) {
-    var action = actions[i];
-    var callback = 'onitems' + action;
-
-    if (event.hasOwnProperty(action) && T.isArray(event[action]) && event[action].length) {
-
-      // invoke listeners for unified calendars
-      if (_listeners.hasOwnProperty(type)) {
-        invokeListeners(_listeners[type], callback, event[action]);
-      }
-
-      var groupedItems = groupItemsByCalendar(event[action]);
-      for (var calendarId in groupedItems) {
-        if (groupedItems.hasOwnProperty(calendarId)) {
-          invokeListeners(_listeners[calendarId], callback, groupedItems[calendarId]);
-        }
-      }
-    }
-  }
-}
-
-Calendar.prototype.addChangeListener = function() {
-  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 = native_.callSync('Calendar_addChangeListener', {
-      type: this.type,
-      listenerId: listenerId
-    });
-    if (native_.isFailure(result)) {
-      throw native_.getErrorObject(result);
-    }
-
-    native_.addListener(listenerId, (this.type === 'EVENT')
-            ? _CalendarEventChangeCallback
-            : _CalendarTaskChangeCallback);
-    _nativeListeners[listenerId] = this.type;
-  }
-
-  // we can't use id in case of unified calendar - which is null for both calendar types
-  var calendarId = (this.isUnified) ? this.type : this.id;
-  if (!_listeners.hasOwnProperty(calendarId)) {
-    _listeners[calendarId] = {};
-  }
-
-  var watchId = ++_nextId;
-  _listeners[calendarId][watchId] = args.successCallback;
-
-  return watchId;
-};
-
-Calendar.prototype.removeChangeListener = function() {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'watchId',
-      type: AV.Types.LONG
-    }
-  ]);
-
-  var watchId = Converter.toString(args.watchId);
-  var calendarId = (this.isUnified) ? this.type : this.id;
-
-  if (!_listeners[calendarId] || !_listeners[calendarId][watchId]) {
-    return;
-  }
-
-  delete _listeners[calendarId][watchId];
-
-  if (T.isEmptyObject(_listeners[calendarId])) {
-    delete _listeners[calendarId];
-  }
-
-  if (T.isEmptyObject(_listeners)) {
-
-    var result;
-    // @todo consider listener unregister when we are not listening on this.type of calendar
-    var fail = false;
-    for (var listenerId in _nativeListeners) {
-      if (_nativeListeners.hasOwnProperty(listenerId)) {
-        result = native_.callSync('Calendar_removeChangeListener', {
-          type: _nativeListeners[listenerId]
-        });
-        if (native_.isFailure(result)) {
-          fail = native_.getErrorObject(result);
-        }
-        native_.removeListener(listenerId, (this.type === 'EVENT')
-                    ? _CalendarEventChangeCallback
-                    : _CalendarTaskChangeCallback);
-
-        delete _nativeListeners[listenerId];
-      }
-    }
-
-    if (fail) {
-      throw fail;
-    }
-  }
-};
-
-tizen.Calendar = Calendar;
diff --git a/src/calendar/js/tizen.calendar.CalendarAlarm.js b/src/calendar/js/tizen.calendar.CalendarAlarm.js
deleted file mode 100644 (file)
index b9ac85d..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-// 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',
-  DISPLAY: 'DISPLAY'
-};
-
-var CalendarAlarm = function(time, method, description) {
-  AV.isConstructorCall(this, CalendarAlarm);
-
-  var _absoluteDate = time instanceof tizen.TZDate && !this.before ? time : null;
-  var _before = time instanceof tizen.TimeDuration && !this.absoluteDate ? time : null;
-  var _method = Converter.toEnum(method, Object.keys(AlarmMethod), false);
-  var _description = (description) ? Converter.toString(description, true) : '';
-
-  Object.defineProperties(this, {
-    absoluteDate: {
-      get: function() {
-        return _absoluteDate;
-      },
-      set: function(v) {
-        _absoluteDate = v instanceof tizen.TZDate && !_before ? v : null;
-      },
-      enumerable: true
-    },
-    before: {
-      get: function() {
-        return _before;
-      },
-      set: function(v) {
-        _before = v instanceof tizen.TimeDuration && !_absoluteDate ? v : null;
-      },
-      enumerable: true
-    },
-    method: {
-      get: function() {
-        return _method;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _method = Converter.toEnum(v, Object.keys(AlarmMethod), false);
-      },
-      enumerable: true
-    },
-    description: {
-      get: function() {
-        return _description;
-      },
-      set: function(v) {
-        _description = Converter.toString(v, true);
-      },
-      enumerable: true
-    }
-  });
-};
-
-tizen.CalendarAlarm = CalendarAlarm;
diff --git a/src/calendar/js/tizen.calendar.CalendarAttendee.js b/src/calendar/js/tizen.calendar.CalendarAttendee.js
deleted file mode 100644 (file)
index 8575764..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-// 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',
-  GROUP: 'GROUP',
-  RESOURCE: 'RESOURCE',
-  ROOM: 'ROOM',
-  UNKNOWN: 'UNKNOWN'
-};
-
-var AttendeeStatus = {
-  PENDING: 'PENDING',
-  ACCEPTED: 'ACCEPTED',
-  DECLINED: 'DECLINED',
-  TENTATIVE: 'TENTATIVE',
-  DELEGATED: 'DELEGATED',
-  COMPLETED: 'COMPLETED',
-  IN_PROCESS: 'IN_PROCESS'
-};
-
-var AttendeeRole = {
-  REQ_PARTICIPANT: 'REQ_PARTICIPANT',
-  OPT_PARTICIPANT: 'OPT_PARTICIPANT',
-  NON_PARTICIPANT: 'NON_PARTICIPANT',
-  CHAIR: 'CHAIR'
-};
-
-var CalendarAttendeeInit = function(data) {
-  var _name = null;
-  var _role = 'REQ_PARTICIPANT';
-  var _status = 'PENDING';
-  var _RSVP = false;
-  var _type = 'INDIVIDUAL';
-  var _group = null;
-  var _delegatorURI = null;
-  var _delegateURI = null;
-  var _contactRef = null;
-
-  Object.defineProperties(this, {
-    name: {
-      get: function() {
-        return _name;
-      },
-      set: function(v) {
-        _name = Converter.toString(v, true);
-      },
-      enumerable: true
-    },
-    role: {
-      get: function() {
-        return _role;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _role = Converter.toEnum(v, Object.keys(AttendeeRole), false);
-      },
-      enumerable: true
-    },
-    status: {
-      get: function() {
-        return _status;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _status = Converter.toEnum(v, Object.keys(AttendeeStatus), false);
-      },
-      enumerable: true
-    },
-    RSVP: {
-      get: function() {
-        return _RSVP;
-      },
-      set: function(v) {
-        _RSVP = Converter.toBoolean(v);
-      },
-      enumerable: true
-    },
-    type: {
-      get: function() {
-        return _type;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _type = Converter.toEnum(v, Object.keys(AttendeeType), false);
-      },
-      enumerable: true
-    },
-    group: {
-      get: function() {
-        return _group;
-      },
-      set: function(v) {
-        _group = Converter.toString(v, true);
-      },
-      enumerable: true
-    },
-    delegatorURI: {
-      get: function() {
-        return _delegatorURI;
-      },
-      set: function(v) {
-        _delegatorURI = Converter.toString(v, true);
-      },
-      enumerable: true
-    },
-    delegateURI: {
-      get: function() {
-        return _delegateURI;
-      },
-      set: function(v) {
-        _delegateURI = Converter.toString(v, true);
-      },
-      enumerable: true
-    },
-    contactRef: {
-      get: function() {
-        return _contactRef;
-      },
-      set: function(v) {
-        _contactRef = v instanceof tizen.ContactRef ? v : _contactRef;
-      },
-      enumerable: true
-    }
-  });
-
-  if (data instanceof Object) {
-    for (var prop in data) {
-      if (this.hasOwnProperty(prop)) {
-        this[prop] = data[prop];
-      }
-    }
-  }
-};
-
-var CalendarAttendee = function(uri, attendeeInitDict) {
-  AV.isConstructorCall(this, CalendarAttendee);
-
-  CalendarAttendeeInit.call(this, attendeeInitDict);
-
-  var _uri = null;
-
-  Object.defineProperties(this, {
-    uri: {
-      get: function() {
-        return _uri;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _uri = Converter.toString(v, true);
-      },
-      enumerable: true
-    }
-  });
-
-  this.uri = uri;
-};
-
-CalendarAttendee.prototype = new CalendarAttendeeInit();
-CalendarAttendee.prototype.constructor = CalendarAttendee;
-
-tizen.CalendarAttendee = CalendarAttendee;
diff --git a/src/calendar/js/tizen.calendar.CalendarItem.js b/src/calendar/js/tizen.calendar.CalendarItem.js
deleted file mode 100644 (file)
index c7de25d..0000000
+++ /dev/null
@@ -1,733 +0,0 @@
-// 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',
-  VCALENDAR_10: 'VCALENDAR_10'
-};
-
-var CalendarItemVisibility = {
-  PUBLIC: 'PUBLIC', //default
-  PRIVATE: 'PRIVATE',
-  CONFIDENTIAL: 'CONFIDENTIAL'
-};
-
-var CalendarItemPriority = {
-  HIGH: 'HIGH',
-  MEDIUM: 'MEDIUM',
-  LOW: 'LOW' //default
-};
-
-var CalendarItemStatus = {
-  TENTATIVE: 'TENTATIVE',
-  CONFIRMED: 'CONFIRMED', //default for CalendarEvent
-  CANCELLED: 'CANCELLED',
-  NEEDS_ACTION: 'NEEDS_ACTION', //default for CalendarTask
-  IN_PROCESS: 'IN_PROCESS',
-  COMPLETED: 'COMPLETED'
-};
-
-var EventAvailability = {
-  BUSY: 'BUSY', //default for CalendarEvent
-  FREE: 'FREE'
-};
-
-var CalendarEventId = function(uid, rid) {
-  AV.isConstructorCall(this, CalendarEventId);
-
-  var _uid = null;
-
-  Object.defineProperties(this, {
-    uid: {
-      get: function() {
-        return _uid;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _uid = Converter.toString(v, true);
-      },
-      enumerable: true
-    },
-    rid: {
-      value: (rid) ? Converter.toString(rid, true) : null,
-      writable: true,
-      enumerable: true
-    }
-  });
-
-  this.uid = uid;
-};
-
-// class CalendarItem
-var CalendarItem = function(data) {
-  var _id = null;
-  var _calendarId = null;
-  var _lastModificationDate = null;
-  var _description = '';
-  var _summary = '';
-  var _isAllDay = false;
-  var _startDate = null;
-  var _duration = null;
-  var _location = '';
-  var _geolocation = null;
-  var _organizer = '';
-  var _visibility = CalendarItemVisibility.PUBLIC;
-  var _status = CalendarItemStatus.CONFIRMED;
-  var _priority = CalendarItemPriority.LOW;
-  var _alarms = [];
-  var _categories = [];
-  var _attendees = [];
-
-  function _validateAlarms(v) {
-    var valid = false;
-
-    if (T.isArray(v)) {
-      for (var i = 0; i < v.length; i++) {
-        if (!(v[i] instanceof tizen.CalendarAlarm)) {
-          return false;
-        }
-      }
-      valid = true;
-    }
-    return valid;
-  }
-
-  function _validateAttendees(v) {
-    var valid = false;
-
-    if (T.isArray(v)) {
-      for (var i = 0; i < v.length; i++) {
-        if (!(v[i] instanceof tizen.CalendarAttendee)) {
-          return false;
-        }
-      }
-      valid = true;
-    }
-    return valid;
-  }
-
-  function _validateCategories(v) {
-    var valid = false;
-
-    if (T.isArray(v)) {
-      for (var i = 0; i < v.length; i++) {
-        if (!(T.isString(v[i]))) {
-          return false;
-        }
-      }
-      valid = true;
-    }
-    return valid;
-  }
-
-  Object.defineProperties(this, {
-    id: {
-      get: function() {
-        return _id;
-      },
-      set: function(v) {
-        if (_edit.canEdit) {
-          if (v instanceof Object) {
-            _id = new CalendarEventId(v.uid, v.rid);
-          } else {
-            _id = Converter.toString(v, true);
-          }
-        }
-      },
-      enumerable: true
-    },
-    calendarId: {
-      get: function() {
-        return _calendarId;
-      },
-      set: function(v) {
-        if (_edit.canEdit) {
-          _calendarId = v;
-        }
-      },
-      enumerable: true
-    },
-    lastModificationDate: {
-      get: function() {
-        return _lastModificationDate;
-      },
-      set: function(v) {
-        if (_edit.canEdit) {
-          _lastModificationDate = v instanceof tizen.TZDate ? v :
-              tizen.time.getCurrentDateTime();
-        }
-      },
-      enumerable: true
-    },
-    description: {
-      get: function() {
-        return _description;
-      },
-      set: function(v) {
-        _description = v ? Converter.toString(v, true) : _description;
-      },
-      enumerable: true
-    },
-    summary: {
-      get: function() {
-        return _summary;
-      },
-      set: function(v) {
-        _summary = v ? Converter.toString(v, true) : _summary;
-      },
-      enumerable: true
-    },
-    isAllDay: {
-      get: function() {
-        return _isAllDay;
-      },
-      set: function(v) {
-        _isAllDay = v ? Converter.toBoolean(v) : _isAllDay;
-      },
-      enumerable: true
-    },
-    startDate: {
-      get: function() {
-        return _startDate;
-      },
-      set: function(v) {
-        _startDate = v instanceof tizen.TZDate ? v : _startDate;
-        this.duration = _duration;
-      },
-      enumerable: true
-    },
-    duration: {
-      get: function() {
-        return _duration;
-      },
-      set: function(v) {
-        // set duration as dueDate or endDate
-        var _startDate = this.startDate ?
-            this.startDate : tizen.time.getCurrentDateTime();
-        if (this instanceof tizen.CalendarEvent) {
-          this.endDate = v instanceof tizen.TimeDuration ?
-              _startDate.addDuration(v) : this.endDate;
-        } else {
-          this.dueDate = v instanceof tizen.TimeDuration ?
-              _startDate.addDuration(v) : this.dueDate;
-        }
-        _duration = v instanceof tizen.TimeDuration ? v : null;
-        //@todo Fix UTC, UTC expect duration value but according to documentation:
-        // ... the implementation may not save the duration itself,
-        // rather convert it to the corresponding endDate/dueDate attribute and save it.
-        // For example, if you set the startDate and the duration attributes and save the item,
-        // you may see that the duration is null while endDate/dueDate is non-null
-        // after retrieving it because the implementation has calculated the endDate/dueDate
-        // based on the duration and the startDate then saved it, not the duration.
-      },
-      enumerable: true
-    },
-    location: {
-      get: function() {
-        return _location;
-      },
-      set: function(v) {
-        _location = v ? Converter.toString(v) : _location;
-      },
-      enumerable: true
-    },
-    geolocation: {
-      get: function() {
-        return _geolocation;
-      },
-      set: function(v) {
-        _geolocation = v instanceof tizen.SimpleCoordinates ? v : _geolocation;
-      },
-      enumerable: true
-    },
-    organizer: {
-      get: function() {
-        return _organizer;
-      },
-      set: function(v) {
-        _organizer = v ? Converter.toString(v) : _organizer;
-      },
-      enumerable: true
-    },
-    visibility: {
-      get: function() {
-        return _visibility;
-      },
-      set: function(v) {
-        _visibility = v ? Converter.toEnum(v, Object.keys(CalendarItemVisibility), false) :
-                _visibility;
-      },
-      enumerable: true
-    },
-    status: {
-      get: function() {
-        return _status;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        if (this instanceof tizen.CalendarEvent) {
-          _status = v ? Converter.toEnum(v, Object.keys(CalendarItemStatus).slice(0, 3), false) :
-                        CalendarItemStatus.CONFIRMED;
-        } else {
-          _status = v ? Converter.toEnum(v, Object.keys(CalendarItemStatus).slice(2), false) :
-                        CalendarItemStatus.NEEDS_ACTION;
-        }
-      },
-      enumerable: true
-    },
-    priority: {
-      get: function() {
-        return _priority;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _priority = v ? Converter.toEnum(v, Object.keys(CalendarItemPriority), false) :
-                    _status;
-      },
-      enumerable: true
-    },
-    alarms: {
-      get: function() {
-        return _alarms;
-      },
-      set: function(v) {
-        _alarms = _validateAlarms(v) ? v : _alarms;
-      },
-      enumerable: true
-    },
-    categories: {
-      get: function() {
-        return _categories;
-      },
-      set: function(v) {
-        _categories = _validateCategories(v) ? v : _categories;
-      },
-      enumerable: true
-    },
-    attendees: {
-      get: function() {
-        return _attendees;
-      },
-      set: function(v) {
-        _attendees = _validateAttendees(v) ? v : _attendees;
-      },
-      enumerable: true
-    }
-  });
-
-  if (data instanceof Object) {
-    for (var prop in data) {
-      if (this.hasOwnProperty(prop)) {
-        this[prop] = data[prop];
-      }
-    }
-  }
-
-};
-
-CalendarItem.prototype.convertToString = function() {
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'format',
-      type: AV.Types.ENUM,
-      values: Object.keys(CalendarTextFormat)
-    }
-  ]);
-
-  var _checkNumber = function(n) {
-    return n < 10 ? '0' + n : n;
-  };
-
-  var _timeFormat = function(d) {
-    return ';TZID=' + d.getTimezone() +
-        ':' + d.getFullYear() + _checkNumber(d.getMonth()) + _checkNumber(d.getDate()) +
-            'T' + _checkNumber(d.getHours()) + _checkNumber(d.getMinutes()) +
-            _checkNumber(d.getSeconds() + 'Z');
-  };
-
-  var _this = this;
-  var _dtStart = '';
-
-  if (_this.startDate) {
-    _dtStart = _timeFormat(_this.startDate);
-  } else {
-    _dtStart = _timeFormat(tizen.time.getCurrentDateTime());
-  }
-
-  var _dtEnd = _dtStart;
-
-  if (_this.endDate) {
-    _dtEnd = _timeFormat(_this.endDate);
-  } else if (_this.dueDate) {
-    _dtEnd = _timeFormat(_this.dueDate);
-  }
-
-  var _description = _this.description.length ? ':' + _this.description : '';
-  var _location = _this.location.length ? ':' + _this.location : '';
-  var _organizer = _this.organizer.length ? ';CN=' + _this.organizer : '';
-  var _priority = _this.priority.length ? ':' + _this.priority : '';
-  var _summary = _this.summary.length ? ':' + _this.summary : '';
-  var _categories = _this.categories.length ? ':' + _this.categories.join(', ') : '';
-  var _visibility = _this.visibility;
-  var _status = _this.status;
-  var _version = args.format === CalendarTextFormat.ICALENDAR_20 ? ':2.0' : ':1.0';
-
-  var vEven = [
-    'BEGIN:VCALENDAR',
-    'VERSION' + _version,
-    'BEGIN:VEVENT',
-    'CLASS:' + _visibility,
-    'TRANSP:OPAQUE',
-    'DTSTART' + _dtStart,
-    'DESCRIPTION' + _description,
-    'LOCATION' + _location,
-    'ORGANIZER' + _organizer,
-    'PRIORITY' + _priority,
-    'SUMMARY' + _summary,
-    'DTEND' + _dtEnd,
-    'CATEGORIES' + _categories,
-    'END:VEVENT',
-    'END:VCALENDAR'
-  ].join('\n');
-
-  var vTodo = [
-    'BEGIN:VCALENDAR',
-    'VERSION' + _version,
-    'BEGIN:VTODO',
-    'SUMMARY' + _summary,
-    'DUE' + _dtEnd,
-    'STATUS' + _status,
-    'END:VTODO',
-    'END:VCALENDAR'
-  ].join('\n');
-
-  if (this instanceof tizen.CalendarTask) {
-    return vTodo;
-  } else {
-    return vEven;
-  }
-
-};
-
-CalendarItem.prototype.clone = function() {
-  var tmp = _itemConverter.toTizenObject(_itemConverter.fromTizenObject(this));
-
-  tmp.id = null;
-
-  return this instanceof tizen.CalendarEvent ? new tizen.CalendarEvent(tmp) :
-      new tizen.CalendarTask(tmp);
-};
-
-function _convertFromStringToItem(str) {
-  if (str.indexOf('VCALENDAR') === -1) {
-    console.logd('Wrong format');
-    return;
-  }
-
-  var _startDate = null;
-  var _description = '';
-  var _location = null;
-  var _organizer = null;
-  var _priority = null;
-  var _summary = null;
-  var _categories = [];
-  var _visibility = null;
-  var _status = null;
-  var _endDate = null;
-  var _dueDate = null;
-  var sep;
-
-  if (str.indexOf('\r\n') > -1) {
-    sep = '\r\n';
-  } else if (str.indexOf('\n') > -1) {
-    sep = '\n';
-  } else {
-    console.logd('Wrong separator');
-    return;
-  }
-
-  function _convertTime(v) {
-    var y = parseInt(v.substring(0, 4) , 10);
-    var m = parseInt(v.substring(4, 6) , 10);
-    var d = parseInt(v.substring(6, 8) , 10);
-    var h = parseInt(v.substring(9, 11) , 10);
-    var n = parseInt(v.substring(11, 13) , 10);
-    var s = parseInt(v.substring(13, 15) , 10);
-
-    return new tizen.TZDate(y, m, d, h, n, s);
-  }
-
-  var arr = str.split(sep);
-
-  for (var i = 0; i < arr.length; i++) {
-    if (arr[i].indexOf('SUMMARY') > -1) {
-      _summary = arr[i].split(':')[1];
-    } else if (arr[i].indexOf('CATEGORIES') > -1) {
-      var c = arr[i].split(':')[1];
-      _categories = c.split(',');
-    } else if (arr[i].indexOf('ORGANIZER') > -1) {
-      _organizer = arr[i].split('=')[1];
-    } else if (arr[i].indexOf('DESCRIPTION') > -1) {
-      _description = arr[i].split(':')[1];
-    } else if (arr[i].indexOf('CLASS') > -1) {
-      _visibility = arr[i].split(':')[1];
-    } else if (arr[i].indexOf('LOCATION') > -1) {
-      _location = arr[i].split(':')[1];
-    } else if (arr[i].indexOf('PRIORITY') > -1) {
-      _priority = arr[i].split(':')[1];
-    } else if (arr[i].indexOf('STATUS') > -1) {
-      _status = arr[i].split(':')[1];
-    } else if (arr[i].indexOf('DTSTART') > -1) {
-      _startDate = _convertTime(arr[i].split(':')[1]);
-    } else if (arr[i].indexOf('DTEND') > -1) {
-      _endDate = _convertTime(arr[i].split(':')[1]);
-    } else if (arr[i].indexOf('DUE') > -1) {
-      _dueDate = _convertTime(arr[i].split(':')[1]);
-    }
-  }
-
-  return {
-    visibility: _visibility,
-    startDate: _startDate,
-    description: _description,
-    location: _location,
-    organizer: _organizer,
-    priority: _priority,
-    summary: _summary,
-    status: _status,
-    categories: _categories,
-    endDate: _endDate,
-    dueDate: _dueDate
-  };
-
-}
-
-var CalendarTaskInit = function(data) {
-  CalendarItem.call(this, {
-    status: CalendarItemStatus.NEEDS_ACTION
-  });
-
-  var _dueDate = null;
-  var _completedDate = null;
-  var _progress = 0;
-
-  Object.defineProperties(this, {
-    dueDate: {
-      get: function() {
-        return _dueDate;
-      },
-      set: function(v) {
-        if (!v instanceof tizen.TZDate && this.startDate) {
-          v = this.startDate;
-        }
-
-        _dueDate = v instanceof tizen.TZDate ? v : _dueDate;
-      },
-      enumerable: true
-    },
-    completedDate: {
-      get: function() {
-        return _completedDate;
-      },
-      set: function(v) {
-        _completedDate = v instanceof tizen.TZDate ? v : _completedDate;
-      },
-      enumerable: true
-    },
-    progress: {
-      get: function() {
-        return _progress;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _progress = (T.isNumber(v) && (v >= 0 || v <= 100)) ? v : _progress;
-      },
-      enumerable: true
-    }
-  });
-
-  if (data instanceof Object) {
-    for (var prop in data) {
-      if (this.hasOwnProperty(prop)) {
-        this[prop] = data[prop];
-      }
-    }
-  }
-};
-
-var CalendarTask = function(taskInitDict, format) {
-  AV.isConstructorCall(this, CalendarTask);
-
-  if (T.isString(taskInitDict) && Object.keys(CalendarTextFormat).indexOf(format) > -1) {
-    CalendarTaskInit.call(this, _convertFromStringToItem(taskInitDict));
-  } else {
-    CalendarTaskInit.call(this, taskInitDict);
-  }
-};
-
-CalendarTask.prototype = new CalendarItem();
-CalendarTask.prototype.constructor = CalendarTask;
-
-
-var CalendarEventInit = function(data) {
-  CalendarItem.call(this, {
-    status: CalendarItemStatus.CONFIRMED
-  });
-
-  var _isDetached = false;
-  var _endDate = null;
-  var _availability = EventAvailability.BUSY;
-  var _recurrenceRule = null;
-
-  var _validateReccurence = function(v) {
-    if (_isDetached && v !== null) {
-      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) {
-      return v;
-    } else {
-      return _recurrenceRule;
-    }
-  };
-
-  Object.defineProperties(this, {
-    isDetached: {
-      get: function() {
-        return _isDetached;
-      },
-      set: function(v) {
-        if (_edit.canEdit) {
-          _isDetached = v;
-        }
-      },
-      enumerable: true
-    },
-    endDate: {
-      get: function() {
-        return _endDate;
-      },
-      set: function(v) {
-        if (!v instanceof tizen.TZDate && this.startDate) {
-          v = this.startDate;
-        }
-
-        _endDate = v instanceof tizen.TZDate ? v : _endDate;
-      },
-      enumerable: true
-    },
-    availability: {
-      get: function() {
-        return _availability;
-      },
-      set: function(v) {
-        _availability = Object.keys(EventAvailability).indexOf(v) > -1 ? v :
-                _availability;
-      },
-      enumerable: true
-    },
-    recurrenceRule: {
-      get: function() {
-        return _recurrenceRule;
-      },
-      set: function(v) {
-        _recurrenceRule = _validateReccurence(v);
-      },
-      enumerable: true
-    }
-  });
-
-  if (data instanceof Object) {
-    for (var prop in data) {
-      if (this.hasOwnProperty(prop)) {
-        this[prop] = data[prop];
-      }
-    }
-  }
-};
-
-var CalendarEvent = function(eventInitDict, format) {
-  AV.isConstructorCall(this, CalendarEvent);
-
-  if (T.isString(eventInitDict) && Object.keys(CalendarTextFormat).indexOf(format) > -1) {
-    CalendarEventInit.call(this, _convertFromStringToItem(eventInitDict));
-  } else {
-    CalendarEventInit.call(this, eventInitDict);
-  }
-};
-
-CalendarEvent.prototype = new CalendarItem();
-CalendarEvent.prototype.constructor = CalendarEvent;
-
-CalendarEvent.prototype.expandRecurrence = function(startDate, endDate, successCallback, errorCallback) {
-  if (arguments.length < 3) {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
-  if (!(startDate instanceof tizen.TZDate)) {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
-  if (!(endDate instanceof tizen.TZDate)) {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
-  if (typeof successCallback !== 'function') {
-    throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-  }
-  if (errorCallback) {
-    if (typeof errorCallback !== 'function') {
-      throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
-    }
-  }
-  if (!(this.recurrenceRule instanceof tizen.CalendarRecurrenceRule)) {
-    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
-      'The event is not recurring.');
-  }
-
-  var args = AV.validateArgs(arguments, [
-    {
-      name: 'startDate',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: tizen.TZDate
-    },
-    {
-      name: 'endDate',
-      type: AV.Types.PLATFORM_OBJECT,
-      values: tizen.TZDate
-    },
-    {
-      name: 'successCallback',
-      type: AV.Types.FUNCTION,
-      nullable: true
-    },
-    {
-      name: 'errorCallback',
-      type: AV.Types.FUNCTION,
-      optional: true,
-      nullable: true
-    }
-  ]);
-
-  // invoke callbacks in "next tick"
-  setTimeout(function() {
-    var result = _recurrenceManager.get(this, startDate, endDate);
-
-    if (result instanceof Array) {
-      args.successCallback(result);
-    } else if (args.errorCallback) {
-      args.errorCallback(result);
-    }
-  }.bind(this), 1);
-};
-
-tizen.CalendarEventId = CalendarEventId;
-tizen.CalendarEvent = CalendarEvent;
-tizen.CalendarTask = CalendarTask;
diff --git a/src/calendar/js/tizen.calendar.CalendarManager.js b/src/calendar/js/tizen.calendar.CalendarManager.js
deleted file mode 100644 (file)
index b6e0f49..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-// 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() {};
-
-// IDs defined in C-API calendar_types2.h
-var DefaultCalendarId = {
-  EVENT: 1, // DEFAULT_EVENT_CALENDAR_BOOK_ID
-  TASK: 2 // DEFAULT_TODO_CALENDAR_BOOK_ID
-};
-
-CalendarManager.prototype.getCalendars = function() {
-  var args = AV.validateArgs(arguments, [{
-    name: 'type',
-    type: AV.Types.ENUM,
-    values: Object.keys(CalendarType)
-  },
-  {
-    name: 'successCallback',
-    type: AV.Types.FUNCTION
-  },
-  {
-    name: 'errorCallback',
-    type: AV.Types.FUNCTION,
-    optional: true,
-    nullable: true
-  }]);
-
-  var callArgs = {
-    type: args.type
-  };
-
-  var callback = function(result) {
-    if (native_.isFailure(result)) {
-      native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
-    } else {
-      var calendars = native_.getResultObject(result);
-      var c = [];
-      calendars.forEach(function(i) {
-        c.push(new Calendar(new InternalCalendar(i)));
-      });
-      args.successCallback(c);
-    }
-  };
-
-  native_.call('CalendarManager_getCalendars', callArgs, callback);
-};
-
-CalendarManager.prototype.getUnifiedCalendar = function() {
-
-  var args = AV.validateArgs(arguments, [{
-    name: 'type',
-    type: AV.Types.ENUM,
-    values: Object.keys(CalendarType)
-  }]);
-
-  return new Calendar(new InternalCalendar({
-    type: args.type,
-    isUnified: true
-  }));
-};
-
-CalendarManager.prototype.getDefaultCalendar = function() {
-
-  var args = AV.validateArgs(arguments, [{
-    name: 'type',
-    type: AV.Types.ENUM,
-    values: Object.keys(CalendarType)
-  }
-  ]);
-
-  return this.getCalendar(args.type, DefaultCalendarId[args.type]);
-};
-
-CalendarManager.prototype.getCalendar = function() {
-
-  var args = AV.validateArgs(arguments, [{
-    name: 'type',
-    type: AV.Types.ENUM,
-    values: Object.keys(CalendarType)
-  },
-  {
-    name: 'id',
-    type: AV.Types.STRING
-  }
-  ]);
-
-  var callArgs = {
-    type: args.type,
-    id: args.id
-  };
-
-  var result = native_.callSync('CalendarManager_getCalendar', callArgs);
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
-
-  return new Calendar(new InternalCalendar(native_.getResultObject(result)));
-};
-
-CalendarManager.prototype.addCalendar = function() {
-
-  var args = AV.validateArgs(arguments, [{
-    name: 'calendar',
-    type: AV.Types.PLATFORM_OBJECT,
-    values: Calendar
-  }]);
-
-  var callArgs = {
-    calendar: args.calendar
-  };
-
-  var result = native_.callSync('CalendarManager_addCalendar', callArgs);
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
-
-  args.calendar.id = new InternalCalendar({
-    id: native_.getResultObject(result)
-  });
-};
-
-CalendarManager.prototype.removeCalendar = function() {
-
-  var args = AV.validateArgs(arguments, [{
-    name: 'type',
-    type: AV.Types.ENUM,
-    values: Object.keys(CalendarType)
-  },
-  {
-    name: 'id',
-    type: AV.Types.STRING
-  }
-  ]);
-
-  var callArgs = {
-    type: args.type,
-    id: args.id
-  };
-
-  var result = native_.callSync('CalendarManager_removeCalendar', callArgs);
-
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
-};
-
-exports = new CalendarManager();
diff --git a/src/calendar/js/tizen.calendar.CalendarRecurrenceRule.js b/src/calendar/js/tizen.calendar.CalendarRecurrenceRule.js
deleted file mode 100644 (file)
index 7e6950a..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-// 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',
-  WEEKLY: 'WEEKLY',
-  MONTHLY: 'MONTHLY',
-  YEARLY: 'YEARLY'
-};
-
-var ByDayValue = {
-  MO: 'MO',
-  TU: 'TU',
-  WE: 'WE',
-  TH: 'TH',
-  FR: 'FR',
-  SA: 'SA',
-  SU: 'SU'
-};
-
-var CalendarRecurrenceRuleInit = function(data) {
-  var _interval = 1;
-  var _untilDate = null;
-  var _daysOfTheWeek = [];
-  var _occurrenceCount = -1;
-  var _setPositions = [];
-  var _exceptions = [];
-
-  function _validateDaysOfTheWeek(v) {
-    if (T.isArray(v)) {
-      var allowedValues = Object.keys(ByDayValue);
-      for (var i = 0; i < v.length; ++i) {
-        if (allowedValues.indexOf(v[i]) < 0) {
-          return false;
-        }
-      }
-      return true;
-    }
-
-    return false;
-  }
-
-  function _validateSetPositions(v) {
-    var valid = false;
-
-    if (T.isArray(v)) {
-      for (var i = 0; i < v.length; i++) {
-        v[i] = parseInt(v[i]);
-        if (isNaN(v[i]) || (v[i] < -366 || v[i] > 366 || v[i] === 0)) {
-          return false;
-        }
-      }
-      valid = true;
-    }
-    return valid;
-  }
-
-  function _validateExceptions(v) {
-    var valid = false;
-
-    if (T.isArray(v)) {
-      for (var i = 0; i < v.length; i++) {
-        if (!(v[i] instanceof tizen.TZDate)) {
-          return false;
-        }
-      }
-      valid = true;
-    }
-    return valid;
-  }
-
-  Object.defineProperties(this, {
-    interval: {
-      get: function() {
-        return _interval;
-      },
-      set: function(v) {
-        _interval = (T.isNumber(v) && v > 0) ? v : _interval;
-      },
-      enumerable: true
-    },
-    untilDate: {
-      get: function() {
-        return _untilDate;
-      },
-      set: function(v) {
-        if (v instanceof tizen.TZDate) {
-          _untilDate = v;
-        }
-      },
-      enumerable: true
-    },
-    occurrenceCount: {
-      get: function() {
-        return _occurrenceCount;
-      },
-      set: function(v) {
-        if (T.isNumber(v) && v >= -1) {
-          _occurrenceCount = v;
-        }
-      },
-      enumerable: true
-    },
-    daysOfTheWeek: {
-      get: function() {
-        return _daysOfTheWeek;
-      },
-      set: function(v) {
-        _daysOfTheWeek = _validateDaysOfTheWeek(v) ? v : _daysOfTheWeek;
-      },
-      enumerable: true
-    },
-    setPositions: {
-      get: function() {
-        return _setPositions;
-      },
-      set: function(v) {
-        _setPositions = _validateSetPositions(v) ? v : _setPositions;
-      },
-      enumerable: true
-    },
-    exceptions: {
-      get: function() {
-        return _exceptions;
-      },
-      set: function(v) {
-        _exceptions = _validateExceptions(v) ? v : _exceptions;
-      },
-      enumerable: true
-    }
-  });
-
-  if (data instanceof Object) {
-    for (var prop in data) {
-      if (this.hasOwnProperty(prop)) {
-        this[prop] = data[prop];
-      }
-    }
-  }
-};
-
-var CalendarRecurrenceRule = function(frequency, ruleInitDict) {
-  AV.isConstructorCall(this, CalendarRecurrenceRule);
-
-  CalendarRecurrenceRuleInit.call(this, ruleInitDict);
-
-  var _frequency = null;
-
-  Object.defineProperties(this, {
-    frequency: {
-      get: function() {
-        return _frequency;
-      },
-      set: function(v) {
-        if (v === null) {
-          return;
-        }
-        _frequency = Converter.toEnum(v, Object.keys(RecurrenceRuleFrequency), false);
-      },
-      enumerable: true
-    }
-  });
-
-  // @todo fix UTC, according to documentation frequency is not optional
-  this.frequency = (!frequency) ? 'DAILY' : frequency;
-};
-
-CalendarRecurrenceRule.prototype = new CalendarRecurrenceRuleInit();
-CalendarRecurrenceRule.prototype.constructor = CalendarRecurrenceRule;
-
-tizen.CalendarRecurrenceRule = CalendarRecurrenceRule;
diff --git a/src/calendar/js/tizen.calendar.Common.js b/src/calendar/js/tizen.calendar.Common.js
deleted file mode 100644 (file)
index 66dde08..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-// 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 native_ = new xwalk.utils.NativeManager(extension);
-
-
-var EditManager = function() {
-  this.canEdit = false;
-};
-
-EditManager.prototype.allow = function() {
-  this.canEdit = true;
-};
-
-EditManager.prototype.disallow = function() {
-  this.canEdit = false;
-};
-
-var _edit = new EditManager();
-
-var DateConverter = function() {};
-
-DateConverter.prototype.toTZDate = function(v, isAllDay) {
-  if (typeof v === 'number') {
-    v = {
-      UTCTimestamp: v
-        };
-    isAllDay = false;
-  }
-
-  if (!(v instanceof Object)) {
-    return v;
-  }
-
-  if (isAllDay) {
-    return new tizen.TZDate(v.year, v.month, v.day,
-        null, null, null, null, v.timezone || null);
-  } else {
-    return new tizen.TZDate(new Date(v.UTCTimestamp * 1000), 'UTC').toLocalTimezone();
-  }
-};
-
-DateConverter.prototype.fromTZDate = function(v) {
-  if (!(v instanceof tizen.TZDate)) {
-    return v;
-  }
-
-  var utc = v.toUTC();
-  var timestamp = new Date(utc.getFullYear(), utc.getMonth(), utc.getDate(), utc.getHours(),
-      utc.getMinutes(), utc.getSeconds()) / 1000;
-
-  return {
-    year: v.getFullYear(),
-    month: v.getMonth(),
-    day: v.getDate(),
-    timezone: v.getTimezone(),
-    UTCTimestamp: timestamp
-  };
-
-};
-
-var _dateConverter = new DateConverter();
-
-var ItemConverter = function() {};
-
-ItemConverter.prototype.toTizenObject = function(item) {
-  var tmp = {};
-  for (var prop in item) {
-    if (prop === 'startDate' ||
-            prop === 'endDate' ||
-            prop === 'dueDate' ||
-            prop === 'completedDate' ||
-            prop === 'lastModificationDate') {
-      tmp[prop] = _dateConverter.toTZDate(item[prop], item.isAllDay);
-    } else {
-      tmp[prop] = item[prop];
-    }
-  }
-
-  var alarms = [];
-  var alarm, time;
-  for (var i = 0; i < tmp.alarms.length; i++) {
-    alarm = tmp.alarms[i];
-    if (alarm.absoluteDate) {
-      time = _dateConverter.toTZDate(alarm.absoluteDate, tmp.isAllDay);
-    } else if (alarm.before) {
-      time = new tizen.TimeDuration(alarm.before.length, alarm.before.unit);
-    }
-    alarms.push(new tizen.CalendarAlarm(time, alarm.method, alarm.description));
-  }
-  tmp.alarms = alarms;
-
-  var attendees = [];
-  for (var i = 0; i < tmp.attendees.length; i++) {
-    if (tmp.attendees[i].contactRef) {
-      var contactRef = new tizen.ContactRef(tmp.attendees[i].contactRef.addressBookId,
-                                                  tmp.attendees[i].contactRef.contactId);
-      tmp.attendees[i].contactRef = contactRef;
-    }
-    if (tmp.attendees[i].uri) {
-      attendees.push(new tizen.CalendarAttendee(tmp.attendees[i].uri, tmp.attendees[i]));
-    }
-  }
-  tmp.attendees = attendees;
-
-  var untilDate;
-  var exceptions = [];
-  if (tmp.recurrenceRule) {
-    untilDate = _dateConverter.toTZDate(tmp.recurrenceRule.untilDate, tmp.isAllDay);
-    tmp.recurrenceRule.untilDate = untilDate;
-
-    for (var i = 0; i < tmp.recurrenceRule.exceptions.length; i++) {
-      exceptions.push(_dateConverter.toTZDate(tmp.recurrenceRule.exceptions[i], tmp.isAllDay));
-    }
-    tmp.recurrenceRule.exceptions = exceptions;
-
-    var recurrenceRule = new tizen.CalendarRecurrenceRule(tmp.recurrenceRule.frequency, tmp.recurrenceRule);
-    tmp.recurrenceRule = recurrenceRule;
-  }
-
-  if (tmp.duration) {
-    var duration = new tizen.TimeDuration(tmp.duration.length, tmp.duration.unit);
-    tmp.duration = duration;
-  }
-
-  if (tmp.geolocation) {
-    var geolocation = new tizen.SimpleCoordinates(tmp.geolocation.latitude, tmp.geolocation.longitude);
-    tmp.geolocation = geolocation;
-  }
-
-  return tmp;
-};
-
-ItemConverter.prototype.fromTizenObject = function(item) {
-  var tmp = {};
-  for (var prop in item) {
-    if (item[prop] instanceof tizen.TZDate) {
-      tmp[prop] = _dateConverter.fromTZDate(item[prop]);
-    } else if (item[prop] instanceof Array) {
-      tmp[prop] = [];
-      for (var i = 0, length = item[prop].length; i < length; i++) {
-        if (item[prop][i] instanceof Object) {
-          tmp[prop][i] = {};
-          for (var p in item[prop][i]) {
-            if (item[prop][i][p] instanceof tizen.TZDate) {
-              tmp[prop][i][p] = _dateConverter.fromTZDate(item[prop][i][p]);
-            } else {
-              tmp[prop][i][p] = item[prop][i][p];
-            }
-          }
-        } else {
-          tmp[prop] = item[prop];
-        }
-      }
-    } else if (item[prop] instanceof Object) {
-      tmp[prop] = {};
-      for (var p in item[prop]) {
-        if (item[prop][p] instanceof tizen.TZDate) {
-          tmp[prop][p] = _dateConverter.fromTZDate(item[prop][p]);
-        } else if (item[prop][p] instanceof Array) {
-          tmp[prop][p] = [];
-          for (var j = 0, l = item[prop][p].length; j < l; j++) {
-            tmp[prop][p].push(_dateConverter.fromTZDate(item[prop][p][j]));
-          }
-        } else {
-          tmp[prop][p] = item[prop][p];
-        }
-      }
-    } else {
-      tmp[prop] = item[prop];
-    }
-  }
-
-  return tmp;
-};
-
-var _itemConverter = new ItemConverter();
-
-function _daysInYear(y) {
-  if ((y % 4 === 0 && y % 100) || y % 400 === 0) {
-    return 366;
-  }
-  return 365;
-}
-
-function _daysInMonth(m, y) {
-  switch (m) {
-    case 1 :
-      return _daysInYear(y) === 366 ? 29 : 28;
-    case 3 :
-    case 5 :
-    case 8 :
-    case 10 :
-      return 30;
-    default :
-      return 31;
-  }
-}
-
-var RecurrenceManager = function() {};
-
-RecurrenceManager.prototype.get = function(event, startDate, endDate) {
-  var events = [];
-  var frequency = event.recurrenceRule.frequency;
-  var interval = event.recurrenceRule.interval;
-  var untilDate = event.recurrenceRule.untilDate;
-  var occurrenceCount = event.recurrenceRule.occurrenceCount;
-  var exceptions = event.recurrenceRule.exceptions;
-  var isDetached = event.isDetached;
-  var startEvent = event.startDate;
-  var startDate = startDate;
-  var endDate = endDate;
-
-  if (isDetached) {
-    return 'The event is detached.';
-  }
-
-  if (startEvent.laterThan(startDate)) {
-    startDate = startEvent;
-  }
-
-  if (untilDate) {
-    endDate = untilDate.laterThan(endDate) ? endDate : untilDate;
-  }
-
-  var timeDifference = endDate.difference(startDate);
-  var daysDifference = timeDifference.length;
-
-  function checkDays(date) {
-    switch (frequency) {
-      case 'DAILY' :
-        return 1;
-      case 'WEEKLY' :
-        return 7;
-      case 'MONTHLY' :
-        return _daysInMonth(date.getMonth(), date.getFullYear());
-      case 'YEARLY' :
-        return _daysInYear(date.getFullYear());
-    }
-  }
-
-  function checkException(date) {
-    for (var j = 0; j < exceptions.length; j++) {
-      if (exceptions[j].equalsTo(date)) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  var dates = [];
-  var date = startDate;
-  var push = true;
-  var _interval = occurrenceCount >= 0 ? occurrenceCount :
-      (daysDifference + 1) / checkDays(startDate);
-
-  for (var i = 0; i < _interval; ++i) {
-    if (exceptions) {
-      checkException(date) ? push = false : null;
-    }
-
-    if (push) {
-      if (endDate.laterThan(date) || endDate.equalsTo(date)) {
-        dates.push(date);
-      }
-    }
-    date = date.addDuration(new tizen.TimeDuration((checkDays(date) * interval), 'DAYS'));
-  }
-
-  var tmp;
-  for (var i = 0; i < dates.length; i++) {
-    tmp = event.clone();
-    _edit.allow();
-    tmp.startDate = dates[i];
-    if (event.id instanceof tizen.CalendarEventId) {
-      tmp.id = new tizen.CalendarEventId(event.id.uid, +new Date());
-      tmp.isDetached = true;
-    }
-    _edit.disallow();
-
-    events.push(tmp);
-  }
-
-  return events;
-};
-
-var _recurrenceManager = new RecurrenceManager();