add correct backlink

This commit is contained in:
Manuel Gugger 2022-07-25 17:33:06 +02:00
parent 76809ddc46
commit 5194febe9b
5 changed files with 11 additions and 5 deletions

View File

@ -18,11 +18,12 @@ pub async fn create_get<T: ActixAdminAppDataTrait, E: ActixAdminViewModelTrait>(
let actix_admin = data.get_actix_admin();
let view_model = actix_admin.view_models.get(&entity_name).unwrap();
let mut ctx = Context::new();
ctx.insert("entity_names", &entity_names);
ctx.insert("view_model", &view_model);
ctx.insert("select_lists", &E::get_select_lists(_db).await);
ctx.insert("list_link", E::get_list_link());
let body = TERA
.render("create.html", &ctx)

View File

@ -27,6 +27,7 @@ pub async fn edit_get<T: ActixAdminAppDataTrait, E: ActixAdminViewModelTrait>(
ctx.insert("view_model", &view_model);
ctx.insert("model", &model);
ctx.insert("select_lists", &E::get_select_lists(db).await);
ctx.insert("list_link", E::get_list_link());
let body = TERA
.render("edit.html", &ctx)

View File

@ -20,6 +20,10 @@ pub trait ActixAdminViewModelTrait {
async fn get_select_lists(db: &DatabaseConnection) -> HashMap<String, Vec<(String, String)>>;
fn get_entity_name() -> String;
fn get_list_link() -> &'static str {
"list"
}
}
#[derive(Clone, Debug, Serialize)]

View File

@ -2,7 +2,7 @@
{% block content %}
<form method="post">
<div class="grid">
<div>
{% for model_field in view_model.fields -%}
{% if model_field.select_list != "" %}
<select name="{{ model_field.field_name }}">
@ -16,7 +16,7 @@
{% endif %}
{%- endfor %}
<button type="submit">Save</button>
<button onclick="history.back()">Cancel</button>
<a href="{{ list_link }}" role="button">Cancel</a>
</div>
</form>
{% endblock content %}

View File

@ -2,7 +2,7 @@
{% block content %}
<form method="post">
<div class="grid">
<div>
{% for model_field in view_model.fields -%}
{% if model_field.select_list != "" %}
<select name="{{ model_field.field_name }}">
@ -16,7 +16,7 @@
{% endif %}
{%- endfor %}
<button type="submit">Save</button>
<button onclick="history.back()">Cancel</button>
<a href="{{ list_link }}" role="button">Cancel</a>
</div>
</form>
{% endblock content %}