Permalink
Browse files

Merge pull request #159 from gigasquid/develop

Wire up ajax events for for server-side data table.  Fixes issue 158
  • Loading branch information...
2 parents 81ff1f2 + 7dd17b8 commit a569d75982c439fa852c7873a0c49fcc00115fa5 @amalloy amalloy committed Oct 10, 2011
Showing with 27 additions and 6 deletions.
  1. +24 −4 resources/public/script/foreclojure.js
  2. +3 −2 src/foreclojure/users.clj
@@ -41,9 +41,9 @@ $(document).ready(function() {
$("#all-users-link").html("[show <a href=\"/users/all\">all</a>]");
- $("#user-table").addClass("js-enabled");
+ $("#user-table,#server-user-table").addClass("js-enabled");
- $("#user-table input.following").live("click", function(e) {
+ $("#user-table,#server-user-table input.following").live("click", function(e) {
e.preventDefault();
var $checkbox = $(this)
var $form = $checkbox.parents("form")
@@ -59,6 +59,7 @@ $(document).ready(function() {
});
return false;
});
+
});
var difficulty = {
@@ -94,6 +95,19 @@ jQuery.fn.dataTableExt.afnSortData['user-name'] = function(oSettings, iColumn)
return aData;
}
+// See comments for above function to make sense of this mess
+jQuery.fn.dataTableExt.afnSortData['following'] = function(oSettings, iColumn)
+{
+ var aData = [];
+ $('td:eq('+iColumn+') span.following', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
+ var followingText = $(this).text();
+ if (!followingText || followingText == "") { followingText = "no" }
+ aData.push(followingText);
+ });
+ return aData;
+}
+
+
function configureDataTables(){
$('#problem-table').dataTable( {
@@ -127,13 +141,19 @@ function configureDataTables(){
{"sType": "numeric"},
{"sSortDataType": "user-name"},
{"sType": "numeric"},
- {"sType": "string"}
+ {"sSortDataType": "following"}
]
} );
$('#server-user-table').dataTable( {
- "iDisplayLength":10,
+ "aoColumns": [
+ null,
+ null,
+ null,
+ {"bSortable": false}
+ ],
+ "iDisplayLength":100,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/datatable/users"
@@ -103,11 +103,12 @@
(str "/user/" (if follow? "follow" "unfollow") "/" username))
(defn following-checkbox [current-user-id following user-id user]
- (when (and current-user-id (not= current-user-id user-id))
+ (if (and current-user-id (not= current-user-id user-id))
(let [following? (contains? following user-id)]
(form-to [:post (follow-url user (not following?))]
[:input.following {:type "checkbox" :checked following?}]
- [:span.following (when following? "yes")]))))
+ [:span.following (when following? "yes")]))
+ [:span.following "me"]))
(defn generate-user-list [user-set table-name]
(let [[user-id following]

0 comments on commit a569d75

Please sign in to comment.