Permalink
Browse files

Test reset

  • Loading branch information...
1 parent 0712c88 commit d76dbc3c6eeb5b50b84bdd04486929f84a2401f1 @winton committed Nov 8, 2010
@@ -109,4 +109,14 @@
:variants => params[:variants]
).to_json
end
+
+ post '/variants/:variant_id/reset.json' do
+ ABPlugin::API.reset_variant(
+ :include => params[:include],
+ :only => params[:only],
+ :methods => params[:methods] || :for_dashboard,
+ :token => current_user.single_access_token,
+ :variant_id => params[:variant_id]
+ ).to_json
+ end
end
@@ -50,32 +50,6 @@
<input class='domains' name='domains[]' type='text' value='<%= (typeof(domain) != "undefined") ? domain : "" %>' />
<img class="remove <% if (typeof(domain) == "undefined") { %>hide<% } %>" src="/image/remove.png">
-%textarea.hide#tests_form_template
- .dialog.span-7.last
- %form{ :action => '/tests', :method => 'post' }
- .span-2
- %label{ :for => 'test_name' } Test
- .span-4.last
- <% if (typeof(test) != "undefined") { %>
- <input name='id' type='hidden' value='<%= test.id %>' />
- <% } %>
- <input id='test_name' name='name' type='text' value='<%= (typeof(test) != "undefined") ? test.name : "" %>' />
- .submit
- %input{ :type => 'submit', :value => 'Submit' }
- %input{ :class => 'cancel', :type => 'reset', :value => 'Cancel' }
-
-%textarea.hide#tests_form_variant_template
- .span-2
- %label
- <% if (typeof control != "undefined" && control) { %>
- Control
- <% } else { %>
- Variant
- <% } %>
- .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 %>' }
%tr
@@ -153,4 +127,49 @@
.remove
%a{ :href => '#' }
%img{ :src => '/image/remove.png' }
- Delete
+ Delete
+ .reset
+ %a{ :href => '#' }
+ %img{ :src => '/image/reset.png' }
+ Reset
+
+%textarea.hide#tests_form_template
+ .dialog.span-7.last
+ %form{ :action => '/tests', :method => 'post' }
+ .span-2
+ %label{ :for => 'test_name' } Test
+ .span-4.last
+ <% if (typeof(test) != "undefined") { %>
+ <input name='id' type='hidden' value='<%= test.id %>' />
+ <% } %>
+ <input id='test_name' name='name' type='text' value='<%= (typeof(test) != "undefined") ? test.name : "" %>' />
+ .submit
+ %input{ :type => 'submit', :value => 'Submit' }
+ %input{ :class => 'cancel', :type => 'reset', :value => 'Cancel' }
+
+%textarea.hide#tests_form_variant_template
+ .span-2
+ %label
+ <% if (typeof control != "undefined" && control) { %>
+ Control
+ <% } else { %>
+ Variant
+ <% } %>
+ .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#tests_reset_form_template
+ .dialog.span-6.last
+ %form{ :action => '/test/reset', :method => 'post' }
+ .span-2
+ %label{ :for => 'variant_id' } Reset
+ .span-4.last
+ %select{ :id => 'variant_id', :name => 'variant_id' }
+ <option>All</option>
+ <% $.each(test.variants, function(i, variant) { %>
+ <option value="<%= variant.id %>"><%= variant.name %></option>
+ <% }); %>
+ .submit
+ %input{ :type => 'submit', :value => 'Submit' }
+ %input{ :class => 'cancel', :type => 'reset', :value => 'Cancel' }
View
@@ -85,7 +85,8 @@
}
.dashboard #tests table .edit,
-.dashboard #tests table .remove {
+.dashboard #tests table .remove,
+.dashboard #tests table .reset {
float: left;
margin: 0px 20px;
}
@@ -128,4 +129,8 @@
.dialog .submit {
float: right;
margin: 15px 20px 0 0;
+}
+
+.dialog #variant_id {
+ width: 125px;
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -177,9 +177,7 @@ window.A_B = new function() {
function toJson(obj) {
var json = [];
- if (obj == null)
- json.push(obj + '');
- else if (obj.constructor == Object) {
+ if (obj.constructor == Object) {
json.push('{');
for (var name in obj) {
json.push('"' + name + '"');
@@ -203,8 +201,6 @@ window.A_B = new function() {
json.push('"' + obj + '"');
else if (typeof obj == 'number')
json.push(obj);
- else
- json.push(obj + '');
return json.join('');
}
View
@@ -9,21 +9,22 @@ window.Dashboard = function(sites) {
$(function() {
addLastClassToSelectables();
- $(document).keyup(function(e) {
- if (e.keyCode == 27) // esc
- removeSelectablesWithForms();
- });
-
- $('.add').click(add);
- $('.dialog .remove').live('click', dialogRemove);
- $('.domains').live('keyup', domainKeyUp);
- $('.header > .edit').live('click', edit);
- $('.header > .remove').live('click', remove);
- $('.selectable:not(.new)').live('click', selectableClick);
- $('select.conditions').live('change', testConditionsChange);
- $('#tests .edit a').live('click', testEdit);
- $('#tests .remove a').live('click', testRemove);
- $('.variants').live('keyup', variantKeyUp);
+ $(document)
+ .delegate('.header > .add', 'click', add)
+ .delegate('.dialog .remove', 'click', dialogRemove)
+ .delegate('.domains', 'keyup', domainKeyUp)
+ .delegate('.header > .edit', 'click', edit)
+ .delegate('.header > .remove', 'click', remove)
+ .delegate('.selectable:not(.new)', 'click', selectableClick)
+ .delegate('select.conditions', 'change', testConditionsChange)
+ .delegate('#tests .edit a', 'click', testEdit)
+ .delegate('#tests .remove a', 'click', testRemove)
+ .delegate('#tests .reset a', 'click', testReset)
+ .delegate('.variants', 'keyup', variantKeyUp)
+ .keyup(function(e) {
+ if (e.keyCode == 27) // esc
+ removeSelectablesWithForms();
+ });
selectFromCookies();
});
@@ -78,7 +79,7 @@ window.Dashboard = function(sites) {
}
function domainKeyUp() {
- if ($(this).val() != '')
+ if ($(this).val() != '')
$(this).next().removeClass('hide');
if ($('.domains[value=]').length < 1) {
$('.dialog .submit').before(
@@ -299,6 +300,45 @@ window.Dashboard = function(sites) {
return false;
}
+ function testReset() {
+ var table = $(this).closest('table');
+ var id = table.attr('id').match(/\d+/)[0];
+ var test = byId(currentState().category.tests, id);
+ var dialog = $('#tests_reset_form_template').tmpl({ test: test });
+
+ lightbox(dialog);
+
+ $('form', dialog).submit(function() {
+ var variant_id = $('#variant_id').val();
+ var submits = $('.submit input', dialog);
+
+ $(submits[0]).attr({
+ 'disabled': true,
+ 'value': 'One moment...'
+ });
+ $(submits[1]).remove();
+
+ queue.queue(function() {
+ $.post(
+ '/variants/' + variant_id + '/reset.json',
+ function(response) {
+ test.variants = $.map(test.variants, function(item) {
+ return (item.id == response.id) ? response : item;
+ });
+ queue.dequeue();
+ $('#categories .selected').click().click();
+ dialog.trigger('close');
+ },
+ 'json'
+ );
+ });
+
+ return false;
+ });
+
+ return false;
+ }
+
function variantKeyUp() {
if ($(this).val() != '')
$(this).next().removeClass('hide');
@@ -712,7 +752,9 @@ window.Dashboard = function(sites) {
destroyOnClose: true,
centered: true,
onLoad: function() {
- $('input:first[type=text]', el)[0].select();
+ var input = $('input:first[type=text]', el)[0];
+ if (input)
+ input.select();
$('.cancel', el).click(function() {
el.trigger('close');
return false;
@@ -88,6 +88,18 @@ def self.delete_test(attributes={})
))
end
+ def self.reset_variant(attributes={})
+ return unless Config.token && Config.url
+ base_uri Config.url
+ variant_id = attributes.delete(:variant_id)
+ post("/variants/#{variant_id}/reset.json", :body => compress(
+ :include => attributes.delete(:include),
+ :methods => attributes.delete(:methods),
+ :only => attributes.delete(:only),
+ :token => attributes.delete(:token) || Config.token
+ ))
+ end
+
def self.spec_js_setup
return unless Config.token && Config.url
base_uri Config.url
@@ -152,7 +164,9 @@ def self.update_test(attributes={})
private
def self.compress(hash)
- hash.delete_if { |key, value| value.nil? || value.empty? }
+ hash.delete_if do |key, value|
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
+ end
end
end
end

0 comments on commit d76dbc3

Please sign in to comment.