mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-06 14:23:00 -06:00
b36df6e9b9
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
643 lines
17 KiB
JavaScript
643 lines
17 KiB
JavaScript
/*jsl:import ipa.js */
|
|
/* Authors:
|
|
* Endi Sukma Dewata <edewata@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: widget.js */
|
|
|
|
/**
|
|
* This is a base class for dialog boxes.
|
|
*/
|
|
IPA.dialog = function(spec) {
|
|
|
|
spec = spec || {};
|
|
|
|
var that = {};
|
|
|
|
that.entity = spec.entity;
|
|
that.name = spec.name;
|
|
that.title = spec.title;
|
|
that.width = spec.width || 400;
|
|
that.height = spec.height;
|
|
|
|
that.buttons = {};
|
|
|
|
that.fields = $.ordered_map();
|
|
that.sections = $.ordered_map();
|
|
|
|
that.conditional_fields = [];
|
|
|
|
that.enable_conditional_fields = function(){
|
|
for (var i =0; i < that.conditional_fields.length; i+=1) {
|
|
$('label[id='+
|
|
that.conditional_fields[i] +'-label]',
|
|
that.container).css('visibility','visible');
|
|
$('input[name='+
|
|
that.conditional_fields[i] +
|
|
']',that.container).css('visibility','visible');
|
|
}
|
|
};
|
|
|
|
that.disable_conditional_fields = function(){
|
|
for (var i =0; i < that.conditional_fields.length; i+=1) {
|
|
$('label[id='+
|
|
that.conditional_fields[i] +'-label]',
|
|
that.container).css('visibility','hidden');
|
|
|
|
$('input[name='+
|
|
that.conditional_fields[i] +
|
|
']',that.container).css('visibility','hidden');
|
|
}
|
|
};
|
|
|
|
that.add_button = function(name, handler) {
|
|
that.buttons[name] = handler;
|
|
};
|
|
|
|
that.get_field = function(name) {
|
|
return that.fields.get(name);
|
|
};
|
|
|
|
that.add_field = function(field) {
|
|
field.dialog = that;
|
|
that.fields.put(field.name, field);
|
|
if (field.conditional){
|
|
that.conditional_fields.push(field.name);
|
|
}
|
|
return field;
|
|
};
|
|
|
|
that.field = function(field) {
|
|
that.add_field(field);
|
|
return that;
|
|
};
|
|
|
|
that.is_valid = function() {
|
|
var fields = that.fields.values;
|
|
for (var i=0; i<fields.length; i++) {
|
|
var field = fields[i];
|
|
if (!field.valid) return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
that.text = function(name){
|
|
that.field(IPA.text_widget({
|
|
name: name,
|
|
undo: false,
|
|
entity : that.entity
|
|
}));
|
|
return that;
|
|
};
|
|
|
|
that.add_section = function(section) {
|
|
that.sections.put(section.name, section);
|
|
return that;
|
|
};
|
|
|
|
that.section = function(section) {
|
|
that.add_section(section);
|
|
return that;
|
|
};
|
|
|
|
that.create_section = function(spec) {
|
|
var section = IPA.details_section(spec);
|
|
that.add_section(section);
|
|
return section;
|
|
};
|
|
|
|
/**
|
|
* Create content layout
|
|
*/
|
|
that.create = function() {
|
|
|
|
var table = $('<table/>').appendTo(that.container);
|
|
|
|
var fields = that.fields.values;
|
|
for (var i=0; i<fields.length; i++) {
|
|
var field = fields[i];
|
|
if (field.hidden) continue;
|
|
|
|
var tr = $('<tr/>').appendTo(table);
|
|
|
|
var td = $('<td/>', {
|
|
style: 'vertical-align: top;',
|
|
title: field.label
|
|
}).appendTo(tr);
|
|
var label_text = field.label;
|
|
if (label_text !== null){
|
|
label_text += ': ';
|
|
}else{
|
|
label_text = '';
|
|
}
|
|
td.append($('<label />',{id: field.name+'-label',
|
|
text: label_text}));
|
|
|
|
td = $('<td/>', {
|
|
style: 'vertical-align: top;'
|
|
}).appendTo(tr);
|
|
|
|
var span = $('<span/>', { 'name': field.name }).appendTo(td);
|
|
field.create(span);
|
|
field.field_span = span;
|
|
|
|
if (field.optional){
|
|
span.css('display','none');
|
|
td.append(
|
|
$('<a/>',{
|
|
text: IPA.messages.widget.optional,
|
|
href:'',
|
|
click: function(){
|
|
var span = $(this).prev();
|
|
span.css('display','inline');
|
|
$(this).css('display','none');
|
|
return false;
|
|
}
|
|
}));
|
|
}
|
|
|
|
}
|
|
|
|
var sections = that.sections.values;
|
|
for (var j=0; j<sections.length; j++) {
|
|
var section = sections[j];
|
|
|
|
var div = $('<div/>', {
|
|
name: section.name,
|
|
'class': 'details-section'
|
|
}).appendTo(that.container);
|
|
|
|
section.create(div);
|
|
}
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
* Open dialog
|
|
*/
|
|
that.open = function(container) {
|
|
|
|
that.container = $('<div/>');
|
|
if (container) {
|
|
container.append(that.container);
|
|
}
|
|
|
|
that.create();
|
|
|
|
that.container.dialog({
|
|
'title': that.title,
|
|
'modal': true,
|
|
'width': that.width,
|
|
'height': that.height,
|
|
'buttons': that.buttons,
|
|
close: function(event, ui) {
|
|
that.close();
|
|
}
|
|
});
|
|
};
|
|
|
|
that.option = function(name, value) {
|
|
that.container.dialog('option', name, value);
|
|
};
|
|
|
|
that.save = function(record) {
|
|
var fields = that.fields.values;
|
|
for (var i=0; i<fields.length; i++) {
|
|
var field = fields[i];
|
|
var values = field.save();
|
|
record[field.name] = values.join(',');
|
|
}
|
|
|
|
var sections = that.sections.values;
|
|
for (var j=0; j<sections.length; j++) {
|
|
var section = sections[j];
|
|
|
|
if (section.save) {
|
|
section.save(record);
|
|
}
|
|
}
|
|
};
|
|
|
|
that.close = function() {
|
|
that.container.dialog('destroy');
|
|
that.container.remove();
|
|
};
|
|
|
|
that.reset = function() {
|
|
var fields = that.fields.values;
|
|
for (var i=0; i<fields.length; i++) {
|
|
var field = fields[i];
|
|
field.reset();
|
|
}
|
|
|
|
var sections = that.sections.values;
|
|
for (var j=0; j<sections.length; j++) {
|
|
sections[j].reset();
|
|
}
|
|
};
|
|
|
|
that.dialog_create = that.create;
|
|
that.dialog_open = that.open;
|
|
|
|
var fields = spec.fields || [];
|
|
for (var i=0; i<fields.length; i++) {
|
|
var field_spec = fields[i];
|
|
var field;
|
|
|
|
if (field_spec instanceof Object) {
|
|
var factory = field_spec.factory || IPA.text_widget;
|
|
field_spec.entity = that.entity;
|
|
field = factory(field_spec);
|
|
|
|
/* This is a bit of a hack, and is here to support ACI
|
|
permissions. The target section is a group of several
|
|
widgets together. It makes more sense to do them as a
|
|
section than as a widget. However, since they can be mixed
|
|
into the flow with the other widgets, the section needs to
|
|
be defined here with the fields to get the order correct.*/
|
|
if (field.section) {
|
|
that.add_section(field);
|
|
} else {
|
|
that.add_field(field);
|
|
}
|
|
|
|
} else {
|
|
field = IPA.text_widget({
|
|
name: field_spec,
|
|
entity:that.entity,
|
|
undo: false });
|
|
that.add_field(field);
|
|
}
|
|
}
|
|
|
|
return that;
|
|
};
|
|
|
|
/**
|
|
* This dialog provides an interface for searching and selecting
|
|
* values from the available results.
|
|
*/
|
|
IPA.adder_dialog = function (spec) {
|
|
var NORMAL_HEIGHT = '151px';
|
|
var EXTERNAL_HEIGHT = '119px';
|
|
|
|
spec = spec || {};
|
|
|
|
var that = IPA.dialog(spec);
|
|
that.external = spec.external;
|
|
that.width = spec.width || 600;
|
|
that.height = spec.height || 360;
|
|
|
|
if (!that.entity){
|
|
var except = {
|
|
expected: false,
|
|
message:'Adder dialog created without entity.'
|
|
};
|
|
throw except;
|
|
}
|
|
|
|
that.columns = $.ordered_map();
|
|
|
|
|
|
that.get_column = function(name) {
|
|
return that.columns.get(name);
|
|
};
|
|
|
|
that.add_column = function(column) {
|
|
that.columns.put(column.name, column);
|
|
};
|
|
|
|
that.set_columns = function(columns) {
|
|
that.clear_columns();
|
|
for (var i=0; i<columns.length; i++) {
|
|
that.add_column(columns[i]);
|
|
}
|
|
};
|
|
|
|
that.clear_columns = function() {
|
|
that.columns.empty();
|
|
};
|
|
|
|
that.create_column = function(spec) {
|
|
spec.entity = that.entity;
|
|
var column = IPA.column(spec);
|
|
that.add_column(column);
|
|
return column;
|
|
};
|
|
|
|
function initialize_table(){
|
|
var table_height = NORMAL_HEIGHT;
|
|
if (that.external){
|
|
table_height = EXTERNAL_HEIGHT;
|
|
}
|
|
|
|
that.available_table = IPA.table_widget({
|
|
entity: that.entity,
|
|
name: 'available',
|
|
scrollable: true,
|
|
height: table_height
|
|
});
|
|
|
|
var columns = that.columns.values;
|
|
that.available_table.set_columns(columns);
|
|
|
|
that.selected_table = IPA.table_widget({
|
|
entity: that.entity,
|
|
name: 'selected',
|
|
scrollable: true,
|
|
height: NORMAL_HEIGHT
|
|
});
|
|
|
|
that.selected_table.set_columns(columns);
|
|
}
|
|
that.create = function() {
|
|
|
|
|
|
// do not call that.dialog_create();
|
|
|
|
var search_panel = $('<div/>', {
|
|
'class': 'adder-dialog-filter'
|
|
}).appendTo(that.container);
|
|
|
|
$('<input/>', {
|
|
type: 'text',
|
|
name: 'filter',
|
|
style: 'width: 244px'
|
|
}).appendTo(search_panel);
|
|
|
|
search_panel.append(' ');
|
|
|
|
$('<input/>', {
|
|
type: 'button',
|
|
name: 'find',
|
|
value: IPA.messages.buttons.find
|
|
}).appendTo(search_panel);
|
|
|
|
$('<input/>', {
|
|
type: 'checkbox',
|
|
name: 'hidememb',
|
|
id: 'hidememb',
|
|
checked: 'checked',
|
|
style: 'margin-left: 5px; vertical-align: middle'
|
|
}).appendTo(search_panel);
|
|
|
|
var label = $('<label/>', {
|
|
'for': 'hidememb',
|
|
style: 'margin-left: 3px'
|
|
});
|
|
|
|
label.text(IPA.messages.dialogs.hide_already_enrolled);
|
|
|
|
label.appendTo(search_panel);
|
|
|
|
search_panel.append(IPA.create_network_spinner());
|
|
|
|
var results_panel = $('<div/>', {
|
|
'class': 'adder-dialog-results'
|
|
}).appendTo(that.container);
|
|
|
|
var available_panel = $('<div/>', {
|
|
name: 'available',
|
|
'class': 'adder-dialog-available'
|
|
}).appendTo(results_panel);
|
|
|
|
$('<div/>', {
|
|
html: IPA.messages.dialogs.available,
|
|
'class': 'ui-widget-header'
|
|
}).appendTo(available_panel);
|
|
|
|
that.available_table.create(available_panel);
|
|
|
|
|
|
var buttons_panel = $('<div/>', {
|
|
name: 'buttons',
|
|
'class': 'adder-dialog-buttons'
|
|
}).appendTo(results_panel);
|
|
|
|
var p = $('<p/>').appendTo(buttons_panel);
|
|
$('<input />', {
|
|
type: 'button',
|
|
name: 'remove',
|
|
value: '<<'
|
|
}).appendTo(p);
|
|
|
|
p = $('<p/>').appendTo(buttons_panel);
|
|
$('<input />', {
|
|
type: 'button',
|
|
name: 'add',
|
|
value: '>>'
|
|
}).appendTo(p);
|
|
|
|
var selected_panel = $('<div/>', {
|
|
name: 'selected',
|
|
'class': 'adder-dialog-selected'
|
|
}).appendTo(results_panel);
|
|
|
|
$('<div/>', {
|
|
html: IPA.messages.dialogs.prospective,
|
|
'class': 'ui-widget-header'
|
|
}).appendTo(selected_panel);
|
|
|
|
that.selected_table.create(selected_panel);
|
|
|
|
that.filter_field = $('input[name=filter]', that.container);
|
|
|
|
var button = $('input[name=find]', that.container);
|
|
that.find_button = IPA.button({
|
|
name: 'find',
|
|
'label': button.val(),
|
|
'click': function() {
|
|
that.search();
|
|
return false;
|
|
}
|
|
});
|
|
button.replaceWith(that.find_button);
|
|
|
|
button = $('input[name=remove]', that.container);
|
|
that.remove_button = IPA.button({
|
|
name: 'remove',
|
|
'label': button.val(),
|
|
'click': function() {
|
|
that.remove();
|
|
return false;
|
|
}
|
|
});
|
|
button.replaceWith(that.remove_button);
|
|
|
|
button = $('input[name=add]', that.container);
|
|
that.add_button = IPA.button({
|
|
name: 'add',
|
|
'label': button.val(),
|
|
'click': function() {
|
|
that.add();
|
|
return false;
|
|
}
|
|
});
|
|
button.replaceWith(that.add_button);
|
|
|
|
if (that.external) {
|
|
var external_panel = $('<div/>', {
|
|
name: 'external',
|
|
'class': 'adder-dialog-external'
|
|
}).appendTo(results_panel);
|
|
|
|
$('<div/>', {
|
|
html: IPA.messages.objects.sudorule.external,
|
|
'class': 'ui-widget-header'
|
|
}).appendTo(external_panel);
|
|
|
|
that.external_field = $('<input/>', {
|
|
type: 'text',
|
|
name: 'external',
|
|
style: 'width: 244px'
|
|
}).appendTo(external_panel);
|
|
|
|
}
|
|
|
|
that.search();
|
|
};
|
|
|
|
|
|
that.open = function(container) {
|
|
|
|
that.buttons[IPA.messages.buttons.enroll] = that.execute;
|
|
that.buttons[IPA.messages.buttons.cancel] = that.close;
|
|
|
|
that.dialog_open(container);
|
|
};
|
|
|
|
that.add = function() {
|
|
var rows = that.available_table.remove_selected_rows();
|
|
that.selected_table.add_rows(rows);
|
|
};
|
|
|
|
that.remove = function() {
|
|
var rows = that.selected_table.remove_selected_rows();
|
|
that.available_table.add_rows(rows);
|
|
};
|
|
|
|
that.get_filter = function() {
|
|
return that.filter_field.val();
|
|
};
|
|
|
|
that.get_hide_checkbox = function() {
|
|
return that.hide_checkbox.checked;
|
|
};
|
|
|
|
that.clear_available_values = function() {
|
|
that.available_table.empty();
|
|
};
|
|
|
|
that.clear_selected_values = function() {
|
|
that.selected_table.empty();
|
|
};
|
|
|
|
that.add_available_value = function(record) {
|
|
that.available_table.add_record(record);
|
|
};
|
|
|
|
that.get_selected_values = function() {
|
|
return that.selected_table.save();
|
|
};
|
|
|
|
/*dialog initialization */
|
|
if (spec.columns){
|
|
for (var i =0; i < spec.columns.length; i +=1){
|
|
that.create_column(spec.columns[i]);
|
|
}
|
|
}
|
|
|
|
initialize_table();
|
|
|
|
that.adder_dialog_create = that.create;
|
|
|
|
return that;
|
|
};
|
|
|
|
/**
|
|
* This dialog displays the values to be deleted.
|
|
*/
|
|
IPA.deleter_dialog = function (spec) {
|
|
|
|
spec = spec || {};
|
|
|
|
var that = IPA.dialog(spec);
|
|
|
|
that.title = spec.title || IPA.messages.buttons.remove;
|
|
|
|
that.values = spec.values || [];
|
|
|
|
that.add_value = function(value) {
|
|
that.values.push(value);
|
|
};
|
|
|
|
that.set_values = function(values) {
|
|
that.values = values;
|
|
};
|
|
|
|
that.create = function() {
|
|
|
|
$('<p/>', {
|
|
'text': IPA.messages.search.delete_confirm
|
|
}).appendTo(that.container);
|
|
|
|
var div = $('<div/>', {
|
|
style: 'overflow:auto; max-height: 100px'
|
|
}).appendTo(that.container);
|
|
|
|
var ul = $('<ul/>');
|
|
ul.appendTo(div);
|
|
|
|
for (var i=0; i<that.values.length; i++) {
|
|
var value = that.values[i];
|
|
if (value instanceof Object){
|
|
var first = true;
|
|
var str_value = "";
|
|
for (var key in value){
|
|
if (value.hasOwnProperty(key)){
|
|
if (!first){
|
|
str_value += ',';
|
|
}
|
|
str_value += (key + ':' +value[key]);
|
|
first = false;
|
|
}
|
|
}
|
|
value = str_value;
|
|
}
|
|
|
|
$('<li/>',{
|
|
'text': value
|
|
}).appendTo(ul);
|
|
}
|
|
};
|
|
|
|
that.open = function(container) {
|
|
|
|
that.buttons[IPA.messages.buttons.remove] = that.execute;
|
|
that.buttons[IPA.messages.buttons.cancel] = that.close;
|
|
|
|
that.dialog_open(container);
|
|
};
|
|
|
|
that.deleter_dialog_create = that.create;
|
|
|
|
return that;
|
|
};
|