               (for [endorsement @endorsements]
                 (endorsement-row endorsement)))]])))
 
+;; User Endorsements
+
+(defn init-user-badge-endorsement [state]
+  (ajax/GET
+    (path-for (str "/obpv1/badge/user/endorsement/" (:id @state)))
+    {:handler (fn [data]
+                (swap! state assoc :user-badge-endorsements data)
+                (when (some #(= (:endorser_id %) (:endorser-id @state)) data)
+                  (swap! state assoc :show-link "none"
+                         :show-content "none"
+                         :show-endorsement-status "block")))}))
+
+
+(defn init-pending-endorsements [state]
+  (ajax/GET
+    (path-for "/obpv1/badge/user/pending_endorsement/")
+    {:handler (fn [data]
+                (swap! state assoc :pending data)
+                )}
+    )
+  )
+
 (defn save-endorsement [state]
-  )
+  (ajax/POST
+    (path-for (str "/obpv1/badge/endorsement/" (:id @state)))
+    {:params {:content @(cursor state [:endorsement-comment]) }
+     :handler (fn [data]
+                (when (= (:status data) "success")
+                  (swap! state assoc :show-link "none"
+                         :show-content "none"
+                         :show-endorsement-status "block")
+                  ))}))
+
+(defn update-status [id status user_badge_id state reload-fn]
+  (ajax/POST
+    (path-for (str "/obpv1/badge/endorsement/update_status/" id))
+    {:params {:user_badge_id user_badge_id
+              :status status}
+     :handler (fn [data]
+                (when (= "success" (:status data))
+                  (reload-fn state)))}))
+
+(defn delete-endorsement [id user_badge_id state]
+  (ajax/DELETE
+    (path-for (str "/obpv1/badge/endorsement/" user_badge_id "/" id))
+    {:handler (fn [data]
+                (when (= "success" (:status data))
+                  (init-user-badge-endorsement state)))}))
 
 
 (defn process-text [s state]
   (let [text (-> js/document
                  (.getElementById "claim")
                  (.-innerHTML))
-        endorsement-claim (str text (if (blank? text) "" "\n\n") "*" s)]
+        endorsement-claim (str text (if (blank? text) "" "\n\n") "* " s)]
     (reset! (cursor state [:endorsement-comment]) endorsement-claim)))
 
 (defn endorse-badge-content [state]
   (fn []
     [:div {:style {:display @(cursor state [:show-content])}}
      [:hr]
+     [:div.row
+      [:div.col-xs-12 [:a.cancel.pull-right {:href "#" :on-click #(do
+                                                                    (.preventDefault %)
+                                                                    (swap! state assoc :show-link "block"
+                                                                           :show-content "none"))} [:i.fa.fa-remove]]]]
 
      [:div.endorse {:style {:margin "5px"}} (t :badge/Endorsehelptext)]
 

            [salava.core.ui.helper :refer [path-for private?]]
            [salava.core.ui.modal :as mo]
            [clojure.string :refer [blank?]]
            [reagent.session :as session]))


(defn endorsement-row [endorsement]

        [:a.list-group-item {:href "#" :on-click #(do
                                                    (.preventDefault %)
                                                    (process-text (t :badge/Endorsephrase2) state)
                                                    )} [:i.fa.fa-plus-circle](t :badge/Endorsephrase2)]
        [:a.list-group-item {:href "#" :on-click #(do
                                                    (.preventDefault %)
