1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

Feature #3748: User password and auth driver dialogs

This commit is contained in:
Carlos Martín 2015-06-03 16:50:54 +02:00
parent 71a2bee336
commit 3ce6213812
10 changed files with 275 additions and 21 deletions

View File

@ -8,6 +8,8 @@ define(function(require) {
var DATATABLE_ID = "dataTableUsers";
var _dialogs = [
require('./users-tab/dialogs/password'),
require('./users-tab/dialogs/auth-driver')
];
var _panels = [

View File

@ -8,6 +8,8 @@ define(function(require) {
var RESOURCE = "User";
var TAB_ID = require('./tabId');
var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
var PASSWORD_DIALOG_ID = require('./dialogs/password/dialogId');
var AUTH_DRIVER_DIALOG_ID = require('./dialogs/auth-driver/dialogId');
var _actions = {
"User.create" : {
@ -55,19 +57,19 @@ define(function(require) {
error: Notifier.onError
},
/* TODO
"User.update_password" : {
type: "custom",
call: popUpUpdatePasswordDialog
call: function(){
Sunstone.getDialog(PASSWORD_DIALOG_ID).show();
}
},
"User.passwd" : {
type: "multiple",
call: OpenNebulaResource.passwd,
elements: userElements,
error: onError
error: Notifier.onError
},
*/
"User.chgrp" : {
type: "multiple",
call: OpenNebulaResource.chgrp,
@ -98,20 +100,20 @@ define(function(require) {
elements : userElements,
error: onError
},
*/
"User.change_authentication" : {
type: "custom",
call: popUpChangeAuthenticationDialog
call: function(){
Sunstone.getDialog(AUTH_DRIVER_DIALOG_ID).show();
}
},
"User.chauth" : {
type: "multiple",
call: OpenNebulaResource.chauth,
callback : function(req){
Sunstone.runAction(RESOURCE+".show",req.request.data[0][0]);
},
elements: userElements,
error: onError
error: Notifier.onError,
},
*/
"User.show" : {
type: "single",
call: OpenNebulaResource.show,

View File

@ -0,0 +1,89 @@
define(function(require) {
/*
DEPENDENCIES
*/
var BaseDialog = require('utils/dialogs/dialog');
var TemplateHTML = require('hbs!./auth-driver/html');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Locale = require('utils/locale');
var UserCreation = require('tabs/users-tab/utils/user-creation');
/*
CONSTANTS
*/
var DIALOG_ID = require('./auth-driver/dialogId');
var TAB_ID = require('../tabId');
/*
CONSTRUCTOR
*/
function Dialog() {
this.dialogId = DIALOG_ID;
BaseDialog.call(this);
}
Dialog.DIALOG_ID = DIALOG_ID;
Dialog.prototype = Object.create(BaseDialog.prototype);
Dialog.prototype.constructor = Dialog;
Dialog.prototype.html = _html;
Dialog.prototype.onShow = _onShow;
Dialog.prototype.setup = _setup;
return Dialog;
/*
FUNCTION DEFINITIONS
*/
function _html() {
return TemplateHTML({
'dialogId': this.dialogId,
'userCreationHTML': UserCreation.html()
});
}
function _setup(context) {
var that = this;
UserCreation.setup(context, {name: false, password: false});
context.off('invalid.fndtn.abide', '#' + DIALOG_ID + 'Form');
context.off('valid.fndtn.abide', '#' + DIALOG_ID + 'Form');
context.on('invalid.fndtn.abide', '#' + DIALOG_ID + 'Form', function(e) {
// Fix for valid event firing twice
if (e.namespace != 'abide.fndtn') { return; }
Notifier.notifyError(Locale.tr("One or more required fields are missing or malformed."));
}).on('valid.fndtn.abide', '#' + DIALOG_ID + 'Form', function(e) {
// Fix for valid event firing twice
if (e.namespace != 'abide.fndtn') { return; }
var inputs = UserCreation.retrieve(context);
var selElems = Sunstone.getDataTable(TAB_ID).elements();
Sunstone.runAction('User.chauth', selElems, inputs.auth_driver);
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).reset();
Sunstone.runAction('User.refresh');
return false;
});
context.foundation('reflow', 'abide');
return false;
}
function _onShow(context) {
return false;
}
});

View File

@ -0,0 +1,3 @@
define(function(require){
return 'userAuthDriverDialog';
});

View File

@ -0,0 +1,18 @@
<div id="{{dialogId}}" class="reveal-modal" role="dialog" data-reveal >
<div class="row">
<h3 class="subheader">{{tr "Change authentication"}}</h3>
</div>
<form data-abide="ajax" id="{{dialogId}}Form">
<div class="row">
<div class="large-12 columns">
{{{userCreationHTML}}}
</div>
</div>
<div class="form_buttons row">
<button type="submit" class="button radius right">
{{tr "Change"}}
</button>
</div>
<a class="close-reveal-modal">&#215;</a>
</form>
</div>

View File

@ -0,0 +1,89 @@
define(function(require) {
/*
DEPENDENCIES
*/
var BaseDialog = require('utils/dialogs/dialog');
var TemplateHTML = require('hbs!./password/html');
var Sunstone = require('sunstone');
var Notifier = require('utils/notifier');
var Locale = require('utils/locale');
var UserCreation = require('tabs/users-tab/utils/user-creation');
/*
CONSTANTS
*/
var DIALOG_ID = require('./password/dialogId');
var TAB_ID = require('../tabId');
/*
CONSTRUCTOR
*/
function Dialog() {
this.dialogId = DIALOG_ID;
BaseDialog.call(this);
}
Dialog.DIALOG_ID = DIALOG_ID;
Dialog.prototype = Object.create(BaseDialog.prototype);
Dialog.prototype.constructor = Dialog;
Dialog.prototype.html = _html;
Dialog.prototype.onShow = _onShow;
Dialog.prototype.setup = _setup;
return Dialog;
/*
FUNCTION DEFINITIONS
*/
function _html() {
return TemplateHTML({
'dialogId': this.dialogId,
'userCreationHTML': UserCreation.html()
});
}
function _setup(context) {
var that = this;
UserCreation.setup(context, {name: false, auth_driver: false});
context.off('invalid.fndtn.abide', '#' + DIALOG_ID + 'Form');
context.off('valid.fndtn.abide', '#' + DIALOG_ID + 'Form');
context.on('invalid.fndtn.abide', '#' + DIALOG_ID + 'Form', function(e) {
// Fix for valid event firing twice
if (e.namespace != 'abide.fndtn') { return; }
Notifier.notifyError(Locale.tr("One or more required fields are missing or malformed."));
}).on('valid.fndtn.abide', '#' + DIALOG_ID + 'Form', function(e) {
// Fix for valid event firing twice
if (e.namespace != 'abide.fndtn') { return; }
var inputs = UserCreation.retrieve(context);
var selElems = Sunstone.getDataTable(TAB_ID).elements();
Sunstone.runAction('User.passwd', selElems, inputs.password);
Sunstone.getDialog(DIALOG_ID).hide();
Sunstone.getDialog(DIALOG_ID).reset();
Sunstone.runAction('User.refresh');
return false;
});
context.foundation('reflow', 'abide');
return false;
}
function _onShow(context) {
return false;
}
});

View File

@ -0,0 +1,3 @@
define(function(require){
return 'userPasswordDialog';
});

View File

@ -0,0 +1,18 @@
<div id="{{dialogId}}" class="reveal-modal" role="dialog" data-reveal >
<div class="row">
<h3 class="subheader">{{tr "Update Password"}}</h3>
</div>
<form data-abide="ajax" id="{{dialogId}}Form">
<div class="row">
<div class="large-12 columns">
{{{userCreationHTML}}}
</div>
</div>
<div class="form_buttons row">
<button type="submit" class="button radius right">
{{tr "Change"}}
</button>
</div>
<a class="close-reveal-modal">&#215;</a>
</form>
</div>

View File

@ -14,14 +14,44 @@ define(function(require) {
return TemplateHTML();
}
function _setup(context){
/**
* Setups the html
* @param {object} context jquery selector
* @param {object} [options] Options to hide/show each field. Each field is
* enabled by default.
* - name: true, false
* - password: true, false
* - auth_driver: true, false
*/
function _setup(context, options){
var passwordEnabled = true;
if (options != undefined){
if (options.name != undefined && options.name == false){
$('#username',context).removeAttr('required');
$('.name_row', context).hide();
}
if (options.password != undefined && options.password == false){
passwordEnabled = false;
$('#pass',context).removeAttr('required');
$('.password_row', context).hide();
}
if (options.auth_driver != undefined && options.auth_driver == false){
$('.auth_driver_row', context).hide();
}
}
$('#driver', context).change(function(){
if ($(this).val() == "ldap"){
$('#pass',context).hide().removeAttr('required');
$('label[for="pass"]',context).hide();
} else {
$('#pass',context).show().attr('required', '');
$('label[for="pass"]',context).show();
$('#pass',context).removeAttr('required');
$('.password_row', context).hide();
} else if (passwordEnabled) {
$('#pass',context).attr('required', '');
$('.password_row', context).show();
}
});

View File

@ -1,16 +1,16 @@
<div class="row">
<div class="row name_row">
<div class="large-12 columns">
<label for="username">{{tr "Username"}}</label>
<input required type="text" name="username" id="username" />
</div>
</div>
<div class="row">
<div class="row password_row">
<div class="large-12 columns">
<label for="pass">{{tr "Password"}}</label>
<input required type="password" name="pass" id="pass" />
</div>
</div>
<div class="row">
<div class="row auth_driver_row">
<div class="large-12 columns">
<label for="driver">{{tr "Authentication"}}</label>
<select name="driver" id="driver">