Moved the image file stuff to the server side.
Fixed up the initial file display.
This commit is contained in:
parent
37dabf6386
commit
e3836b5a41
@ -60,7 +60,13 @@ class MediaController(BaseController):
|
|||||||
|
|
||||||
def _get_files(self, dirpath):
|
def _get_files(self, dirpath):
|
||||||
for root, dirs, files in os.walk(os.path.abspath(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
|
break
|
||||||
|
|
||||||
def index(self):
|
def index(self):
|
||||||
@ -79,7 +85,6 @@ 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(dirpath)
|
|
||||||
return {u'results': self._get_files(dirpath)}
|
return {u'results': self._get_files(dirpath)}
|
||||||
|
|
||||||
@jsonify
|
@jsonify
|
||||||
|
@ -36,25 +36,23 @@ ScribeEngine.Namespace.create("ScribeEngine.Media", {
|
|||||||
function (data, textStatus) {
|
function (data, textStatus) {
|
||||||
$("#file-list > ul").html("");
|
$("#file-list > ul").html("");
|
||||||
$.each(data.results, function () {
|
$.each(data.results, function () {
|
||||||
var filename = this;
|
var file = this;
|
||||||
var extension = filename.substr(filename.length - 4);
|
if (file.name.length > 15)
|
||||||
if (extension == ".png" || extension == ".jpg")
|
|
||||||
{
|
{
|
||||||
var filetype = "file-image";
|
file.name = file.name.substr(0, 12) + "...";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var filetype = "file-unknown";
|
|
||||||
}
|
|
||||||
if (filename.length > 15)
|
|
||||||
{
|
|
||||||
filename = filename.substr(0, 12) + "...";
|
|
||||||
}
|
}
|
||||||
$("#file-list > ul").append(
|
$("#file-list > ul").append(
|
||||||
$("<li>")
|
$("<li>")
|
||||||
.append($("<a>").attr("href", "#").attr("class", "file")
|
.append(
|
||||||
.html("<img src=\"/images/" + filetype + ".png\" />").click(ScribeEngine.Media.selectFile))
|
$("<a>").attr("href", "#").attr("class", "file")
|
||||||
.append($("<a>").attr("href", "#").attr("class", "caption").attr("title", filename).text(filename).click(ScribeEngine.Media.selectFile))
|
.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)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,13 @@
|
|||||||
<div id="directory-tree"></div>
|
<div id="directory-tree"></div>
|
||||||
<div id="file-list">
|
<div id="file-list">
|
||||||
<ul>
|
<ul>
|
||||||
% for filename in c.files:
|
% for file in c.files:
|
||||||
<li>
|
<li>
|
||||||
<div class="file"> </div>
|
<a href="#" class="file"><img src="${file[u'type']}" /></div>
|
||||||
% if len(filename) > 15:
|
% if len(file[u'name']) > 15:
|
||||||
<div class="caption" title="${filename}">${filename[:12]}...</div>
|
<a href="#" class="caption" title="${file[u'name']}">${file[u'name'][:12]}...</div>
|
||||||
% else:
|
% else:
|
||||||
<div class="caption">${filename}</div>
|
<a href="#" class="caption">${file[u'name']}</div>
|
||||||
% endif
|
% endif
|
||||||
</li>
|
</li>
|
||||||
% endfor
|
% endfor
|
||||||
|
Reference in New Issue
Block a user