forked from Banana-In-Black/item-selector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
120 lines (109 loc) · 3.16 KB
/
index.html
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
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>item-selector example huiming is here</title>
<script src="lib/jquery-1.10.2.js"></script>
<script src="lib/jquery-ui-1.10.3.js"></script>
<script src="lib/backbone-dependency/underscore-1.5.1.js"></script>
<script src="lib/backbone-1.0.0.js"></script>
<script src="lib/bootstrap-2.3.2.js"></script>
<script src="item-selector.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/item-selector.css">
<script type="text/javascript">
$(function() {
var items = [{
name: 'testItem1'
}, {
attribute1: 'This is for long text testing.'
}, {
name: 'testItem1'
}, {
attribute1: 'This is for long text testing.'
}, {
name: 'test3'
}, {
name: 'test4'
}, {
name: 'test5'
}, {
name: 'test6'
}];
items = items.concat(items).concat(items);
itemsView =
new ItemsView({
cols: 4,
rows: 4,
collection: items,
draggable: true,
/**
* Overrite to custimize behavior
* @param selectedModels the models which is selected in item-selector
* @return error message; return null or nothing if validation is passed
*/
validate: function(selectedModels) {
if(selectedModels.length < 1) {
return 'Please select at least 1 item.';
}
},
/**
* Overrite to custimize behavior
* @param selectedModels the models which is selected in item-selector
*/
ok: function(selectedModels) {
alert(JSON.stringify(selectedModels, '', 4));
}
}).render('body');
/* Control-panel functions */
$('.control-panel').find('.add').click(function(event) {
event.preventDefault();
console.log({
name: $('input.name').val(),
attribute1: $('input.attribute1').val(),
attribute2: $('input.attribute2').val()
});
itemsView.collection.add(
new Item({
name: $('input.name').val(),
attribute1: $('input.attribute1').val(),
attribute2: $('input.attribute2').val()
}));
});
})
</script>
<style type="text/css">
body > * {
vertical-align: top;
}
.control-panel {
display: inline-block;
margin: 5px;
padding: 10px;
border: 1px solid #ccc;
border: 1px solid rgba(0,0,0,.2);
border-radius: 6px;
box-shadow: 0 5px 10px rgba(0,0,0,.2);
background-clip: padding-box;
}
.button-panel {
text-align: right;
}
</style>
</head>
<body>
<form name="inputForm" class="control-panel">
<label>Name</label>
<input type="text" class="name" placeholder="Item Name"/>
<label>Attribute 1</label>
<input type="text" class="attribute1" placeholder="Item Attribute"/>
<label>Attribute 2</label>
<input type="text" class="attribute2" placeholder="Item Attribute"/>
<div class="button-panel">
<button class="btn btn-small add">
<i class="icon-plus"></i> Add
</button>
</div>
</form>
</body>
</html>