Commit 69f4efda authored by Marcel's avatar Marcel
Browse files

Fix json encoding, change $.getJSON to $.ajax, introduce encode_json in remote filesystem.

parent 8186bdf9
......@@ -71,26 +71,21 @@ class FSAjaxController(AbstractController):
@cherrypy.expose
@cherrypy.tools.allow(methods=['POST', 'GET'])
@cherrypy.tools.json_out()
def filelist(self, path, deep=False, filter=[], reverse=False):
try:
fs = self.get('fs')
cherrypy.session.save()
cherrypy.session.loaded = False
path = self.convert(path, 'string')
deep = self.convert(deep, 'boolean')
filter = self.convert(filter, 'string')
reverse = self.convert(reverse, 'boolean')
# get the files with the filter
files = fs.get_file_list(
path, deep=deep, filter=filter, reverse=reverse)
files = fs.get_file_list(path, deep=deep, filter=filter, reverse=reverse, encode_json=True)
rjson = vispa.rpc.get(cherrypy.request.user, cherrypy.request.workspace).getmodule("json")
cherrypy.response.headers['Content-Type'] = "application/json"
return rjson.dumps(files)
return self.success({'data': json.loads(files)})
except Exception, e:
vispa.log_exception()
return self.fail(msg='Couldn\'t load files: %s' % str(e))
......
......@@ -8,6 +8,7 @@ import locale
import shutil
from mimetypes import guess_type
from zipfile import ZipFile
import json
class FileSystem(object):
......@@ -68,7 +69,7 @@ class FileSystem(object):
return None
return target_type if target_type == type else None
def get_file_list(self, path, deep=False, filter=[], reverse=False, hide_hidden=True):
def get_file_list(self, path, deep=False, filter=[], reverse=False, hide_hidden=True, encode_json=False):
filelist = []
path_expand = os.path.expanduser(os.path.expandvars(path))
for elem in os.listdir(path_expand):
......@@ -103,7 +104,11 @@ class FileSystem(object):
# Determine the parent
parentpath = path_expand[:-1] if path_expand.endswith(os.sep) and path_expand!=os.sep else path_expand
parentpath = os.path.dirname(path_expand)
return {'filelist': filelist, 'parentpath': parentpath}
data = {'filelist': filelist, 'parentpath': parentpath}
if encode_json:
return json.dumps(data)
return data
def get_suggestions(self, path, length=1, append_hidden=True):
suggestions = []
......
......@@ -51,16 +51,22 @@ var FileBase = Class.extend({
},
updateView: function() {
// this.workflow.data = this.ajax.fileList(this.workflow.path);
// this.currentView.setContent(this.workflow.data);
var _this = this;
$.getJSON(
this.urlFormatter('ajax/fs/filelist' + "?path=" + this.workflow.path),
function(data) {
_this.workflow.data = data;
_this.currentView.setContent(data);
console.log(data);
});
$.ajax({
url: this.urlFormatter('ajax/fs/filelist'),
type: 'POST',
data: {
path: this.workflow.path
},
success: function(response) {
if (response.success) {
_this.workflow.data = response.data;
_this.currentView.setContent(response.data);
} else {
$.Topic('msg.error').publish(response.msg);
}
}
});
}
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment