add old flash to realtion create

master
Ondřej Hruška 4 years ago
parent d43ddfa8bd
commit 780ad36696
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      yopa-web/resources/templates/property_create.html.tera
  2. 12
      yopa-web/resources/templates/relation_create.html.tera
  3. 18
      yopa-web/src/routes/relation_model.rs

@ -13,8 +13,6 @@ Define property
{# The parent can be either object or relation model #} {# The parent can be either object or relation model #}
<h1>Add new property to {{object.describe}}</h1> <h1>Add new property to {{object.describe}}</h1>
{# TODO implement value restoration on error #}
<form action="/model/property/create" method="POST"> <form action="/model/property/create" method="POST">
<input type="hidden" name="object" value="{{object.id}}"> <input type="hidden" name="object" value="{{object.id}}">

@ -12,28 +12,26 @@ Define relation
<h1>Define new relation from "{{object.name}}"</h1> <h1>Define new relation from "{{object.name}}"</h1>
{# TODO implement value restoration on error #}
<form action="/model/relation/create" method="POST"> <form action="/model/relation/create" method="POST">
<input type="hidden" name="object" value="{{object.id}}"> <input type="hidden" name="object" value="{{object.id}}">
<label for="name">Name:</label> <label for="name">Name:</label>
<input type="text" id="name" name="name" autocomplete="off"><br> <input type="text" id="name" name="name" value="{{old.name}}" autocomplete="off"><br>
<label for="reciprocal_name">Reciprocal name:</label> <label for="reciprocal_name">Reciprocal name:</label>
<input type="text" id="reciprocal_name" name="reciprocal_name" autocomplete="off"><br> <input type="text" id="reciprocal_name" name="reciprocal_name" value="{{old.reciprocal_name}}" autocomplete="off"><br>
<label for="optional">Optional:</label> <label for="optional">Optional:</label>
<input type="checkbox" name="optional" id="optional" value="true" autocomplete="off"> <input type="checkbox" name="optional" id="optional" value="true" {{opt(checked=old.optional)}} autocomplete="off">
<br> <br>
<label for="multiple">Multiple:</label> <label for="multiple">Multiple:</label>
<input type="checkbox" name="multiple" id="multiple" value="true" autocomplete="off"><br> <input type="checkbox" name="multiple" id="multiple" value="true" {{opt(checked=old.multiple)}} autocomplete="off"><br>
<label for="related">Related object:</label> <label for="related">Related object:</label>
<select name="related" id="related" autocomplete="off"> <select name="related" id="related" autocomplete="off">
{% for m in models %} {% for m in models %}
<option value="{{ m.id }}">{{ m.name }}</option> <option value="{{ m.id }}" {{selected(val=old.related, opt=m.id)}}>{{ m.name }}</option>
{% endfor %} {% endfor %}
</select><br> </select><br>

@ -30,6 +30,19 @@ pub(crate) async fn create_form(
debug!("ID = {}", object_id); debug!("ID = {}", object_id);
if let Ok(Some(form)) = session.take::<RelationModelCreateForm>("old") {
context.insert("old", &form);
} else {
context.insert("old", &RelationModelCreateForm {
object: Default::default(),
name: "".to_string(),
reciprocal_name: "".to_string(),
optional: false,
multiple: false,
related: Default::default()
});
}
let object = rg.get_object_model(object_id.parse_or_bad_request()?) let object = rg.get_object_model(object_id.parse_or_bad_request()?)
.ok_or_else(|| actix_web::error::ErrorNotFound("No such source object"))?; .ok_or_else(|| actix_web::error::ErrorNotFound("No such source object"))?;
@ -40,10 +53,12 @@ pub(crate) async fn create_form(
context.insert("models", &models); context.insert("models", &models);
context.insert("object", &object); context.insert("object", &object);
TERA.build_response("relation_create", &context) TERA.build_response("relation_create", &context)
} }
#[derive(Deserialize)] #[derive(Serialize,Deserialize)]
pub(crate) struct RelationModelCreateForm { pub(crate) struct RelationModelCreateForm {
pub object: ID, pub object: ID,
pub name: String, pub name: String,
@ -80,6 +95,7 @@ pub(crate) async fn create(
Err(e) => { Err(e) => {
warn!("Error creating relation model: {}", e); warn!("Error creating relation model: {}", e);
session.flash_error(e.to_string()); session.flash_error(e.to_string());
session.set("old", &form);
redirect(format!("/model/relation/create/{}", form.object)) redirect(format!("/model/relation/create/{}", form.object))
} }
} }

Loading…
Cancel
Save