Commit f8e382d0 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Smarty function can include .js files from places other than htdocs/js

parent cfc74c0c
......@@ -29,7 +29,7 @@ define('MENUITEM', 'myfiles');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'file');
$strings = array('nofilesfound');
$strings = array('cancel', 'delete', 'description', 'edit', 'editfile', 'editfolder', 'home', 'name', 'nofilesfound', 'savechanges');
$getstring = array();
foreach ($strings as $string) {
$getstring[$string] = "'" . get_string($string) . "'";
......@@ -37,71 +37,16 @@ foreach ($strings as $string) {
$javascript = <<<JAVASCRIPT
var filelist = new TableRenderer(
'filelist',
'myfiles.json.php',
[
formatname,
'size',
'mtime',
function () {return TD(null)},
]
);
function formatname(r) {
if (r.artefacttype == 'file') {
var cell = r.name;
}
if (r.artefacttype == 'folder') {
var dir = cwd + r.name + '/';
pathids[dir] = r.id;
var link = A({'href':'', 'onclick':"return changedir('" + dir.replace(escre,"\\\'") + "')"},r.name);
var cell = link;
}
return TD(null, cell);
}
function changedir(path) {
cwd = path;
linked_path();
uploader.updatedestination(pathids[path], path);
var args = path == '/' ? null : {'folder':pathids[path]};
filelist.doupdate(args);
return false;
}
function linked_path() {
var dirs = cwd.split('/');
var homedir = A({'href':'', 'onclick':"return changedir('/')"}, get_string('home'));
var sofar = '/';
var folders = [homedir];
for (i=0; i<dirs.length; i++) {
if (dirs[i] != '') {
sofar = sofar + dirs[i] + '/';
var dir = A({'href':'', 'onclick':"return changedir('" + sofar.replace(escre,"\\\'") + "')"}, dirs[i]);
folders.push(' / ');
folders.push(dir);
}
}
replaceChildNodes($('foldernav'),folders);
}
filelist.emptycontent = {$getstring['nofilesfound']};
filelist.paginate = false;
filelist.statevars.push('folder');
pathids = {'/':null};
cwd = '/';
escre = /\'/g;
var browser = new FileBrowser('filelist');
alert('browser');
var uploader = new FileUploader('uploader', 'upload.json.php', filelist.doupdate);
addLoadEvent(function () { changedir(cwd); });
JAVASCRIPT;
$smarty = smarty(array('tablerenderer','fileuploader'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty = smarty(array('tablerenderer', 'artefact/file/js/filebrowser.js', 'fileuploader'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('artefact:file:index.tpl');
?>
......@@ -27,6 +27,8 @@
define('INTERNAL', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
//log_debug('myfiles.json.php');
$limit = param_integer('limit', null);
$offset = param_integer('offset', 0);
$folder = param_integer('folder', null);
......@@ -65,7 +67,7 @@ $result = array(
'message' => get_string('filelistloaded'),
);
log_debug($result);
//log_debug($result);
json_headers();
print json_encode($result);
......
function FileUploader(element, script, callback, foldername, folderid) {
function FileUploader(element, callback, foldername, folderid) {
var self = this;
this.element = element;
this.script = script;
this.foldername = foldername ? foldername : get_string('home');
this.folderid = folderid;
......
......@@ -50,13 +50,17 @@ defined('INTERNAL') || die();
* @param $strings A list of language strings required by the javascript code.
* @return Smarty
*/
//smarty(array('js/tablerenderer.js', 'artefact/file/js/filebrowser.js'))
function &smarty($javascript = array(), $headers = array(), $strings = array()) {
global $USER, $SESSION;
require_once(get_config('libroot') . 'smarty/Smarty.class.php');
$wwwroot = get_config('wwwroot');
// Insert the appropriate javascript tags
$jsroot = get_config('wwwroot') . 'js/';
$jsroot = $wwwroot . 'js/';
// TinyMCE must be included first for some reason we're not sure about
if (($key = array_search('tinymce', $javascript)) !== FALSE) {
......@@ -73,8 +77,17 @@ function &smarty($javascript = array(), $headers = array(), $strings = array())
$jsstrings = jsstrings();
foreach ($javascript as $jsfile) {
$javascript_array[] = $jsroot . $jsfile . '.js';
if ($jsstrings[$jsfile]) {
// For now, if there's no path in the js file, assume it's in
// $jsroot and append '.js' to the name. Later we may want to
// ensure all smarty() calls include the full path to the js
// file, with the proper extension.
if (strpos($jsfile,'/') === false) {
$javascript_array[] = $jsroot . $jsfile . '.js';
}
else {
$javascript_array[] = $jsfile;
}
if (isset($jsstrings[$jsfile])) {
foreach ($jsstrings[$jsfile] as $string) {
if (!in_array($string, $strings)) {
$strings[] = $string;
......@@ -111,7 +124,7 @@ function &smarty($javascript = array(), $headers = array(), $strings = array())
$smarty->cache_dir = get_config('dataroot').'smarty/cache';
$smarty->assign('THEMEURL', get_config('themeurl'));
$smarty->assign('WWWROOT', get_config('wwwroot'));
$smarty->assign('WWWROOT', $wwwroot);
$sitename = get_config('sitename');
$smarty->assign('title', $sitename);
$smarty->assign('heading', $sitename);
......
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