-
Notifications
You must be signed in to change notification settings - Fork 0
/
issues.html
173 lines (144 loc) · 5.31 KB
/
issues.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Hub Issues Tracker Demo</title>
<style type="text/css" media="screen">
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="./hub.js"></script>
<script type="text/javascript" charset="utf-8">
var WS;
function setupPush(store) {
// Setup WebSocket
if (!window.WebSocket) alert('No socket');
if (window.WebSocket) {
WS = new WebSocket("ws://localhost:8003/memstore");
WS.onopen = function() {
hub.debug("Connection open ...") ;
WS.send("READY") ;
};
WS.onmessage = function(evt) {
var data = evt.data, pk ;
hub.debug("Got Message from Socket:") ;
if (data.indexOf("#") === 0) {
hub.debug("#"+data) ;
} else if (data.indexOf(":") === -1) { // This is an array of pk's
hub.debug("Key List");
var pks = JSON.parse(data),
i = pks.length, fetched = 0 ;
while (i--){
pk = pks[i] ;
// sc_log("^ Checking PK: "+pk);
if (!store.hasCommit(pk)) {
hub.debug("^ Getting PK: "+pk) ;
fetched++;
WS.send(pk);
}
}
var keysToSend = store.extraKeys(pks) ;
keysToSend.forEach(function(key){
store.sendPack(key);
});
// if (fetched === 0) {
// WS.send("PING");
// }
} else { // it's a pack
pk = data.substr(0,64) ;
var json = data.substr(65) ;
hub.debug("^ Adding Pack: "+pk) ;
var pack = JSON.parse(json) ;
store.addPack(pack, pk) ;
}
};
WS.onclose = function(evt) {
hub.debug("Connection closed.") ;
};
// Hook into store to be told when a pack is commited.
store.packCommitted = function(version, pack) {
hub.debug("Sending Pack") ;
// WS.send(version+":"+JSON.stringify(pack)) ;
}
}
}
Issues = hub.Object.create({
issues: null,
add: function() {
var reply = prompt("Issue Description", "New Issue") ;
hub.debug('About to add a new issue - ' + reply);
Issues.store.createRecord(Issues.Issue, {
description: reply,
isDone: false
})
hub.debug('Issue added ' + reply);
}
});
Issues.Issue = hub.Record.extend({
isDone: hub.Record.attr(Boolean),
description: hub.Record.attr(String)
});
hub.mixin(Issues.Issue, {
recordTypeName: 'Issues.Issue'
});
Issues.IssueListView = hub.Object.create({
layerId: 'issues',
contentLengthDidChange: function() {
hub.debug('updating list');
this.updateList();
}.observes('Issues.issues.length'),
updateList: function() {
var content = Issues.issues,
layerId = '#'+this.get('layerId'),
layer = $(layerId),
id, isDone, checked, newEle ;
layer.empty();
content.forEach(function(item, idx) {
id = item.get('guid') ;
isDone = item.get('isDone') ;
checked = isDone ? " checked=checked " : ""
newEle = hub.fmt("<li id='issue-%@' id> <input type=checkbox %@ name='%@'> %@</li>",
idx, checked, 'isDone', item.get('description')) ;
layer.append(newEle) ;
newEle = $(hub.fmt('#issue-%@', id)) ;
if(isDone) {
newEle.addClass('done') ;
}
}) ;
$(layerId+' :checkbox').click(this.checkBoxClicked) ;
},
checkBoxClicked: function(event) {
Issues.target = event.target ;
var idx = $(event.target).parent().attr('id').split("-")[1],
obj = Issues.get('issues').objectAt(idx) ;
obj.setIfChanged('isDone', !obj.get('isDone')); // Toggle The value.
}
})
$(document).ready(function(){
hub.debug('Running Main');
Issues.store = hub.Hub.create({
uti: 'com.hub.demo.web',
commitRecordsAutomatically: true
});
Issues.store.checkout() ;
var issues = Issues.store.find(hub.Query.local(Issues.Issue, {
orderBy: 'isDone,description'
})) ;
Issues.set('issues', issues) ;
// JQuery Code.
$('#add').click(function(event) {
Issues.add() ;
});
setupPush(Issues.store);
});
</script>
</head>
<body>
<h1>Issues</h1>
<div id="buttons">
<input type="button" value="New Issue" id="add">
</div>
<ul id="issues">
</ul>
</body>
</html>