Hello Steve,

sorry for the delay.


On 05/18/2017 04:50 PM, Steve Huston wrote:
On Thu, May 18, 2017 at 3:36 AM, Pavel Vomacka<pvoma...@redhat.com>  wrote:
Hello Steve,

On 05/16/2017 05:21 PM, Steve Huston wrote:
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:

https://www.dropbox.com/s/j56mze39va3u7m0/Screenshot%202017-05-18%2010.42.38.png?dl=0

Thank you for the example.
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

_______________________________________________
FreeIPA-users mailing list -- freeipa-users@lists.fedorahosted.org
To unsubscribe send an email to freeipa-users-le...@lists.fedorahosted.org

Reply via email to