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
# Media upload directory
paths.media = %(here)s/media
paths.media = %(here)s/scribeengine/public/files
# Themes directory
paths.themes = %(here)s/themes

View File

@ -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

View File

@ -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(
$("<li>")
@ -49,29 +58,41 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", {
)
.append(
$("<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;
},
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);
});

View File

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