Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from HeWhoWas/template_fixes
Browse files Browse the repository at this point in the history
Template fixes
  • Loading branch information
oovoo committed Nov 20, 2014
2 parents f8ad0df + a45754c commit a9f19dc
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 149 deletions.
18 changes: 2 additions & 16 deletions app/models/concerns/fog_extensions/xenserver/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module FogExtensions
module Xenserver
module Server

attr_accessor :memory_min, :memory_max, :custom_template_name, :builtin_template_name

def to_s
name
end
Expand All @@ -10,14 +12,6 @@ def nics_attributes=(attrs); end

def volumes_attributes=(attrs); end

def memory_min
memory_static_min.to_i
end

def memory_max
memory_static_max.to_i
end

def memory
memory_static_max.to_i
end
Expand All @@ -38,14 +32,6 @@ def state
power_state
end

def custom_template_name
template_name
end

def builtin_template_name
template_name
end

end
end
end
2 changes: 2 additions & 0 deletions app/views/compute_resources_vms/form/_network.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
selected = ""
if params && params['host'] && params['host']['compute_attributes']
selected = params['host']['compute_attributes']['VIFs']['print']
elsif new.__vifs
selected = new.__vifs['print']
end
-%>

Expand Down
23 changes: 3 additions & 20 deletions app/views/compute_resources_vms/form/_templates.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,12 @@
%>

<div id='templates' class=''>

<div class="form-group">
<label class="col-md-2 control-label" for="host_compute_attributes_custom_template_name">Custom template</label>
<div class="col-md-4">
<div class="controls">
<select class="form-control span2" id="host_compute_attributes_custom_template_name" name="host[compute_attributes][custom_template_name]">
<%= options_for_select([[_("No template"), ""]] + compute_resource.custom_templates.map { |t| [t.name, t.name] }, selected_item_c) %>
</select>
<div class="form-group">
<%= selectable_f f, :custom_template_name,[[_("No template"), ""]] + compute_resource.custom_templates.map { |t| [t.name, t.name] }, {}, :class => 'form-control span2', :label => 'Custom Template' %>
</div>
</div>
</div>

<div class="form-group ">
<label class="col-md-2 control-label" for="host_compute_attributes_builtin_template_name">Built-in template</label>
<div class="col-md-4">
<div class="controls">
<select class="form-control span2" id="host_compute_attributes_builtin_template_name" name="host[compute_attributes][builtin_template_name]">
<%= options_for_select([[_("No template"), ""]] + compute_resource.builtin_templates.map { |t| [t.name, t.name] }, selected_item_b) %>
</select>
</div>
<%= selectable_f f, :builtin_template_name,[[_("No template"), ""]] + compute_resource.builtin_templates.map { |t| [t.name, t.name] }, {}, :class => 'form-control span2', :label => 'Builtin Template' %>
</div>
</div>

</div>

</div>
5 changes: 4 additions & 1 deletion app/views/compute_resources_vms/form/_volume.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
<%
selected = ""
size = ""
if params && params['host'] && params['host']['compute_attributes']
if params && params['host'] && params['host']['compute_attributes'] && params['host']['compute_attributes']['VBDs']['physical_size'] != ""
selected = params['host']['compute_attributes']['VBDs']['print']
size = params['host']['compute_attributes']['VBDs']['physical_size']
elsif new.__vbds
selected = new.__vbds['print']
size = new.__vbds['physical_size']
end
-%>
<%= selectable_f f, :print, compute_resource.storage_pools.map(&:name), { :selected => selected }, :class => "span2", :label => _("Storage Repository") %>
Expand Down
79 changes: 43 additions & 36 deletions app/views/compute_resources_vms/form/_xenserver.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,91 @@
if params && params['host'] && params['host']['compute_attributes'] && params['host']['compute_attributes']['custom_template_name'] != ''
hide_raw = 'display:none;'
end

if controller_name == 'hosts'
fields_enabled = true
elsif controller_name == 'compute_attributes'
fields_enabled = true
else
fields_enabled = false
end
-%>

