From 11579fc6049e582012e214cf9fe0505261b041a3 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 3 Jun 2010 15:32:07 +0200 Subject: [PATCH] Got stuff working! --- scribeengine/controllers/media.py | 11 ++++++-- .../public/scripts/ScribeEngine.Media.js | 28 ++++++++++++++++--- scribeengine/public/scripts/ScribeEngine.js | 4 +-- scribeengine/templates/media/index.mako | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/scribeengine/controllers/media.py b/scribeengine/controllers/media.py index 536fef1..f3d0436 100644 --- a/scribeengine/controllers/media.py +++ b/scribeengine/controllers/media.py @@ -42,12 +42,12 @@ class MediaController(BaseController): def __before__(self): BaseController.__before__(self) - self._add_javascript('ScribeEngine.Media.js') + self._add_javascript(u'ScribeEngine.Media.js') def _get_directories(self, parent=None, tree=[]): old_root = parent dirname = os.path.split(parent)[1] - node = {'data': dirname, u'state': u'open'} + node = {u'data': dirname, u'state': u'open'} for root, dirs, files in os.walk(parent): if root != old_root: break @@ -75,6 +75,13 @@ class MediaController(BaseController): #return pformat(c.directories, indent=2) return render(u'/media/index.mako') + @jsonify + def get_files(self): + path = request.GET.get(u'path', u'').split(u',') + dirpath = os.path.join(config[u'paths.media'], *path) + #log.debug(dirpath) + return self._get_files(dirpath) + @jsonify def create_directory(self): """ diff --git a/scribeengine/public/scripts/ScribeEngine.Media.js b/scribeengine/public/scripts/ScribeEngine.Media.js index f9e5c78..323e718 100644 --- a/scribeengine/public/scripts/ScribeEngine.Media.js +++ b/scribeengine/public/scripts/ScribeEngine.Media.js @@ -18,17 +18,37 @@ *****************************************************************************/ ScribeEngine.Namespace.create("ScribeEngine.Media", { - new_directory: function () + newDirectory: function () { var dirname = prompt("New Directory:", "directory"); }, - get_files: function (event, data) + getFiles: function (event) { - alert(data.inst.get_path(ScribeEngine.Events.getElement(event))); + var tree = jQuery.jstree._focused(); + var path = tree.get_path(ScribeEngine.Events.getElement(event)); + $.getJSON( + '/media/get-files', + {"path": path.toString()}, + function (data, textStatus) { + $("#file-list > ul").html(""); + $.each(data, function () { + var filename = this; + if (filename.length > 15) + { + filename = filename.substr(0, 12) + "..."; + } + $("#file-list > ul").append( + $("
  • ") + .append($("
    ").attr("class", "file").html(" ")) + .append($("
    ").attr("class", "caption").attr("title", filename).text(filename)) + ); + }); + } + ); } }); ScribeEngine.Events.load(function () { - ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.new_directory); + ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.newDirectory); ScribeEngine.Events.click("#file-select", window.close); }); diff --git a/scribeengine/public/scripts/ScribeEngine.js b/scribeengine/public/scripts/ScribeEngine.js index 9bdab02..33f4967 100644 --- a/scribeengine/public/scripts/ScribeEngine.js +++ b/scribeengine/public/scripts/ScribeEngine.js @@ -133,7 +133,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", { }, fileBrowser: function (field_name, url, type, win) { - alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing + //alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing var cmsURL = window.location.toString(); // script URL - use an absolute path! if (cmsURL.indexOf("?") < 0) { @@ -180,7 +180,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", { tree: function (selector, tree_data, onselect) { $(selector) - .bind("set_focus.jstree", onselect) + .bind("click.jstree", onselect) .jstree({ plugins: ["themes", "json_data"], json_data: {data: tree_data}, diff --git a/scribeengine/templates/media/index.mako b/scribeengine/templates/media/index.mako index 5a95c69..1ea90c7 100644 --- a/scribeengine/templates/media/index.mako +++ b/scribeengine/templates/media/index.mako @@ -43,7 +43,7 @@