$ -> $(window).bind('body_loaded', => fb = new FileBrowser() ) class FileBrowser constructor: -> $(window).on('hashchange', @hashchange) @hashchange() hashchange: => location = window.location.hash location = location.slice(1,location.length) @load_dir(location) load_dir: (path) => $('#file-list').html("") $('#dir-path').html("") $.ajax '/api/file_system/metadata' data: path: path dataType: 'json' success: (data) => console.log data for file in data.contents $('#dir-path').html(@path_element(path)) $('#file-list').append(@create_element(file)) error: => alert "Cant load directory #{path}" create_element: (file) => if file.is_dir el = $("#{file.name}DIR") else app = "" app = "texteditor" if file.mime_type.match("text/") app = "photobrowser" if file.mime_type.match("image/") if (app == "" and not file.binary) app = "texteditor" if app.length > 0 el = $("#{file.name}#{file.mime_type}") else el = $("#{file.name}#{file.mime_type}") return el path_element: (path) => ret = $("") ar = path.split('/') for dir in ar ret.append("
  • / #{dir}
  • ") return ret