<div class="children_fields">
<fieldset id="vm_profile">
<legend>VM Profile</legend>
<div class="fields">
<%= text_f f, :name, :disabled => !new if controller_name != 'hosts' %>
<%= selectable_f f, :vcpus_max, 1..compute_resource.max_cpu_count, {}, :class => 'input-mini', :disabled => !new, :label => 'vCPUs' %>
<%= selectable_f f, :memory_min, memory_options(compute_resource.max_memory), {}, :class => 'form-control span2', :disabled => !new, :label => 'Memory Min' %>
<%= selectable_f f, :memory_max, memory_options(compute_resource.max_memory), {}, :class => 'form-control span2', :disabled => !new, :label => 'Memory Max' %>
<%= text_f f, :name, :disabled => !fields_enabled, :label => 'Name' if controller_name != 'hosts' %>
<%= selectable_f f, :vcpus_max, 1..compute_resource.max_cpu_count, {}, :class => 'input-mini', :disabled => !fields_enabled, :label => 'vCPUs' %>
<%= selectable_f f, :memory_min, memory_options(compute_resource.max_memory), {}, :class => 'form-control span2', :disabled => !fields_enabled, :label => 'Memory Min' %>
<%= selectable_f f, :memory_max, memory_options(compute_resource.max_memory), {}, :class => 'form-control span2', :disabled => !fields_enabled, :label => 'Memory Max' %>
</div>
</fieldset>
</div>
<!--Templates -->
<div class="children_fields">
<%= field_set_tag 'VM Template', :id => 'xen_templates', :title => _('Template') do -%>
<%= render 'compute_resources_vms/form/templates', :f => f, :compute_resource => compute_resource %>
<%= render 'compute_resources_vms/form/templates', :f => f, :compute_resource => compute_resource, :new => new %>
<% end -%>
</div>

<!-- XenStore Data -->
<div class="children_fields" id="xenserver-xenstore-data">
<%= field_set_tag 'Xen Store Data', :id => 'xen_store_data', :title => _('Xen Store Data') do -%>
<%= render 'compute_resources_vms/form/xenstore', :f => f, :compute_resource => compute_resource, :new => new %>
<%= render 'compute_resources_vms/form/xenstore', :f => f, :compute_resource => compute_resource, :new => new %>
<% end %>
</div>


<!--Storage-->
<div class="children_fields xenserver-raw" id="xenserver-storage" style="<%= hide_raw %>">
<%= new_child_fields_template(f, :VBDs, {
:object => compute_resource.new_volume,
:partial => 'compute_resources_vms/form/volume', :form_builder_attrs => { :compute_resource => compute_resource } }) %>
:object => compute_resource.new_volume,
:partial => 'compute_resources_vms/form/volume', :form_builder_attrs => { :compute_resource => compute_resource, :new => new } }) %>
<%= field_set_tag 'Storage', :id => 'storage_volumes', :title => _('Storage') do -%>
<%= f.fields_for :VBDs do |i| %>
<%= render 'compute_resources_vms/form/volume', :f => i, :compute_resource => compute_resource %>
<% end -%>
<%= f.fields_for :VBDs do |i| %>
<%= render 'compute_resources_vms/form/volume', :f => i, :compute_resource => compute_resource, :new => new %>
<% end -%>
<% end -%>
</div>

<div class="children_fields" id="xenserver-network" style="<%= hide_raw %>">
<%= field_set_tag 'Network interfaces', :id => 'network_interfaces', :title => _('Networks') do -%>
<%= f.fields_for :VIFs do |i| %>
<%= render 'compute_resources_vms/form/network', :f => i, :compute_resource => compute_resource %>
<% end -%>
<%= f.fields_for :VIFs do |i| %>
<%= render 'compute_resources_vms/form/network', :f => i, :compute_resource => compute_resource, :new => new %>
<% end -%>
<% end -%>
</div>

<div class="children_fields" id="xenserver-vm-start" style="<%= hide_raw %>">
<%= field_set_tag 'VM Startup Options', :id => 'vm_starup_options', :title => _('Power ON this machine') do -%>
<div class="form-group">
<label class="col-md-2 control-label" for="xenserver-vm-start-params">Power ON this VM</label>
<div class="col-md-4">
<div class="controls">
<% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %>
<%= checkbox_f f, :start, { :checked => (checked == '1')} if new %>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="xenserver-vm-start-params">Power ON this VM</label>
<div class="col-md-4">
<div class="controls">
<% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %>
<%= checkbox_f f, :start, { :checked => (checked == '1')} if fields_enabled %>
</div>
</div>
</div>
<% end -%>
</div>



<script type="text/javascript">

$(document).off('change.xenserver', '#host_compute_attributes_custom_template_name');
$(document).on('change.xenserver', '#host_compute_attributes_custom_template_name', function (data) {
if ($('option:selected', data.target).val() == "") {
$('.xenserver-raw').show(1000)
} else {
$('.xenserver-raw').hide(1000)
}
$(document).off('change.xenserver', '#host_compute_attributes_custom_template_name');
$(document).on('change.xenserver', '#host_compute_attributes_custom_template_name', function (data) {
if ($('option:selected', data.target).val() == "") {
$('.xenserver-raw').show(1000)
} else {
$('.xenserver-raw').hide(1000)
}

});
});

$(document).off('change.xenserver', '#host_compute_attributes_builtin_template_name');
$(document).on('change.xenserver', '#host_compute_attributes_builtin_template_name', function (data) {
$('.xenserver-raw').show(1000)
})
$(document).off('change.xenserver', '#host_compute_attributes_builtin_template_name');
$(document).on('change.xenserver', '#host_compute_attributes_builtin_template_name', function (data) {
$('.xenserver-raw').show(1000)
})
</script>
Loading

0 comments on commit a9f19dc

Please sign in to comment.