forked from bitovi/jquerypp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.html
More file actions
188 lines (174 loc) · 4.94 KB
/
store.html
File metadata and controls
188 lines (174 loc) · 4.94 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>store</title>
<style type='text/css'>
body {font-family: verdana}
.error {border: solid 1px red;}
.error_text { color: red; font-size: 10px;}
td {padding: 3px;}
.folder {display: block;}
#accounts {
width: 250px;
float: left;
}
</style>
</head>
<body>
<h1>store Demo</h1>
<ul id='accounts'>
</ul>
<ul id='grid'>
</ul>
<script type='text/javascript'
src='../../../steal/steal.js'>
</script>
<script type='text/ejs' id='accountsEJS'>
<% for(var i =0; i < this.length; i++){ %>
<li <%= this[i]%>>
<h3>
<%== $.route.link(this[i].name , {file: this[i].id}) %>
</h3>
<ul class='contents' <%= plugin('folder_contents',{item: this[i]})%>></ul>
</li>
<% } %>
</script>
<script type='text/ejs' id='foldersEJS'>
<% for(var i =0; i < this.length; i++){ %>
<li <%= this[i]%>>
<%== $.route.link(this[i].name , {file: this[i].id},{className: 'folder'}) %>
<ul class='contents' <%= plugin('folder_contents',{item: this[i]})%> ></ul>
</li>
<% } %>
</script>
<script type='text/javascript'>
steal('mj/store','jquerypp/controller',
'jquerypp/dom/fixture',
'jquerypp/dom/route',
'jquerypp/lang/observe/delegate',
'jquerypp/view/ejs',
function(){
// lets create a grid widget ...
$.route("file/:file",{});
$.Model('Item',{},{
has : function(id){
return new RegExp("(^|\\/)"+id+"(\\/|$)").test(this.path)
}
});
$.Model.List('Item.List');
$.Model.Store('Item.Store');
var folderIds = [],
rand = $.fixture.rand,
getPath = function(items, parentId){
var path = parentId == null ? [] : [parentId],
next
while(next = items[parentId]){
if(next.parentId != null){
path.unshift(next.parentId)
}
parentId = next.parentId
}
return {
path: path.join('/'),
accountId: path.length ? path[0] : null
}
};
$.fixture.make('item',500, function(i, items){
var parentId = i < 5 ? null : rand(folderIds, 1)[0],
type = i < 5 ? 'folder' : rand(['file','folder'],1)[0];
if(type === 'folder'){
folderIds.push(i)
}
var data = getPath(items, parentId)
return {
name: parentId === null ? "Account "+i : type+" "+i,
parentId : parentId,
type: type,
path : data.path,
accountId: data.accountId
}
})
$.Controller('Grid',{
init : function(){
//check the list, render if it's there
this.fillIn();
},
fillIn : function(){
var file = $.route.data.attr('file');
if(file){
Item.Store.findOne(file, this.callback('fill'))
}
},
fill : function(item){
if(item.type === "folder"){
this.list = Item.Store.findAll({type: "files", parentId: this.item.id})
} else {
this.list = Item.Store.findAll({type: "files", parentId: this.item.parentId})
}
}
});
$('#grid')
// a folder's contents
// should essentially come alive if the path in the file
// is 'in me'
// this means request data from the store
// but ... the store might already have this ...
// how do you handle this situation
$.Controller('FolderContents',{
setup : function(el, options){
options.items = Item.Store.findAll({
parentId: options.item.id,
type: "folder"
}, true);
this._super(el, options)
},
init : function(){
this.fillIn();
},
"{items} add" : function(accounts, ev, items){
this.element.html("foldersEJS", items);
//check the state and add a new folder
},
fillIn : function(file){
var file = $.route.attr('file');
if(file){
Item.Store.findOne(file, this.callback('fill'))
}
},
// path 34/4/23/1123/
fill : function(item){
if(( item.id == this.options.item.id ||
item.has(this.options.item.id) )&&
!this.options.items.length){
// get this content!
Item.Store.findAll({
parentId: this.options.item.id,
type: "folder"
})
}
},
"{$.route} file change" : function(){
// if it's in us ... get our shit
this.fillIn();
// if it's not, hide ourselves?
}
})
// Immediately get accounts ....
$.Controller('Accounts',{
setup : function(element){
this._super(element, {
accounts : Item.Store.findAll({parentId: null})
})
},
"{accounts} add" : function(accounts, ev, accounts){
// add something for each account
this.element.html("accountsEJS", accounts)
}
})
$('#accounts').accounts();
$.route.ready();
})
</script>
</body>
</html>