This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
/
Contact.js
103 lines (98 loc) · 2.82 KB
/
Contact.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* Copyright 2011 Research In Motion Limited.
*
* 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.
*/
var transport = require('ripple/platform/webworks/2.0.0/client/transport'),
_uri = "blackberry/pim/contact/";
function Contact(service) {
var _self = {
anniversary: null,
birthday: null,
categories: [],
company: null,
email1: null,
email2: null,
email3: null,
faxPhone: null,
firstName: null,
homeAddress: null,
homePhone: null,
homePhone2: null,
jobTitle: null,
lastName: null,
mobilePhone: null,
note: null,
otherPhone: null,
pagerPhone: null,
picture: null,
pin: null,
title: null,
uid: null,
user1: null,
user2: null,
user3: null,
user4: null,
webpage: null,
workAddress: null,
workPhone: null,
workPhone2: null,
remove: function () {
if (!_self.uid) {
throw "task has not yet been saved (has no uid)";
}
transport.call(_uri + "remove", {
get: { id: _self.uid }
});
},
save: function () {
if (!_self.uid) {
_self.uid = Math.uuid(null, 16);
}
transport.call(_uri + "save", {
post: { contact: _self }
});
},
setPicture: function (picture) {
throw "not implemented";
}
};
return _self;
}
function _massage(property, name) {
if ((name === "anniversary" || name === "birthday") && property) {
return new Date(property);
}
return property;
}
Contact.find = function (fieldFilter, orderBy, maxReturn, service, isAscending) {
return transport.call(_uri + "find", {
post: {
fieldFilter: fieldFilter,
orderBy: orderBy,
maxReturn: maxReturn,
service: service,
isAscending: isAscending
}
}).map(function (properties) {
var contact = new Contact(),
key;
for (key in properties) {
if (contact.hasOwnProperty(key)) {
contact[key] = _massage(properties[key], key);
}
}
return contact;
});
};
module.exports = Contact;