% include header.html title="urraka", urlroot=urlroot
<h1>{{username}}@urraka</h1>
% if defined('message'):
<div class="message">{{message}}</div>
<p/>
% end
<!-- Article upload -->
<form id="article">
<fieldset>
<legend>Upload article</legend>
<label for="url">URL</label>
<input type="text" name="url"/>
<input type="submit" value="Go"/><br/>
</fieldset>
</form>
<div class="result" id="article_result"></div>
<script>
$("#article").submit(function(event) {
event.preventDefault();
resultsdiv = $("#article_result");
resultsdiv.text("Loading article...");
function on_ok(data) {
if (data.success) {
resultsdiv.text("OK");
resultsdiv.css('color', 'green');
} else {
resultsdiv.text(data.message);
resultsdiv.css('color', 'red');
}
}
function on_error(jqhxr, status, error) {
resultsdiv.text("Error sending request: " + status + " - " + error);
}
$.post(
"article",
{ url: $(this).find('input[name="url"]').val() }
)
.done(on_ok)
.fail(on_error);
});
</script>
<p/>
<!-- File upload
We can't upload files via ajax without going crazy, so this is just a
normal form, and will get back to us with the outcome. -->
<form action="ebook" method="POST" enctype="multipart/form-data">
<fieldset>
<legend>Upload ebook file</legend>
<label for="filename">Ebook File</label>
<input type="file" name="ebook"/>
<input type="submit" value="Go"/><br/>
</fieldset>
</form>
% if defined('ebook_result'):
<div class="message">{{ebook_result}}</div>
% end
<p/>
<!-- File list -->
<div>
<form id="remove">
<table class="nice" id="file_list">
<thead>
<tr>
<th>Books</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<input type="submit" value="Remove files"/><br/>
</form>
</div>
<div class="result" id="remove_result"></div>
<script>
function fmt() {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
function refresh_list() {
$.get('list', function(data) {
target = $("#file_list tbody");
target.empty();
$.each(data.file_info, function(i, item) {
e = '<tr><td><label>';
e += fmt(
'<input type="checkbox" value="{0}" name="fname"/>\n',
item[0]);
e += item[1];
e += '</label></td></tr>';
target.append(e);
});
});
}
refresh_list();
</script>
<script>
$("#remove").submit(function(event) {
event.preventDefault();
resultsdiv = $("#remove_result");
resultsdiv.text("Removing files...");
function on_ok(data) {
if (data.success) {
resultsdiv.text("OK");
resultsdiv.css('color', 'green');
} else {
resultsdiv.text(data.message);
resultsdiv.css('color', 'red');
}
refresh_list();
}
function on_error(jqhxr, status, error) {
resultsdiv.text("Error sending request: " + status + " - " + error);
refresh_list();
}
var data = { 'fnames[]': [] };
$('input[name="fname"]:checked').each(function() {
data['fnames[]'].push($(this).val());
});
$.post("remove", data)
.done(on_ok)
.fail(on_error);
});
</script>
% include footer.html