mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Feature #3748: Fix user settings
Use user template append, fix page refresh after settings change
This commit is contained in:
parent
273b3381fe
commit
aab1264c82
@ -65,7 +65,11 @@ module OpenNebulaJSON
|
||||
end
|
||||
|
||||
def update(params=Hash.new)
|
||||
super(params['template_raw'])
|
||||
if !params['append'].nil?
|
||||
super(params['template_raw'], params['append'])
|
||||
else
|
||||
super(params['template_raw'])
|
||||
end
|
||||
end
|
||||
|
||||
def set_quota(params=Hash.new)
|
||||
|
@ -72,6 +72,10 @@ define(function(require) {
|
||||
var action_obj = {"template_raw" : params.data.extra_param};
|
||||
OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj);
|
||||
},
|
||||
"append": function(params) {
|
||||
var action_obj = {"template_raw" : params.data.extra_param, append : true};
|
||||
OpenNebulaAction.simple_action(params, RESOURCE, "update", action_obj);
|
||||
},
|
||||
"fetch_template" : function(params) {
|
||||
OpenNebulaAction.show(params, RESOURCE, "template");
|
||||
},
|
||||
|
@ -7,6 +7,8 @@ define(function(require) {
|
||||
var Locale = require('utils/locale');
|
||||
var Config = require('sunstone-config');
|
||||
var OpenNebula = require('opennebula');
|
||||
var Sunstone = require('sunstone');
|
||||
var Notifier = require('utils/notifier');
|
||||
|
||||
/*
|
||||
TEMPLATES
|
||||
@ -96,93 +98,26 @@ define(function(require) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OpenNebula.User.show({
|
||||
data : {
|
||||
id: "-1"
|
||||
},
|
||||
success: function(request, user_json) {
|
||||
var template = user_json.USER.TEMPLATE;
|
||||
var template_str = 'SSH_PUBLIC_KEY = "'+keypair+'"';
|
||||
|
||||
template["SSH_PUBLIC_KEY"] = keypair;
|
||||
Sunstone.runAction("User.append_template", "-1", template_str);
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
Sunstone.runAction("User.update_template", "-1", template_str);
|
||||
}
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#provision_change_view_form").submit(function() {
|
||||
var view = $('#provision_user_views_select', this).val();
|
||||
var template_str = 'DEFAULT_VIEW = "'+$('#provision_user_views_select', this).val()+'"';
|
||||
|
||||
OpenNebula.User.show({
|
||||
data : {
|
||||
id: "-1"
|
||||
},
|
||||
success: function(request, user_json) {
|
||||
var template = user_json.USER.TEMPLATE;
|
||||
Sunstone.runAction("User.append_template_refresh", "-1", template_str);
|
||||
|
||||
template["DEFAULT_VIEW"] = view;
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
var data = OpenNebula.Helper.action('update', {"template_raw" : template_str});
|
||||
|
||||
$.ajax({
|
||||
url: 'config',
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(data),
|
||||
success: function() {
|
||||
window.location.href = ".";
|
||||
},
|
||||
error: function(response) {
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#provision_change_language_form").submit(function() {
|
||||
var lang = $('#provision_new_language', this).val();
|
||||
var template_str = 'LANG = "'+$('#provision_new_language', this).val()+'"';
|
||||
|
||||
OpenNebula.User.show({
|
||||
data : {
|
||||
id: "-1"
|
||||
},
|
||||
success: function(request, user_json) {
|
||||
var template = user_json.USER.TEMPLATE;
|
||||
Sunstone.runAction("User.append_template_refresh", "-1", template_str);
|
||||
|
||||
template["LANG"] = lang;
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
var data = OpenNebula.Helper.action('update', {"template_raw" : template_str});
|
||||
|
||||
$.ajax({
|
||||
url: 'config',
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(data),
|
||||
success: function() {
|
||||
window.location.href = ".";
|
||||
},
|
||||
error: function(response) {
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
return false;
|
||||
});
|
||||
|
||||
|
@ -152,6 +152,17 @@ define(function(require) {
|
||||
type: "single",
|
||||
call: OpenNebulaResource.update,
|
||||
callback: function(request) {
|
||||
$.ajax({
|
||||
url: 'config',
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function() {
|
||||
return false;
|
||||
},
|
||||
error: function(response) {
|
||||
}
|
||||
});
|
||||
|
||||
Sunstone.runAction(RESOURCE+'.show',request.request.data[0][0]);
|
||||
if (request.request.data[0][0] == config['user_id']) {
|
||||
Sunstone.runAction('Settings.refresh');
|
||||
@ -160,28 +171,43 @@ define(function(require) {
|
||||
error: Notifier.onError
|
||||
},
|
||||
|
||||
"User.update_language" : {
|
||||
"User.append_template" : {
|
||||
type: "single",
|
||||
call: OpenNebulaResource.update,
|
||||
call: OpenNebulaResource.append,
|
||||
callback: function(request) {
|
||||
$.ajax({
|
||||
url: 'config',
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function() {
|
||||
return false;
|
||||
},
|
||||
error: function(response) {
|
||||
}
|
||||
});
|
||||
|
||||
Sunstone.runAction(RESOURCE+'.show',request.request.data[0][0]);
|
||||
if (request.request.data[0][0] == config['user_id']) {
|
||||
Sunstone.runAction('Settings.refresh');
|
||||
}
|
||||
Notifier.notifyMessage(Locale.tr("The user must refresh the page for the change to take effect"));
|
||||
},
|
||||
error: Notifier.onError
|
||||
},
|
||||
|
||||
"User.update_view" : {
|
||||
"User.append_template_refresh" : {
|
||||
type: "single",
|
||||
call: OpenNebulaResource.update,
|
||||
call: OpenNebulaResource.append,
|
||||
callback: function(request) {
|
||||
Sunstone.runAction(RESOURCE+'.show',request.request.data[0][0]);
|
||||
if (request.request.data[0][0] == config['user_id']) {
|
||||
Sunstone.runAction('Settings.refresh');
|
||||
}
|
||||
Notifier.notifyMessage(Locale.tr("The user must refresh the page for the change to take effect"));
|
||||
$.ajax({
|
||||
url: 'config',
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function() {
|
||||
window.location.href = ".";
|
||||
},
|
||||
error: function(response) {
|
||||
}
|
||||
});
|
||||
},
|
||||
error: Notifier.onError
|
||||
},
|
||||
|
@ -146,27 +146,9 @@ define(function(require) {
|
||||
|
||||
context.off("change", "#user_ssh_public_key_textarea");
|
||||
context.on("change", "#user_ssh_public_key_textarea", function() {
|
||||
var user_id = that.element.ID;
|
||||
var template_str = 'SSH_PUBLIC_KEY = "'+$(this).val()+'"';
|
||||
|
||||
// TODO: use update --append instead of a show + update
|
||||
|
||||
OpenNebulaUser.show({
|
||||
data : {
|
||||
id: user_id
|
||||
},
|
||||
success: function(request, user_json) {
|
||||
var template = that.element.TEMPLATE;
|
||||
|
||||
template["SSH_PUBLIC_KEY"] = $("#user_ssh_public_key_textarea", context).val();
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
Sunstone.runAction("User.update_template", user_id, template_str);
|
||||
}
|
||||
});
|
||||
Sunstone.runAction("User.append_template", that.element.ID, template_str);
|
||||
});
|
||||
|
||||
context.off("focusout", "#user_ssh_public_key_textarea");
|
||||
@ -190,24 +172,9 @@ define(function(require) {
|
||||
|
||||
context.off("change", "#table_order_select")
|
||||
context.on("change", "#table_order_select", function() {
|
||||
var user_id = that.element.ID;
|
||||
OpenNebulaUser.show({
|
||||
data : {
|
||||
id: user_id
|
||||
},
|
||||
success: function(request, user_json) {
|
||||
var template = that.element.TEMPLATE;
|
||||
var template_str = 'TABLE_ORDER = "'+$(this).val()+'"';
|
||||
|
||||
template["TABLE_ORDER"] = $("#table_order_select", context).val();
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
Sunstone.runAction("User.update_template", user_id, template_str);
|
||||
}
|
||||
});
|
||||
Sunstone.runAction("User.append_template", that.element.ID, template_str);
|
||||
});
|
||||
|
||||
// Change language
|
||||
@ -224,36 +191,9 @@ define(function(require) {
|
||||
|
||||
context.off("change", "#language_select")
|
||||
context.on("change", "#language_select", function() {
|
||||
var user_id = that.element.ID;
|
||||
OpenNebulaUser.show({
|
||||
data : {
|
||||
id: user_id
|
||||
},
|
||||
success: function(request, user_json) {
|
||||
var template = that.element.TEMPLATE;
|
||||
var template_str = 'LANG = "'+$(this).val()+'"';
|
||||
|
||||
template["LANG"] = $("#language_select", context).val();
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
Sunstone.runAction("User.update_language", user_id, template_str);
|
||||
|
||||
$.ajax({
|
||||
url: 'config',
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(template_str),
|
||||
success: function() {
|
||||
window.location.href = ".";
|
||||
},
|
||||
error: function(response) {
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Sunstone.runAction("User.append_template_refresh", that.element.ID, template_str);
|
||||
});
|
||||
|
||||
// Change view
|
||||
@ -275,24 +215,9 @@ define(function(require) {
|
||||
|
||||
context.off("change", "#view_select")
|
||||
context.on("change", "#view_select", function() {
|
||||
var user_id = that.element.ID;
|
||||
OpenNebulaUser.show({
|
||||
data : {
|
||||
id: user_id
|
||||
},
|
||||
success: function(request, user_json) {
|
||||
var template = that.element.TEMPLATE;
|
||||
var template_str = 'DEFAULT_VIEW = "'+$(this).val()+'"';
|
||||
|
||||
template["DEFAULT_VIEW"] = $("#view_select", context).val();
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
Sunstone.runAction("User.update_view", user_id, template_str);
|
||||
}
|
||||
});
|
||||
Sunstone.runAction("User.append_template_refresh", that.element.ID, template_str);
|
||||
});
|
||||
|
||||
return false;
|
||||
|
@ -162,26 +162,11 @@ define(function(require) {
|
||||
// Remember page length only for non selectable datatables
|
||||
if (!this.conf.select) {
|
||||
this.dataTable.on( 'length.dt', function ( e, settings, len ) {
|
||||
|
||||
config['page_length'] = len;
|
||||
|
||||
OpenNebulaUser.show({
|
||||
data : {
|
||||
id: config['user_id']
|
||||
},
|
||||
success: function(request, response) {
|
||||
var template = response.USER.TEMPLATE;
|
||||
var template_str = 'TABLE_DEFAULT_PAGE_LENGTH = "'+len+'"';
|
||||
|
||||
template["TABLE_DEFAULT_PAGE_LENGTH"] = len;
|
||||
|
||||
template_str = "";
|
||||
$.each(template, function(key, value) {
|
||||
template_str += (key + '=' + '"' + value + '"\n');
|
||||
});
|
||||
|
||||
Sunstone.runAction("User.update_template", config['user_id'], template_str);
|
||||
}
|
||||
});
|
||||
Sunstone.runAction("User.append_template", config['user_id'], template_str);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -454,7 +454,7 @@ post '/config' do
|
||||
session[:table_order] = user['TEMPLATE/TABLE_ORDER'] if user['TEMPLATE/TABLE_ORDER']
|
||||
session[:display_name] = user[DISPLAY_NAME_XPATH] || user['NAME']
|
||||
|
||||
[200, ""]
|
||||
[204, ""]
|
||||
end
|
||||
|
||||
get '/vm/:id/log' do
|
||||
|
Loading…
x
Reference in New Issue
Block a user