Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit b68000c1 authored by Pierre Jarriges's avatar Pierre Jarriges
Browse files

admin panel create update

parent 2a2ea206
No related branches found
No related tags found
No related merge requests found
"use strict";
class Article {
constructor(data) {
if (data) {
this.from(data)
} else {
this.title = "";
this.subtitle = "";
this.category = "";
this.details = [];
this.images = [];
this.body = "";
this.locale = "";
}
}
from(data) {
Object.entries(data).forEach(k_v => {
const [key, value] = k_v;
this[key] = value;
});
}
}
module.exports = Article;
\ No newline at end of file
"use strict";
const Article = require("../article");
const { images_url } = require("../constants");
const { fetch_post_article, fetch_article, fetch_update_article } = require("../xhr");
......@@ -7,27 +8,13 @@ class CreateArticleForm {
constructor(params) {
this.params = params || {};
this.state = {
output: this.params.data || {
title: "",
subtitle: "",
category: "",
details: [],
images: [],
body: "",
},
output: new Article(this.params.data),
article_sent: {},
}
}
reset() {
this.state.output = {
title: "",
subtitle: "",
category: "",
details: [],
images: [],
body: "",
};
this.state.output = new Article();
this.state.article_sent = {};
this.refresh();
}
......@@ -274,6 +261,7 @@ class CreateArticleForm {
fetch_article(id)
.then(article => {
this.state.article_sent = article;
this.params.on_article_sent && this.params.on_article_sent();
this.refresh();
})
.catch(er => console.log(er));
......@@ -287,6 +275,22 @@ class CreateArticleForm {
value: this.state.output.category,
oninput: this.handle_text_input.bind(this, "category")
},
{
tag: "select", value: this.state.output.locale,
onchange: e => this.state.output.locale = e.target.value,
contents: [{
tag: "option",
value: "",
contents: "-- LOCALE --"
}].concat(["fr", "en", "es"].map(loc => {
return {
tag: "option",
value: loc,
contents: loc,
selected: this.state.output.locale === loc
}
}))
},
{
tag: "input", type: "text",
placeholder: "Article title",
......
......@@ -18,8 +18,6 @@ class UpdateArticleForm {
search_result: {},
article_to_update: {},
};
this.refresh();
}
handle_search_article() {
......@@ -43,6 +41,7 @@ class UpdateArticleForm {
.then(res => {
alert(res);
this.reset();
this.refresh();
})
.catch(err => alert(err))
}
......@@ -114,7 +113,13 @@ class UpdateArticleForm {
tag: "div",
id: "update-article-form-container",
contents: this.state.article_to_update._id
? [new CreateArticleForm({ data: this.state.article_to_update }).render()]
? [new CreateArticleForm({
data: this.state.article_to_update,
on_article_sent: () => {
this.reset();
this.refresh_search_result();
}
}).render()]
: []
}
}
......@@ -136,6 +141,7 @@ class UpdateArticleForm {
contents: [
this.render_search(),
this.render_search_result(),
{ tag: "hr", style_rules: { width: "100%" } },
this.render_update_form(),
]
}
......
......@@ -24,6 +24,7 @@ pub struct Article {
pub details: Vec<ArticleDetail>,
pub images: Vec<String>,
pub category: String,
pub locale: String,
}
impl Article {
......@@ -47,6 +48,7 @@ impl Article {
],
images: vec!["an_image.png".to_string()],
category: "testing".to_string(),
locale: "fr".to_string(),
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment