Skip to content

Commit f651c68

Browse files
committed
Save active tab in cookie in order to restore after page refresh
1 parent 0f2c093 commit f651c68

File tree

9 files changed

+99
-65
lines changed

9 files changed

+99
-65
lines changed

web/dispatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta/core/utils/error_logger.php'
3+
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta/core/utils/error_logger.php';
44
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta/app.init.php';
55

66
?>

web/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ <h1 class="logo"><a href="#">Vesta panel <span>&nbsp;</span></a></h1>
204204

205205

206206
<!-- script type="text/javascript" src="js/lib/jquery-1.4.4.min.js"></script -->
207+
<script type="text/javascript" src="js/lib/cookie.js"></script>
207208
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.js"></script>
208209
<script type="text/javascript" src="js/date_format.js"></script>
209210
<script type="text/javascript" src="js/lib/custom-form-elements.js"></script>

web/js/__init__.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
$(document).ready(function(){
22
try{
33
App.Utils.detectBrowser();
4-
App.Env.world = 'CRON';
4+
5+
if ('undefined' != typeof App.Tmp.loadTAB) {
6+
App.Env.world = App.Tmp.loadTAB;
7+
}
8+
9+
if ('undefined' == typeof App.Tmp.loadTAB && cookieEnabled()) {
10+
var tab = getCookie('tab');
11+
if (null != tab && $.inArray(tab, App.Constants.TABS)) {
12+
App.Env.world = tab;
13+
}
14+
else {
15+
App.Env.world = App.Constants.TABS[0];
16+
}
17+
}
18+
519
App.Pages.init();
620
App.Ref.init();
721

web/js/app.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ var App = {
7878
Core: {},
7979
Bash: {},
8080
Console: {},
81-
Constants: {},
81+
Constants: {
82+
TABS: ['USER','WEB_DOMAIN','MAIL','DB','DNS','IP','CRON']
83+
},
8284
Actions: {},
8385
Helpers: {},
8486
Filters: {},
@@ -175,16 +177,7 @@ App.Ajax.request = function(jedi_method, data, callback)
175177
{
176178
App.Helpers.beforeAjax(jedi_method);
177179
$.ajax({
178-
url: function() {
179-
var url_parts = location.href.replace('#', '').split('/');
180-
if (url_parts[url_parts.length -1] == 'index.html') {
181-
url_parts[url_parts.length -1] = 'dispatch.php';
182-
}
183-
else {
184-
url_parts.push('dispatch.php');
185-
}
186-
return url_parts.join('/');
187-
}(),
180+
url: App.Helpers.getBackendUrl(),
188181
global: false,
189182
type: data.request_method || "POST",
190183
data: $.extend(data, {'jedi_method': jedi_method}),

web/js/helpers.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,26 @@ App.Helpers.closeInnerPopup = function(evt)
264264
{
265265
$('#inner-popup').remove();
266266
}
267+
268+
App.Helpers.getBackendUrl = function()
269+
{
270+
var url_parts = location.href.split('#');
271+
if (url_parts.length > 1) {
272+
var tab = url_parts[url_parts.length - 1];
273+
if ($.inArray(tab, App.Constants.TABS) != -1) {
274+
App.Tmp.loadTAB = tab;
275+
}
276+
}
277+
278+
var url_parts = location.href.split('?', 1);
279+
var url = url_parts[0];
280+
url_parts = url.split('/');
281+
if (url_parts[url_parts.length -1] == 'index.html') {
282+
url_parts[url_parts.length -1] = 'dispatch.php';
283+
}
284+
else {
285+
url_parts.push('dispatch.php');
286+
}
287+
288+
return url_parts.join('/');
289+
}

web/js/pages.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ App.Pages.init = function(){
88

99
$('.section.active').removeClass('active');
1010
$('#'+App.Env.world).addClass('active');
11+
12+
if (cookieEnabled()) {
13+
setCookie('tab', App.Env.world);
14+
}
1115
}
1216

1317
App.Pages.prepareHTML = function()

web/vesta/api/AjaxHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ static function getInstance($request=null)
2424
{
2525
return null == self::$instance ? self::$instance = new self() : self::$instance;
2626
}
27+
28+
public function getLoggedUser()
29+
{
30+
return VestaSession::getInstance()->getUser();
31+
}
2732

2833
/**
2934
* Called functions should reply in the following way

web/vesta/api/USER.class.php

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class USER extends AjaxHandler
1717
* @param Request $request
1818
* @return string - Ajax Reply
1919
*/
20-
public function getListExecute($request)
20+
public function getListExecute(Request $request)
2121
{
2222
$reply = array();
2323
$result = Vesta::execute(Vesta::V_LIST_SYS_USERS, array(Config::get('response_type')));
@@ -34,40 +34,40 @@ public function getListExecute($request)
3434
$reply[$user] = array(
3535
"LOGIN_NAME" => $user,
3636
"FULLNAME" => $fullname, // TODO skid
37-
"PACKAGE" => $details['PACKAGE'],
38-
"WEB_DOMAINS" => $details['WEB_DOMAINS'],
39-
"WEB_SSL" => $details['WEB_SSL'],
40-
"WEB_ALIASES" => $details['WEB_ALIASES'],
41-
"DATABASES" => $details['DATABASES'],
42-
"MAIL_DOMAINS" => $details['MAIL_DOMAINS'],
43-
"MAIL_BOXES" => $details['MAIL_BOXES'],
44-
"MAIL_FORWARDERS" => $details['MAIL_FORWARDERS'],
45-
"DNS_DOMAINS" => $details['DNS_DOMAINS'],
46-
"DISK_QUOTA" => $details['DISK_QUOTA'],//$disk_quota,
47-
"BANDWIDTH" => $details['BANDWIDTH'],//$bandwidth,
48-
"NS_LIST" => array($details['NS1'], $details['NS2']), // TODO skid
49-
"SHELL" => $details['"SHELL'],
50-
"BACKUPS" => $details['BACKUPS'],
51-
"WEB_TPL" => $details['WEB_TPL'],
52-
"MAX_CHILDS" => $details['MAX_CHILDS'],
53-
"SUSPENDED" => $details['SUSPENDED'],
54-
"OWNER" => $details['OWNER'],
55-
"ROLE" => $details['ROLE'],
56-
"IP_OWNED" => $details['IP_OWNED'],
57-
"U_CHILDS" => $details['U_CHILDS'],
58-
"U_DISK" => $details['U_DISK'],//$u_disk,
59-
"U_BANDWIDTH" => $details['U_BANDWIDTH'],//$u_bandwidth,
60-
"U_WEB_DOMAINS" => $details['U_WEB_DOMAINS'],
61-
"U_WEB_SSL" => $details['U_WEB_SSL'],
62-
"U_DNS_DOMAINS" => $details['U_DNS_DOMAINS'],
63-
"U_DATABASES" => $details['U_DATABASES'],
64-
"U_MAIL_DOMAINS" => $details['U_MAIL_DOMAINS'],
65-
"CONTACT" => $details['CONTACT'],
66-
"DATE" => $details['DATE'],
37+
"PACKAGE" => $details['PACKAGE'],
38+
"WEB_DOMAINS" => $details['WEB_DOMAINS'],
39+
"WEB_SSL" => $details['WEB_SSL'],
40+
"WEB_ALIASES" => $details['WEB_ALIASES'],
41+
"DATABASES" => $details['DATABASES'],
42+
"MAIL_DOMAINS" => $details['MAIL_DOMAINS'],
43+
"MAIL_BOXES" => $details['MAIL_BOXES'],
44+
"MAIL_FORWARDERS" => $details['MAIL_FORWARDERS'],
45+
"DNS_DOMAINS" => $details['DNS_DOMAINS'],
46+
"DISK_QUOTA" => $details['DISK_QUOTA'],//$disk_quota,
47+
"BANDWIDTH" => $details['BANDWIDTH'],//$bandwidth,
48+
"NS_LIST" => array($details['NS1'], $details['NS2']), // TODO skid
49+
"SHELL" => $details['"SHELL'],
50+
"BACKUPS" => $details['BACKUPS'],
51+
"WEB_TPL" => $details['WEB_TPL'],
52+
"MAX_CHILDS" => $details['MAX_CHILDS'],
53+
"SUSPENDED" => $details['SUSPENDED'],
54+
"OWNER" => $details['OWNER'],
55+
"ROLE" => $details['ROLE'],
56+
"IP_OWNED" => $details['IP_OWNED'],
57+
"U_CHILDS" => $details['U_CHILDS'],
58+
"U_DISK" => $details['U_DISK'],//$u_disk,
59+
"U_BANDWIDTH" => $details['U_BANDWIDTH'],//$u_bandwidth,
60+
"U_WEB_DOMAINS" => $details['U_WEB_DOMAINS'],
61+
"U_WEB_SSL" => $details['U_WEB_SSL'],
62+
"U_DNS_DOMAINS" => $details['U_DNS_DOMAINS'],
63+
"U_DATABASES" => $details['U_DATABASES'],
64+
"U_MAIL_DOMAINS" => $details['U_MAIL_DOMAINS'],
65+
"CONTACT" => $details['CONTACT'],
66+
"DATE" => $details['DATE'],
6767

68-
"U_MAIL_BOXES" => rand(1, 10), // TODO: skid
69-
"U_MAIL_FORWARDERS" => rand(1, 10), // TODO: skid
70-
"REPORTS_ENABLED" => 'enabled' // TODO: skid
68+
"U_MAIL_BOXES" => rand(1, 10), // TODO: skid
69+
"U_MAIL_FORWARDERS" => rand(1, 10), // TODO: skid
70+
"REPORTS_ENABLED" => 'enabled' // TODO: skid
7171
);
7272
}
7373

@@ -80,26 +80,19 @@ public function getListExecute($request)
8080
* @param Request $request
8181
* @return string - Ajax Reply
8282
*/
83-
public function addExecute($_spell = FALSE)
83+
public function addExecute(Request $request)
8484
{
85-
$r = new Request();
86-
if ($_spell) {
87-
$_s = $_spell;
88-
}
89-
else {
90-
$_s = $r->getSpell();
91-
}
92-
93-
$_user = 'vesta';
85+
$spell = $request->getParameter('spell');
86+
$user = $this->getLoggedUser();
9487
$params = array(
95-
'USER' => $_s['USER'],
96-
'PASSWORD' => $_s['PASSWORD'],
97-
'EMAIL' => $_s['EMAIL'],
98-
'ROLE' => $_s['ROLE'],
99-
'OWNER' => $_user,
100-
'PACKAGE' => $_s['PACKAGE'],
101-
'NS1' => $_s['NS1'],
102-
'NS2' => $_s['NS2']
88+
'USER' => $spell['USER'],
89+
'PASSWORD' => $spell['PASSWORD'],
90+
'EMAIL' => $spell['EMAIL'],
91+
'ROLE' => $spell['ROLE'],
92+
'OWNER' => $user['uid'],
93+
'PACKAGE' => $spell['PACKAGE'],
94+
'NS1' => $spell['NS1'],
95+
'NS2' => $spell['NS2']
10396
);
10497

10598
$result = Vesta::execute(Vesta::V_ADD_SYS_USER, $params);

web/vesta/app.init.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
define('V_ROOT_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
44

55
require_once V_ROOT_DIR . 'config/Config.class.php';
6+
require_once V_ROOT_DIR . 'core/VestaSession.class.php';
67
require_once V_ROOT_DIR . 'core/Vesta.class.php';
78
require_once V_ROOT_DIR . 'core/exceptions/SystemException.class.php';
89
require_once V_ROOT_DIR . 'core/exceptions/ProtectionException.class.php';

0 commit comments

Comments
 (0)