-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraxor-plugin.js
114 lines (75 loc) · 2.77 KB
/
traxor-plugin.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
104
105
106
107
108
109
110
111
112
113
114
var traxor = function ()
{
var isArray = function (o)
{
if (o === null)
{
return false;
}
return o.constructor == (new Array).constructor;
};
return {
getContactIds : function (successCB, errorCB)
{
navigator.contacts.find (
// Fields to return.
[
navigator.contacts.fieldType.id
],
function (objs)
{
var ids = [];
// Iterate over to strip out the junk (reduce memory).
for (var i = 0; i < objs.length; i++)
{
ids.push (objs[i].id);
}
successCB (ids);
},
function (error)
{
if (error.code != ContactError.NOT_FOUND_ERROR)
{
traxor.utils.logError (null,
'cannot process contacts: ' + error,
error);
} else {
successCB ([]);
}
},
{
multiple : true,
filter : '',
desiredFields : [ navigator.contacts.fieldType.id ]
});
},
getContactsByIds : function (ids, successCB, errorCB, fields)
{
if (!successCB) {
throw new TypeError("You must specify a success callback for the getByIds command.");
}
if (!fields || (isArray(fields) && fields.length === 0))
{
if (typeof errorCB === "function") {
errorCB(new ContactError(ContactError.INVALID_ARGUMENT_ERROR));
}
} else {
var win = function(result) {
var cs = [];
for (var i = 0, l = result.length; i < l; i++) {
cs.push(navigator.contacts.create(result[i]));
}
successCB(cs);
};
try{
cordova.exec(win, errorCB, "TraxorPlugin", "getContactsByIds", [ids, fields]);
}catch(e){console.log(e);}
}
},
modelAsString : function (successCB,
errorCB)
{
}
};
}();
module.exports = traxor;