 )
 
 
+(defn OnCalcLeaveDays [response]
+  ( let [ 
+    newdata (map leaves-to-map response)
+    leavecodes (map leaves-to-leavecodes response)
+  ]
+     
+     
+     (swap! app-state assoc :leavetypes  (into {} newdata) )
+     (swap! app-state assoc :leavecodes leavecodes) 
+  )
+   
+
+   ;(.log js/console (:leavetypes @app-state)) 
+
+)
+
+
 
 (defn error-handler [{:keys [status status-text]}]
   (.log js/console (str "something bad happened: " status " " status-text))

)

(def custom-formatter1 (tf/formatter "MMM dd yyyy hh:mm:ss"))
(def custom-formatter2  (tf/formatter (:datemask (:User @t5pcore/app-state)) ))

(def custom-formatter3 (tf/formatter "yyyyMMdd"))

(defn setdatepicker [field]
  (if (and
      (= (:fieldtype (nth field 1) ) 1 )
      (= (:timeformat (nth field 1) ) 0 )
    ) 
     
    (jquery
     (fn []
       (-> (jquery (str "#" (name (nth field 0) )) )
         (.datepicker #js{:format "dd/mm/yyyy" })
         (.on "show"
           (fn [e] (
              let [
                ;;dt (js/Date (.. e -date))
                ;dtstring (tf/parse custom-formatter1 (subs (str (.. e -date)  )  4 24)  )
                dtstring (if
                  (= (count (.. e -dates) ) 0)
                    (tf/parse custom-formatter1 "May 26 2016 08:00:00"  )
                    (tf/parse custom-formatter1 (subs (str (.. e -date)  )  4 24)  )
                )


              ]
              ;;(swap! app-state assoc-in [:leavetypes :ivyt03 :fields :leavefromdate :value] (str (subs dt 8 10)  "/05/"    (subs dt 11 16)  ) )
             ;;(.log js/console dt) 
             ;;(.log js/console (str (.. e -date)  ) )
             ;(.log js/console (count (.. e -dates)))
             ;(.log js/console (subs (str (.. e -date)  ) 4 24))
             (.log js/console (tf/unparse custom-formatter3 (tm/date-time 2010 10 3)))  ;;dtstring
             )
           )
         )
       )      
     )
    )  


   


  )

  (if (and
      (= (:fieldtype (nth field 1) ) 1 )
      (= (:timeformat (nth field 1) ) 2 )
    ) 
     
    (jquery
     (fn []
       (-> (jquery (str "#" (name (nth field 0) )) )
         (.timepicker #js{:timeFormat "H:i:s" } )
       )      
     )
    )  
  )




  )
)

(defn setcontrols []
  (setdatepickers)
  (setcalculatedfields)
)

(defn alertselected1 [event param]
  ;(js/alert (str event  "ClojureScript says 'Boo!'" ))
