if (status.IsError()) return status;
const JsonObject& contact = FromJson<JsonObject>(args, "contact");
+ long addressBookId = common::stol(FromJson<JsonString>(args, "addressBookId"));
if (!IsNull(contact, "id")) {
LoggerW("Contact already exists");
ContactUtil::ExportContactToContactsRecord(*contacts_record_ptr, contact);
if (status.IsError()) return status;
+ status = ContactUtil::SetIntInRecord(
+ contacts_record, _contacts_contact.address_book_id, addressBookId);
+ if (status.IsError()) return status;
+
int id = -1;
err = contacts_db_insert_record(*contacts_record_ptr, &id);
if (CONTACTS_ERROR_NONE != err) {
if (status.IsError()) return status;
const JsonObject& contact = FromJson<JsonObject>(args, "contact");
- const JsonObject& addressbook = FromJson<JsonObject>(args, "addressBook");
long contactId = common::stol(FromJson<JsonString>(contact, "id"));
if (IsNull(contact, "id")) {
return PlatformResult(ErrorCode::UNKNOWN_ERR, "Contact doesn't exist");
}
- if (IsNull(addressbook, "id")) {
- LoggerE("Contact is not saved in database");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
- "Contact is not saved in database");
- }
-
contacts_record_h to_update = nullptr;
int err = contacts_db_get_record(_contacts_contact._uri, contactId, &to_update);
if (CONTACTS_ERROR_NONE != err) {
if (status.IsError()) return status;
const JsonArray& batch_args = FromJson<JsonArray>(args, "batchArgs");
- const JsonObject& addressBook = FromJson<JsonObject>(args, "addressBook");
- if (IsNull(addressBook, "id")) {
- LoggerE("Contact is not saved in database");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
- "Contact is not saved in database");
- }
contacts_list_h contacts_list = NULL;
int err = 0;
err = contacts_list_create(&contacts_list);
PlatformResult status = ContactUtil::CheckDBConnection();
if (status.IsError()) return status;
const JsonArray& batch_args = FromJson<JsonArray>(args, "batchArgs");
- const JsonObject& addressBook = FromJson<JsonObject>(args, "addressBook");
- if (IsNull(addressBook, "id")) {
- LoggerE("Contact is not saved in database");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR,
- "Contact is not saved in database");
- }
int length = static_cast<int>(batch_args.size());
int ids[length], i=0;
for (auto& item : batch_args) {
ContactUtil::ContactsRecordHPtr record(&contacts_record,
ContactUtil::ContactsDeleter);
-
- long addressbook_id =
- common::stol(FromJson<JsonString>(args, "addressBook", "id"));
+ long addressbook_id = common::stol(FromJson<std::string>(args, "addressBookId"));
if (IsUnified(addressbook_id)) {
int address_book_id = 0;
status = ContactUtil::GetIntFromRecord(
}
int err;
- long addressbook_id = AddressBookId(args);
+ long addressbook_id = common::stol(FromJson<std::string>(args, "addressBookId"));
if (!IsUnified(addressbook_id)) {
contacts_record_h contacts_record = nullptr;
err = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
if (status.IsError()) return status;
}
+ const auto sort_mode_it = args.find("sortMode");
+ if (args.end() != sort_mode_it) {
+ if (!sort_mode_it->second.is<picojson::object>()) {
+ LoggerD("Failed to set sort mode.");
+ return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Failed to set sort mode");
+ }
+ const auto sort_mode = sort_mode_it->second;
+ std::string attribute = sort_mode.get("attributeName").to_str();
+
+ Person::PersonProperty property;
+ status = Person::PersonPropertyFromString(attribute, &property);
+ if (status.IsError()) return status;
+
+ bool is_asc = sort_mode.get("order").to_str() == "ASC";
+ error_code = contacts_query_set_sort(contacts_query, property.propertyId, is_asc);
+ status = ContactUtil::ErrorChecker(error_code,
+ "Failed contacts_query_set_sort");
+ if (status.IsError()) return status;
+ }
+
contacts_list_h person_list = nullptr;
error_code =
contacts_db_get_records_with_query(contacts_query, 0, 0, &person_list);
};
// implementation ported from wrt-plugins-tizen
-// TODO: instead of executing multiple queries and combining the results,
-// create multiple filters, combine them into one, add sorting and
-// execute a single query
ContactSearchEngine::ContactSearchEngine()
: addressbook_id_(0),
is_sort_mode_set_ = true;
sort_mode_attribute_ = attribute;
- is_sort_mode_asc_ = sort_mode.get("attributeName").to_str() == "ASC";
+ is_sort_mode_asc_ = sort_mode.get("order").to_str() == "ASC";
return PlatformResult(ErrorCode::NO_ERROR);
}
ContactUtil::ContactsFilterPtr sub_filter_ptr(sub_filter,
ContactUtil::ContactsFilterDeleter);
- // TODO To be supported: start
error_code = contacts_filter_add_str(sub_filter, property_id,
CONTACTS_MATCH_STARTSWITH,
initial_value);
nickname_ptr.release();
}
- // TODO update displayName in JS!
-
return PlatformResult(ErrorCode::NO_ERROR);
}
}
var result = native_.callSync('AddressBook_get', {
- // TODO move to only sending the address book id (in all functions)
- addressBook: this,
id: args.id
});
]);
var result = native_.callSync('AddressBook_add', {
- // TODO move to only sending the address book id (in all functions)
- addressBook: this,
+ addressBookId: this.id,
contact: _toJsonObject(args.contact)
});
}
]);
+ if (args.contact.addressBookId !== this.id && UNIFIED_ADDRESSBOOK_ID !== this.id) {
+ throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR);
+ }
+
var result = native_.callSync('AddressBook_update', {
- addressBook: this,
contact: _toJsonObject(args.contact)
});
native_.callIfPossible(args.successCallback);
};
+ var thatId = this.id;
+ args.contacts.forEach(function(c) {
+ if (c.addressBookId !== thatId && UNIFIED_ADDRESSBOOK_ID !== thatId) {
+ setTimeout(function() {
+ native_.callIfPossible(args.errorCallback, new WebAPIException(
+ WebAPIException.INVALID_VALUES_ERR,
+ 'Contact is not saved in database'));
+ }, 0);
+
+ return;
+ }
+ });
+
native_.call('AddressBook_updateBatch', {
- addressBook: this,
batchArgs: _toJsonObject(args.contacts)
}, callback);
};
}
var result = native_.callSync('AddressBook_remove', {
- addressBook: this,
id: args.id
});
};
native_.call('AddressBook_removeBatch', {
- addressBook: this,
batchArgs: args.ids
}, callback);
};
}
var result = native_.callSync('AddressBook_getGroup', {
- addressBook: this,
+ addressBookId: this.id,
id: args.groupId
});
if (native_.isFailure(result)) {
}
var result = native_.callSync('AddressBook_removeGroup',
- {addressBook: this, id: args.groupId});
+ {addressBookId: this.id, id: args.groupId});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
return _canEdit > 0;
};
-var _editGuard = new EditGuard();
-
-//TODO: Move sorting and filtering to native code
-var Common = function() {};
-Common.prototype.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;
-};
-
-Common.prototype.filter = function(arr, filter) {
- if (type_.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 C = new Common();
+var _editGuard = new EditGuard();
\ No newline at end of file
}
]);
- // TODO implement contact filtering/sorting.
var data = {
filter: utils_.repackFilter(args.filter),
sortMode: args.sortMode
for (var i = 0; i < _result.length; ++i) {
retval.push(self.get(String(_result[i])));
}
- //TODO: Move sorting to native code
- retval = C.sort(retval, args.sortMode);
args.successCallback(retval);
} else {
native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
}
var result = native_.callSync('Person_link', {
- // TODO move to only sending the person id (in all functions)
- person: this,
+ personId: this.id,
id: args.personId
});
if (native_.isFailure(result)) {
}
var result = native_.callSync('Person_unlink', {
- // TODO move to only sending the person id (in all functions)
- person: this,
+ personId: this.id,
id: args.contactId
});
if (native_.isFailure(result)) {
if (status.IsError()) return status;
long id = common::stol(FromJson<JsonString>(args, "id"));
- long person_id = common::stol(FromJson<JsonString>(args, "person", "id"));
+ long person_id = common::stol(FromJson<JsonString>(args, "personId"));
contacts_record_h contacts_record = nullptr;
"Contact is not a member of person");
if (status.IsError()) return status;
- long person_id = common::stol(FromJson<JsonString>(args, "person", "id"));
+ long person_id = common::stol(FromJson<JsonString>(args, "personId"));
if (contacts_person_id != person_id) {
LoggerW("Contact is not a member of person (wrong id's)");
return PlatformResult(ErrorCode::INVALID_VALUES_ERR,