Webdar 1.0.0
Web user interface to libdar
/home/denis/Webdar/webdar/src/html_form_input_file.hpp

define an events object to register for the html_form_input_file::repo_updated event

define an events object to register for the html_form_input_file::repo_updated event

Note
instead of calling set_entrepot() above whenever an entrepot is changed or updated a better approach is to update the entrepot by this method only when this html_form_input_file component needs it.
  • The need is expressed by the event html_form_input_file::repo_update_needed generated by 'this'
  • the actor has then to setup the necessary things to in-fine call set_entrepot() with the updated entrepot
  • then the updater (which would probably be the same as the actor just above), will generate the html_form_input_file::repo_updated event, on which this object is waiting (thanks to this set_entrepo_updater() method. When this event is received, the 'this' component continue its process using the, now updated, entrepot.
if updater is set to nullptr (or set_entrepot_updater() is never invoked), no html_form_input_file::repo_update_needed event is generated by 'this'.
/*********************************************************************/
// webdar - a web server and interface program to libdar
// Copyright (C) 2013-2025 Denis Corbin
//
// This file is part of Webdar
//
// Webdar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Webdar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Webdar. If not, see <http://www.gnu.org/licenses/>
//
//----
// to contact the author: dar.linux@free.fr
/*********************************************************************/
#ifndef HTML_FORM_INPUT_FILE_HPP
#define HTML_FORM_INPUT_FILE_HPP
// C system header files
#include "my_config.h"
extern "C"
{
}
// C++ system header files
#include <memory>
// webdar headers
#include "html_div.hpp"
#include "events.hpp"
#include "jsoner.hpp"
#include "html_form_input.hpp"
#include "html_double_button.hpp"
#include "html_text.hpp"
public events,
public actor,
public jsoner
{
public:
static const std::string changed_event;
static const std::string changed_entrepot;
static const std::string repo_update_needed;
static const std::string repo_updated;
html_form_input_file(const std::string & label,
const std::string & initial_value,
const std::string & size,
const std::string & css_class,
const std::string & popup_message);
html_form_input_file(html_form_input_file && ref) noexcept = delete;
html_form_input_file & operator = (const html_form_input_file & ref) = delete;
html_form_input_file & operator = (html_form_input_file && ref) noexcept = delete;
~html_form_input_file() = default;
// relayed from html_form_input
void change_label(const std::string & label) { input.change_label(label); };
const std::string & get_value() const { return input.get_value(); };
void set_value(const std::string & val) { input.set_value(val); };
void set_change_event_name(const std::string & name);
// relayed from html_select_file
enum select_mode { select_dir, select_file, select_slice, select_symlink };
void set_select_mode(select_mode val);
void set_can_create_dir(bool val) { user_select.set_can_create_dir(val); };
void set_entrepot(std::shared_ptr<libdar::entrepot> entrepot);
void set_entrepot_updater(events* updater);
std::string get_min_digits() const;
// inherited from events
virtual void on_event(const std::string & event_name) override;
virtual void load_json(const json & source) override { input.load_json(source); };
virtual json save_json() const override { return input.save_json(); };
virtual void clear_json() override { input.clear_json(); };
void set_tooltip(const std::string & val) { input.set_tooltip(val); };
protected:
// inherited from body_builder
virtual void new_css_library_available() override;
virtual std::string inherited_get_body_part(const chemin & path,
const request & req) override;
private:
std::string changed_event_name;
std::shared_ptr<libdar::entrepot> entrep;
bool refresh_get_body;
select_mode selmode;
std::string min_digits;
bool internal_change;
events* repo_updater;
// adoption tree:
//
// html_div (this)
// |
// +--- input_div
// | |
// | +- input
// +--- trigger
// +--- user_select
// +--- empty_text
//
html_div input_div;
html_select_file user_select;
html_text empty_text;
std::string slicename_to_basename_update_min_digits(const std::string & val);
static const std::string triggered_event;
static const std::string css_input;
static const std::string css_button_box;
};
#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class chemin definition
Definition: chemin.hpp:51
class css_class gather css attributed under a given label
Definition: css_class.hpp:51
class events
Definition: events.hpp:52
class html_div is the implementation of
Definition: html_div.hpp:46
html_button equivalent with changing path to trigger the button event
Definition: html_double_button.hpp:48
class html_form_input_file provides a mean to the user to navigate in a file system to select a file ...
Definition: html_form_input_file.hpp:60
std::string get_min_digits() const
in select_slice mode, obtain the min-digits from the provided filename
Definition: html_form_input_file.cpp:154
virtual void on_event(const std::string &event_name) override
implementation in inherited class of the action triggered by the event given in argument
Definition: html_form_input_file.cpp:162
void set_entrepot(std::shared_ptr< libdar::entrepot > entrepot)
change the entrepot to search into (if not called, local file system is used)
Definition: html_form_input_file.cpp:138
virtual void clear_json() override
inherited from jsoner
Definition: html_form_input_file.hpp:159
void set_change_event_name(const std::string &name)
change the name of the "changed" event
Definition: html_form_input_file.cpp:106
static const std::string changed_entrepot
triggered once the entrepot has been modified by mean of set_entrepot() method
Definition: html_form_input_file.hpp:64
static const std::string repo_updated
triggered by the events object passed to set_entrepot_updater() after calling set_entrepot() method o...
Definition: html_form_input_file.hpp:66
static const std::string repo_update_needed
triggered when user clicked on the '+' button to browse the entrepot if set_entrepot_updater() has be...
Definition: html_form_input_file.hpp:65
static const std::string changed_event
triggered (unless the event name is modified) when the field name is modified
Definition: html_form_input_file.hpp:63
virtual json save_json() const override
inherited from jsoner
Definition: html_form_input_file.hpp:156
virtual void load_json(const json &source) override
inherited from jsoner
Definition: html_form_input_file.hpp:153
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
inherited from body_builder
Definition: html_form_input_file.cpp:249
void set_entrepot_updater(events *updater)
Definition: html_form_input_file.cpp:146
void set_tooltip(const std::string &val)
tooltip for the component
Definition: html_form_input_file.hpp:162
virtual void new_css_library_available() override
inherited from body_builder
Definition: html_form_input_file.cpp:221
class html_form_input implements HTML input feature
Definition: html_form_input.hpp:57
virtual void clear_json() override
inherited from jsoner
Definition: html_form_input.cpp:217
void set_tooltip(const std::string &msg)
set tooltip for the html label of the input form
Definition: html_form_input.hpp:122
virtual json save_json() const override
inherited from jsoner
Definition: html_form_input.cpp:206
virtual void load_json(const json &source) override
inherited from jsoner
Definition: html_form_input.cpp:179
class html_select_file
Definition: html_select_file.hpp:110
void set_can_create_dir(bool val)
whether to show the button allowing the user to create a subdirectory
Definition: html_select_file.hpp:144
class html_text manage text and header in html document
Definition: html_text.hpp:52
class jsoner
Definition: jsoner.hpp:73
unsigned int size() const
the number of peers
Definition: reference.hpp:97
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines the event class
defines html_select_file class
defines jsoner class and class exception_json