             [cruncher.utils.lib :as lib]
             [cruncher.utils.views :as vlib]))
 
+;;;; Selections
+(defn select-all-but-favorite
+  []
+  (let [rows (gdom/getElementsByClass "poketable-row")]
+    (doall (map (fn [row]
+                  (let [id (.getAttribute row "data-id")
+                        favorite (.getAttribute row "data-favorite")
+                        checkbox (gdom/getElement (str "poketable-checkbox-" id))]
+                    (when-not (= "true" favorite)
+                      (set! (.. checkbox -checked) true)))) rows))))
+
 ;;;; Controls
 (defui Controls
   Object

               (lib/get-info)))))
(def info-message (om/factory InfoMessage))

;;;; Poketable
(defui PokeTableEntry
  Object
  (render [this]
    (let [pokemon (om/props this)]
      (dom/tr nil
              (dom/td nil
                      (dom/div #js {:className "checkbox"}
                               (dom/label nil
                                          (dom/input #js {:className "poketable-checkbox"
                                                          :type      "checkbox"
                                                          :value     (:id pokemon)}))))
              (dom/td nil (if (:favorite pokemon) (vlib/fa-icon "fa-star") (vlib/fa-icon "fa-star-o")))
              (dom/td nil (:pokemon_id pokemon))
              (dom/td nil (:name pokemon))

             (dom/span #js {:className "pull-right"} (vlib/loader (om/props this)))
             (vlib/button-primary #(com/route :get-all-pokemon) "Get all Pokemon")
             " "
             (vlib/button-primary #(shredder/power-on this) (dom/span nil (vlib/fa-icon "fa-eraser") " Crunch selected Pokemon"))
             " "
             (vlib/button-primary select-all-but-favorite "Select all but favorite")
             (dom/br nil)
             (dom/br nil)
             (dom/div nil (progress/progress-bar (om/props this))))))
