commit 92bf092dcf735404bd00172b87191c99305b3b07
Author: Amos Benari <abenari@redhat.com>
Date:   Mon May 7 10:10:48 2012 +0300

    UI - more explicit button description for the add child node.

diff --git a/app/views/common_parameters/_parameters.erb b/app/views/common_parameters/_parameters.erb
index 5121d9803..13de16ec4 100644
--- a/app/views/common_parameters/_parameters.erb
+++ b/app/views/common_parameters/_parameters.erb
@@ -2,5 +2,5 @@
   <%= f.fields_for type do |builder| -%>
     <%= render "common_parameters/parameter", :f => builder %>
   <% end -%>
-  <p><%= authorized_via_my_scope("host_editing", "create_params") ? link_to_add_fields("+", f, type, "common_parameters/parameter") : "" %></p>
+  <p><%= authorized_via_my_scope("host_editing", "create_params") ? link_to_add_fields("+ Add Parameter", f, type, "common_parameters/parameter") : "" %></p>
 <% end -%>
diff --git a/app/views/compute_resources/vms/form/_libvirt.html.erb b/app/views/compute_resources/vms/form/_libvirt.html.erb
index 247687da4..647125187 100644
--- a/app/views/compute_resources/vms/form/_libvirt.html.erb
+++ b/app/views/compute_resources/vms/form/_libvirt.html.erb
@@ -12,7 +12,7 @@
     <%= f.fields_for :nics do |i| %>
       <%= render 'compute_resources/vms/form/libvirt/network', :f => i, :compute_resource => compute_resource %>
     <% end -%>
-    <%= add_child_link "+", :nics, { :class => "info", :title => 'add new network interface' } %>
+    <%= add_child_link "+ Add Interface", :nics, { :class => "info", :title => 'add new network interface' } %>
   <% end -%>
 </div>
 
@@ -25,7 +25,7 @@
     <%= f.fields_for :volumes do |i| %>
       <%= render 'compute_resources/vms/form/libvirt/volume', :f => i, :compute_resource => compute_resource %>
     <% end -%>
-    <%= add_child_link "+", :volumes, { :class => "info", :title => 'add new storage volume' } %>
+    <%= add_child_link "+ Add Volume", :volumes, { :class => "info", :title => 'add new storage volume' } %>
   <% end -%>
 </div>
 <!--TODO # Move to a helper-->
diff --git a/app/views/compute_resources/vms/form/_ovirt.html.erb b/app/views/compute_resources/vms/form/_ovirt.html.erb
index 17b23e6fd..12cd39c6f 100644
--- a/app/views/compute_resources/vms/form/_ovirt.html.erb
+++ b/app/views/compute_resources/vms/form/_ovirt.html.erb
@@ -25,7 +25,7 @@
       <%= f.fields_for :interfaces do |i| %>
         <%= render 'compute_resources/vms/form/ovirt/network', :f => i, :clusters => clusters, :compute_resource => compute_resource %>
       <% end -%>
