-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontacts.js
71 lines (62 loc) · 2.29 KB
/
contacts.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
// Contacts page
//
var lodash = require('lodash');
exports.View =
{
title: "Contacts",
elements:
[
{ control: "stackpanel", orientation: "Vertical", width: "*", height: "*", contents: [
{ control: "text", value: "Your Contacts", fontsize: 12 },
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "button", caption: "Add", binding: "add"},
{ control: "button", caption: "Remove", binding: "remove", enabled: "{selectedContacts}" },
{ control: "button", caption: "Sort", binding: "sort" },
] },
{ control: "listview", select: "Multiple", height: "*", width: "*", binding: { items: "contacts", selection: "selectedContacts" }, itemTemplate: [
{ control: "stackpanel", orientation: "Horizontal", padding: 5, contents: [
{ control: "image", resource: "{$root.imgUser}", height: 50, width: 50 },
{ control: "stackpanel", orientation: "Vertical", contents: [
{ control: "text", value: "{first}" },
{ control: "text", value: "{last}" },
] },
] },
] },
] },
]
}
exports.InitializeViewModel = function(context, session, params, state)
{
var viewModel = state;
if (viewModel == null)
{
viewModel =
{
imgUser: Synchro.getResourceUrl(context, "user.png"),
contacts: [ { first: "John", last: "Smith" }, { first: "George", last: "Washington" }, ],
selectedContacts: [],
}
}
if (session.addedContact)
{
viewModel.contacts.push(session.addedContact);
delete session.addedContact;
}
return viewModel;
}
exports.Commands =
{
add: function(context, session, viewModel)
{
return Synchro.pushAndNavigateTo(context, "contacts_add", null, viewModel );
},
sort: function(context, session, viewModel)
{
viewModel.contacts.sort(function(a,b){return a.last == b.last ? a.first > b.first : a.last > b.last});
},
remove: function(context, session, viewModel)
{
lodash.pullAllWith(viewModel.contacts, viewModel.selectedContacts, lodash.isEqual);
viewModel.selectedContacts = [];
},
}