                                                               (link-to-javascript {:class "btn btn-default"} "window.close()" (string/capitalize (dog-mission/translate :cancel)))))))]])))
 
 (defn new-view
-  [entity-key entity]
-  (layout (string/capitalize (dog-mission/translate :new-view-title (dog-mission/translate entity-key)))
-          (input-form-panel entity-key entity :post (<< "/~(name entity-key)") :create)))
+  [entity-class-key entity]
+  (layout (string/capitalize (dog-mission/translate :new-view-title (dog-mission/translate entity-class-key)))
+          (input-form-panel entity-class-key entity :post (<< "/~(name entity-class-key)") :create)))
 
 (defn edit-view
-  [entity-key entity]
-  (layout (string/capitalize (dog-mission/translate :edit-view-title (dog-mission/translate entity-key)))
-          (input-form-panel entity-key entity :patch (<< "/~(name entity-key)/~(:key entity)") :update)))
+  [entity-class-key entity]
+  (layout (string/capitalize (dog-mission/translate :edit-view-title (dog-mission/translate entity-class-key)))
+          (input-form-panel entity-class-key entity :patch (<< "/~(name entity-class-key)/~(:key entity)") :update)))
 
 ;; Controllers.
 
 (defmulti condition
-  (fn [entity-key property-key] (property-type entity-key property-key)))
+  (fn [entity-class-key property-key] (property-type entity-class-key property-key)))
 
 (defn- string-condition
-  [entity-key property-key]
-  (if-let [param-value (get-in *request* [:entity-params (param-key entity-key property-key)])]
+  [entity-class-key property-key]
+  (if-let [param-value (get-in *request* [:entity-params (param-key entity-class-key property-key)])]
     ($like property-key (format "%%%s%%" param-value))))
 
 (defmethod condition :string
-  [entity-key property-key]
-  (string-condition entity-key property-key))
+  [& args]
+  (apply string-condition args))
 
 (defmethod condition :text
-  [entity-key property-key]
-  (string-condition entity-key property-key))
+  [& args]
+  (apply string-condition args))
 
 (defn- range-condition
-  [entity-key property-key]
-  (let [param-key (param-key entity-key property-key)]
+  [entity-class-key property-key]
+  (let [param-key (param-key entity-class-key property-key)]
     (if-let [conditions (not-empty (keep identity [(if-let [param-value (get-in *request* [:entity-params (keyword (format "%s-1--" (name param-key)))])]
                                                      ($>= property-key param-value))
                                                    (if-let [param-value (get-in *request* [:entity-params (keyword (format "%s-2--" (name param-key)))])]

  param-value)

(defmulti format-property-param
  (fn [entity-key property-key param-value] (property-type entity-key property-key)))

(defmethod format-property-param :date
  [_ _ param-value]

     (label param-key-key (string/capitalize (dog-mission/translate param-key)))
     (hidden-field param-key-key (get entity (many-to-one-relationship-key-to-physical-column-key property-key)))
     [:div.input-group
      (text-field {:class "form-control", :readonly "readonly"} param-key-name-key (format-property-param entity-class-key property-key (get entity property-key)))
      [:span.input-group-addon {:data-open-window-uri (to-uri (<< "/~(name (:table-key (property-schema entity-class-key property-key)))/select?target-element-id=~(URLEncoder/encode (name param-key-key))"))}
       [:span.glyphicon.glyphicon-search]]]]))

(defmethod input-control :one-to-many
  [entity-class-key entity property-key]
  (let [param-key (param-key entity-class-key property-key)]
    [:div.form-group
     (label param-key (string/capitalize (dog-mission/translate param-key)))
     (text-field {:class "form-control", :disabled "disabled"} param-key (format-property-param entity-class-key property-key (get entity property-key)))]))

(defmethod input-control :default
  [entity-class-key entity property-key]
  nil)

(defn input-form-panel
  [entity-class-key entity method uri submit-button-caption]
  (form-to
   [method uri]
   (hidden-field :index-params (get-in *request* [:params :index-params]))
   (map (partial input-control entity-class-key entity) (property-keys entity-class-key))
   [:p
    (submit-button {:class "btn btn-primary"} (string/capitalize (dog-mission/translate submit-button-caption)))
    "&nbsp;"
    (link-to-with-method-and-params {:class "btn btn-default"} (<< "/~(name entity-class-key)") :get (base64-decode (get-in *request* [:params :index-params])) (string/capitalize (dog-mission/translate :back)))]))

;; views.

(defn list-entities-panel
  [entity-class-key entities page-count page entity-command-fn command-fn]
  (if entities
    (list [:table.table.table-condensed.table-hover
           [:thead
            [:tr
             (map (fn [property-key]
                    [:th (string/capitalize (dog-mission/translate (param-key entity-class-key property-key)))])
                  (list-property-keys entity-class-key))
             [:th]]]
           [:tbody
            (map (fn [entity]
                   [:tr
                    (map (fn [property-key]
                           [:td
                            [:div (format-property-param entity-class-key property-key (get entity property-key))]])
                         (list-property-keys entity-class-key))
                    [:td.command-cell
                     (entity-command-fn entity)]])
                 entities)]]
