Revision 4d8b2799
Added by Ohad Levy over 12 years ago
- ID 4d8b27996f4ba9a0b879295c48aac876e58038ce
app/controllers/subnets_controller.rb | ||
---|---|---|
end
|
||
|
||
def create_multiple
|
||
if params[:subnets].empty?
|
||
return redirect_to subnets_path, :notice => "No Subnets selected"
|
||
end
|
||
|
||
@subnets = Subnet.create(params[:subnets]).reject { |s| s.errors.empty? }
|
||
if @subnets.empty?
|
||
process_success(:object => @subnets, :success_msg => "Imported Subnets")
|
app/helpers/subnets_helper.rb | ||
---|---|---|
module SubnetsHelper
|
||
|
||
# expand or minimize the subnet when importing
|
||
def minimal? subnets
|
||
subnets.each {|s| return false unless s.errors.empty?}
|
||
subnets.count > 1
|
||
end
|
||
|
||
# which options should be shown when importing subnets
|
||
def options subnets
|
||
minimal?(subnets) ? "#{edit} or #{ignore}" : ignore
|
||
end
|
||
|
||
def ignore
|
||
link_to_function "ignore", "$(this).closest('.imported_subnet').remove()"
|
||
end
|
||
|
||
def edit
|
||
link_to_function "review", "$(this).parent().parent().children('.subnet_fields').show()"
|
||
end
|
||
end
|
app/views/subnets/_fields.html.erb | ||
---|---|---|
<%= f.text_field :mask, :title => "netmask for this subnet", :class => "last" %>
|
||
</p>
|
||
|
||
<p>
|
||
<%= f.label :ranges, nil, :class => "span-3" %>
|
||
<%= f.text_field :ranges, :title => "A list of comma separated single IPs or start-end couples.", :class => "last" %>
|
||
</p>
|
||
|
||
<p title="DHCP Proxy to use within this subnet">
|
||
<%= f.label :dhcp_id, "DHCP Proxy", :class => "span-3" %>
|
||
<%= f.collection_select :dhcp_id, Feature.find_by_name("DHCP").smart_proxies, :id, :name, {:include_blank => "None"}, {:class => "last"} %>
|
||
... | ... | |
<%= f.label :vlanid, nil, :class => "span-3" %>
|
||
<%= f.text_field :vlanid, :class => "last" %>
|
||
</p>
|
||
|
||
<p>
|
||
<%= f.label :priority, nil, :class => "span-3"%>
|
||
<%= f.text_field :priority, :class => "last"%>
|
||
</p>
|
app/views/subnets/import.html.erb | ||
---|---|---|
<% title "Import subnets" %>
|
||
|
||
<h2>We've found the following subnets</h2>
|
||
<% form_tag create_multiple_subnets_path do -%>
|
||
<% @subnets.each do |subnet| -%>
|
||
<h3><%= subnet -%></h3>
|
||
<hr>
|
||
<% fields_for "subnets[]", subnet do |f| -%>
|
||
<%= render 'fields', :f => f %>
|
||
<% end -%>
|
||
<div id="<% subnet.to_s %>", class="imported_subnet">
|
||
<li><%= subnet %>(<%= options(@subnets) %>)</li>
|
||
<span class="subnet_fields" <%= display?(minimal?(@subnets)) %>>
|
||
<hr>
|
||
<% fields_for "subnets[]", subnet do |f| -%>
|
||
<%= render 'fields', :f => f %>
|
||
<% end -%>
|
||
</span>
|
||
</div>
|
||
<% end -%>
|
||
<%= submit_tag %>
|
||
<% end -%>
|
public/stylesheets/style.css | ||
---|---|---|
float:right;
|
||
}
|
||
|
||
#settings li {
|
||
.imported_subnet, #settings li {
|
||
list-style-type:none;
|
||
padding:0 0 8px;
|
||
}
|
Also available in: Unified diff
refs #1201 - adds the ability not to import all subnets
TODO: redo this at some point with checkboxes