-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.js
53 lines (48 loc) · 1.52 KB
/
list.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
// List page
//
var lodash = require('lodash');
exports.View =
{
title: "List example",
elements:
[
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "text", value: "New item:", fontsize: 12 },
{ control: "edit", binding: "itemToAdd" },
] },
{ control: "button", caption: "Add", binding: "add", enabled: "{itemToAdd}" },
{ control: "text", value: "Your items", fontsize: 12 },
{ control: "listbox", width: 250, height: 300, select: "Multiple", binding: { items: "items", selection: "selectedItems" } },
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "button", caption: "Remove", binding: "remove", enabled: "{selectedItems}" },
{ control: "button", caption: "Sort", binding: "sort", enabled: "{items}" },
] },
]
}
exports.InitializeViewModel = function(context, session)
{
var viewModel =
{
itemToAdd: "",
items: [ "white", "black", "yellow" ],
selectedItems: [ "black" ]
}
return viewModel;
}
exports.Commands =
{
add: function(context, session, viewModel)
{
viewModel.items.push(viewModel.itemToAdd);
viewModel.itemToAdd = "";
},
sort: function(context, session, viewModel)
{
viewModel.items.sort();
},
remove: function(context, session, viewModel)
{
lodash.pullAllWith(viewModel.items, viewModel.selectedItems, lodash.isEqual);
viewModel.selectedItems = [];
},
}