Commit 7c725b97 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add file uploader and clickable path in file browser

parent 3388177c
......@@ -36,6 +36,7 @@ foreach ($strings as $string) {
}
$javascript = <<<JAVASCRIPT
var filelist = new TableRenderer(
'filelist',
'myfiles.json.php',
......@@ -50,21 +51,57 @@ function formatname(r) {
var cell = r.name;
}
if (r.type == 'folder') {
var link = A({'href':'scuzzbag'},r.name);
link.onclick = function () { stop(); filelist.doupdate({'folder':r.id}); return false; };
paths[cwd + r.name + '/'] = r.id;
var link = A({'href':''},r.name);
link.onclick = function () {
stop();
return changedir(cwd + r.name + '/');
}
var cell = link;
}
return TD(null, cell);
}
filelist.statevars.push('folder');
function changedir(path) {
cwd = path;
linked_path(path);
uploader.updatedestination(paths[path], path);
var args = paths[cwd] ? {'folder':paths[cwd]} : null;
filelist.doupdate(args);
return false;
}
function linked_path(path) {
var dirs = cwd.split('/');
var homedir = A({'href':''}, get_string('home'));
homedir.onclick = function () { stop(); return changedir('/'); };
var sofar = '/';
var folders = [homedir];
for (i=0; i<dirs.length; i++) {
if (dirs[i] != '') {
sofar = sofar + dirs[i] + '/';
var dir = A({'href':'bar'}, dirs[i]);
dir.onclick = function () { stop(); return changedir(sofar);};
folders.push(' / ');
folders.push(dir);
}
}
replaceChildNodes(filelist.thead,TR(null,TD({'colspan':2},folders)));
}
filelist.emptycontent = {$getstring['nofilesfound']};
filelist.paginate = false;
filelist.statevars.push('folder');
filelist.updateOnLoad();
paths = {'/':null};
cwd = '/';
var uploader = new FileUploader('uploader', 'upload.json.php', filelist.doupdate);
JAVASCRIPT;
$smarty = smarty(array('tablerenderer'));
$smarty = smarty(array('tablerenderer','fileuploader'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('artefact:file:index.tpl');
......
......@@ -50,6 +50,7 @@ if (!$filedata) {
$filedata = array();
}
$result = array(
'count' => count($filedata),
'limit' => $limit,
......@@ -59,8 +60,6 @@ $result = array(
'message' => get_string('filelistloaded'),
);
//log_debug($result);
json_headers();
print json_encode($result);
......
......@@ -3,7 +3,11 @@
<div class="content">
<h2>{str section="artefact.file" tag="myfiles"}</h2>
<table id="filelist"><tbody><tr><td></td></tr></tbody></table>
<div id="uploader"></div>
<table id="filelist">
<thead><tr><td></td></tr></thead>
<tbody><tr><td></td></tr></tbody>
</table>
</div>
{include file="footer.tpl"}
function FileUploader(element, script, callback, foldername, folderid) {
var self = this;
this.element = element;
this.script = script;
this.foldername = foldername ? foldername : get_string('home');
this.folderid = folderid;
this.init = function() {
self.nextupload = 1;
// Create the upload form
self.uploadform = self.initform();
// Create the button which opens up the upload form
var buttontext = self.nextupload == 1 ? get_string('uploadfile') : get_string('uploadanotherfile');
var button = INPUT({'type':'button','value':buttontext});
button.onclick = function () {
hideElement(self.openbutton);
showElement(self.uploadform);
};
self.openbutton = button;
appendChildNodes(self.element, self.uploadform, self.openbutton);
}
this.initform = function () {
var form = FORM({'method':'post', 'id':'uploadform',
'enctype':'multipart/form-data', 'encoding':'multipart/form-data',
'action':'upload.php', 'target':'iframe'+self.nextupload});
var rows = map(self.formrow,
[{'text':'destination', 'elem':SPAN({'id':'uploaddest'},self.foldername)},
{'text':'file', 'elem':INPUT({'type':'file','name':'userfile'})},
{'text':'title', 'elem':INPUT({'type':'text','name':'title'})},
{'text':'description', 'elem':INPUT({'type':'text','name':'description'})}]);
var uploadbutton = INPUT({'type':'button','value':get_string('upload')});
uploadbutton.onclick = self.sendform;
var cancelbutton = INPUT({'type':'button','value':get_string('cancel')});
cancelbutton.onclick = function () {
hideElement(self.uploadform);
showElement(self.openbutton);
};
appendChildNodes(form, TABLE(null, TBODY(null, rows)), uploadbutton, cancelbutton);
hideElement(form);
return form;
}
this.formrow = function (r) {
return TR(null, TD(null, get_string(r.text) + ':'),
TD(null, r.elem));
}
this.updatedestination = function (folderid, foldername) {
self.foldername = foldername;
self.folderid = folderid;
$('uploaddest').innerHTML = foldername;
}
addLoadEvent(this.init);
//var formparams = [INPUT({'type':'hidden','name':'uploaddir','value':self.folder}),
// INPUT({'type':'hidden','name':'uploadnum','value':self.nextupload})];
//var messageline = DIV({'id':'uploadmessage','class':'uploadmessage'});
//var extrabuttons = DIV({'id':'extrabuttons'});
//var buttonline = DIV({'id':'buttonline'},uploadbutton,cancelbutton);
}
\ No newline at end of file
......@@ -78,6 +78,15 @@ function &smarty($javascript = array(), $headers = array(), $strings = array())
}
}
if (in_array('fileuploader', $javascript)) {
$javascript_array[] = $jsroot . 'fileuploader.js';
foreach (fileuploaderjsstrings() as $string) {
if (!in_array($string, $strings)) {
$strings[] = $string;
}
}
}
$javascript_array[] = $jsroot . 'mahara.js';
$javascript_array[] = $jsroot . 'debug.js';
......@@ -149,6 +158,10 @@ function tablerendererjsstrings() {
);
}
function fileuploaderjsstrings() {
return array();
}
/**
* This function sets up and caches info about the current selected theme
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment