Skip to content

Loading…

Wire up ajax events for for server-side data table. Fixes issue 158 #159

Merged
merged 5 commits into from

3 participants

@gigasquid
4clojure member

Wire up ajax events for for server-side data table. Fixes issue #158

@daviddavis

Looks good to me!

:+1:

@gigasquid
4clojure member

Added custom sorting for the following page on the top100 page. Disabled the sorting on the all users page for the following column because it is a bit involved for now. This is a first step. Still plan on tackling it later.

This addresses issue 155

@amalloy amalloy commented on an outdated diff
resources/public/script/foreclojure.js
((6 lines not shown))
- $("#user-table input.following").live("click", function(e) {
+ $("[id*=user-table] input.following").live("click", function(e) {
@amalloy 4clojure member
amalloy added a note

Really? This seems kinda delicate to me - if we change the id from server-user-table to something else, and grep for server-user-table in order to make sure we find the places where that id was used, we won't spot this one. Can/should we do something more explicit instead, like #user-table,#server-user-table?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gigasquid
4clojure member

Being more explicit

@amalloy amalloy merged commit a569d75 into 4clojure:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 27 additions and 6 deletions.
  1. +24 −4 resources/public/script/foreclojure.js
  2. +3 −2 src/foreclojure/users.clj
View
28 resources/public/script/foreclojure.js
@@ -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"
View
5 src/foreclojure/users.clj
@@ -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]
Something went wrong with that request. Please try again.