2010-08-23 21:32:23 -05:00
|
|
|
/* Authors:
|
2010-09-16 09:28:07 -05:00
|
|
|
* Pavel Zuna <pzuna@redhat.com>
|
2010-10-27 22:32:30 -05:00
|
|
|
* Endi Sukma Dewata <edewata@redhat.com>
|
2010-08-23 21:32:23 -05:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat
|
|
|
|
* see file 'COPYING' for use and warranty information
|
|
|
|
*
|
2010-12-09 06:59:11 -06:00
|
|
|
* 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.
|
2010-08-23 21:32:23 -05:00
|
|
|
*
|
|
|
|
* 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
|
2010-12-09 06:59:11 -06:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-09-16 09:28:07 -05:00
|
|
|
*/
|
2010-08-23 21:32:23 -05:00
|
|
|
|
|
|
|
/* REQUIRES: ipa.js */
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
function ipa_add_dialog(spec) {
|
|
|
|
|
|
|
|
spec = spec || {};
|
|
|
|
|
2010-11-09 14:22:31 -06:00
|
|
|
var that = ipa_dialog(spec);
|
|
|
|
|
2010-10-27 22:32:30 -05:00
|
|
|
that.name = spec.name;
|
|
|
|
that.title = spec.title;
|
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
|
|
|
that._entity_name = spec.entity_name;
|
2010-10-27 22:32:30 -05:00
|
|
|
|
2010-11-09 14:22:31 -06:00
|
|
|
that.init = function() {
|
|
|
|
|
|
|
|
that.add_button('Add', function() {
|
2010-11-17 20:12:55 -06:00
|
|
|
var record = that.get_record();
|
|
|
|
that.add(
|
|
|
|
record,
|
|
|
|
function() {
|
|
|
|
var entity = IPA.get_entity(that.entity_name);
|
|
|
|
var facet = entity.get_facet('search');
|
|
|
|
var table = facet.table;
|
2010-11-18 20:17:14 -06:00
|
|
|
table.refresh();
|
2010-11-17 20:12:55 -06:00
|
|
|
that.close();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
that.add_button('Add and Add Another', function() {
|
2010-11-09 14:22:31 -06:00
|
|
|
var record = that.get_record();
|
|
|
|
that.add(
|
|
|
|
record,
|
|
|
|
function() {
|
|
|
|
var entity = IPA.get_entity(that.entity_name);
|
|
|
|
var facet = entity.get_facet('search');
|
|
|
|
var table = facet.table;
|
2010-11-18 20:17:14 -06:00
|
|
|
table.refresh();
|
2010-12-09 14:20:40 -06:00
|
|
|
that.reset();
|
2010-11-09 14:22:31 -06:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
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
|
|
|
|
2010-11-09 14:22:31 -06:00
|
|
|
that.add_button('Add and Edit', function() {
|
|
|
|
var record = that.get_record();
|
|
|
|
that.add(
|
|
|
|
record,
|
|
|
|
function() {
|
|
|
|
that.close();
|
|
|
|
|
|
|
|
var pkey_name = IPA.metadata[that.entity_name].primary_key;
|
|
|
|
var pkey = record[pkey_name];
|
|
|
|
|
|
|
|
var state = {};
|
|
|
|
state[that.entity_name + '-facet'] = 'details';
|
|
|
|
state[that.entity_name + '-pkey'] = pkey;
|
|
|
|
$.bbq.pushState(state);
|
|
|
|
},
|
2011-01-03 10:40:54 -06:00
|
|
|
function() { }
|
2010-11-09 14:22:31 -06:00
|
|
|
);
|
|
|
|
});
|
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
|
|
|
|
2010-11-09 14:22:31 -06:00
|
|
|
that.add_button('Cancel', function() {
|
|
|
|
that.close();
|
|
|
|
});
|
2010-12-06 16:30:10 -06:00
|
|
|
|
|
|
|
that.dialog_init();
|
2010-10-27 22:32:30 -05:00
|
|
|
};
|
|
|
|
|
2010-10-25 18:55:57 -05:00
|
|
|
|
|
|
|
function save_field(field, record, args, options){
|
2010-11-09 14:22:31 -06:00
|
|
|
var pkey_name = IPA.metadata[that.entity_name].primary_key;
|
2010-10-25 18:55:57 -05:00
|
|
|
var value = record[field.name];
|
|
|
|
if (!value) return;
|
|
|
|
if (field.name == pkey_name) {
|
|
|
|
args.push(value);
|
|
|
|
} else {
|
|
|
|
options[field.name] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
that.add = function(record, on_success, on_error) {
|
2010-10-27 22:32:30 -05:00
|
|
|
|
2010-11-09 14:22:31 -06:00
|
|
|
var args = [];
|
|
|
|
var options = {};
|
2010-10-27 22:32:30 -05:00
|
|
|
|
2010-11-09 14:22:31 -06:00
|
|
|
for (var i=0; i<that.fields.length; i++) {
|
2010-10-25 18:55:57 -05:00
|
|
|
save_field(that.fields[i], record, args, options);
|
|
|
|
}
|
2010-09-16 09:28:07 -05:00
|
|
|
|
2010-11-09 14:22:31 -06:00
|
|
|
ipa_cmd('add', args, options, on_success, on_error, that.entity_name);
|
2010-09-16 09:28:07 -05:00
|
|
|
};
|
|
|
|
|
2010-11-16 18:10:40 -06:00
|
|
|
that.add_dialog_init = that.init;
|
2010-10-27 22:32:30 -05:00
|
|
|
|
|
|
|
return that;
|
2010-09-16 09:28:07 -05:00
|
|
|
}
|
2010-08-23 21:32:23 -05:00
|
|
|
|