Permalink
Browse files

Adding remove button to test dialogs

  • Loading branch information...
1 parent 389f979 commit 7c0ed4845ce0d474e5ddcb3d4d4ca5f7b15d7c7e @winton committed Nov 1, 2010
Showing with 41 additions and 1 deletion.
  1. +2 −1 lib/a_b_front_end/view/dashboard.haml
  2. +5 −0 public/css/dashboard.css
  3. +34 −0 public/js/dashboard.js
@@ -73,6 +73,7 @@
<% } %>
.span-4.last
<input class='variants' name='<%= (typeof(id) != "undefined") ? "old_variants[" + id + "]" : "variants[]" %>' type='text' value='<%= (typeof(name) != "undefined") ? name : "" %>' />
+ <img class="remove <% if (typeof(id) == "undefined") { %>hide<% } %>" src="/image/remove.png">
%textarea.hide#test_template
%table{ :id => 'test_<%= test.id %>' }
@@ -127,7 +128,7 @@
%td 0
%td -
%td -
- %td 0%
+ %td -
<% } %>
<% }); %>
%tr{ :class => '<% if (!odd) { %>odd<% } %>'}
View
@@ -120,6 +120,11 @@
line-height: 27px;
}
+.dialog .remove {
+ cursor: pointer;
+ vertical-align: -4px;
+}
+
.dialog .submit {
float: right;
margin: 15px 20px 0 0;
View
@@ -15,6 +15,7 @@ window.Dashboard = function(sites) {
});
$('.add').click(add);
+ $('.dialog .remove').live('click', dialogRemove);
$('.domains').live('keyup', domainKeyUp);
$('.header > .edit').live('click', edit);
$('.header > .remove').live('click', remove);
@@ -45,6 +46,37 @@ window.Dashboard = function(sites) {
return false;
}
+ function dialogRemove() {
+ var input_container = $(this).parent();
+ var text_container = input_container.prev();
+ var input = $(this).prev();
+ var form = $(this).parents('form');
+ var variant_template = $('#tests_form_variant_template');
+ var control = ($.trim(text_container.text()) == 'Control');
+
+ if (input.attr('name').indexOf('old_variants') > -1)
+ form.append(
+ $('<input type="hidden" value="" />').attr({
+ name: input.attr('name')
+ })
+ );
+
+ if (control) {
+ var variant = variant_template.tmpl({
+ control: true
+ });
+ text_container.replaceWith(variant);
+ $('input', variant).focus();
+ } else
+ text_container.remove();
+
+ input_container.remove();
+ $('.variants', form).keyup();
+
+ if (!control)
+ $('.variants[value=]:last').focus();
+ }
+
function domainKeyUp() {
if ($('.domains[value=]').length < 1) {
$('.dialog .submit').before(
@@ -266,6 +298,8 @@ window.Dashboard = function(sites) {
}
function variantKeyUp() {
+ if ($(this).val() != '')
+ $(this).next().removeClass('hide');
if ($('.variants[value=]').length < 1) {
$('.dialog .submit').before(
$('#tests_form_variant_template').tmpl()

0 comments on commit 7c0ed48

Please sign in to comment.