forked from perkeep/perkeep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zembed_filetree.js.go
295 lines (291 loc) · 9.4 KB
/
zembed_filetree.js.go
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
// THIS FILE IS AUTO-GENERATED FROM filetree.js
// DO NOT EDIT.
package newui
import "time"
import "camlistore.org/pkg/fileembed"
func init() {
Files.Add("filetree.js", 7346, time.Unix(0, 1370942742232957700), fileembed.String("/*\n"+
"Copyright 2011 The Camlistore Authors.\n"+
"\n"+
"Licensed under the Apache License, Version 2.0 (the \"License\");\n"+
"you may not use this file except in compliance with the License.\n"+
"You may obtain a copy of the License at\n"+
"\n"+
" http://www.apache.org/licenses/LICENSE-2.0\n"+
"\n"+
"Unless required by applicable law or agreed to in writing, software\n"+
"distributed under the License is distributed on an \"AS IS\" BASIS,\n"+
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"+
"See the License for the specific language governing permissions and\n"+
"limitations under the License.\n"+
"*/\n"+
"\n"+
"/**\n"+
" * @fileoverview Filetree page.\n"+
" *\n"+
" */\n"+
"goog.provide('camlistore.FiletreePage');\n"+
"\n"+
"goog.require('goog.dom');\n"+
"goog.require('goog.events.EventType');\n"+
"goog.require('goog.ui.Component');\n"+
"goog.require('camlistore.ServerConnection');\n"+
"\n"+
"/**\n"+
" * @param {camlistore.ServerType.DiscoveryDocument} config Global config\n"+
" * of the current server this page is being rendered for.\n"+
" * @param {goog.dom.DomHelper=} opt_domHelper DOM helper to use.\n"+
" *\n"+
" * @extends {goog.ui.Component}\n"+
" * @constructor\n"+
" */\n"+
"camlistore.FiletreePage = function(config, opt_domHelper) {\n"+
" goog.base(this, opt_domHelper);\n"+
"\n"+
" /**\n"+
" * @type {Object}\n"+
" * @private\n"+
" */\n"+
" this.config_ = config;\n"+
"\n"+
" /**\n"+
" * @type {camlistore.ServerConnection}\n"+
" * @private\n"+
" */\n"+
" this.connection_ = new camlistore.ServerConnection(config);\n"+
"\n"+
"};\n"+
"goog.inherits(camlistore.FiletreePage, goog.ui.Component);\n"+
"\n"+
"\n"+
"/**\n"+
" * @type {number}\n"+
" * @private\n"+
" */\n"+
"camlistore.FiletreePage.prototype.indentStep_ = 20;\n"+
"\n"+
"\n"+
"function getDirBlobrefParam() {\n"+
" var blobRef = getQueryParam('d');\n"+
" return (blobRef && isPlausibleBlobRef(blobRef)) ? blobRef : null;\n"+
"}\n"+
"\n"+
"// Returns the first value from the query string corresponding to |key|.\n"+
"// Returns null if the key isn't present.\n"+
"getQueryParam = function(key) {\n"+
" var params = document.location.search.substring(1).split('&');\n"+
" for (var i = 0; i < params.length; ++i) {\n"+
" var parts = params[i].split('=');\n"+
" if (parts.length == 2 && decodeURIComponent(parts[0]) == key)\n"+
" return decodeURIComponent(parts[1]);\n"+
" }\n"+
" return null;\n"+
"};\n"+
"\n"+
"// Returns true if the passed-in string might be a blobref.\n"+
"isPlausibleBlobRef = function(blobRef) {\n"+
" return /^\\w+-[a-f0-9]+$/.test(blobRef);\n"+
"};\n"+
"\n"+
"\n"+
"/**\n"+
" * Called when component's element is known to be in the document.\n"+
" */\n"+
"camlistore.FiletreePage.prototype.enterDocument = function() {\n"+
" camlistore.FiletreePage.superClass_.enterDocument.call(this);\n"+
" var blobref = getDirBlobrefParam();\n"+
"\n"+
" if (blobref) {\n"+
" this.connection_.describeWithThumbnails(\n"+
" blobref,\n"+
" 0,\n"+
" goog.bind(this.handleDescribeBlob_, this, blobref),\n"+
" function(msg) {\n"+
" alert(\"failed to get blob description: \" + msg);\n"+
" }\n"+
" );\n"+
" }\n"+
"}\n"+
"\n"+
"/**\n"+
" * @param {string} blobref blob to describe.\n"+
" * @param {camlistore.ServerType.DescribeResponse} describeResult Object of prope"+
"rties for the node.\n"+
" * @private\n"+
" */\n"+
"camlistore.FiletreePage.prototype.handleDescribeBlob_ =\n"+
"function(blobref, describeResult) {\n"+
" var meta = describeResult.meta;\n"+
" if (!meta[blobref]) {\n"+
" alert(\"didn't get blob \" + blobref);\n"+
" return;\n"+
" }\n"+
" var binfo = meta[blobref];\n"+
" if (!binfo) {\n"+
" alert(\"Error describing blob \" + blobref);\n"+
" return;\n"+
" }\n"+
" if (binfo.camliType != \"directory\") {\n"+
" alert(\"Does not contain a directory\");\n"+
" return;\n"+
" }\n"+
" this.connection_.getBlobContents(\n"+
" blobref,\n"+
" goog.bind(function(data) {\n"+
" var finfo = JSON.parse(data);\n"+
" var fileName = finfo.fileName;\n"+
" var curDir = document.getElementById('curDir');\n"+
" curDir.innerHTML = \"<a href='./?b=\" + blobref + \"'>\" + fileName + \"</a>\";\n"+
" this.buildTree_();\n"+
" }, this),\n"+
" function(msg) {\n"+
" alert(\"failed to get blobcontents: \" + msg);\n"+
" }\n"+
" );\n"+
"}\n"+
"\n"+
"/**\n"+
" * @private\n"+
" */\n"+
"camlistore.FiletreePage.prototype.buildTree_ = function() {\n"+
" var blobref = getDirBlobrefParam();\n"+
" var children = goog.dom.getElement(\"children\");\n"+
" this.connection_.getFileTree(blobref,\n"+
" goog.bind(function(jres) {\n"+
" this.onChildrenFound_(children, 0, jres);\n"+
" }, this)\n"+
" );\n"+
"}\n"+
"\n"+
"/**\n"+
" * @param {string} div node used as root for the tree\n"+
" * @param {number} depth how deep we are in the tree, for indenting\n"+
" * @param {camlistore.ServerType.DescribeResponse} jres describe result\n"+
" * @private\n"+
" */\n"+
"camlistore.FiletreePage.prototype.onChildrenFound_ =\n"+
"function(div, depth, jres) {\n"+
" var indent = depth * camlistore.FiletreePage.prototype.indentStep_;\n"+
" div.innerHTML = \"\";\n"+
" for (var i = 0; i < jres.children.length; i++) {\n"+
" var children = jres.children;\n"+
" var pdiv = goog.dom.createElement(\"div\");\n"+
" var alink = goog.dom.createElement(\"a\");\n"+
" alink.style.paddingLeft=indent + \"px\"\n"+
" alink.id = children[i].blobRef;\n"+
" switch (children[i].type) {\n"+
" case 'directory':\n"+
" goog.dom.setTextContent(alink, \"+ \" + children[i].name);\n"+
" goog.events.listen(alink,\n"+
" goog.events.EventType.CLICK,\n"+
" goog.bind(function (b, d) {\n"+
" this.unFold_(b, d);\n"+
" }, this, alink.id, depth),\n"+
" false, this\n"+
" );\n"+
" break;\n"+
" case 'file':\n"+
" goog.dom.setTextContent(alink, \" \" + children[i].name);\n"+
" alink.href = \"./?b=\" + alink.id;\n"+
" break;\n"+
" default:\n"+
" alert(\"not a file or dir\");\n"+
" break;\n"+
" }\n"+
" var newPerm = goog.dom.createElement(\"span\");\n"+
" newPerm.className = \"cam-filetree-newp\";\n"+
" goog.dom.setTextContent(newPerm, \"P\");\n"+
" goog.events.listen(newPerm,\n"+
" goog.events.EventType.CLICK,\n"+
" this.newPermWithContent_(alink.id),\n"+
" false, this\n"+
" );\n"+
" goog.dom.appendChild(pdiv, alink);\n"+
" goog.dom.appendChild(pdiv, newPerm);\n"+
" goog.dom.appendChild(div, pdiv);\n"+
" }\n"+
"}\n"+
"\n"+
"\n"+
"/**\n"+
" * @param {string} content blobref of the content\n"+
" * @private\n"+
" */\n"+
"camlistore.FiletreePage.prototype.newPermWithContent_ =\n"+
"function(content) {\n"+
" var fun = function(e) {\n"+
" this.connection_.createPermanode(\n"+
" goog.bind(function(permanode) {\n"+
" this.connection_.newAddAttributeClaim(\n"+
" permanode, \"camliContent\", content,\n"+
" function() {\n"+
" alert(\"permanode created\");\n"+
" },\n"+
" function(msg) {\n"+
" // TODO(mpl): \"cancel\" new permanode\n"+
" alert(\"set permanode content failed: \" + msg);\n"+
" }\n"+
" );\n"+
" }, this),\n"+
" function(msg) {\n"+
" alert(\"create permanode failed: \" + msg);\n"+
" }\n"+
" );\n"+
" }\n"+
" return goog.bind(fun, this);\n"+
"}\n"+
"\n"+
"\n"+
"/**\n"+
" * @param {string} blobref dir to unfold.\n"+
" * @param {number} depth so we know how much to indent.\n"+
" * @private\n"+
" */\n"+
"camlistore.FiletreePage.prototype.unFold_ =\n"+
"function(blobref, depth) {\n"+
" var node = goog.dom.getElement(blobref);\n"+
" var div = goog.dom.createElement(\"div\");\n"+
" this.connection_.getFileTree(blobref,\n"+
" goog.bind(function(jres) {\n"+
" this.onChildrenFound_(div, depth+1, jres);\n"+
" insertAfter(node, div);\n"+
" goog.events.removeAll(node);\n"+
" goog.events.listen(node,\n"+
" goog.events.EventType.CLICK,\n"+
" goog.bind(function(b, d) {\n"+
" this.fold_(b, d);\n"+
" }, this, blobref, depth),\n"+
" false, this\n"+
" );\n"+
" }, this)\n"+
" );\n"+
"}\n"+
"\n"+
"function insertAfter( referenceNode, newNode ) {\n"+
" // nextSibling X2 because of the \"P\" span\n"+
" referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling.nextSi"+
"bling );\n"+
"}\n"+
"\n"+
"/**\n"+
" * @param {string} nodeid id of the node to fold.\n"+
" * @param {depth} depth so we know how much to indent.\n"+
" * @private\n"+
" */\n"+
"camlistore.FiletreePage.prototype.fold_ =\n"+
"function(nodeid, depth) {\n"+
" var node = goog.dom.getElement(nodeid);\n"+
" // nextSibling X2 because of the \"P\" span\n"+
" node.parentNode.removeChild(node.nextSibling.nextSibling);\n"+
" goog.events.removeAll(node);\n"+
" goog.events.listen(node,\n"+
" goog.events.EventType.CLICK,\n"+
" goog.bind(function(b, d) {\n"+
" this.unFold_(b, d);\n"+
" }, this, nodeid, depth),\n"+
" false, this\n"+
" );\n"+
"}\n"+
"\n"+
""))
}