From 12fa4bce4f99b5d05d43377f0d3e1b87a5af8ca2 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 11 Nov 2010 08:16:08 +0200 Subject: [PATCH] Pass the file name back to TinyMCE. --- development.ini | 2 +- scribeengine/controllers/media.py | 2 +- .../public/scripts/ScribeEngine.Media.js | 31 ++++++++++++++++--- scribeengine/templates/media/index.mako | 2 ++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/development.ini b/development.ini index 5212c77..5370edd 100644 --- a/development.ini +++ b/development.ini @@ -35,7 +35,7 @@ beaker.session.timeout = 1209600 sqlalchemy.url = sqlite:///%(here)s/scribeengine.sqlite # Media upload directory -paths.media = %(here)s/media +paths.media = %(here)s/scribeengine/public/files # Themes directory paths.themes = %(here)s/themes diff --git a/scribeengine/controllers/media.py b/scribeengine/controllers/media.py index ae50db1..d98b80c 100644 --- a/scribeengine/controllers/media.py +++ b/scribeengine/controllers/media.py @@ -71,7 +71,6 @@ class MediaController(BaseController): break def index(self): - log.debug(request.params) self._add_javascript(u'jstree/jquery.jstree.js') directories = [] path = os.path.join(config[u'paths.media'], u'user%s' % c.current_user.id) @@ -87,6 +86,7 @@ class MediaController(BaseController): def get_files(self): path = request.GET.get(u'path', u'').split(u',') dirpath = os.path.join(config[u'paths.media'], *path) + log.debug("Path: %s", path) return {u'results': self._get_files(dirpath)} @jsonify diff --git a/scribeengine/public/scripts/ScribeEngine.Media.js b/scribeengine/public/scripts/ScribeEngine.Media.js index 2a77354..6a97e8c 100644 --- a/scribeengine/public/scripts/ScribeEngine.Media.js +++ b/scribeengine/public/scripts/ScribeEngine.Media.js @@ -18,6 +18,10 @@ *****************************************************************************/ ScribeEngine.Namespace.create("ScribeEngine.Media", { + init: function () + { + // do nothing for the moment. in future, pre-select the file. + }, closeWindow: function () { window.close(); @@ -30,6 +34,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", { { var tree = jQuery.jstree._focused(); var path = tree.get_path(ScribeEngine.Events.getElement(event)); + $("#selected-path").val(path); $.getJSON( '/media/get-files', {"path": path.toString()}, @@ -39,7 +44,11 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", { var file = this; if (file.name.length > 15) { - file.name = file.name.substr(0, 12) + "..."; + file.display_name = file.name.substr(0, 12) + "..."; + } + else + { + file.display_name = file.name; } $("#file-list > ul").append( $("
  • ") @@ -49,29 +58,41 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", { ) .append( $("").attr("href", "#").attr("class", "caption") - .attr("title", file.name).text(file.name) + .attr("title", file.name).text(file.display_name) ) + .attr("title", file.name) ); }); } ); return false; }, - selectFile: function (e) + selectFile: function (event) { - var li = ScribeEngine.Events.getElement(e).parent(); + var li = ScribeEngine.Events.getElement(event).parent(); if (!li.is("li")) { li = li.parent(); } li.parent().children("li").children(".selected").removeClass("selected"); li.children("a").addClass("selected").blur(); + $("#selected-file").val(li.attr("title")); return false; + }, + finishSelect: function (event) + { + var file = $("#selected-file").val(); + var path = "/files/" + $("#selected-path").val().replace(",", "/"); + var win = tinyMCEPopup.getWindowArg("window"); + win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = path + "/" + file; + tinyMCEPopup.close(); + //window.close(); } }); ScribeEngine.Events.load(function () { ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.newDirectory); - ScribeEngine.Events.click("#file-select", ScribeEngine.Media.closeWindow); + ScribeEngine.Events.click("#file-select", ScribeEngine.Media.finishSelect); ScribeEngine.Events.liveClick("#file-list > ul > li > a", ScribeEngine.Media.selectFile); + tinyMCEPopup.onInit.add(ScribeEngine.Media.init, ScribeEngine.Media); }); diff --git a/scribeengine/templates/media/index.mako b/scribeengine/templates/media/index.mako index 43a9cda..a6e100c 100644 --- a/scribeengine/templates/media/index.mako +++ b/scribeengine/templates/media/index.mako @@ -43,6 +43,8 @@
    + +