Module: ProxmoxFormHelper
- Includes:
- ProxmoxVMInterfacesHelper
- Defined in:
- app/helpers/proxmox_form_helper.rb
Overview
You should have received a copy of the GNU General Public License along with ForemanFogProxmox. If not, see <www.gnu.org/licenses/>.
Instance Method Summary collapse
- #add_child_link_typed(name, association, type, opts = {}) ⇒ Object
- #new_child_fields_template_typed(form_builder, association, options = {}) ⇒ Object
- #password_proxmox_f(f, attr, options = {}) ⇒ Object
- #password_proxmox_placeholder(obj, attr = nil) ⇒ Object
- #proxmox_vm_type_and_node_id(host, form_object, params) ⇒ Object
- #remove_child_link_typed(name, f, type, opts = {}) ⇒ Object
Methods included from ProxmoxVMInterfacesHelper
#add_or_delete_typed_interface, #compute_dhcps, #interface_common_typed_keys, #interface_compute_attributes_typed_keys, #parse_typed_interfaces, #parsed_typed_interfaces, #sync_dhcp_for_ip
Instance Method Details
#add_child_link_typed(name, association, type, opts = {}) ⇒ Object
109 110 111 112 113 114 115 |
# File 'app/helpers/proxmox_form_helper.rb', line 109 def add_child_link_typed(name, association, type, opts = {}) opts[:class] = [opts[:class], 'add_nested_fields btn btn-primary'].compact.join(' ') opts[:"data-association"] = (type + '_' + association.to_s).to_sym hide = '' hide += '$("[data-association=' + type + '_volumes]").hide();' unless ['hard_disk', 'mp'].include?(type) link_to_function(name.to_s, 'add_child_node(this);' + hide, opts) end |
#new_child_fields_template_typed(form_builder, association, options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/proxmox_form_helper.rb', line 90 def new_child_fields_template_typed(form_builder, association, = {}) if [:object].blank? association_object = form_builder.object.class.reflect_on_association(association) [:object] = association_object.klass.new(association_object.foreign_key => form_builder.object.id) end [:partial] ||= association.to_s.singularize [:form_builder_local] ||= :f [:form_builder_attrs] ||= {} content_tag(:div, :class => "#{[:type]}_#{association}_fields_template form_template", :style => 'display: none;') do form_builder.fields_for(association, [:object], :child_index => "new_#{[:type]}_#{association}") do |f| render(:partial => [:partial], :layout => [:layout], :locals => { [:form_builder_local] => f }.merge([:form_builder_attrs])) end end end |
#password_proxmox_f(f, attr, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/proxmox_form_helper.rb', line 62 def password_proxmox_f(f, attr, = {}) = .delete(:unset) value = f.object[attr] if .delete(:keep_value) password_field_tag(:fakepassword, value, :style => 'display: none', :autocomplete => 'new-password-fake') + field(f, attr, ) do [:autocomplete] ||= 'new-password' [:placeholder] ||= password_proxmox_placeholder(f.object, attr) [:disabled] = true if [:value] = value if value.present? addClass , 'form-control' pass = f.password_field(attr, ) + tag(:span, '', class: 'glyphicon glyphicon-warning-sign input-addon', title: 'Caps lock ON', style: 'display:none') if = link_to_function(icon_text('edit', '', :kind => 'pficon'), 'toggle_input_group(this)', :id => 'disable-pass-btn', :class => 'btn btn-default', :title => _('Change the password')) input_group(pass, input_group_btn()) else pass end end end |
#password_proxmox_placeholder(obj, attr = nil) ⇒ Object
85 86 87 88 |
# File 'app/helpers/proxmox_form_helper.rb', line 85 def password_proxmox_placeholder(obj, attr = nil) pass = obj.attributes.key?(attr) pass ? '********' : '' end |
#proxmox_vm_type_and_node_id(host, form_object, params) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/proxmox_form_helper.rb', line 23 def proxmox_vm_type_and_node_id(host, form_object, params) compute_attributes = form_object.compute_attributes || {} host_compute_attrs = host.respond_to?(:compute_attributes) ? (host.compute_attributes || {}) : {} host_vm_type = extract_attr(host_compute_attrs, :type) profile_attrs = profile_compute_attributes(host) profile_vm_type = extract_attr(profile_attrs, :type) vm_type = [ params.dig(:host, :compute_attributes, :type).presence, params.dig(:compute_attribute, :vm_attrs, :type).presence, host_vm_type, profile_vm_type, 'qemu', ].find(&:present?) compute_attributes = proxmox_default_interface_compute_attributes(host, vm_type) unless proxmox_valid_interface_compute_attributes?(compute_attributes, vm_type) compute_node_id = extract_attr(compute_attributes, :node_id) object_node_id = form_object.respond_to?(:node_id) ? form_object.node_id : nil host_node_id = extract_attr(host_compute_attrs, :node_id) profile_node_id = extract_attr(profile_attrs, :node_id) node_id = [ params.dig(:host, :compute_attributes, :node_id).presence, params.dig(:compute_attribute, :vm_attrs, :node_id).presence, object_node_id, compute_node_id, host_node_id, profile_node_id, ].find(&:present?) { compute_attributes: compute_attributes, vm_type: vm_type, node_id: node_id, } end |
#remove_child_link_typed(name, f, type, opts = {}) ⇒ Object
117 118 119 120 121 122 |
# File 'app/helpers/proxmox_form_helper.rb', line 117 def remove_child_link_typed(name, f, type, opts = {}) opts[:class] = [opts[:class], 'remove_nested_fields'].compact.join(' ') hide = '' hide += '$("[data-association=' + type + '_volumes]").show();' unless ['hard_disk', 'mp'].include?(type) f.hidden_field(opts[:method] || :_destroy) + link_to_function(name, 'remove_child_node(this);' + hide, opts) end |