Permalink
Browse files

Add Collect and Visit buttons for bulk update of collections.

  • Loading branch information...
1 parent 3f4258e commit 615e09defef888e2a7d8b2507355c7d186cd76d6 @ignar committed Oct 23, 2012
View
4 app/views/countries/index.html.erb
@@ -18,6 +18,7 @@
<label for="name-filter">Name</label>
<input id="name-filter" name="name" type="text" />
<input type="button" value="Check/Uncheck All" id="select-all-controll" data-action="check" disabled="disabled" />
+ <input type="button" value="Visit" id="apply-filter-controll" disabled="disabled" />
</div>
<table id="collection">
@@ -37,7 +38,8 @@
<td><%= check_box_tag("country[]", country.code, current_user.visited?(country),
:id => "country_#{country.code}",
:"data-code" => country.code,
- :"data-url" => visit_country_path(country)) %></td>
+ :"data-url" => visit_country_path(country),
+ :"data-dirty" => "false") %></td>
<td class="name"><%= country.name %></td>
<td class="code"><%= country.code %></td>
<td class="status"><%= current_user.visited?(country) ? 'Visited' : 'Not Visited' %></td>
View
4 app/views/currencies/index.html.erb
@@ -17,6 +17,7 @@
<label for="name-filter">Name</label>
<input id="name-filter" name="name" type="text" />
<input type="button" value="Check/Uncheck All" id="select-all-controll" data-action="check" disabled="disabled" />
+ <input type="button" value="Collect" id="apply-filter-controll" disabled="disabled" />
</div>
<table id="collection">
@@ -36,7 +37,8 @@
<td><%= check_box_tag("currency[]", currency.code, current_user.collect?(currency),
:id => "currency_#{currency.code}",
:"data-code" => currency.code,
- :"data-url" => collect_currency_path(currency)) %></td>
+ :"data-url" => collect_currency_path(currency),
+ :"data-dirty" => "false") %></td>
<td class="name"><%= currency.name %></td>
<td class="code"><%= currency.code %></td>
<td class="status"><%= current_user.collect?(currency) ? 'Collected' : 'Not Collected' %></td>
View
2 ctracker.org
@@ -109,3 +109,5 @@ Clock summary at [2012-10-23 Tue 16:44]
* DONE Filter on currencies page
CLOSED: [2012-10-23 Tue 16:44]
CLOCK: [2012-10-23 Tue 16:07]--[2012-10-23 Tue 16:44] => 0:37
+* TODO Add apply controll
+ CLOCK: [2012-10-23 Tue 16:50]--[2012-10-23 Tue 17:04] => 0:14
View
12 public/javascripts/update_elements.js
@@ -10,6 +10,7 @@ var update_collection = function(table, collection, complete_callback){
, success: function(data, status, jq){
tr = table.find("tr#record_"+checkbox.data("code"));
tr.find("td.status").html(data.status);
+ checkbox.data("dirty", "false");
}
, error: function(jq, status, error){
alert(error);
@@ -33,6 +34,7 @@ table.find("input[type='checkbox']").on("change", function(e){
var check_controll = $("#select-all-controll");
+var apply_controll = $("#apply-filter-controll");
var filter = $("#name-filter");
var filter_updated_callback = function(e){
var target = $(e.currentTarget);
@@ -41,6 +43,7 @@ var filter_updated_callback = function(e){
check_controll.attr("disabled", false);
check_controll.data("action", "check");
check_controll.val("Check All");
+ apply_controll.attr("disabled", false);
table.find("tbody tr").each(function(ind, elem){
var el = $(elem);
var pattern = new RegExp("^"+target.val(), "i");
@@ -52,6 +55,7 @@ var filter_updated_callback = function(e){
});
} else if(target.val().length == 0) {
check_controll.attr("disabled", true);
+ apply_controll.attr("disabled", true);
table.find("tbody tr").removeClass("hidden");
}
};
@@ -76,5 +80,13 @@ check_controll.on("click", function(e){
}
checkboxes.attr("checked", chk);
+ checkboxes.data("dirty", "true");
+});
+
+apply_controll.on("click", function(e){
+ e.preventDefault();
+ var checkboxes = table.find("tbody tr:visible input[type='checkbox']:checked").filter(function(ind){
+ return $(this).data("dirty") === "true";
+ });
update_collection(table, $.makeArray(checkboxes), update_chart);
});

0 comments on commit 615e09d

Please sign in to comment.