Pass the file name back to TinyMCE.

This commit is contained in:
Raoul Snyman 2010-11-11 08:16:08 +02:00
parent e10466d808
commit 12fa4bce4f
4 changed files with 30 additions and 7 deletions

View File

@ -35,7 +35,7 @@ beaker.session.timeout = 1209600
sqlalchemy.url = sqlite:///%(here)s/scribeengine.sqlite sqlalchemy.url = sqlite:///%(here)s/scribeengine.sqlite
# Media upload directory # Media upload directory
paths.media = %(here)s/media paths.media = %(here)s/scribeengine/public/files
# Themes directory # Themes directory
paths.themes = %(here)s/themes paths.themes = %(here)s/themes

View File

@ -71,7 +71,6 @@ class MediaController(BaseController):
break break
def index(self): def index(self):
log.debug(request.params)
self._add_javascript(u'jstree/jquery.jstree.js') self._add_javascript(u'jstree/jquery.jstree.js')
directories = [] directories = []
path = os.path.join(config[u'paths.media'], u'user%s' % c.current_user.id) 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): def get_files(self):
path = request.GET.get(u'path', u'').split(u',') path = request.GET.get(u'path', u'').split(u',')
dirpath = os.path.join(config[u'paths.media'], *path) dirpath = os.path.join(config[u'paths.media'], *path)
log.debug("Path: %s", path)
return {u'results': self._get_files(dirpath)} return {u'results': self._get_files(dirpath)}
@jsonify @jsonify

View File

@ -18,6 +18,10 @@
*****************************************************************************/ *****************************************************************************/
ScribeEngine.Namespace.create("ScribeEngine.Media", { ScribeEngine.Namespace.create("ScribeEngine.Media", {
init: function ()
{
// do nothing for the moment. in future, pre-select the file.
},
closeWindow: function () closeWindow: function ()
{ {
window.close(); window.close();
@ -30,6 +34,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", {
{ {
var tree = jQuery.jstree._focused(); var tree = jQuery.jstree._focused();
var path = tree.get_path(ScribeEngine.Events.getElement(event)); var path = tree.get_path(ScribeEngine.Events.getElement(event));
$("#selected-path").val(path);
$.getJSON( $.getJSON(
'/media/get-files', '/media/get-files',
{"path": path.toString()}, {"path": path.toString()},
@ -39,7 +44,11 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", {
var file = this; var file = this;
if (file.name.length > 15) 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( $("#file-list > ul").append(
$("<li>") $("<li>")
@ -49,29 +58,41 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", {
) )
.append( .append(
$("<a>").attr("href", "#").attr("class", "caption") $("<a>").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; 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")) if (!li.is("li"))
{ {
li = li.parent(); li = li.parent();
} }
li.parent().children("li").children(".selected").removeClass("selected"); li.parent().children("li").children(".selected").removeClass("selected");
li.children("a").addClass("selected").blur(); li.children("a").addClass("selected").blur();
$("#selected-file").val(li.attr("title"));
return false; 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.load(function () {
ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.newDirectory); 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); ScribeEngine.Events.liveClick("#file-list > ul > li > a", ScribeEngine.Media.selectFile);
tinyMCEPopup.onInit.add(ScribeEngine.Media.init, ScribeEngine.Media);
}); });

View File

@ -43,6 +43,8 @@
</ul> </ul>
</div> </div>
<div id="button-bar"> <div id="button-bar">
<input type="hidden" id="selected-file" />
<input type="hidden" id="selected-path" />
<input type="button" id="file-select" value="Select"/> <input type="button" id="file-select" value="Select"/>
<span class="separator"></span> <span class="separator"></span>
<input type="button" id="new-directory" value="New Directory"/> <input type="button" id="new-directory" value="New Directory"/>