//= require('tizen.contact.Common.js');
//= require('tizen.contact.ContactDataStructures.js');
-//= require('tizen.contact.AddressBook.js');
//= require('tizen.contact.Contact.js');
+//= require('tizen.contact.AddressBook.js');
//= require('tizen.contact.Person.js');
//= require('tizen.contact.ContactManager.js');
ContactExtension::ContactExtension() {
SetExtensionName("tizen.contact");
SetJavaScriptAPI(kSource_contact_api);
+
+ const char* entry_points[] = {
+ "tizen.ContactRef",
+ "tizen.ContactName",
+ "tizen.ContactOrganization",
+ "tizen.ContactWebSite",
+ "tizen.ContactAnniversary",
+ "tizen.ContactAddress",
+ "tizen.ContactPhoneNumber",
+ "tizen.ContactEmailAddress",
+ "tizen.ContactGroup",
+ "tizen.ContactRelationship",
+ "tizen.ContactInstantMessenger",
+ "tizen.Contact",
+ "tizen.AddressBook",
+ "tizen.Person",
+ NULL
+ };
+ SetExtraJSEntryPoints(entry_points);
}
ContactExtension::~ContactExtension() {}
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// import ContactClass /////////////////////////////////////////////////////
-var _contact = require('./tizen.contact.Contact');
-var Contact = _contact.Contact;
-_contact = undefined;
-
-// Import auxiliary classes for Contact
-var _dataStructures = require('./tizen.contact.ContactDataStructures');
-var ContactGroup = _dataStructures.group;
-var ContactName = _dataStructures.name;
-_dataStructures = undefined;
-
-// import flag /////////////////////////////////////////////////////////////
-var _struct = require('./tizen.contact.ContactDataStructures');
-var _editGuard = _struct.editGuard;
-var _toJsonObject = _struct.toJsonObject;
-var _getNextWatchId = _struct.getNextWatchId;
-var _promote = _struct.promote;
-_struct = undefined;
-
-var _registered = false;
-var _listenerId = 'ContactChangeListener';
+var _contactListenerRegistered = false;
var _contactCallbackMap = {};
var _filterById = function(array, id) {
if (_contactCallbackMap.hasOwnProperty(unifiedId)) {
for (watchId in _contactCallbackMap[unifiedId]) {
if (_contactCallbackMap[unifiedId].hasOwnProperty(watchId)) {
+ var callback = _contactCallbackMap[unifiedId][watchId].successCallback;
if (result.added.length) {
- Common.callIfPossible(_contactCallbackMap[unifiedId][watchId]
- .successCallback.oncontactsadded,
- _promote(result.added, Contact));
+ native_.callIfPossible(callback.oncontactsadded, _promote(result.added, Contact));
}
if (result.updated.length) {
- Common.callIfPossible(_contactCallbackMap[unifiedId][watchId]
- .successCallback.oncontactsupdated,
- _promote(result.updated, Contact));
+ native_.callIfPossible(callback.oncontactsupdated, _promote(result.updated, Contact));
}
if (result.removed.length) {
var allRemoved = [];
for (i = 0; i < result.removed.length; ++i) {
allRemoved.push(result.removed[i].id);
}
- Common.callIfPossible(_contactCallbackMap[unifiedId][watchId]
- .successCallback.oncontactsremoved,
- result.allRemoved);
+ native_.callIfPossible(callback.oncontactsremoved, result.allRemoved);
}
}
}
for (watchId in _contactCallbackMap[callbackAddressbookId]) {
if (_contactCallbackMap[callbackAddressbookId].hasOwnProperty(watchId)) {
+ var callback = _contactCallbackMap[callbackAddressbookId][watchId].successCallback;
if (filteredAdded.length) {
- Common.callIfPossible(
- _contactCallbackMap[callbackAddressbookId][watchId]
- .successCallback.oncontactsadded,
- filteredAdded);
+ native_.callIfPossible(callback.oncontactsadded, filteredAdded);
}
if (filteredUpdated.length) {
- Common.callIfPossible(
- _contactCallbackMap[callbackAddressbookId][watchId]
- .successCallback.oncontactsupdated,
- filteredUpdated);
+ native_.callIfPossible(callback.oncontactsupdated, filteredUpdated);
}
if (filteredRemoved.length) {
- Common.callIfPossible(
- _contactCallbackMap[callbackAddressbookId][watchId]
- .successCallback.oncontactsremoved,
- filteredRemoved);
+ native_.callIfPossible(callback.oncontactsremoved, filteredRemoved);
}
}
}
}
};
-// class AddressBook ///////////////////////////////////////////////////////
var AddressBook = function(id, name, readOnly) {
- AV.validateConstructorCall(this, AddressBook);
+ AV.isConstructorCall(this, AddressBook);
var _id = '';
var _name = '';
};
AddressBook.prototype.get = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'id',
type: AV.Types.STRING,
}
]);
- var result = _callSync('AddressBook_get', {
+ var result = native_.callSync('AddressBook_get', {
// TODO move to only sending the address book id (in all functions)
addressBook: this,
id: args.id
});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
return _editGuard.run(function() {
- var contact = new Contact(Common.getResultObject(result));
+ var contact = new Contact(native_.getResultObject(result));
if (contact.name instanceof ContactName) {
contact.name.displayName = '';
};
AddressBook.prototype.add = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'contact',
type: AV.Types.PLATFORM_OBJECT,
}
]);
- var result = _callSync('AddressBook_add', {
+ var result = native_.callSync('AddressBook_add', {
// TODO move to only sending the address book id (in all functions)
addressBook: this,
contact: _toJsonObject(args.contact)
});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
- var _updatedContact = Common.getResultObject(result);
+ var _updatedContact = native_.getResultObject(result);
_editGuard.run(function() {
for (var prop in _updatedContact) {
if (args.contact.hasOwnProperty(prop)) {
};
AddressBook.prototype.addBatch = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'contacts',
type: AV.Types.ARRAY,
]);
var callback = function(result) {
- if (Common.isFailure(result)) {
- Common.callIfPossible(args.errorCallback, Common.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
_editGuard.run(function() {
- var _result = Common.getResultObject(result);
+ var _result = native_.getResultObject(result);
for (var i = 0; i < _result.length; ++i) {
for (var prop in _result[i]) {
if (args.contacts[i].hasOwnProperty(prop)) {
}
});
- Common.callIfPossible(args.successCallback, args.contacts);
+ native_.callIfPossible(args.successCallback, args.contacts);
};
- var result = _call('AddressBook_addBatch',
+ var result = native_.call('AddressBook_addBatch',
{addressBookId: this.id, batchArgs: _toJsonObject(args.contacts) },
callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
AddressBook.prototype.update = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'contact',
type: AV.Types.PLATFORM_OBJECT,
}
]);
- var result = _callSync('AddressBook_update', {
+ var result = native_.callSync('AddressBook_update', {
addressBook: this,
contact: _toJsonObject(args.contact)
});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
- var _updatedContact = Common.getResultObject(result);
+ var _updatedContact = native_.getResultObject(result);
_editGuard.run(function() {
for (var prop in _updatedContact) {
if (args.contact.hasOwnProperty(prop)) {
};
AddressBook.prototype.updateBatch = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'contacts',
type: AV.Types.ARRAY,
]);
var callback = function(result) {
- if (Common.isFailure(result)) {
- Common.callIfPossible(args.errorCallback, Common.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
_editGuard.run(function() {
- var _result = Common.getResultObject(result);
+ var _result = native_.getResultObject(result);
for (var i = 0; i < _result.length; ++i) {
for (var prop in _result[i].result) {
if (args.contacts[i].hasOwnProperty(prop)) {
}
});
- Common.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback);
};
- var result = _call('AddressBook_updateBatch',
+ var result = native_.call('AddressBook_updateBatch',
{addressBook: this, batchArgs: _toJsonObject(args.contacts) },
callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
AddressBook.prototype.remove = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'id',
type: AV.Types.STRING,
}
]);
- var result = _callSync('AddressBook_remove', {
+ var result = native_.callSync('AddressBook_remove', {
addressBook: this,
id: args.id
});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
AddressBook.prototype.removeBatch = function(ids, successCallback, errorCallback) {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'ids',
type: AV.Types.ARRAY,
]);
var callback = function(result) {
- if (Common.isFailure(result)) {
- Common.callIfPossible(args.errorCallback, Common.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- Common.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback);
};
- var result = _call('AddressBook_removeBatch',
+ var result = native_.call('AddressBook_removeBatch',
{addressBook: this, batchArgs: args.ids },
callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
AddressBook.prototype.find = function(successCallback, errorCallback, filter, sortMode) {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'successCallback',
type: AV.Types.FUNCTION,
var self = this;
var callback = function(result) {
- if (Common.isFailure(result)) {
- Common.callIfPossible(errorCallback, Common.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(errorCallback, native_.getErrorObject(result));
}
var _contacts = [];
- var _result = Common.getResultObject(result);
+ var _result = native_.getResultObject(result);
_result.forEach(function(data) {
try {
_contacts.push(self.get(String(data)));
});
//TODO: Move filtering to native code
- try {
- _contacts = Common.filter(_contacts, args.filter);
- } catch (e) {
- Common.callIfPossible(errorCallback, e);
- return;
- }
+ //try {
+ // _contacts = Common.filter(_contacts, args.filter);
+ //} catch (e) {
+ // native_.callIfPossible(errorCallback, e);
+ // return;
+ //}
//TODO: Move sorting to native code
- _contacts = Common.sort(_contacts, args.sortMode);
+ //_contacts = Common.sort(_contacts, args.sortMode);
- Common.callIfPossible(successCallback, _contacts);
+ native_.callIfPossible(successCallback, _contacts);
};
- var result = _call('AddressBook_find',
+ var result = native_.call('AddressBook_find',
{addressBook: this, filter: filter, sortMode: sortMode},
callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
AddressBook.prototype.addChangeListener = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'successCallback',
type: AV.Types.LISTENER,
]);
if (Type.isEmptyObject(_contactCallbackMap)) {
- var result = _callSync('AddressBook_startListening', {});
+ var result = native_.callSync('AddressBook_startListening', {});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
}
- if (!_registered) {
- native.addListener(_listenerId, _contactChangeListener);
- _registered = true;
+ if (!_contactListenerRegistered) {
+ native_.addListener('ContactChangeListener', _contactChangeListener);
+ _contactListenerRegistered = true;
}
if (!_contactCallbackMap.hasOwnProperty(this.id)) {
};
AddressBook.prototype.removeChangeListener = function(watchId) {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'watchId',
type: AV.Types.LONG,
]);
if (args.watchId === 0) {
- Common.throwInvalidValues('id is null or undefined');
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+ 'id is null or undefined');
}
if (args.watchId < 0) {
- Common.throwInvalidValues('Negative watch id');
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+ 'Negative watch id');
}
if (!_contactCallbackMap.hasOwnProperty(this.id) ||
!_contactCallbackMap[this.id].hasOwnProperty(args.watchId)) {
- Common.throwNotFound('watch id not found for this address book');
+ throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR,
+ 'watch id not found for this address book');
}
delete _contactCallbackMap[this.id][args.watchId];
}
if (Type.isEmptyObject(_contactCallbackMap)) {
- native.removeListener(_listenerId, _contactChangeListener);
- _registered = false;
+ native_.removeListener('ContactChangeListener', _contactChangeListener);
+ _contactListenerRegistered = false;
- var result = _callSync('AddressBook_stopListening', {});
+ var result = native_.callSync('AddressBook_stopListening', {});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
}
};
AddressBook.prototype.getGroup = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'groupId',
type: AV.Types.STRING,
}
]);
- var result = _callSync('AddressBook_getGroup',
+ var result = native_.callSync('AddressBook_getGroup',
{addressBook: this, id: args.groupId});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
return _editGuard.run(function() {
- return new ContactGroup(Common.getResultObject(result));
+ return new ContactGroup(native_.getResultObject(result));
});
};
AddressBook.prototype.addGroup = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'group',
type: AV.Types.PLATFORM_OBJECT,
}
]);
- var result = _callSync('AddressBook_addGroup',
+ var result = native_.callSync('AddressBook_addGroup',
{addressBookId: this.id, group: args.group});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
_editGuard.run(function() {
- result = Common.getResultObject(result);
+ result = native_.getResultObject(result);
args.group.id = result.id;
args.group.addressBookId = result.addressBookId;
});
};
AddressBook.prototype.updateGroup = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'group',
type: AV.Types.PLATFORM_OBJECT,
}
]);
- var result = _callSync('AddressBook_updateGroup',
+ var result = native_.callSync('AddressBook_updateGroup',
{addressBookId: this.id, group: args.group});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
AddressBook.prototype.removeGroup = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'groupId',
type: AV.Types.STRING,
}
]);
- var result = _callSync('AddressBook_removeGroup',
+ var result = native_.callSync('AddressBook_removeGroup',
{addressBook: this, id: args.groupId});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
AddressBook.prototype.getGroups = function() {
- var result = _callSync('AddressBook_getGroups', {addressBook: this});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ var result = native_.callSync('AddressBook_getGroups', {addressBook: this});
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
- result = Common.getResultObject(result);
+ result = native_.getResultObject(result);
var _tab = [];
_editGuard.run(function() {
result.forEach(function(data) {
-/* global xwalk */
+/* global xwalk, extension */
// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
var Type = _common.type;
var Converter = _common.converter;
var AV = _common.validator;
-var Common = _common.Common;
-var _callSync = Common.getCallSync('contact');
-var _call = Common.getCall('contact');
+
+var native_ = new _common.NativeManager(extension);
var _currentWatchId = 1;
};
function _checkError(result) {
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
}
EditGuard.prototype.enable = function() {
_canEdit++;
- console.log('RAISING LEVEL TO ' + _canEdit);
};
EditGuard.prototype.disable = function() {
_canEdit--;
- console.log('LOWERING LEVEL TO ' + _canEdit);
};
EditGuard.prototype.isEditEnabled = function() {
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-function _checkError(result) {
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
- }
-}
-
-var TypeEnum = ['VCARD_30'];
-
-// import flag and auxiliary Contact classes ///////////////////////////////
-var _dataStructures = require('./tizen.contact.ContactDataStructures');
-var ContactRef = _dataStructures.ref;
-var ContactGroup = _dataStructures.group;
-var ContactEmailAddress = _dataStructures.emailAddress;
-var ContactPhoneNumber = _dataStructures.phoneNumber;
-var ContactAddress = _dataStructures.address;
-var ContactAnniversary = _dataStructures.anniversary;
-var ContactRelationship = _dataStructures.relationship;
-var ContactInstantMessenger = _dataStructures.instantMessenger;
-var ContactWebSite = _dataStructures.webSite;
-var ContactOrganization = _dataStructures.organization;
-var ContactName = _dataStructures.name;
-var _editGuard = _dataStructures.editGuard;
-var _fromJsonDate = _dataStructures.fromJsonDate;
-_dataStructures = undefined;
-
-// class Contact ///////////////////////////////////////////////////////////
var Contact = function(data) {
- AV.validateConstructorCall(this, Contact);
+ AV.isConstructorCall(this, Contact);
- var val;
var _forceEditMode = false;
if (Type.isString(data)) {
- var result = _callSync('ContactManager_importFromVCard', {
+ var result = native_.callSync('ContactManager_importFromVCard', {
'contact': data
});
_checkError(result);
- data = Common.getResultObject(result);
+ data = native_.getResultObject(result);
// These need to be forced to null as a contact created from a vcard is not added
// to any address book
data.id = null;
// Force edit mode so that anonymous objects can be promoted to their correct types.
_forceEditMode = true;
} else if (Type.isObject(data) || Type.isFunction(data)) {
- // It's a dictionary
+ // It's a dictionary
} else {
// null or invalid types.
data = {};
}
-
var _id = null;
var _personId = null;
var _addressBookId = null;
for (var i = 0; i < arr.length; ++i) {
if (Type.isString(type)) {
if (!Type.isString(arr[i])) {
- return previousValue;
+ return previousValue;
}
} else if (_editGuard.isEditEnabled()) {
arr[i] = new type(arr[i]);
},
set: function(v) {
if (_editGuard.isEditEnabled()) {
- _id = Converter.toString(v, false);
+ _id = Converter.toString(v, false);
}
},
enumerable: true
},
set: function(v) {
if (_editGuard.isEditEnabled()) {
- _personId = Converter.toString(v, false);
+ _personId = Converter.toString(v, false);
}
},
enumerable: true
},
set: function(v) {
if (_editGuard.isEditEnabled()) {
- _addressBookId = Converter.toString(v, false);
+ _addressBookId = Converter.toString(v, false);
}
},
enumerable: true
},
set: function(v) {
if (_editGuard.isEditEnabled()) {
- if (v instanceof Date || v === null) {
+ if (v instanceof Date || v === null) {
_lastUpdate = v;
- } else if (Type.isString(v)) {
+ } else if (Type.isString(v)) {
_lastUpdate = new Date(v);
- } else {
+ } else {
_lastUpdate = _fromJsonDate(v);
- }
+ }
}
},
enumerable: true
},
set: function(v) {
if (_editGuard.isEditEnabled()) {
- _isFavorite = Converter.toBoolean(v, false);
+ _isFavorite = Converter.toBoolean(v, false);
}
},
enumerable: true
},
set: function(v) {
if (_editGuard.isEditEnabled()) {
- _name = new ContactName(v);
+ _name = new ContactName(v);
} else {
- _name = (v instanceof ContactName || v === null) ? v : _name;
+ _name = (v instanceof ContactName || v === null) ? v : _name;
}
},
enumerable: true
},
set: function(v) {
if (v instanceof Date || v === null) {
- _birthday = v;
+ _birthday = v;
} else if (Type.isString(v)) {
- _birthday = new Date(v);
+ _birthday = new Date(v);
} else if (_editGuard.isEditEnabled()) {
- _birthday = _fromJsonDate(v);
+ _birthday = _fromJsonDate(v);
}
},
enumerable: true
var str = '';
for (var mail in obj.emails) {
if (!mail instanceof ContactEmailAddress || !Type.isArray(mail.types) ||
- mail.types.length === 0) {
+ mail.types.length === 0) {
console.log('Incorrect email type');
continue;
}
// Convert organizations info from Contact object to string
var _contactOrganizationToString = function(obj) {
if (obj.organizations.length === 0 ||
- !obj.organizations[0] instanceof ContactOrganization) {
+ !obj.organizations[0] instanceof ContactOrganization) {
return '';
}
var str = '';
// Convert organizations roles from Contact object to string
var _contactRoleToString = function(obj) {
if (obj.organizations.length === 0 ||
- !obj.organizations[0] instanceof ContactOrganization) {
+ !obj.organizations[0] instanceof ContactOrganization) {
return '';
}
var str = '';
// Convert relationships to string
var _contactRelationshipsToString = function(obj) {
if (obj.relationships.length === 0 ||
- !obj.relationships[0] instanceof ContactRelationship) {
+ !obj.relationships[0] instanceof ContactRelationship) {
return '';
}
var str = '';
for (var rel in obj.relationships) {
if (rel instanceof ContactRelationship) {
str += 'X-RELATIONSHIP;' + rel.relativeName + ':' + rel.type +
- ':' + rel.label + ';\n';
+ ':' + rel.label + ';\n';
}
}
return str;
for (var messenger in obj.messengers) {
if (messenger instanceof ContactInstantMessenger) {
str += 'X-MESSANGER;' + messenger.imAddress + ':' + messenger.type +
- ':' + messenger.label + ';\n';
+ ':' + messenger.label + ';\n';
}
}
return str;
Contact.prototype.convertToString = function(format) {
if (arguments.length) {
if (!Type.isString(format)) {
- Common.throwTypeMismatch('Invalid format type');
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+ 'Invalid format type');
}
if (TypeEnum.indexOf(format) < 0) {
- Common.throwTypeMismatch('Invalid format');
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+ 'Invalid format');
}
} else {
console.logd('No format selected. Default VCARD 3.0 has been set');
}
if (this.id === '') {
- Common.throwTypeMismatch('Contact ID is empty.');
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR,
+ 'Contact ID is empty.');
}
var str = 'BEGIN:VCARD\nVERSION:3.0\n';
// set contact name
str += 'N:' + this.name.lastName + ';' + this.name.firstName + ';' +
- this.name.middleName + ';' + this.name.prefix + ';' + this.name.suffix + '\n';
+ this.name.middleName + ';' + this.name.prefix + ';' + this.name.suffix + '\n';
str += 'FN' + this.name.displayName + '\n';
// set phonetic names
str += 'X-PHONETIC-FIRST-NAME' + this.name.phoneticFirstName + '\n' +
- 'X-PHONETIC-LAST-NAME' + this.name.phoneticLastName + '\n';
+ 'X-PHONETIC-LAST-NAME' + this.name.phoneticLastName + '\n';
// set contact address
str += _contactAddressToString(this);
// set Birthday
if (this.birthday) {
str += 'BDAY:' + this.birthday.getYear() + '-' + this.birthday.getMonth() +
- '-' + this.birthday.getDay() + '\n';
+ '-' + this.birthday.getDay() + '\n';
}
// set anniversary
// set last revision
str += 'REV:' + this.lastUpdated.getYear() + '-' + this.lastUpdated.getMonth() +
- '-' + this.lastUpdated.getDay() + 'T' + this.lastUpdated.getHours() + ':' +
- this.lastUpdated.getMinutes() + ':' + this.lastUpdated.getSeconds() + 'Z\n';
+ '-' + this.lastUpdated.getDay() + 'T' + this.lastUpdated.getHours() + ':' +
+ this.lastUpdated.getMinutes() + ':' + this.lastUpdated.getSeconds() + 'Z\n';
str += 'END:VCARD\n';
// class ContactRef ////////////////////////////////////////////////////////
var ContactRef = function(data) {
- AV.validateConstructorCall(this, ContactRef);
+ AV.isConstructorCall(this, ContactRef);
var _contactId = '';
var _addressBookId = '';
Object.defineProperties(this, {
this.contactId = data.contactId;
} else {
try {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'addressBookId',
type: AV.Types.STRING,
// class ContactGroup //////////////////////////////////////////////////
var ContactGroup = function(name, ringtone, photo) {
- AV.validateConstructorCall(this, ContactGroup);
+ AV.isConstructorCall(this, ContactGroup);
var _id = null;
var _address = null;
// class ContactEmailAddress ///////////////////////////////////////////
var ContactEmailAddress = function(address, types, isDefault) {
- AV.validateConstructorCall(this, ContactEmailAddress);
+ AV.isConstructorCall(this, ContactEmailAddress);
var _email = '';
var _label = '';
// class ContactPhoneNumber ////////////////////////////////////////////
var ContactPhoneNumber = function(number, type, isDefault) {
- AV.validateConstructorCall(this, ContactPhoneNumber);
+ AV.isConstructorCall(this, ContactPhoneNumber);
var _isDefault = false;
var _number = '';
// class ContactAddress ////////////////////////////////////////////////
var ContactAddress = function(data) {
- AV.validateConstructorCall(this, ContactAddress);
+ AV.isConstructorCall(this, ContactAddress);
var _isDefault = false;
var _types = ['HOME'];
// class ContactAnniversary ////////////////////////////////////////////////
var ContactAnniversary = function(anniversary_date, anniversary_label) {
- AV.validateConstructorCall(this, ContactAnniversary);
+ AV.isConstructorCall(this, ContactAnniversary);
var _anniversary_date = new Date();
var _anniversary_label = null;
// class ContactWebSite ////////////////////////////////////////////////////
var ContactWebSite = function(contact_url, contact_type) {
- AV.validateConstructorCall(this, ContactWebSite);
+ AV.isConstructorCall(this, ContactWebSite);
var _url = '';
var _type = 'HOMEPAGE';
// class ContactOrganization ///////////////////////////////////////////////
var ContactOrganization = function(data) {
- AV.validateConstructorCall(this, ContactOrganization);
+ AV.isConstructorCall(this, ContactOrganization);
Object.defineProperties(this, {
name: {
value: null,
// class ContactName ///////////////////////////////////////////////////////
var ContactName = function(data) {
- AV.validateConstructorCall(this, ContactName);
+ AV.isConstructorCall(this, ContactName);
var _displayName = null;
};
var ContactRelationship = function(relativeName, type) {
- AV.validateConstructorCall(this, ContactRelationship);
+ AV.isConstructorCall(this, ContactRelationship);
Object.defineProperties(this, {
relativeName: {
};
var ContactInstantMessenger = function(imAddress, type) {
- AV.validateConstructorCall(this, ContactInstantMessenger);
+ AV.isConstructorCall(this, ContactInstantMessenger);
Object.defineProperties(this, {
imAddress: {
tizen.ContactGroup = ContactGroup;
tizen.ContactRelationship = ContactRelationship;
tizen.ContactInstantMessenger = ContactInstantMessenger;
-tizen.ContactRelationshipType = ContactRelationshipType;
-tizen.ContactInstantMessengerType = ContactInstantMessengerType;
-tizen.ContactRef = ContactRef;
-tizen.ContactRef = ContactRef;
-tizen.ContactRef = ContactRef;
-tizen.ContactRef = ContactRef;
-tizen.ContactRef = ContactRef;
-tizen.ContactRef = ContactRef;
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-var _dataStructures = require('./tizen.contact.ContactDataStructures');
-var _editGuard = _dataStructures.editGuard;
-var _toJsonObject = _dataStructures.toJsonObject;
-var _getNextWatchId = _dataStructures.getNextWatchId;
-var _promote = _dataStructures.promote;
-_dataStructures = undefined;
-
-function _checkError(result) {
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
- }
-}
-var _registered = false;
-var _listenerId = 'ContactPersonChangeListener';
+var _personListenerRegistered = false;
var _personCallbackMap = {};
var _personChangeListener = function(result) {
result = JSON.parse(result);
for (var key in _personCallbackMap) {
if (_personCallbackMap.hasOwnProperty(key)) {
if (result.added.length) {
- Common.callIfPossible(_personCallbackMap[key].onpersonsadded,
+ native_.callIfPossible(_personCallbackMap[key].onpersonsadded,
_promote(result.added, Person));
}
if (result.updated.length) {
- Common.callIfPossible(_personCallbackMap[key].onpersonsupdated,
+ native_.callIfPossible(_personCallbackMap[key].onpersonsupdated,
_promote(result.updated, Person));
}
if (result.removed.length) {
- Common.callIfPossible(_personCallbackMap[key].onpersonsremoved,
+ native_.callIfPossible(_personCallbackMap[key].onpersonsremoved,
result.removed);
}
}
}
};
-// import AddressBook class ////////////////////////////////////////////////
-var AddressBook = require('./tizen.contact.AddressBook');
-
-// import Person class /////////////////////////////////////////////////////
-var Person = require('./tizen.contact.Person');
-
-// class ContactManager ////////////////////////////////////////////////////
var ContactManager = function() {};
// Gets the available address books
ContactManager.prototype.getAddressBooks = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'successCallback',
type: AV.Types.FUNCTION,
]);
var callback = function(result) {
- if (Common.isFailure(result)) {
- Common.callIfPossible(args.errorCallback, Common.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
} else {
- var books = Common.getResultObject(result);
+ var books = native_.getResultObject(result);
var tmp = [];
books.forEach(function(data) {
tmp.push(new AddressBook(data.id, data.name, data.readOnly));
});
- Common.callIfPossible(args.successCallback, tmp);
+ native_.callIfPossible(args.successCallback, tmp);
}
};
- var result = _call('ContactManager_getAddressBooks', {}, callback);
+ var result = native_.call('ContactManager_getAddressBooks', {}, callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
// Gets the aggregation of all address books.
ContactManager.prototype.getUnifiedAddressBook = function() {
// validation
- var result = _callSync('CheckReadPrivileges', {});
- if (Common.isFailure(result)) {
+ var result = native_.callSync('CheckReadPrivileges', {});
+ if (native_.isFailure(result)) {
throw new WebAPIException(WebAPIException.SECURITY_ERR,
'You do not have privileges for this operation');
}
// Gets the address book with the specified identifier.
ContactManager.prototype.getAddressBook = function() {
// validation
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'addressBookId',
type: AV.Types.STRING,
}
]);
- var result = _callSync('ContactManager_getAddressBook', {
+ var result = native_.callSync('ContactManager_getAddressBook', {
addressBookID: args.addressBookId
});
- _checkError(result);
- return new AddressBook(args.addressBookId, result.name,
- Boolean(result.readOnly === 'true' ? true : false));
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ result = native_.getResultObject(result);
+
+ return new AddressBook(args.addressBookId, result.name, Boolean(result.readOnly === 'true'));
};
// Gets the person with the specified identifier.
ContactManager.prototype.get = function() {
// validation
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'personId',
type: AV.Types.STRING,
}
]);
- var result = _callSync('ContactManager_get', {
+ var result = native_.callSync('ContactManager_get', {
personID: args.personId
});
_checkError(result);
return _editGuard.run(function() {
- return new Person(Common.getResultObject(result));
+ return new Person(native_.getResultObject(result));
});
};
// Updates a person in the address book synchronously.
ContactManager.prototype.update = function() {
// validation
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'person',
type: AV.Types.PLATFORM_OBJECT,
nullable: false
}
]);
- var result = _callSync('ContactManager_update', { person: args.person });
+ var result = native_.callSync('ContactManager_update', { person: args.person });
_checkError(result);
- result = Common.getResultObject(result);
+ result = native_.getResultObject(result);
for (var prop in result) {
if (args.person.hasOwnProperty(prop)) {
args.person[prop] = result[prop];
// Updates several existing persons in the contact DB asynchronously.
ContactManager.prototype.updateBatch = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'persons',
type: AV.Types.ARRAY,
]);
var callback = function(result) {
- if (Common.isFailure(result)) {
- Common.callIfPossible(args.errorCallback, Common.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- Common.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback);
};
- var result = _call('ContactManager_updateBatch',
- {addressBook: {}, batchArgs: _toJsonObject(args.persons) },
- callback);
+ var result = native_.call('ContactManager_updateBatch', {
+ addressBook: {},
+ batchArgs: _toJsonObject(args.persons)
+ }, callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
// Removes a person from the contact DB synchronously.
ContactManager.prototype.remove = function() {
// validation
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'personId',
type: AV.Types.STRING,
}
]);
- var result = _callSync('ContactManager_remove', {personId: args.personId});
+ var result = native_.callSync('ContactManager_remove', {personId: args.personId});
_checkError(result);
};
// Removes persons from contact DB asynchronously.
ContactManager.prototype.removeBatch = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'personIds',
type: AV.Types.ARRAY,
]);
var callback = function(result) {
- if (Common.isFailure(result)) {
- Common.callIfPossible(args.errorCallback, Common.getErrorObject(result));
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
return;
}
- Common.callIfPossible(args.successCallback);
+ native_.callIfPossible(args.successCallback);
};
- var result = _call('ContactManager_removeBatch',
+ var result = native_.call('ContactManager_removeBatch',
{addressBook: {}, batchArgs: _toJsonObject(args.personIds) },
callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
// Gets an array of all Person objects from the contact DB or the ones that match the
// optionally supplied filter.
ContactManager.prototype.find = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'successCallback',
type: AV.Types.FUNCTION,
}
]);
- // TODO implement contact sorting.
-
+ // TODO implement contact filtering/sorting.
var data = {
- filter: Common.repackFilter(args.filter),
+ //filter: Common.repackFilter(args.filter),
sortMode: args.sortMode
};
var self = this;
var callback = function(result) {
- if (Common.isSuccess(result)) {
- var _result = Common.getResultObject(result);
+ if (native_.isSuccess(result)) {
+ var _result = native_.getResultObject(result);
var retval = [];
for (var i = 0; i < _result.length; ++i) {
retval.push(self.get(String(_result[i])));
}
//TODO: Move sorting to native code
- retval = Common.sort(retval, args.sortMode);
+ //retval = Common.sort(retval, args.sortMode);
args.successCallback(retval);
} else {
- Common.callIfPossible(args.errorCallback, Common.getErrorObject(result));
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
}
};
- var result = _call('ContactManager_find', data, callback);
+ var result = native_.call('ContactManager_find', data, callback);
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
};
// Subscribes to receive notifications about persons' changes.
ContactManager.prototype.addChangeListener = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'successCallback',
type: AV.Types.LISTENER,
]);
if (Type.isEmptyObject(_personCallbackMap)) {
- var result = _callSync('ContactManager_startListening', {});
+ var result = native_.callSync('ContactManager_startListening', {});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
}
- if (!_registered) {
- native.addListener(_listenerId, _personChangeListener);
- _registered = true;
+ if (!_personListenerRegistered) {
+ native_.addListener('ContactPersonChangeListener', _personChangeListener);
+ _personListenerRegistered = true;
}
var currentWatchId = _getNextWatchId();
// Unsubscribes a persons' changes watch operation.
ContactManager.prototype.removeChangeListener = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'watchId',
type: AV.Types.LONG,
// This makes UTC_contact_removeChangeListenerPerson_N_001 pass.
// watch id's start at 1
if (args.watchId === 0) {
- Common.throwInvalidValues('id is null or undefined');
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+ 'id is null or undefined');
}
if (args.watchId < 0) {
- Common.throwInvalidValues('Negative watch id');
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+ 'Negative watch id');
}
if (!_personCallbackMap.hasOwnProperty(args.watchId)) {
- Common.throwNotFound('watch id not found');
+ throw new tizen.WebAPIException(tizen.WebAPIException.NOT_FOUND_ERR,
+ 'watch id not found');
}
delete _personCallbackMap[args.watchId];
if (Type.isEmptyObject(_personCallbackMap)) {
- native.removeListener(_listenerId, _personChangeListener);
- _registered = false;
+ native_.removeListener('ContactPersonChangeListener', _personChangeListener);
+ _personListenerRegistered = false;
- var result = _callSync('ContactManager_stopListening', {});
+ var result = native_.callSync('ContactManager_stopListening', {});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
}
};
// exports /////////////////////////////////////////////////////////////////
-tizen.ContactManager = ContactManager;
+exports = new ContactManager();
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// import flag /////////////////////////////////////////////////////////////
-var _struct = require('./tizen.contact.ContactDataStructures');
-var _editGuard = _struct.editGuard;
-_struct = undefined;
-
-// class Person ////////////////////////////////////////////////////////////
var Person = function(data) {
- AV.validateConstructorCall(this, Person);
+ AV.isConstructorCall(this, Person);
var _id = '';
var _displayName = '';
// Aggregates another person to this person.
Person.prototype.link = function() {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'personId',
type: AV.Types.STRING,
}
]);
- var result = _callSync('Person_link', {
+ var result = native_.callSync('Person_link', {
// TODO move to only sending the person id (in all functions)
person: this,
id: args.personId
});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
var _this = this;
_editGuard.run(function() {
// Separates a contact from this person.
Person.prototype.unlink = function(contactId) {
- var args = AV.validateMethod(arguments, [
+ var args = AV.validateArgs(arguments, [
{
name: 'contactId',
type: AV.Types.STRING,
}
]);
- var result = _callSync('Person_unlink', {
+ var result = native_.callSync('Person_unlink', {
// TODO move to only sending the person id (in all functions)
person: this,
id: args.contactId
});
- if (Common.isFailure(result)) {
- throw Common.getErrorObject(result);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
}
var _this = this;
return _editGuard.run(function() {
_this.contactCount = _this.contactCount - 1;
- return new Person(Common.getResultObject(result));
+ return new Person(native_.getResultObject(result));
});
};
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-(function () {
- 'use strict';
-
- // Import ContactDataStructures class
- var ContactRef = require('./tizen.contact.ContactDataStructures.ref');
- var ContactGroup = require('./tizen.contact.ContactDataStructures.group');
- var ContactEmailAddress = require('./tizen.contact.ContactDataStructures.emailAddress');
- var ContactPhoneNumber = require('./tizen.contact.ContactDataStructures.phoneNumber');
- var ContactAddress = require('./tizen.contact.ContactDataStructures.address');
- var ContactAnniversary = require('./tizen.contact.ContactDataStructures.anniversary');
- var ContactWebSite = require('./tizen.contact.ContactDataStructures.webSite');
- var ContactOrganization = require('./tizen.contact.ContactDataStructures.organization');
- var ContactName = require('./tizen.contact.ContactDataStructures.name');
- var ContactRelationship = require('./tizen.contact.ContactDataStructures.relationship');
- var ContactInstantMessenger = require('./tizen.contact.ContactDataStructures.instantMessenger');
- var ContactRelationshipType = require('./tizen.contact.ContactDataStructures.relationshipType');
- var ContactInstantMessengerType = require('./tizen.contact.ContactDataStructures.instantMessengerType');
-
- // Import Contact and ContactInit class
- var Contact = require('./tizen.contact.Contact.Contact');
-
- // Import ContactManager class
- var ContactManager = require('./tizen.contact.ContactManager');
-
- // Import Person class
- var Person = require('./tizen.contact.Person');
-
- // Import AddressBook class
- var AddressBook = require('./tizen.contact.AddressBook');
-
-})();