diff --git a/scribeengine/controllers/media.py b/scribeengine/controllers/media.py index 43b7cff..134d373 100644 --- a/scribeengine/controllers/media.py +++ b/scribeengine/controllers/media.py @@ -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 diff --git a/scribeengine/public/scripts/ScribeEngine.Media.js b/scribeengine/public/scripts/ScribeEngine.Media.js index 2ee0875..fb6f60c 100644 --- a/scribeengine/public/scripts/ScribeEngine.Media.js +++ b/scribeengine/public/scripts/ScribeEngine.Media.js @@ -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( $("
  • ") - .append($("").attr("href", "#").attr("class", "file") - .html("").click(ScribeEngine.Media.selectFile)) - .append($("").attr("href", "#").attr("class", "caption").attr("title", filename).text(filename).click(ScribeEngine.Media.selectFile)) + .append( + $("").attr("href", "#").attr("class", "file") + .html("") + .click(ScribeEngine.Media.selectFile) + ) + .append( + $("").attr("href", "#").attr("class", "caption") + .attr("title", file.name).text(file.name) + .click(ScribeEngine.Media.selectFile) + ) ); }); } diff --git a/scribeengine/templates/media/index.mako b/scribeengine/templates/media/index.mako index d33464b..6743731 100644 --- a/scribeengine/templates/media/index.mako +++ b/scribeengine/templates/media/index.mako @@ -29,13 +29,13 @@
    +% if len(file[u'name']) > 15: + ${file[u'name'][:12]}... % else: -
    ${filename}
    +
    ${file[u'name']} % endif
  • % endfor