forked from viur-framework/viur-vi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
142 lines (110 loc) · 3.75 KB
/
__init__.py
File metadata and controls
142 lines (110 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#-*- coding: utf-8 -*-
from . import html5
from . import network
from . import utils
from . import sidebarwidgets
from . import exception
from .login import LoginScreen
from .admin import AdminScreen
from .config import conf
from .i18n import translate
from . import i18n
class Application(html5.Div):
def __init__(self):
super(Application, self).__init__()
self.addClass("vi-application")
conf["theApp"] = self
# Main Screens
self.loginScreen = None
self.adminScreen = None
try:
self.isFramed = bool(html5.jseval("window.top !== window.self"))
except:
self.isFramed = True
self.startup()
def startup(self, *args, **kwargs):
if conf["core.version"] is None:
network.NetworkService.request(None, "/vi/getVersion",
successHandler=self.getVersionSuccess,
failureHandler=self.startupFailure,
cacheable=True)
else:
network.NetworkService.request(None, "/vi/config",
successHandler=self.getConfigSuccess,
failureHandler=self.startupFailure,
cacheable=True)
def getVersionSuccess(self, req):
conf["core.version"] = network.NetworkService.decode(req)
if ((conf["core.version"][0] >= 0 # check version?
#and (conf["core.version"][0] != conf["vi.version"][0] # major version mismatch (disabled)
and (conf["core.version"][0] not in [2, conf["vi.version"][0]]# major version mismatch (used currently!)
or (conf["core.version"][0] == 3 and conf["core.version"][1] > conf["vi.version"][1])))): # minor version mismatch
params = {
"core.version": ".".join(str(x) for x in conf["core.version"]),
"vi.version": ".".join(str(x) for x in conf["vi.version"]),
}
html5.ext.Alert(
translate("ViUR-core (v{core.version}) is incompatible to this Vi (v{vi.version}).", **params)
+ "\n" + translate("There may be a lack on functionality.")
+ "\n" + translate("Please update either your server or Vi!"),
title=translate("Version mismatch"),
okCallback=self.startup,
okLabel=translate("Continue at your own risk")
)
return
self.startup()
def getConfigSuccess(self, req):
conf["mainConfig"] = network.NetworkService.decode(req)
if not self.adminScreen:
self.adminScreen = AdminScreen()
self.adminScreen.invoke()
def startupFailure(self, req, err):
if err in [403, 401]:
self.login()
else:
html5.ext.Alert(
translate("The connection to the server could not be correctly established."),
title=translate("Communication error"),
okCallback=self.startup,
okLabel=translate("Retry")
)
def login(self, logout=False):
if not self.loginScreen:
self.loginScreen = LoginScreen()
if self.adminScreen:
self.adminScreen.reset()
self.adminScreen.hide()
self.loginScreen.invoke(logout=logout)
def admin(self):
if self.loginScreen:
self.loginScreen.hide()
self.startup()
def logout(self):
self.login(logout=True)
def setTitle(self, title = None):
if title:
title = [title]
else:
title = []
addendum = conf.get("vi.name")
if addendum:
title.append(addendum)
html5.document.title = conf["vi.title.delimiter"].join(title)
def setPath(self, path = ""):
hash = html5.window.location.hash
if "?" in hash and not "?" in path:
hash = hash.split("?", 1)[1]
if hash:
hash = "?" + hash
else:
hash = ""
html5.window.location.hash = path + hash
def start():
# Configure vi as network render prefix
network.NetworkService.prefix = "/vi"
network.NetworkService.host = ""
conf["currentLanguage"] = i18n.getLanguage()
conf["indexeddb"] = utils.indexeddb("vi-cache")
# Application
app = Application()
html5.Body().appendChild(app)