Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Finished the work for adding the "following" checkboxes to the users page #133

Merged
merged 2 commits into from

2 participants

@darrenaustin

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).
darrenaustin added some commits
@darrenaustin darrenaustin 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).
54c9333
@darrenaustin darrenaustin Switched the way we were detecting JS for the users page follow check…
…boxes
adbd030
@amcnamara amcnamara merged commit adbd030 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 30, 2011
  1. @darrenaustin

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

    darrenaustin authored
    …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).
  2. @darrenaustin
This page is out of date. Refresh to see the latest.
View
24 resources/public/css/style.css
@@ -217,6 +217,30 @@ a.novisited {color: #00e;}
padding: 15px;
}
+
+/*
+ * By default only show the text label for the "Following" column on
+ * the users page. If they have javascript turned on (detected
+ * via. the js-enabled class set by our page's javascript) then turn
+ * off the text label and turn on the checkbox.
+ */
+#user-table input.following {
+ display: none;
+}
+
+#user-table span.following {
+ display: inline;
+}
+
+#user-table.js-enabled input.following {
+ display: inline;
+}
+
+#user-table.js-enabled span.following {
+ display: none;
+}
+
+
span.error, div.error {
color: red;
}
View
21 resources/public/script/foreclojure.js
@@ -22,7 +22,26 @@ $(document).ready(function() {
$(this).parents("form").attr("action", "/problem/edit").submit();
});
- $("form input.following").live("click", function(e) {
+ $("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").addClass("js-enabled");
+
+ $("#user-table input.following").live("click", function(e) {
e.preventDefault();
var $checkbox = $(this)
var $form = $checkbox.parents("form")
View
11 src/foreclojure/users.clj
@@ -81,17 +81,16 @@
(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? (contains? following user-id)]
(form-to [:post (follow-url user (not following?))]
- [:input.following {:type "checkbox" :name "following"
- :checked following? :value following?}]))))
+ [:input.following {:type "checkbox" :checked 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
Something went wrong with that request. Please try again.