-      <%= add_child_link "+", :interfaces, { :class => "info", :title => 'add new network interface' } %>
+      <%= add_child_link "+ Add Interface", :interfaces, { :class => "info", :title => 'add new network interface' } %>
     <% end -%>
 
     <%= new_child_fields_template(f, :volumes, {
@@ -35,7 +35,7 @@
         <%= f.fields_for :volumes do |i| %>
             <%= render 'compute_resources/vms/form/ovirt/volume', :f => i, :compute_resource => compute_resource %>
         <% end -%>
-        <%= add_child_link "+", :volumes, { :class => "info", :title => 'add new volume' } %>
+        <%= add_child_link "+ Add Volume", :volumes, { :class => "info", :title => 'add new volume' } %>
     <% end -%>
   </div>
 </div>
diff --git a/app/views/config_templates/_combinations.html.erb b/app/views/config_templates/_combinations.html.erb
index 80ff8c547..ef926711f 100644
--- a/app/views/config_templates/_combinations.html.erb
+++ b/app/views/config_templates/_combinations.html.erb
@@ -2,5 +2,5 @@
   <%= f.fields_for :template_combinations do |builder| -%>
     <%= render 'combination', :f => builder %>
   <% end -%>
-  <p><%= link_to_add_fields("+", f, :template_combinations, "combination") %></p>
+  <p><%= link_to_add_fields("+ Add Combination", f, :template_combinations, "Add new combination") %></p>
 <% end -%>
diff --git a/app/views/lookup_keys/_fields.html.erb b/app/views/lookup_keys/_fields.html.erb
index 7ae042e9c..792d41660 100644
--- a/app/views/lookup_keys/_fields.html.erb
+++ b/app/views/lookup_keys/_fields.html.erb
@@ -1,5 +1,5 @@
-<div <%= "id=#{f.object.key || 'new_lookup_keys'} class='tab-pane fields' " %> >
-  <%= remove_child_link "Remove #{f.object.new_record? ? "Variable" : f.object}", f , {:class => 'btn btn-danger action_btn'} unless controller_name == "lookup_keys" %>
+<div <%= "id=#{f.object.key || 'new_lookup_keys'} class='tab-pane fields well' " %> >
+  <%= remove_child_link "Remove #{f.object.new_record? ? "Variable" : f.object}", f , {:class => 'btn btn-danger hide'} unless controller_name == "lookup_keys" %>
   <%= text_f f, :key, :label => "Name" %>
   <%= text_f f, :description %>
   <%= text_f f, :default_value, :class => "input-xxlarge", :help_inline => popover("?","value to use when there is no match", :title => "Default Value").html_safe %>
@@ -24,7 +24,7 @@
     <%= f.fields_for :lookup_values do |lookup_values| %>
       <%= render 'lookup_keys/value', :f => lookup_values %>
     <% end %>
-    <%= add_child_link "+", :lookup_values, { :class => "info smart_var_add_match", :title => 'add new matcher / value'} %>
+    <%= add_child_link "+ Add Matcher-Value", :lookup_values, { :title => 'add a new matcher-value pair'} %>
   </div>
   <hr>
 </div>
diff --git a/app/views/puppetclasses/_form.html.erb b/app/views/puppetclasses/_form.html.erb
index 92b19b18d..9192051d9 100644
--- a/app/views/puppetclasses/_form.html.erb
+++ b/app/views/puppetclasses/_form.html.erb
@@ -23,11 +23,12 @@
           <p><strong>Help!</strong> What is a <a href=http://theforeman.org/projects/foreman/wiki/Smart_Variables rel="external">Smart variable</a>?</p>
         </div>
       <% end -%>
-      <p class="ra"><%= add_child_link "New Variable", :lookup_keys %></p>
+
       <ul class="nav nav-stacked nav-pills span2" data-tabs="pills">
         <% @puppetclass.lookup_keys.each do |key| -%>
-          <li><a data-toggle="pill" id="pill_<%= key %>" href="#<%= key %>"><%= key %></a></li>
+          <li><a data-toggle="pill" id="pill_<%= key %>" href="#<%= key %>"><%= key %><span class="label label-important fr">&times;</span></a></li>
         <% end -%>
+        <li><%= link_to_function "+ Add Variable", "add_child_node(this);" ,:class=>"label label-success", :"data-association" => :lookup_keys %></li>
       </ul>
 
       <div class="tab-content span8 pill-content">
diff --git a/app/views/users/_filters.html.erb b/app/views/users/_filters.html.erb
index 39fb6dc78..41a711348 100644
--- a/app/views/users/_filters.html.erb
+++ b/app/views/users/_filters.html.erb
@@ -33,7 +33,7 @@
               <%= render "user_fact", :f => builder %>
           <% end -%>
           <% if authorized_for(params[:controller], params[:action]) -%>
-              <p><%= link_to_add_fields("+", f, :user_facts, "user_fact", :title => "Add a fact filter") %></p>
+              <p><%= link_to_add_fields("+ Add Filter", f, :user_facts, "user_fact", :title => "Add a fact filter") %></p>
           <% end -%>
         </div>
       </div>
diff --git a/public/javascripts/lookup_keys.js b/public/javascripts/lookup_keys.js
index 401242c2f..3d332b727 100644
--- a/public/javascripts/lookup_keys.js
+++ b/public/javascripts/lookup_keys.js
@@ -1,10 +1,37 @@
 //on load
 $(function() {
-  //set selected tab
-  $('.tab-content .fields').first().addClass('active');
-  $('.nav-pills li').first().addClass('active');
+  //select the first tab
+  $('.nav-pills li a span').hide();
+  select_first_tab();
+  //make the remove variable button visible only on the active pill
+  $('.nav-pills li a').on('click',function(){ show_delete_button(this);});
+  //remove variable click event
+  $('.nav-pills li a span').on('click',function(){ remove_node(this);});
 })
 
+function select_first_tab(){
+  if ($('.nav-pills li').size() > 1){
+    $('.tab-content .fields').first().addClass('active');
+    $('.nav-pills li').first().addClass('active');
+  }
+  $('.nav-pills li.active a span').show('highlight',5  );
+}
+
+function show_delete_button(item){
+  $('.nav-pills li a span:visible').hide();
+  $(item).children("span").show('highlight',5);
+  if($(item).hasClass('label-success') && ($('.nav-pills li').size()>1)){
+    select_first_tab();
+  }
+}
+
+function remove_node(item){
+  $($(item).parent("a").attr("href")).children('.btn-danger').click();
+  var pills = $('.nav-pills li a');
+  if (pills.size() > 1){pills.first().click();}
+  $('.nav-pills li.active a').click();
+}
+
 function add_child_node(item) {
     // Setup
     var assoc   = $(item).attr('data-association');           // Name of child
@@ -42,28 +69,30 @@ function add_child_node(item) {
     var field   = '';
     if (assoc == 'lookup_keys') {
       $('.nav-pills .active, .pill-content .active').removeClass('active');
-      var pill = "<li class='active'><a data-toggle='pill'  href='#new_" + new_id + "' id='pill_new_" + new_id + "'>new</a></li>"
+      var pill = "<li class='active'><a onclick='show_delete_button(this);' data-toggle='pill' href='#new_" + new_id + "' id='pill_new_" + new_id + "'>new<span onclick='remove_node(this);' class='label label-important fr'>&times;</span></a></li>"
       $('.nav-pills').prepend(pill);
       field = $('.pill-content').prepend($(content).addClass('active'));
+      $('.nav-pills li.active a').show('highlight', 500);
     } else {
       field = $(content).insertBefore($(item));
     }
     $(item).closest("form").trigger({type: 'nested:fieldAdded', field: field});
     $('a[rel="popover"]').popover();
     return new_id;
-};
+}
 
 function remove_child_node(item) {
   var hidden_field = $(item).prev('input[type=hidden]')[0];
   if(hidden_field) {
     hidden_field.value = '1';
   }
+
   $(item).closest('.fields').hide();
   if($(item).parent().hasClass('fields')) {
-    $('#pill_' + $(item).closest('.fields').attr('id')).hide();
-    $('.nav-pills li :visible').first().click();
+    $('#pill_' + $(item).closest('.fields').attr('id')).empty().remove();
   }
   $(item).closest("form").trigger('nested:fieldRemoved');
+
   return false;
 }
 
