Skip to content

Commit

Permalink
administration: preview when creating new form
Browse files Browse the repository at this point in the history
for #835
  • Loading branch information
opqdonut committed Apr 11, 2019
1 parent 49f918a commit abbcb21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions resources/translations/en.edn
Expand Up @@ -116,6 +116,7 @@
:no-licenses "No licenses"
:organization "Organization"
:organization-placeholder "testorganization.org"
:preview "Preview"
:resource "Resource"
:resources "Resources"
:rounds "Rounds"
Expand Down
1 change: 1 addition & 0 deletions resources/translations/fi.edn
Expand Up @@ -116,6 +116,7 @@
:no-licenses "Ei lisenssejä"
:organization "Organisaatio"
:organization-placeholder "testorganization.org"
:preview "Esikatselu"
:resource "Resurssi"
:resources "Resurssit"
:rounds "Rounds"
Expand Down
28 changes: 25 additions & 3 deletions src/cljs/rems/administration/create_form.cljs
Expand Up @@ -8,7 +8,7 @@
[rems.atoms :refer [enrich-user]]
[rems.collapsible :as collapsible]
[rems.config :refer [dev-environment?]]
[rems.fields :refer [normalize-option-key]]
[rems.fields :as fields]
[rems.text :refer [text text-format localize-item]]
[rems.util :refer [dispatch! post!]]
[rems.status-modal :as status-modal]
Expand Down Expand Up @@ -190,7 +190,7 @@
[remove-form-item-option-button item-index option-index]]]
[text-field context {:keys [:items item-index :options option-index :key]
:label (text :t.create-form/option-key)
:normalizer normalize-option-key}]
:normalizer fields/normalize-option-key}]
[localized-text-field context {:keys [:items item-index :options option-index :label]
:label (text :t.create-form/option-label)}]])

Expand Down Expand Up @@ -272,6 +272,24 @@
[form-item-option-fields item-index])])
items)))

(defn- form-field-to-application-field
"Convert a field from the form create model to the application view model."
[field]
{:field/type (keyword (:type field))
:field/title (:title field)
:field/placeholder (:input-prompt field)
:field/max-length (:maxlength field)
:field/optional (:optional field)
:field/options (:options field)})

(defn- field-preview [field]
[fields/field (form-field-to-application-field field)])

(defn- form-preview [form]
(into [:div]
(for [field (:items form)]
[field-preview field])))

(defn create-form-page []
(let [form @(rf/subscribe [::form])]
[:div
Expand All @@ -290,4 +308,8 @@

[:div.col.commands
[cancel-button]
[save-form-button #(rf/dispatch [::create-form %])]]]}]]))
[save-form-button #(rf/dispatch [::create-form %])]]]}]
[collapsible/component
{:id "create-form"
:title (text :t.administration/preview)
:always [form-preview form]}]]))

0 comments on commit abbcb21

Please sign in to comment.