Commit 6eea66f0 authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Code cleanup.

parent 9d4783a3
......@@ -28,49 +28,6 @@ class StaticController(object):
}
def success(data=None, encode_json=None, set_header=True, **kwargs):
# data is the default key, when using this method with 1 argument
# like "success(<somedata>, encode_json=...)"
if data is not None:
kwargs["data"] = data
# no encoding when encode_json is None
if encode_json is None:
result = {"success": True}
result.update(kwargs)
return result
# explicitly not json encoded, return a dict
elif not encode_json:
result = {"success": True}
for key, value in kwargs.items():
# 'value' may be a json encoded string, e.g. '{"foo": "bar"}', try to load it
try:
result[key] = json.loads(value)
except Exception:
result[key] = value
return result
# explicitly json encoded, return a string
else:
data = ['"success": true']
for key, value in kwargs.items():
if value and isinstance(value, (str, unicode)) and value[0] + value[-1] in ["{}", "[]"]:
data.append('"%s": %s' % (key, value))
else:
data.append(json.dumps({key: value})[1:-1])
if set_header:
cherrypy.response.headers["Content-Type"] = "application/json"
return '{%s}' % ", ".join(data)
def fail(msg=None, encode_json=False, set_header=True):
if encode_json and set_header:
cherrypy.response.headers['Content-Type'] = 'application/json'
result = {'success': False}
if msg:
result.update({'msg': msg})
return result if not encode_json else json.dumps(result)
class AbstractController(object):
def __init__(self, mount_static=True):
......@@ -115,6 +72,8 @@ class AbstractController(object):
workspace = request.workspace if len(args) == 0 else args[0]
return vispa.workspace.get_instance(
"vispa.remote.filesystem.FileSystem", workspace=workspace)
elif key == "workspace_id":
return request.private_params.get("_workspaceId", None)
elif key == "view_id":
return request.private_params.get("_viewId", None)
elif key == "proxy":
......
# -*- coding: utf-8 -*-
import cherrypy
from vispa.controller import AbstractController, success, fail
from vispa.controller import AbstractController
from vispa.controller.filesystem import FSAjaxController
from vispa.models.user import User
from vispa.models.workspace import Workspace, WorkspaceState
......
......@@ -412,7 +412,7 @@ var Workspace = Emitter.extend({
var prevent = self.loading()
|| (!self.selected() && vispa.extensions.getWorkspaceInstances(self.getId()).length)
if (prevent) {
setTimeout(function() { $("body").trigger("click") }, 0);
setTimeout(function() { $("body").trigger("click"); }, 0);
event.preventDefault();
}
if (!self.loading())
......
Supports Markdown
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