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( + $("