        #(common-update-callback "Project don't deleted!" {} %))))
 
 (defn ^:export update-project [project-id new-name]
-  (.modal ($ :#iModalProjectMenu) "hide")
-  (ajax
-   (str "/api/projects/" project-id) "PUT"
-   {:name new-name} 
-   (wrap-error-alert #(common-update-callback "Project don't renamed!" {} %))))
+  (let [data {:name new-name}]
+    (if (s/check schm/Project data)
+      (msg/danger "Data is wrong! Check out it please.")
+      (do
+        (.modal ($ :#iModalProjectMenu) "hide")
+        (ajax
+         (str "/api/projects/" project-id) "PUT"  data
+         (wrap-error-alert #(common-update-callback "Project don't renamed!" {} %)))))))
 
 
 (defn get-library [library callback]

(ns hatnik.web.client.z-actions
  (:require [jayq.core :as jq]
            [hatnik.web.client.app-state :as state]
            [hatnik.web.client.message :as msg])
  (:use [jayq.core :only [$]]))

(defn get-data-from-input [id]

    (when (= "ok" (get resp "result"))
      (state/update-all-view))))


(defmulti send-new-action #(:type %))

(defmethod send-new-action :email [data-pack]
  (let [data {:project-id (:project-id data-pack)
              :type "email"
              :address (:user-email data-pack)
              :template (:email-template data-pack)
              :library (:artifact-value data-pack)}]
    (if (s/check schm/EmailAction data)
      (msg/danger "Data is wrong! Check out it please.")
      (do
        (.modal ($ :#iModalAddAction) "hide")
        (ajax "/api/actions" "POST" data 
              (wrap-error-alert #(create-new-action-callback data %)))))))

(defmethod send-new-action :noop [data-pack]
  (let [data {:type "noop"
              :project-id (:project-id data-pack)
              :library (:artifact-value data-pack)}]
    (if (s/check schm/NoopAction data)
      (msg/danger "Data is wrong! Check out it please.")
      (do
        (.modal ($ :#iModalAddAction) "hide")
        (ajax "/api/actions" "POST" data 
              (wrap-error-alert #(create-new-action-callback data %)))))))

(defmethod send-new-action :github-issue [data-pack]
  (let [data {:project-id (:project-id data-pack)
              :type "github-issue"
              :repo (:gh-repo data-pack)
              :title (:gh-issue-title data-pack)
              :body (:gh-issue-body data-pack)
              :library (:artifact-value data-pack)}]
    (if (s/check schm/GithubIssueAction data)
      (msg/danger "Data is wrong! Check out it please.")
      (do
        (.modal ($ :#iModalAddAction) "hide")
        (ajax "/api/actions" "POST" data 
              (wrap-error-alert #(create-new-action-callback data %)))))))


(defmulti test-action #(:type %))
(defmethod test-action :email [data-pack]
  (let [data {:project-id (:project-id data-pack)
              :type "email"
              :address (:user-email data-pack)
              :template (:email-template data-pack)
              :library (:artifact-value data-pack)}]
    (if (s/check schm/EmailAction data)
      (msg/danger "Data is wrong! Check out it please.")      
      (do
        (msg/info "We are trying to send email to you...")
       (ajax "/api/actions/test" "POST" data
            (wrap-error-alert (fn [e] (msg/success "Email sent. Check your inbox."))))))))

(defmethod test-action :github-issue [data-pack]
  (let [data {:project-id (:project-id data-pack)
              :type "github-issue"
              :repo (:gh-repo data-pack)
              :title (:gh-issue-title data-pack)
              :body (:gh-issue-body data-pack)
              :library (:artifact-value data-pack)}]
    (if (s/check schm/GithubIssueAction data)
      (msg/danger "Data is wrong! Check out it please.")
      (do
        (msg/info "We are trying to create issue on Github...")
        (ajax "/api/actions/test" "POST" data
              (wrap-error-alert (fn [e] (msg/success "GitHub issue created. Check out your project."))))))))


(defmulti update-action #(:type %))
(defmethod update-action :email [data-pack]
  (let [data {:project-id (:project-id data-pack)
              :type "email"
              :address (:user-email data-pack)
              :template (:email-template data-pack)
              :library (:artifact-value data-pack)}]
    (if (s/check schm/EmailAction data)
      (msg/danger "Data is wrong! Check out it please.")
      (do
        (.modal ($ :#iModalAddAction) "hide")
        (ajax 
         (str "/api/actions/" (:action-id data-pack)) "PUT" 
         data (wrap-error-alert
               #(common-update-callback "Action don't updated!" data %)))))))

(defmethod update-action :noop [data-pack]
  (let [data {:project-id (:project-id data-pack)
              :type "noop"
              :library (:artifact-value data-pack)}]
    (if (s/check schm/NoopAction data)
      (msg/danger "Data is wrong! Check out it please.")
      (do
        (.modal ($ :#iModalAddAction) "hide")
        (ajax 
         (str "/api/actions/" (:action-id data-pack)) "PUT" 
         data (wrap-error-alert
               #(common-update-callback "Action don't updated!" data %)))))))

(defmethod update-action :github-issue [data-pack]
  (let [data {:project-id (:project-id data-pack)
              :type "github-issue"
              :repo (:gh-repo data-pack)
              :title (:gh-issue-title data-pack)
              :body (:gh-issue-body data-pack)
              :library (:artifact-value data-pack)}]
    (if (s/check schm/GithubIssueAction data)
      (msg/danger "Data is wrong! Check out it please.")
      (do
        (.modal ($ :#iModalAddAction) "hide")
        (ajax 
         (str "/api/actions/" (:action-id data-pack)) "PUT" 
         data (wrap-error-alert
               #(common-update-callback "Action don't updated!" data %)))))))
   
(defn delete-action [action-id]
  (.modal ($ :#iModalAddAction) "hide")
  (ajax 
