   [entity-key property-key]
   nil)
 
-(defn- get-condition-matched-entities
+(defn get-condition-matched-entities
   [entity-key]
   (if (and (= (get-in *request* [:params :command]) "search") (empty? (:entity-param-errors *request*)))
     (let [pages      (->> (-> (->> (if-let [conditions (not-empty (keep (partial condition entity-key) (search-condition-property-keys entity-key)))]

       (map #(pagination-item-control (str %) true (= % page) %) (take pagination-item-count (iterate inc pagination-item-start))))
     (pagination-item-control "&raquo;" (< page page-count) false page-count)]))

(defn- search-condition-panel
  [entity-key & [params]]
  [:div.panel.panel-default
   [:div.panel-heading


(defn index-view
  [entity-key & [entities page-count page]]
  (layout (string/capitalize (dog-mission/translate :list-view-title (dog-mission/translate entity-key)))
          [:div.row
           [:div.col-md-3 (search-condition-panel entity-key)]
           [:div.col-md-9 (list-entities-panel    entity-key entities page-count page
                                                  (fn [entity]
                                                    (list (link-to-with-method-and-params
                                                           {:class "btn btn-primary btn-xs"} (<< "/~(name entity-key)/~(:key entity)/edit") :get {:index-params (base64-encode (:query-params *request*))}
                                                           [:span.glyphicon.glyphicon-pencil])
                                                          "&nbsp;"
                                                          (link-to-with-method-and-params
                                                           {:class "btn btn-danger btn-xs", :data-confirm (string/capitalize (dog-mission/translate :are-you-sure?))} (<< "/~(name entity-key)/~(:key entity)") :delete {:index-params (base64-encode (:query-params *request*))}
                                                           [:span.glyphicon.glyphicon-trash])))
                                                  (fn []
                                                    (link-to-with-method-and-params {:class "btn btn-primary"} (<< "/~(name entity-key)/new") :get {:index-params (base64-encode (:query-params *request*))} (string/capitalize (dog-mission/translate :new)))))]]))

(defn select-view
  [entity-key & [entities page-count page]]
  (let [target-element-id           (get-in *request* [:params :target-element-id])
        representative-property-key (representative-property-key entity-key)]
    (layout (string/capitalize (dog-mission/translate :select-view-title (dog-mission/translate entity-key)))
            [:div.row
             [:div.col-md-3 (search-condition-panel entity-key {:target-element-id (get-in *request* [:params :target-element-id])})]
             [:div.col-md-9 (list-entities-panel    entity-key entities page-count page
                                                    (fn [entity]
                                                      (link-to-javascript
                                                       {:class "btn btn-primary btn-xs"} (<< "$.crossplane.setOpenerSelectProperty('~{target-element-id}', '~(:key entity)', '~(format-property-param entity-key representative-property-key (get entity representative-property-key))'); window.close()")
                                                       [:span.glyphicon.glyphicon-link]))
                                                    (fn []
                                                      (let [target-element-id (get-in *request* [:params :target-element-id])]
                                                        (list (link-to-javascript {:class "btn btn-default"} (<< "$.crossplane.setOpenerSelectProperty('~{target-element-id}', '', ''); window.close()") (string/capitalize (dog-mission/translate :select-nothing)))
                                                              "&nbsp;"
                                                              (link-to-javascript {:class "btn btn-default"} "window.close()" (string/capitalize (dog-mission/translate :cancel)))))))]])))

;; Controllers.

