Skip to content
Browse files

Finished the work for adding the "following" checkboxes to the users …

…page. (Issue 117)

- In the case where the user has javascript disabled, we fall back to
just showing a "yes" in the following column instead of the checkbox.
- Optimized checking to see if a user was being followed by making the
following vector into a set.
- Hooked up the "Follow" buttons on the user profile page to use AJAX
instead of another page load (which also fixes the back button issue
with this).
  • Loading branch information...
1 parent 611e296 commit 54c9333b4c387121144be4c5c3fd6cc36d4b5c02 @darrenaustin committed
Showing with 52 additions and 6 deletions.
  1. +27 −0 resources/public/css/style.css
  2. +19 −0 resources/public/script/foreclojure.js
  3. +6 −6 src/foreclojure/users.clj
View
27 resources/public/css/style.css
@@ -217,6 +217,33 @@ a.novisited {color: #00e;}
padding: 15px;
}
+/*
+ * If the user has javascript turned on, show the
+ * "following" checkboxes and turn off the "following"
+ * text labels.
+ */
+#user-table input.following, {
+ display: inline;
+}
+
+#user-table span.following {
+ display: none;
+}
+
+/*
+ * If the user has javascript disabled, hide the
+ * "following" checkboxes and fallback to showing
+ * the "following" text labels.
+ */
+#user-table.javascript-disabled input.following {
+ display: none;
+}
+
+#user-table.javascript-disabled span.following {
+ display: inline;
+}
+
+
span.error, div.error {
color: red;
}
View
19 resources/public/script/foreclojure.js
@@ -22,6 +22,25 @@ $(document).ready(function() {
$(this).parents("form").attr("action", "/problem/edit").submit();
});
+ $("button.user-follow-button").live("click", function(e) {
+ e.preventDefault();
+ var $form = $(this).parents("form");
+ var $button = $(this);
+ $.ajax({type: "POST",
+ url: "/rest" + $form.attr("action"),
+ dataType: "json",
+ success: function(data) {
+ if (data) {
+ $button.text(data["next-label"]);
+ $form.attr("action", data["next-action"]);
+ }
+ },
+ });
+ return false;
+ });
+
+ $("#user-table").removeClass('javascript-disabled');
+
$("form input.following").live("click", function(e) {
e.preventDefault();
var $checkbox = $(this)
View
12 src/foreclojure/users.clj
@@ -81,20 +81,20 @@
(defn following-checkbox [current-user-id following user-id user]
(when (and current-user-id (not= current-user-id user-id))
- (let [following? (some #{user-id} following)]
+ (let [following? (following user-id)]
(form-to [:post (follow-url user (not following?))]
[:input.following {:type "checkbox" :name "following"
- :checked following? :value following?}]))))
+ :checked following? :value following?}]
+ [:span.following (when following? "yes")]))))
(defn generate-user-list [user-set]
(let [[user-id following]
- (if (session/session-get :user)
+ (when (session/session-get :user)
(with-user [{:keys [_id following]}]
- [_id following])
- [nil nil])]
+ [_id (set following)]))]
(list
[:br]
- [:table#user-table.my-table
+ [:table#user-table.my-table.javascript-disabled
[:thead
[:tr
[:th {:style "width: 40px;"} "Rank"]

0 comments on commit 54c9333

Please sign in to comment.
Something went wrong with that request. Please try again.