24#ifndef arriere_boutique_HPP
25#define arriere_boutique_HPP
36#include <dar/tools.hpp>
41#include "body_builder.hpp"
45#include "html_text.hpp"
46#include "html_form.hpp"
47#include "html_form_fieldset.hpp"
48#include "html_form_input.hpp"
49#include "html_form_radio.hpp"
50#include "html_double_button.hpp"
52#include "bibliotheque_subconfig.hpp"
53#include "webdar_css_style.hpp"
54#include "html_div.hpp"
56#include "html_yes_no_box.hpp"
57#include "tooltip_messages.hpp"
92 static const std::string changed;
96 std::unique_ptr<T> & obj,
97 const std::string ch_event_name,
107 virtual void on_event(
const std::string & event_name)
override;
125 static constexpr const char* event_delete =
"delete_conf";
126 static constexpr const char* event_clear =
"clear_cur_conf";
127 static constexpr const char* css_float =
"arriere_boutique_float";
128 static constexpr const char* css_warn =
"arriere_boutique_warn";
129 static constexpr const char* css_margin_above =
"arriere_boutique_margin";
131 std::string currently_loaded;
132 std::shared_ptr<bibliotheque> biblio;
134 std::string change_event_name;
137 std::unique_ptr<T> wrapped;
160 void set_warning(
const std::string & wm);
161 void clear_warning() { warning_message.
set_visible(
false); };
162 void silently_update_config_name(
const std::string & val);
169 std::unique_ptr<T> & obj,
170 const std::string ch_event_name,
171 bool add_form_around):
172 currently_loaded(
""),
174 config_form(
"Save/Save as"),
177 listing_form(
"Load selected"),
178 listing_fs(
"Available configurations"),
179 delete_selected(
"Delete loaded config", event_delete),
180 clear_cur_config(
"Clear", event_clear),
181 change_event_name(ch_event_name),
183 around_form(
"Update"),
191 wrapped = std::move(obj);
192 if(wrapped.get() ==
nullptr)
195 wrapped_jsoner =
dynamic_cast<jsoner*
>(wrapped.get());
196 if(wrapped_jsoner ==
nullptr)
199 wrapped_body_builder =
dynamic_cast<body_builder*
>(wrapped.get());
200 if(wrapped_body_builder ==
nullptr)
203 wrapped_events =
dynamic_cast<events*
>(wrapped.get());
204 if(wrapped_events ==
nullptr)
211 if(change_event_name == html_form_input::changed)
213 if(change_event_name == event_delete)
215 if(change_event_name == html_form_radio::changed)
219 if(change_event_name == html_form::changed)
227 need_saving.
add_text(0,
"configuration not saved");
231 listing_fs.
adopt(&listing);
232 listing_form.
adopt(&listing_fs);
233 floteur.
adopt(&listing_form);
235 floteur.
adopt(&delete_selected);
236 floteur.
adopt(&clear_cur_config);
239 adopt(&warning_message);
241 around_fs.
adopt(wrapped_body_builder);
244 around_form.
adopt(&around_fs);
250 config_fs.
adopt(&config_name);
251 config_fs.
adopt(&need_saving);
252 config_form.
adopt(&config_fs);
270 delete_selected.
add_css_class(webdar_css_style::spacing_vertical);
272 clear_cur_config.
add_css_class(webdar_css_style::spacing_vertical);
292 if(event_name == change_event_name)
300 else if(event_name == html_form::changed)
306 if(config_name.get_value().empty())
307 set_warning(
"Cannot save a configuration without a name");
316 json config = wrapped_jsoner->
save_json();
320 if(config_name.get_value() != currently_loaded)
322 currently_loaded = config_name.get_value();
324 if(wrapped_subconfig ==
nullptr)
325 biblio->add_config(categ,
326 config_name.get_value(),
329 biblio->add_config(categ,
330 config_name.get_value(),
336 if(wrapped_subconfig ==
nullptr)
337 biblio->update_config(categ,
341 biblio->update_config(categ,
352 set_warning(libdar::tools_printf(
"Failed saving configuration as %s: %s",
353 config_name.get_value().c_str(),
354 e.get_message().c_str()));
358 else if(event_name == event_delete)
363 confirm.
ask_question(
"Are you sure to delete the loaded configuration?",
false);
365 else if(event_name == html_yes_no_box::answer_yes)
373 silently_update_config_name(currently_loaded);
374 biblio->delete_config(categ, todelete);
376 currently_loaded =
"";
381 set_warning(
"Select and load first the configuration to be deleted");
383 else if(event_name == event_clear)
385 currently_loaded =
"";
386 config_name.set_value(
"");
392 else if(event_name == html_form_radio::changed)
396 ignore_events =
true;
402 silently_update_config_name(currently_loaded);
403 wrapped_jsoner->
load_json(biblio->fetch_config(categ, currently_loaded));
408 set_warning(
"Select first the configuration to load");
412 ignore_events =
false;
415 ignore_events =
false;
420 ignore_events =
true;
426 if(!currently_loaded.empty())
428 if(biblio->has_config(categ, currently_loaded))
432 currently_loaded =
"";
433 silently_update_config_name(currently_loaded);
439 ignore_events =
false;
442 ignore_events =
false;
451 return get_body_part_from_all_children(path, req);
456 std::deque<std::string> content = biblio->listing(categ);
460 for(std::deque<std::string>::iterator it = content.begin(); it != content.end(); ++it)
461 listing.add_choice(*it, *it);
469 std::unique_ptr<css_library> & csslib = lookup_css_library();
474 if(!csslib->class_exists(css_float))
477 tmp.css_border_width(css::bd_all, css::bd_medium);
478 tmp.css_float(css::fl_right);
479 tmp.css_margin_left(
"1em");
480 csslib->add(css_float, tmp);
483 if(!csslib->class_exists(css_warn))
487 tmp.css_font_weight_bold();
488 tmp.css_text_shadow(
"0.1em",
"0.1em",
"0.1em",
"#888888");
489 csslib->add(css_warn, tmp);
492 if(!csslib->class_exists(css_margin_above))
496 tmp.css_margin_top(
"2em");
498 csslib->add(css_margin_above, tmp);
507 warning_message.
clear();
514 bool original_status = ignore_events;
516 ignore_events =
true;
519 config_name.set_value(val);
526 ignore_events = original_status;
529 ignore_events = original_status;
defines bibliotheque class
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class arriere_boutique provides mean to add/load a given component type to/from a bibliotheque object
Definition: arriere_boutique.hpp:90
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from class body_builder
Definition: arriere_boutique.hpp:448
virtual void on_event(const std::string &event_name) override
inherited from class actor
Definition: arriere_boutique.hpp:284
const jsoner * get_wrapped() const
get access to the wrapped object
Definition: arriere_boutique.hpp:110
virtual void new_css_library_available() override
inherited from class body_builder
Definition: arriere_boutique.hpp:466
arriere_boutique(const std::shared_ptr< bibliotheque > &ptr, bibliotheque::category cat, std::unique_ptr< T > &obj, const std::string ch_event_name, bool add_form_around)
Definition: arriere_boutique.hpp:167
class bibliotheque_subconfig is an interface (pure virtual class)
Definition: bibliotheque_subconfig.hpp:50
virtual bibliotheque::using_set get_using_set() const =0
provide a standard mean for an object to tell its configuration relies on other configuration(s)
static std::string changed(category cat)
change event per category
Definition: bibliotheque.cpp:45
category
change event is replaced by a static method with category in argument
Definition: bibliotheque.hpp:63
class body_builder is the root class of object generating HTML body
Definition: body_builder.hpp:99
void adopt(body_builder *obj)
Definition: body_builder.cpp:117
void set_visible(bool mode)
ask for the object to become visible in HTML page or temporarily hidden
Definition: body_builder.cpp:211
void add_css_class(const std::string &name)
set this object with a additional css_class (assuming it is defined in a css_library available for th...
Definition: body_builder.cpp:247
class chemin definition
Definition: chemin.hpp:51
class managing Cascading Style Sheets attributes
Definition: css.hpp:48
void clear()
set css attributes to their default
Definition: css.cpp:116
class events
Definition: events.hpp:52
void record_actor_on_event(actor *ptr, const std::string &name)
record an actor for an given event
Definition: events.cpp:62
void register_name(const std::string &name)
add a new event for actors to register against
Definition: events.cpp:107
exception used to report out or range value or argument
Definition: exceptions.hpp:109
class html_div is the implementation of
Definition: html_div.hpp:46
class html_text manage text and header in html document
Definition: html_text.hpp:52
void clear()
clear the whole component value (gets as if it was just created)
Definition: html_text.hpp:79
void add_text(unsigned int level, const std::string &text)
Definition: html_text.cpp:44
html component for user to answer by yes or no to a provided question
Definition: html_yes_no_box.hpp:51
void ask_question(const std::string &message, bool default_value)
make the question to appear to the user
Definition: html_yes_no_box.cpp:74
class jsoner
Definition: jsoner.hpp:73
virtual void load_json(const json &source)=0
setup the components from the json provided information
virtual json save_json() const =0
produce a json structure from the component configuration
virtual void clear_json()=0
instruct the object to get to its default/initial configuration
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines jsoner class and class exception_json
the webdar_css_style namespace defines a set of global css objets and some routines to use them
Definition: webdar_css_style.cpp:45
void normal_button(T &obj, bool fullwidth=false)
apply to the given button the css_classe names defined by update_library to get a normal button style
Definition: webdar_css_style.hpp:94
void update_library(css_library &csslib)
update a css_library with all css definitions of this webdar_css_style module
Definition: webdar_css_style.cpp:452