Discussion:
[Freeipa-users] UI customization: Default values on host addition
Steve Huston
2017-05-16 15:21:32 UTC
Permalink
I've extended the UI for host addition by including a multivalued
widget which stores puppetVar values (as well as the accompanying
Python plugin to handle it and schema update in the directory). This
works well, but I'd like to add one more thing and am not sure how to
do it.

There are certain variables which are basically always set for every
host, and so I'd like them to default to those values in the UI, while
still giving the admin the choice to edit or remove them just like
they were entered by hand. I'm not sure, however, how to "push"
values into the UI that way.

Is there some attribute of a field I can edit to insert a default
value into the UI, while still allowing that to be removed or edited
before the user submits the page?
--
Steve Huston - W2SRH - Unix Sysadmin, PICSciE/CSES & Astrophysical Sci
Princeton University | ICBM Address: 40.346344 -74.652242
345 Lewis Library |"On my ship, the Rocinante, wheeling through
Princeton, NJ 08544 | the galaxies; headed for the heart of Cygnus,
(267) 793-0852 | headlong into mystery." -Rush, 'Cygnus X-1'
--
Manage your subscription for the Freeipa-users mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-users
Go to http://freeipa.org for more info on the project
Steve Huston
2017-05-18 14:50:36 UTC
Permalink
Hello Steve,
Post by Steve Huston
I've extended the UI for host addition by including a multivalued
widget which stores puppetVar values (as well as the accompanying
Python plugin to handle it and schema update in the directory). This
works well, but I'd like to add one more thing and am not sure how to
do it.
There are certain variables which are basically always set for every
host, and so I'd like them to default to those values in the UI, while
still giving the admin the choice to edit or remove them just like
they were entered by hand. I'm not sure, however, how to "push"
values into the UI that way.
Could you please write an example of the variable?
Sure, here's the UI code I wrote (limited to just this one in particular):

// adds things we want on the adder page
astrocustom_plugin.add_host_pre_op = function() {

var section = get_item(host_mod.entity_spec.adder_dialog.sections,
'name', 'other');
{
name: 'puppetvar',
$type: 'multivalued',
label: 'Puppet Variables',
});

return true;
};

phases.on('customization', astrocustom_plugin.add_host_pre_op);

This works perfectly, giving me a multivalued entry on the host adding
dialog box where I can add puppetvars to the resultant LDAP record
when the host is saved. What I'd like to do now is make it so that
there defaults to being a few pre-filled as if I typed them, with the
'undo' buttons shown so they can be removed if not needed, or edited
before saving. Here's an example of me having added three values -
basically, when I click the add button from the host page and this
dialog appears, I'd like it to look something like this with those
values there already that I can edit or remove if I don't need them:

Loading Image...
Post by Steve Huston
Is there some attribute of a field I can edit to insert a default
value into the UI, while still allowing that to be removed or edited
before the user submits the page?
In case you want to prefill a dialog by default values you can do it by
using that.get_field('fieldname').set_value(['value1']); in open() method of
the dialog. But I'm not sure whether this is what you want. If not please
send an example of what you want to achieve.
Hopefully the above example explains my intention. It's possible that
the answer you just gave here is exactly what I need, but I don't know
enough about javascript hacking yet to follow it.

--
Steve Huston - W2SRH - Unix Sysadmin, PICSciE/CSES & Astrophysical Sci
Princeton University | ICBM Address: 40.346344 -74.652242
345 Lewis Library |"On my ship, the Rocinante, wheeling through
Princeton, NJ 08544 | the galaxies; headed for the heart of Cygnus,
(267) 793-0852 | headlong into mystery." -Rush, 'Cygnus X-1'
_______________________________________________
FreeIPA-users mailing list -- freeipa-***@lists.fedorahosted.org
To unsubscribe send an email to freeipa-users-***@li
Pavel Vomacka
2017-05-22 16:19:05 UTC
Permalink
Hello Steve,

sorry for the delay.
Post by Steve Huston
Hello Steve,
Post by Steve Huston
I've extended the UI for host addition by including a multivalued
widget which stores puppetVar values (as well as the accompanying
Python plugin to handle it and schema update in the directory). This
works well, but I'd like to add one more thing and am not sure how to
do it.
There are certain variables which are basically always set for every
host, and so I'd like them to default to those values in the UI, while
still giving the admin the choice to edit or remove them just like
they were entered by hand. I'm not sure, however, how to "push"
values into the UI that way.
Could you please write an example of the variable?
// adds things we want on the adder page
astrocustom_plugin.add_host_pre_op = function() {
var section = get_item(host_mod.entity_spec.adder_dialog.sections,
'name', 'other');
{
name: 'puppetvar',
$type: 'multivalued',
label: 'Puppet Variables',
});
return true;
};
phases.on('customization', astrocustom_plugin.add_host_pre_op);
This works perfectly, giving me a multivalued entry on the host adding
dialog box where I can add puppetvars to the resultant LDAP record
when the host is saved. What I'd like to do now is make it so that
there defaults to being a few pre-filled as if I typed them, with the
'undo' buttons shown so they can be removed if not needed, or edited
before saving. Here's an example of me having added three values -
basically, when I click the add button from the host page and this
dialog appears, I'd like it to look something like this with those
https://www.dropbox.com/s/j56mze39va3u7m0/Screenshot%202017-05-18%2010.42.38.png?dl=0
Thank you for the example.
Post by Steve Huston
Post by Steve Huston
Is there some attribute of a field I can edit to insert a default
value into the UI, while still allowing that to be removed or edited
before the user submits the page?
In case you want to prefill a dialog by default values you can do it by
using that.get_field('fieldname').set_value(['value1']); in open() method of
the dialog. But I'm not sure whether this is what you want. If not please
send an example of what you want to achieve.
Hopefully the above example explains my intention. It's possible that
the answer you just gave here is exactly what I need, but I don't know
enough about javascript hacking yet to follow it.
Yes, now it is clear. This is example of plugin which adds what you want. :

define([
'freeipa/ipa',
'freeipa/phases',
'freeipa/host'
],
function(IPA, phases, host_mod) {


var exp = {};

exp.change_factory = function() {
var host_adder_spec = host_mod.entity_spec.adder_dialog;

exp.original_host_adder_dialog = IPA.host_adder_dialog;

IPA.host_adder_dialog = function(spec) {
var that = exp.original_host_adder_dialog(spec);

that.open = function() {
that.dialog_open();
that.get_field('puppetvar').set_value(['test', 'test2']);
};

return that;
};

host_adder_spec.$factory = IPA.host_adder_dialog;
};

phases.on('customization', exp.change_factory);

return exp;
});

You can add as many strings ('test', 'test2', ...) as you want, each
string means one field in the multivalued widget. If you have any
additional questions, feel free to ask.

HTH
--
Pavel^3 Vomacka
Continue reading on narkive:
Search results for '[Freeipa-users] UI customization: Default values on host addition' (Questions and Answers)
14
replies
Creating a "Why we should switch to Mac" Speech. Help Please?
started 2007-10-26 15:44:14 UTC
desktops
Loading...