]>
git.proxmox.com Git - pve-manager.git/blob - www/mobile/Workspace.js
1 Ext
.define('PVE.Page', {
2 extend
: 'Ext.Container',
3 alias
: 'widget.pvePage',
6 pathMatch: function(loc
) {
7 throw "implement this in subclass";
17 Ext
.define('PVE.ErrorPage', {
31 pveReloadButton
: false,
32 title
: gettext('Error')
38 Ext
.define('PVE.Workspace', { statics
: {
39 // this class only contains static functions
41 loginData
: null, // Data from last login call
53 'PVE.ClusterTaskList',
59 setHistory: function(h
) {
60 PVE
.Workspace
.history
= h
;
62 PVE
.Workspace
.history
.setUpdateUrl(true);
64 PVE
.Workspace
.loadPage(PVE
.Workspace
.history
.getToken());
65 PVE
.Workspace
.history
.on('change', function(loc
) {
66 PVE
.Workspace
.loadPage(loc
);
71 var actions
= PVE
.Workspace
.history
.getActions(),
72 lastAction
= actions
[actions
.length
- 2];
77 url
= lastAction
.getUrl();
80 // use loadPage directly so we don't cause new additions to the history
81 PVE
.Workspace
.loadPage(url
);
84 __setAppWindow: function(comp
, dir
) {
86 var old
= PVE
.Workspace
.appWindow
;
88 PVE
.Workspace
.appWindow
= comp
;
91 if (dir
=== 'noanim') {
92 Ext
.Viewport
.setActiveItem(PVE
.Workspace
.appWindow
);
94 var anim
= { type
: 'slide', direction
: dir
|| 'left' };
95 Ext
.Viewport
.animateActiveItem(PVE
.Workspace
.appWindow
, anim
);
97 // remove old after anim (hack, because anim.after does not work in 2.3.1a)
98 Ext
.Function
.defer(function(){
100 Ext
.Viewport
.remove(old
);
104 Ext
.Viewport
.setActiveItem(PVE
.Workspace
.appWindow
);
108 updateLoginData: function(loginData
) {
109 PVE
.Workspace
.loginData
= loginData
;
110 PVE
.CSRFPreventionToken
= loginData
.CSRFPreventionToken
;
111 PVE
.UserName
= loginData
.username
;
113 // creates a session cookie (expire = null)
114 // that way the cookie gets deleted after browser window close
115 Ext
.util
.Cookies
.set('PVEAuthCookie', loginData
.ticket
, null, '/', null, true);
117 PVE
.Workspace
.gotoPage('');
120 showLogin: function() {
121 Proxmox
.Utils
.authClear();
123 PVE
.Workspace
.loginData
= null;
125 PVE
.Workspace
.gotoPage('');
128 gotoPage: function(loc
) {
131 var old
= PVE
.Workspace
.appWindow
;
134 var old_loc
= old
.getAppUrl();
135 if (old_loc
!== loc
) {
136 PVE
.Workspace
.history
.add(Ext
.create('Ext.app.Action', { url
: loc
}));
138 PVE
.Workspace
.loadPage(loc
);
141 PVE
.Workspace
.history
.add(Ext
.create('Ext.app.Action', { url
: loc
}));
145 loadPage: function(loc
) {
150 if (!Proxmox
.Utils
.authOK()) {
151 comp
= Ext
.create('PVE.Login', {});
153 Ext
.Array
.each(PVE
.Workspace
.pages
, function(p
, index
) {
154 var c
= Ext
.ClassManager
.get(p
);
155 var match
= c
.pathMatch(loc
);
157 comp
= Ext
.create(p
, { appUrl
: loc
});
158 return false; // stop iteration
162 comp
= Ext
.create('PVE.ErrorPage', {});
166 PVE
.Workspace
.__setAppWindow(comp
, 'noanim');
169 obj_to_kv: function(d
, names
) {
171 var done
= { digest
: 1 };
172 var pushItem = function(item
) {
173 if (done
[item
.key
]) return;
175 if (item
.value
) kv
.push(item
);
178 var keys
= Ext
.Array
.sort(Ext
.Object
.getKeys(d
));
179 Ext
.Array
.each(names
, function(k
) {
180 if (typeof(k
) === 'object') {
181 Ext
.Array
.each(keys
, function(n
) {
183 pushItem({ key
: n
, value
: d
[n
] });
188 pushItem({ key
: k
, value
: d
[k
] });
191 Ext
.Array
.each(keys
, function(k
) {
192 pushItem({ key
: k
, value
: d
[k
] });