-
Notifications
You must be signed in to change notification settings - Fork 1
/
counter.js
89 lines (80 loc) · 3.72 KB
/
counter.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
// Counter page
//
var util = require('./lib/util');
var fontStyle =
{
normal: { color: "Green", isBold: false },
highlighted: { color: "Red", isBold: true }
}
exports.View =
{
title: "Click Counter",
elements:
[
{ control: "text", value: "This sample app demonstrates updating a remote value. Each time you click increment or decrement, the counter is updated in your Synchro app on the server. This app demonstrates the round-trip performance of that kind of operation.", width: "*" },
{ control: "rectangle", width: "*", height: 5, color: "Black" },
{ control: "text", value: "Count: {count}", foreground: "{font.color}", font: { size: 24, bold: "{font.isBold}" } },
{ control: "button", caption: "Increment Count", binding: { command: "vary", amount: 1 } },
{ control: "button", caption: "Decrement Count", binding: { command: "vary", amount: -1 }, enabled: "{count}" },
// Toolbar support for ther various platforms
//
{ select: "First", contents: [
{ select: "All", filter: { deviceMetric: "os", is: ["Windows", "WinPhone"] }, contents: [
{ control: "commandBar.button", text: "Add", winIcon: "Add", commandBar: "Bottom", commandType: "Secondary", binding: { command: "vary", amount: 1 } },
{ control: "commandBar.button", text: "Subtract", winIcon: "Remove", commandBar: "Bottom", commandType: "Secondary", binding: { command: "vary", amount: -1 }, enabled: "{count}" },
{ control: "commandBar.button", text: "Reset", winIcon: "Delete", commandBar: "Bottom", binding: "reset" },
]
},
{ select: "All", filter: { deviceMetric: "os", is: "Android" }, contents: [
{ control: "actionBar.item", text: "Add", binding: { command: "vary", amount: 1 } },
{ control: "actionBar.item", text: "Subtract", binding: { command: "vary", amount: -1 }, enabled: "{count}" },
{ control: "actionBar.item", text: "Reset", icon: "delete", showAsAction: "IfRoom", binding: "reset", enabled: "{count}" },
]
},
{ select: "All", filter: { deviceMetric: "os", is: "iOS" }, contents: [
{ control: "navBar.button", systemItem: "Trash", binding: "reset", enabled: "{count}" },
{ control: "toolBar.button", text: "Add", icon: "add", binding: { command: "vary", amount: 1 } },
{ control: "toolBar.button", text: "Subtract", icon: "remove", binding: { command: "vary", amount: -1 }, enabled: "{count}" },
]
},
]
},
]
}
exports.InitializeViewModel = function(context, session)
{
session.count = session.count || 0; // Initialize if undefined
console.log("Initializing count to: " + session.count);
var viewModel =
{
count: session.count,
font: (session.count < 10) ? fontStyle.normal : fontStyle.highlighted
}
return viewModel;
}
exports.OnViewModelChange = function(context, session, viewModel, source, changes)
{
viewModel.font = (viewModel.count < 10) ? fontStyle.normal : fontStyle.highlighted;
}
exports.Commands =
{
vary: function(context, session, viewModel, params)
{
viewModel.count = util.Vary(viewModel.count, params.amount);
},
reset: function(context, session, viewModel)
{
viewModel.count = 0;
},
exit: function(context, session, viewModel)
{
session.count = viewModel.count;
console.log("Updated session count to: " + session.count);
return Synchro.navigateToView(context, "menu");
},
}
exports.OnBack = function(context, session, viewModel)
{
Synchro.popTo(context, "menu");
return true; // Nav handled
}