Thanks for the feedback guys. The deface module was the solution. I was 
able to follow how other modules (like foreman_salt which inserts a 
complete tab onto the hosts page).



On Monday, July 4, 2016 at 2:06:52 AM UTC-7, Timo Goebel wrote:
>
>
> > On 04.07.2016, at 09:00, Dominic Cleal <[email protected] <javascript:>> 
> wrote: 
> > 
> >> On 04/07/16 03:00, Matthew Ceroni wrote: 
> >> I am attempting to develop a plugin. 
> >> 
> >> The main functionality of the plugin is going to be to automatically 
> set 
> >> the Virtual machine network based off the subnet set on the interface 
> >> tab. The initial version would just match the name set in the interface 
> >> tab to the name of the network on the virtual machine tab. Future 
> >> versions might take a config file to set that mapping. 
> >> 
> >> I believe the change should be pretty simple, just run a javascript 
> >> function onchange when the subnet is selected. Therefore I need to 
> >> include a new javascript (asset) on the host edit page. I see that 
> >> plugins such as foreman_salt and foreman_bootdisk do just that. In my 
> >> plugin I created a new asset and created the javascript file. However I 
> >> am not sure how to tie that asset to the host edit page. 
> > 
> > Using the Deface gem (https://github.com/spree/deface) is perhaps the 
> > easiest method, which will allow you to inject the following into the 
> > page template: 
> > 
> >  <% javascript "foreman_example/your_asset" %> 
> > 
> > Add deface ~> 1.0 as a dependency to the plugin, then create a file 
> > under app/overrides/ containing something like: 
> > 
> >  Deface::Override.new(:virtual_path => "hosts/_form", 
> >                       :name => "foreman_example/js", 
> >                       :insert_before => 
> "erb[loud]:contains(:javascript)", 
> >                       :text => "<% javascript 
> > "foreman_example/your_asset" %>") 
> > 
> > Untested, but the idea is that will match the <%= javascript %> at the 
> > top of app/views/hosts/_form.html.erb and insert your own line there. 
>
> You can also have a look at the forman_expire_hosts plugin as an example. 
> The plugin injects an js asset via deface to the host show page. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to