74
80
"The path specified is invalid.")
76
82
# Start writing data
78
<!-- Top bar section -->
83
84
# FIXME: This isn't completely reliable! We're not inside the jail, so we
84
85
# can't know the type for sure. This is now only used for adding a / to the
85
86
# end of displayed paths, so I'm leaving this although it will often break.
86
87
isdir = os.path.isdir(localpath)
87
presentpath(req, browsepath, isdir)
101
<!-- Body. The JavaScript places content here relevant to the path -->
107
def presentpath(req, path, isdir):
109
Presents a path list (address bar inside the page) for clicking.
110
Writes to req, expecting to have just written the opening div containing
112
This will also have a revision indicator on the end, if we are viewing a
89
gen_path(req, browsepath, ctx)
92
ctx['fileservice_action'] = util.make_path(os.path.join("fileservice", req.path))
93
ctx['filename'] = cgi.escape(req.path)
95
loader = genshi.template.TemplateLoader(".", auto_reload=True)
96
tmpl = loader.load(util.make_local_path("apps/browser/template.html"))
98
req.write(tmpl.generate(ctx).render('html')) #'xhtml', doctype='xhtml'))
100
#TODO: Move all this logic into the template
101
def gen_path(req, path, ctx):
115
103
href_path = util.make_path(THIS_APP)
118
105
revision = ivle.svn.revision_from_string(
119
106
req.get_fieldstorage().getfirst('r'))
122
108
revno = revision.number
126
114
# Create all of the paths
127
115
pathlist = path.split("/")
128
segs_left = len(pathlist)
129
117
for path_seg in pathlist:
130
118
if path_seg == "":
132
# Write a slash at the end unless this is the last path seg AND
133
# it's not a directory.
135
add_slash = segs_left != 0 or isdir
136
# Make an 'a' element
122
nav_path = nav_path + path_seg
137
123
href_path = href_path + '/' + path_seg
138
nav_path = nav_path + path_seg
140
nav_path = nav_path + '/'
141
link = '<a href="%s" title="Navigate to %s">%s</a>' % (
142
href_path if revno is None else href_path + '?r=%d' % revno,
148
if revno is not None:
149
req.write(' (revision %d)' % revno)
151
def present_actions1(req):
125
new_seg['path'] = path_seg
126
new_seg['nav_path'] = nav_path
127
new_seg['href_path'] = href_path
128
if revno is not None:
129
new_seg['href_path'] += '?r=%d' % revno
131
ctx['paths'].append(new_seg)
134
def gen_actions(req, ctx):
153
136
Presents a set of links/buttons for the "actions1" row of the top bar.
154
137
This is always exactly the same - the JavaScript will customize it later.
156
139
# Set up our actions. The second field of each group is whether to disable
157
140
# the items by default.
141
ctx['moreactions'] = [
159
142
('Publishing', True, [
160
143
('publish', ['Publish', 'Make it so this directory can be seen by anyone on the web']),
161
144
('share', ['Share this file', 'Get a link to this published file, to give to friends']),
186
169
('svnlog', ['View Log', 'View the log of commits of the selected file']),
190
req.write(""" <a id="act_open" class="disabled">Open</a> :
192
title="View this file on the web, running your code if this is a CGI file"
193
class="disabled" target="_blank">Serve</a> :
194
<a id="act_run" title="Run the selected Python file in the console"
195
class="disabled">Run</a> :
196
<a id="act_download" class="choice">Download</a> :
197
<a title="Refresh the current page" onclick="refresh()"
198
class="choice">Refresh</a><span id="moreactions_area"> :
199
<select id="moreactions" onchange="handle_moreactions()"
200
onblur="handle_moreactions()">
201
<option class="moreactions" value="top"
202
selected="selected">More actions...</option>
205
for (name, disablement, group) in moreactions:
207
disable = 'class="disabled" disabled="disabled"'
210
req.write('<optgroup label="%s">' % name)
211
for (id, bits) in group:
212
req.write('<option id="act_%s" %s title="%s" value="%s">%s</option>'
213
% (id, disable, bits[1], id, bits[0]))
214
req.write('</optgroup>')
216
req.write('</select></span>')
218
def present_actions2(req):
220
Presents a set of links/buttons for the "actions2" row of the top bar.
221
This depends on whether it is a directory (listing) or normal file
222
(editor), but we'll let the JavaScript decide which.
224
req.write(""" <form id="actions2_directory"
225
target="upload_iframe"
227
enctype="multipart/form-data" method="post">
229
<span id="selectallpanel">
231
<a onclick="action_selectall(true)"
232
title="Select all files in this directory">All</a> :
233
<a onclick="action_selectall(false)"
234
title="Deselect all files in this directory">None</a>
237
<span style="display:none" id="uploadpanel">|
238
<label for="upload_file">Upload file:</label>
239
<input type="hidden" value="putfiles" name="action" />
240
<input type="hidden" value="" name="path" />
241
<input type="file" name="data" id="upload_file" />
242
<input type="checkbox" checked="checked" value="true" name="unpack" id="unpack" />
243
<label title="Extract files and directories from a ZIP file if one is uploaded" for="unpack">Unpack ZIP</label>
244
<input type="button" onclick="show_uploadpanel(false)" value="Cancel" />
245
<input type="submit" value="Upload" />
247
<!-- This iframe is for making a call to upload the file without
248
refreshing the page. (It will refresh the listing). -->
249
<iframe onload="upload_callback()" style="display: none;"
250
name="upload_iframe" id="upload_iframe"></iframe>
253
""" % cgi.escape(util.make_path(os.path.join("fileservice", req.path))))
255
req.write(""" <p id="actions2_file">
256
<input type="button" id="save_button" value="Save" onclick="save_file('%s')" />
257
<input type="button" id="saveas_button" value="Save As..." onclick="save_file_as('%s')" />
258
<select id="highlighting_select" onchange="highlighting_changed(this)">
259
<option value="text">Text</option>
260
<option value="python">Python</option>
261
<option value="html">HTML</option>
262
<option value="javascript">JavaScript</option>
263
<option value="css">CSS</option>
266
""" % ((cgi.escape(req.path),) * 2))