Revision 04687d07
Added by Tomer Brisker over 8 years ago
app/assets/javascripts/hidden_values.js | ||
---|---|---|
function turn_textarea_switch() {
|
||
$('.hidden_value_textarea_switch').each(function (index, switch_field) {
|
||
if ($(switch_field).attr('data-switch-active') != 'true') {
|
||
$(switch_field).change(function () {
|
||
var source = $(this).closest('tr').children('td.value').children()[0];
|
||
if (source === undefined) {
|
||
source = $(this).closest('div.form-group').parent().prev().children().children('div.col-md-4').children()[0];
|
||
}
|
||
if (this.checked) {
|
||
var target = '<input class="form-control" type="password" id="' + source.id + '" name="' + source.name + '" value ="' + source.value + '"></input>'
|
||
} else {
|
||
var target = '<textarea class="form-control" cols="40" id="' + source.id + '" name="' + source.name + '" placeholder="Value" rows="1">' + source.value + '</textarea>'
|
||
}
|
||
$(source).replaceWith(target);
|
||
});
|
||
this.value = '1';
|
||
$(this).attr('data-switch-active', 'true');
|
||
}
|
||
})
|
||
function turn_textarea_switch(checkbox) {
|
||
var id = checkbox.id.replace(/hidden_value$/,"value");
|
||
var source = document.getElementById(id);
|
||
if (checkbox.checked) {
|
||
var target = '<input class="form-control" type="password" id="' + id + '" name="' + source.name + '" value ="' + source.value + '"></input>'
|
||
} else {
|
||
var target = '<textarea class="form-control" id="' + id + '" name="' + source.name + '" placeholder="Value" rows="1">' + source.value + '</textarea>'
|
||
}
|
||
$(source).replaceWith(target);
|
||
}
|
||
|
||
function hidden_value_control(){
|
||
... | ... | |
link.parent().parent().find('a.pull-left').toggleClass("hide");
|
||
}
|
||
|
||
// normal page load trigger
|
||
$(document).ready(turn_textarea_switch);
|
||
|
||
// two-pane ajax trigger
|
||
$(document).ajaxComplete(turn_textarea_switch);
|
||
|
||
// normal page load trigger
|
||
$(document).ready(hidden_value_control);
|
||
|
app/helpers/application_helper.rb | ||
---|---|---|
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
|
||
render((partial.nil? ? association.to_s.singularize + "_fields" : partial), :f => builder)
|
||
end
|
||
link_to_function(name, ("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\"); turn_textarea_switch();").html_safe, add_html_classes(options, "btn btn-success") )
|
||
link_to_function(name, ("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")").html_safe, add_html_classes(options, "btn btn-success") )
|
||
end
|
||
|
||
def link_to_remove_puppetclass(klass, host)
|
app/views/common_parameters/_form.html.erb | ||
---|---|---|
:fullscreen => :true,
|
||
:placeholder => _("Value")) %>
|
||
<% end %>
|
||
<%= checkbox_f f, :hidden_value, :class => 'hidden_value_textarea_switch', :checked => f.object.hidden_value? %>
|
||
<%= checkbox_f f, :hidden_value, :class => 'hidden_value_textarea_switch', :onchange => 'turn_textarea_switch(this)', :checked => f.object.hidden_value? %>
|
||
<%= submit_or_cancel f %>
|
||
<% end %>
|
app/views/common_parameters/_parameter.html.erb | ||
---|---|---|
<%= fullscreen_button("$(this).parent().prev().find('textarea')") unless f.object.hidden_value? %>
|
||
</td>
|
||
<td>
|
||
<span class="help-block">
|
||
<%= f.check_box(:hidden_value,
|
||
:class => 'hidden_value_textarea_switch',
|
||
:onclick => 'turn_textarea_switch()',
|
||
:disabled => disabled) %>
|
||
<%= _('hide') %><br />
|
||
<%= link_to_remove_fields('', f) if authorized_via_my_scope("host_editing", "destroy_params") %><%= _('remove') %>
|
||
</span>
|
||
<%= f.check_box(:hidden_value,
|
||
:class => 'hidden_value_textarea_switch',
|
||
:onchange => 'turn_textarea_switch(this)',
|
||
:checked => f.object.hidden_value?,
|
||
:disabled => disabled) %>
|
||
<%= _('hide') %><br />
|
||
<%= link_to_remove_fields('', f) if authorized_via_my_scope("host_editing", "destroy_params") %><%= _('remove') %>
|
||
</td>
|
||
<span class="help-block">
|
||
<%= f.object.errors.full_messages.to_sentence %>
|
Also available in: Unified diff
Fixes #11450 - Improve hidden parameter handling