Moved the image file stuff to the server side.

Fixed up the initial file display.
This commit is contained in:
Raoul Snyman 2010-06-05 19:38:28 +02:00
parent 37dabf6386
commit e3836b5a41
3 changed files with 25 additions and 22 deletions

View File

@ -60,7 +60,13 @@ class MediaController(BaseController):
def _get_files(self, dirpath):
for root, dirs, files in os.walk(os.path.abspath(dirpath)):
return files
filelist = []
for filename in files:
if os.path.splitext(filename)[1] in [u'.png', u'.jpg', u'.gif']:
filelist.append({u'name': filename, u'type': u'/images/file-image.png'})
else:
filelist.append({u'name': filename, u'type': u'/images/file-unknown.png'})
return filelist
break
def index(self):
@ -79,7 +85,6 @@ 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(dirpath)
return {u'results': self._get_files(dirpath)}
@jsonify

View File

@ -36,25 +36,23 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", {
function (data, textStatus) {
$("#file-list > ul").html("");
$.each(data.results, function () {
var filename = this;
var extension = filename.substr(filename.length - 4);
if (extension == ".png" || extension == ".jpg")
var file = this;
if (file.name.length > 15)
{
var filetype = "file-image";
}
else
{
var filetype = "file-unknown";
}
if (filename.length > 15)
{
filename = filename.substr(0, 12) + "...";
file.name = file.name.substr(0, 12) + "...";
}
$("#file-list > ul").append(
$("<li>")
.append($("<a>").attr("href", "#").attr("class", "file")
.html("<img src=\"/images/" + filetype + ".png\" />").click(ScribeEngine.Media.selectFile))
.append($("<a>").attr("href", "#").attr("class", "caption").attr("title", filename).text(filename).click(ScribeEngine.Media.selectFile))
.append(
$("<a>").attr("href", "#").attr("class", "file")
.html("<img src=\""+ file.type +"\" />")
.click(ScribeEngine.Media.selectFile)
)
.append(
$("<a>").attr("href", "#").attr("class", "caption")
.attr("title", file.name).text(file.name)
.click(ScribeEngine.Media.selectFile)
)
);
});
}

View File

@ -29,13 +29,13 @@
<div id="directory-tree"></div>
<div id="file-list">
<ul>
% for filename in c.files:
% for file in c.files:
<li>
<div class="file">&nbsp;</div>
% if len(filename) > 15:
<div class="caption" title="${filename}">${filename[:12]}...</div>
<a href="#" class="file"><img src="${file[u'type']}" /></div>
% if len(file[u'name']) > 15:
<a href="#" class="caption" title="${file[u'name']}">${file[u'name'][:12]}...</div>
% else:
<div class="caption">${filename}</div>
<a href="#" class="caption">${file[u'name']}</div>
% endif
</li>
% endfor