freeipa/install/ui/user.js

507 lines
14 KiB
JavaScript
Raw Normal View History

/*jsl:import ipa.js */
/* Authors:
* Pavel Zuna <pzuna@redhat.com>
* Adam Young <ayoung@redhat.com>
*
* Copyright (C) 2010 Red Hat
* see file 'COPYING' for use and warranty information
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js */
IPA.user = {};
IPA.user.entity = function(spec) {
var that = IPA.entity(spec);
var link = true;
if (IPA.nav && IPA.nav.name == 'self-service') {
link = false;
}
that.init = function(params) {
params.builder.search_facet({
columns: [
'uid',
'givenname',
'sn',
'uidnumber',
'mail',
'telephonenumber',
'title'
]
}).
details_facet({ sections: [
{
name: 'identity',
label: IPA.messages.details.identity,
fields: [
'title',
'givenname',
'sn',
'cn',
'displayname',
'initials'
]
},
{
name: 'account',
fields: [
{
factory: IPA.user_status_widget,
name: 'nsaccountlock',
label: IPA.messages.objects.user.account_status
},
'uid',
{ factory: IPA.user_password_widget, name: 'userpassword' },
'uidnumber',
'gidnumber',
'loginshell',
'homedirectory'
]
},
{
name: 'contact',
fields: [
{ type: 'multivalued', name: 'mail' },
{ type: 'multivalued', name: 'telephonenumber' },
{ type: 'multivalued', name: 'pager' },
{ type: 'multivalued', name: 'mobile' },
{ type: 'multivalued', name: 'facsimiletelephonenumber' }
]
},
{
name: 'mailing',
fields: ['street', 'l', 'st', 'postalcode']
},
{
name: 'employee',
fields: [
'ou',
{
type: 'entity_select',
name: 'manager',
other_entity: 'user',
other_field: 'uid'
}
]
},
{
name: 'misc',
fields: ['carlicense']
}]
}).
association_facet({
name: 'memberof_group',
associator: IPA.serial_associator,
link: link
}).
association_facet({
name: 'memberof_netgroup',
associator: IPA.serial_associator,
link: link
}).
association_facet({
name: 'memberof_role',
associator: IPA.serial_associator,
link: link
}).
association_facet({
name: 'memberof_hbacrule',
associator: IPA.serial_associator,
add_method: 'add_user',
remove_method: 'remove_user',
link: link
}).
association_facet({
name: 'memberof_sudorule',
associator: IPA.serial_associator,
add_method: 'add_user',
remove_method: 'remove_user',
link: link
}).
standard_association_facets({
link: link
}).
adder_dialog({
factory: IPA.user_adder_dialog,
sections: [
{
fields: [
{
name: 'uid',
required: false
},
'givenname',
'sn'
]
},
{
fields: [
{
name: 'userpassword',
label: IPA.messages.password.new_password,
type: 'password'
},
{
name: 'userpassword2',
label: IPA.messages.password.verify_password,
type: 'password'
}
]
}
]
});
};
return that;
};
IPA.user_adder_dialog = function(spec) {
var that = IPA.entity_adder_dialog(spec);
that.validate = function() {
var valid = that.dialog_validate();
var field1 = that.fields.get_field('userpassword');
var field2 = that.fields.get_field('userpassword2');
var password1 = field1.save()[0];
var password2 = field2.save()[0];
if (password1 !== password2) {
field2.show_error(IPA.messages.password.password_must_match);
valid = false;
}
return valid;
};
that.save = function(record) {
that.dialog_save(record);
delete record.userpassword2;
};
return that;
};
IPA.user_status_widget = function(spec) {
spec = spec || {};
var that = IPA.input_widget(spec);
that.create = function(container) {
that.widget_create(container);
that.status_span = $('<span/>', {
name: 'status'
}).appendTo(container);
that.link_span = $('<span/>', {
name: 'link'
}).appendTo(container);
that.link_span.append(': ');
that.status_link = $('<a/>', {
name: 'link',
click: function() {
removing setters setup and init change widget and widget unit tests to hold on to entity, not entity name. Replacing entity_name with entity.name in most places. The one exception is columns for table_widget. Widgets that refer to other entities have to have late resolution of the entity object, due to circular dependencies. cleanup entity assignment. removed template and layout, merged setup into create adder dialogs adjust height for external removed init from widget, isection, association, facet, host and service Make unit tests use factory. fix functional tests to click find link correctly. tweak to activation test, but still broken. moved initialization code to the end use --all for hbacrule find, so the type shows up now fixed dns exception code and exception handling for get_entity replace metadata look up with value from entity. fixed author lines removed duplicate columns in managed by facets. tweak to nav fix in order to initialize tab. more defensive code update metadata for true false one line init for entity_name in widget move init code to end of constructor functions moved constants to start of function for adder_dialog external fields for dialogs initialized at dialog creation sudo sections: move add fields and columns to widget definition. The parameter validation in IPA.column ...This is precondition checking. Note that it merely throws an exception if the entity_name is not set. I want this stuff at the top of the function so that it is obvious to people looking to use them what is required. I added a comment to make this clear, but I'd like to keep precondition checking at the top of the function. decreased the scope of the pkey_name and moved the initiailzation fof columns into the setup_column function for association_tables return false at the end of click handler removed blank labels in sudo command section fix radio buttons for sudo category fixed table side for adder dialogs with external fields comments for future direction with add_columns https://fedorahosted.org/freeipa/ticket/1451 https://fedorahosted.org/freeipa/ticket/1462 https://fedorahosted.org/freeipa/ticket/1493 https://fedorahosted.org/freeipa/ticket/1497 https://fedorahosted.org/freeipa/ticket/1532 https://fedorahosted.org/freeipa/ticket/1534
2011-07-25 11:15:14 -05:00
var facet = that.entity.get_facet();
if (facet.is_dirty()) {
var dialog = IPA.dirty_dialog({
facet: facet
});
dialog.callback = function() {
that.show_activation_dialog();
};
dialog.open(container);
} else {
that.show_activation_dialog();
}
return false;
}
}).appendTo(that.link_span);
};
that.update = function(values) {
//if (!that.record) return;
HBAC Details Page The UI framework has been extended to include a collection of widgets: - ipa_widget: base class - ipa_text_widget: text field - ipa_radio_widget: radio button - ipa_textarea_widget: textarea - ipa_button_widget: button - ipa_column_widget: column for table - ipa_table_widget: table These widgets can be used to create input controls. They can also be extended to create custom controls. The framework has also been enhanced to support custom layouts. This can be used to change the look of the application without changing the code. Initially this is only available in details section. Layout consists of a collection of HTML templates. Each template is a complete and valid HTML file representing a portion of a page. The template will be loaded and initialized by the code, then filled with the data from the server. The layouts are located in install/static/layouts/<name> folder. By default, if no templates are used, the fields in the details page are rendered vertically using dd/dt/dd tags. For pages that require different layout, a custom UI needs to be developed. There are two ways to do that: - write a custom widget to generate the UI dynamically - create an HTML template and write the initialization code For components that are quite complex or used frequently, it's might be better to use the first method. For simple pages that are used only in one location or need to support customization, the second method might be preferable. Other benefits of templates: - cleaner code and UI separation - more flexibility in customization - new pages can be developed quickly and require less coding - multiple templates can be used with the same initialization code - easier to maintain The HBAC details page has been implemented using both methods. By default it will use custom widgets to generate the page. To use a custom layout, add the following parameter to the URL, then reload the page: &layout=<name> Currently the only available layout is 'default' which produces the same look as the custom widgets. The HBAC details page is usable, but it still needs additional work. The access time is not working yet. There is no undo button, hint, or validation yet. The table in the association facet has also been changed to use ipa_association_widget which is derived from ipa_table_widget. The Makefile has been updated to include the layouts. The unit tests have been updated as well.
2010-11-02 20:16:55 -05:00
//var lock_field = 'nsaccountlock';
//var locked_field = that.record[lock_field];
var locked_field = values;
var locked = false;
if (locked_field instanceof Array) {
locked_field = locked_field[0];
}
if (typeof locked_field === 'boolean') {
locked = locked_field;
} else {
locked = locked_field && locked_field.toLowerCase() === 'true';
}
var status;
var action;
if (locked) {
status = IPA.messages.objects.user.inactive;
action = 'activate';
} else {
status = IPA.messages.objects.user.active;
action = 'deactivate';
}
that.status_span.html(status);
that.status_link.attr('href', action);
var message = IPA.messages.objects.user.activation_link;
var action_label = IPA.messages.objects.user[action];
message = message.replace('${action}', action_label);
that.status_link.html(message);
if (that.writable) {
that.link_span.css('display', '');
} else {
that.link_span.css('display', 'none');
}
};
that.clear = function() {
that.link_span.css('display', 'none');
that.status_span.text('');
};
that.show_activation_dialog = function() {
var action = that.status_link.attr('href');
var message = IPA.messages.objects.user.activation_confirmation;
var action_label = IPA.messages.objects.user[action];
message = message.replace('${action}', action_label.toLocaleLowerCase());
var dialog = IPA.dialog({
'title': IPA.messages.dialogs.confirmation
});
dialog.create = function() {
dialog.container.append(message);
};
dialog.create_button({
name: 'set_status',
label: action_label,
click: function() {
that.set_status(
action == 'activate',
function(data, textStatus, xhr) {
var facet = that.entity.get_facet();
facet.refresh();
dialog.close();
}
);
}
});
dialog.create_button({
name: 'cancel',
label: IPA.messages.buttons.cancel,
click: function() {
dialog.close();
}
});
dialog.open(that.container);
};
that.set_status = function(enabled, on_success, on_error) {
var pkey = IPA.nav.get_state('user-pkey');
var method = enabled ? 'enable' : 'disable';
IPA.command({
entity: 'user',
method: method,
args: [pkey],
on_success: on_success,
on_error: on_error
}).execute();
};
that.widgets_created = function() {
that.widget = that;
};
return that;
};
IPA.user_password_widget = function(spec) {
spec = spec || {};
var that = IPA.input_widget(spec);
that.create = function(container) {
that.widget_create(container);
$('<a/>', {
href: 'jslink',
title: 'userpassword',
text: IPA.messages.password.reset_password,
click: function() {
that.show_dialog();
return false;
}
}).appendTo(container);
};
that.show_dialog = function() {
that.pkey = IPA.nav.get_state('user-pkey');
that.self_service = that.pkey === IPA.whoami.uid[0];
var sections = [];
if(that.self_service) {
sections.push({
fields: [
{
name: 'current_password',
label: IPA.messages.password.current_password,
type: 'password'
}
]
});
}
sections.push({
fields: [
{
name: 'password1',
label: IPA.messages.password.new_password,
type: 'password'
},
{
name: 'password2',
label: IPA.messages.password.verify_password,
type: 'password'
}
]
});
var dialog = IPA.dialog({
entity: that.entity,
title: IPA.messages.password.reset_password,
width: 400,
sections: sections
});
dialog.create_button({
name: 'reset_password',
label: IPA.messages.password.reset_password,
click: function() {
var record = {};
dialog.save(record);
var current_password;
if (that.self_service) {
current_password = record.current_password[0];
if (!current_password) {
alert(IPA.messages.password.current_password_required);
return;
}
}
var new_password = record.password1[0];
var repeat_password = record.password2[0];
if (new_password != repeat_password) {
alert(IPA.messages.password.password_must_match);
return;
}
that.set_password(
current_password,
new_password,
function(data, text_status, xhr) {
alert(IPA.messages.password.password_change_complete);
dialog.close();
},
function(xhr, text_status, error_thrown) {
dialog.close();
}
);
}
});
dialog.create_button({
name: 'cancel',
label: IPA.messages.buttons.cancel,
click: function() {
dialog.close();
}
});
dialog.open(that.container);
};
that.set_password = function(current_password, password, on_success, on_error) {
var args;
if (that.self_service) {
args = [];
} else {
args = [that.pkey];
}
var command = IPA.command({
method: 'passwd',
args: args,
options: {
current_password: current_password,
password: password
},
on_success: on_success,
on_error: on_error
});
command.execute();
};
return that;
};
IPA.register('user', IPA.user.entity);