New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toolbars: allow passing additional html attributes to button <a> tags. #8079
Conversation
ping @dkorn |
I couldnt really figure out how to use this. |
Sorry ;-)
|
I'm a bit afraid that allowing to add any Probably better to allow just custom |
Also related is the custom toolbar content #6320. There will be a need to add code to support the custom toolbar content. Such as collecting values from input fields. Etc. |
71cdff8
to
6c33036
Compare
Yes, display of an input form with one or more fields that are then passed to the backend ruby code are a use case for me. And I would like to get this done by passing a definition of my form and not by coding it in html/js/css. |
Thanks! I'll try that out. |
<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush. |
@martinpovolny c8d922d illustrates my idea via code. |
@pilhuhn that would need some more refactoring on |
@himdel This is certainly not a/the final version, but for illustration purposes. One would probably also want to support more than 1 field. |
Understood :) but.. to tie it back into the previous discussion, is the form case really that significant compared to the other possible customizations? What I'm trying to see is whether it really makes sense to add another special case to that code that works just for forms, or if it'd be better to go the more generic |
The form case allows to declaratively put this without the knowledge of the underlying javascript, which can/could then be exchanged transparently. |
Yeah, but if we do have a predefined function to do that, it's the same.. |
6c33036
to
a1a1ae8
Compare
To utilize
|
@@ -1403,6 +1403,11 @@ function miqToolbarOnClick(e) { | |||
} | |||
} | |||
} | |||
} else if (button.data('function') { | |||
// hack to support data-function and data-function-data | |||
var fn = new Function(button.data('function')); // eval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually broken because new Function("foobar")
returns a function that evaluates foobar
and ..nothing, doesn't call it, whereas new Function("foobar()")
would call it but can't pass in arguments...
Simple fix:
var fn = new Function("return " + button.data('function')); // eval - returns a function returning the right function
fn().call(button, button.data('functionData'));
And then any function name (without parentheses) will work in data-function
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thx!
f91e9c6
to
ae3e7f8
Compare
@martinpovolny do I need to place this function in my controller/somewhere else? |
@dkorn : anywhere. I thought you just try to use is. It uses the scope saved in This is to call angular stuff from non-angular context (toolbar button click). Adding it in a separate commit. Wait a sec... |
f8e5f67
to
8aaa139
Compare
8aaa139
to
323a425
Compare
@martinpovolny you tagged the wrong guy :) (its dkorn) |
@martinpovolny please also update the example in the commit message Example:
|
@h-kataria, @dclarizio : merge, please? |
323a425
to
49e9c40
Compare
@dkorn : updated the commit message |
To support support data-function= on buttons we need a way to call Angular code (in a scope) from outside. Example: button( :ems_container_deployment, 'pficon pficon-add-circle-o fa-lg', t = N_('Create #{ui_lookup(:table=>"ems_container")}'), t, :data => { 'function' => 'miqCallAngular', 'function-data' => '{ "name": "showListener", "args": [] }'} ),
Custom button attributes can be passed in 'data' key and are added to the <a> tag as 'data-*' attributes.
49e9c40
to
754a318
Compare
Checked commits martinpovolny/manageiq@d410d44~...754a318 with ruby 2.2.3, rubocop 0.37.2, and haml-lint 0.16.1 |
@dclarizio is there a BZ for this? |
Toolbars: allow passing additional html attributes to button <a> tags. (cherry picked from commit db30bc9)
No description provided.