                 (accountant/navigate! "/misc"))]
     (http-delete (str serverhost "miscs/" id)  onres)))
 
-
-
-
 (defroute misc-add-path "/misc/add" []
   (if (nil? (get-value! :user)) (accountant/navigate! "/login")
       (let [onres (fn[json](
-                           (set-key-value :villages (getdata json))
-                           (set-page! [misc-add-template])))]
+                            (set-key-value :villages (getdata json))
+                            (set-page! [misc-add-template])))]
         (http-get-auth (str serverhost "villages") onres))))
 
 (defroute misc-upd-path "/misc/update/:id" [id]

                (accountant/navigate! "/consolidation"))]
    (http-delete (str serverhost "consolidations/" id)  onres)))


(defroute consolidation-add-path "/consolidation/add" []
  (if (nil? (get-value! :user)) (accountant/navigate! "/login")
      (let [onres (fn[json](
                           (set-key-value :subdivisions (getdata json))
                           (set-page! [consolidation-add-template])))]
        (http-get-auth (str serverhost "subdivisions") onres))))

(defroute consolidation-upd-path "/consolidation/update/:id" [id]
  (let [onres (fn[json](
                       (set-key-value :villages (getdata json))
                       (set-page! [consolidation-update-template id
                                   (first (filter (fn[obj]
                                                    (=(.-id obj) (.parseInt js/window id))) (get-value! :consolidations)))])))
        sub-res (fn[json](set-key-value :subdivisions (getdata json)))]
    (do
      (http-get-auth (str serverhost "villages") onres)
      (http-get-auth (str serverhost "subdivisions") sub-res))))

(defn consolidation-add [event]
  (accountant/navigate! "/consolidation/add"))



(defn render-consolidation [consolidations]
  [:div.col-md-12
   [:div {:class "box"}
    [:div {:class "box-header"}
     [:h3.box-title "List of consolidation"]]
    [:div.box-body
      [:div.form-group
       [:input {:type "button" :value "Add"
                :class "btn btn-primary" :on-click consolidation-add}]]
      [:div.table-responsive
       [:table {:class "table table-bordered table-striped dataTable"}
        [:thead
         [:tr
          (when (is-admin-or-super-admin)[:th " "])
          (when (is-admin-or-super-admin)[:th " "])
          [:th "S.No"]
          [:th "Sub Division Name"]
          [:th "Name of the Village"]
          ;; [:th "Tehsil"]
          [:th "Year"]
          [:th "Rack Number"]
          [:th "Description"]]]
        [:tbody
         (doall (for [mt consolidations]
                  ^{:key (.-id mt)}
                  [:tr
                   (when (is-admin-or-super-admin)
                     [:td [button {:bs-style "success"
                                   :on-click  #(consolidation-update(.-id mt))} "Update"]])
                   (when (is-admin-or-super-admin)
                     [:td  [button {:bs-style "danger"
                                    :on-click #(consolidation-delete(.-id mt))} "Delete"]])
                   [:td (.-serialnumber mt)]
                   [:td (.-subdivisionname mt)]
                   [:td (.-villagename mt)]
                   ;; [:td (.-tehsil mt)]
                   [:td (.-year mt)]
                   [:td (.-racknumber mt)]
                   [:td (.-description mt)]
                   ]))]]]
       [:div.col-sm-6.col-md-offset-5 [shared-state 0]]]]])


(defroute consolidation-list "/consolidation" []
  (let [onres (fn [json]
                (cond (= (get-status json) 200) (set-authorized-list json :consolidations render-consolidation)
                      :else (sign-out)))]
    (set-url "/consolidation")
    (set-key-value :is-searched-results false)
    (http-get-auth (str serverhost "consolidations?pageIndex="(dec (get-value! :current-page))"&pageSize=10") onres)))


;; ---------------------------------------------------------
;; fieldbook-records


(defn fieldbook-form-validator [data-set]
  (first (b/validate data-set
                     :serialnumber [[v/required :message "Field is required Must be number"]]
                     :year [[v/required :message "Field is required Must be number"]
                            [year-after? :message "Year must greater than 1900"]
                            [year-before? :message "Year must less than 9999"]]
                     :racknumber [[v/required :message "Field is required"]]
                     :description [[v/required :message "Field is required"]])))

(defn fieldbook-input-int [id ttype data-set placeholder in-focus]
  [:input.form-control {:id id
                        :type ttype
                        :value (@data-set id)
                        :placeholder placeholder
                        :on-change #(swap! data-set assoc id (int (-> % .-target .-value )))
                        :on-blur  #(reset! in-focus "on")
                        }])


(defn fieldbook-input-int-row [id label ttype data-set focus]
  (let [input-focus (r/atom nil)]
    (fn []
      [:div.form-group
       [:label.col-sm-3.control-label label]
       [:div.col-sm-6 [fieldbook-input-int id ttype data-set label input-focus]]
       [:div.col-sm-3 (if (or @input-focus @focus)
                        (if (= nil (fieldbook-form-validator @data-set))
                          [:div]

          (when (is-admin-or-super-admin)[:th " "])
          (when (is-admin-or-super-admin)[:th " "])
          [:th "S.No"]
          [:th "Name of the Village"]
          [:th "Sub Division Name"]
          ;; [:th "Tehsil"]
          [:th "Year"]
          [:th "Rack Number"]
          [:th "Description"]
          ]]
        [:tbody
         (doall (for [mt khasragirdwanis]
                  ^{:key (.-id mt)}
