2021-11-14 14:19:13 +01:00
|
|
|
#include "building_controller.h"
|
|
|
|
|
|
|
|
#include "core/html/form_validator.h"
|
|
|
|
#include "core/html/html_builder.h"
|
|
|
|
#include "core/http/cookie.h"
|
|
|
|
#include "core/http/http_session.h"
|
|
|
|
#include "core/http/request.h"
|
|
|
|
#include "core/http/session_manager.h"
|
|
|
|
|
|
|
|
#include "building_model.h"
|
|
|
|
|
|
|
|
void BuildingController::handle_request_default(Request *request) {
|
|
|
|
}
|
|
|
|
|
2021-11-14 21:37:04 +01:00
|
|
|
void BuildingController::admin_handle_request_main(Request *request) {
|
|
|
|
String seg = request->get_current_path_segment();
|
|
|
|
|
|
|
|
if (seg == "") {
|
|
|
|
admin_render_building_list(request);
|
|
|
|
return;
|
2021-11-16 17:00:58 +01:00
|
|
|
} else if (seg == "new") {
|
|
|
|
admin_render_building(request, Ref<Building>());
|
|
|
|
return;
|
2021-11-14 21:37:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
request->send_error(404);
|
|
|
|
}
|
|
|
|
String BuildingController::admin_get_section_name() {
|
2021-11-14 22:12:32 +01:00
|
|
|
return "Buildings";
|
2021-11-14 21:37:04 +01:00
|
|
|
}
|
|
|
|
void BuildingController::admin_add_section_links(Vector<AdminSectionLinkInfo> *links) {
|
2021-11-14 22:12:32 +01:00
|
|
|
links->push_back(AdminSectionLinkInfo("- Building Editor", ""));
|
2021-11-14 21:37:04 +01:00
|
|
|
}
|
|
|
|
bool BuildingController::admin_full_render() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuildingController::admin_render_building_list(Request *request) {
|
|
|
|
Vector<Ref<Building> > buildings = BuildingModel::get_singleton()->get_all();
|
|
|
|
|
|
|
|
HTMLBuilder b;
|
|
|
|
|
|
|
|
b.div()->cls("back")->f()->a()->href(request->get_url_root_parent())->f()->w("<--- Back")->ca()->cdiv();
|
|
|
|
b.br();
|
2021-11-14 22:12:32 +01:00
|
|
|
b.div()->cls("top_menu")->f()->w("Building Editor")->cdiv();
|
2021-11-14 21:37:04 +01:00
|
|
|
b.br();
|
|
|
|
b.div()->cls("top_menu")->f()->a()->href(request->get_url_root("new"))->f()->w("Create New")->ca()->cdiv();
|
|
|
|
b.br();
|
|
|
|
|
|
|
|
b.div()->cls("list_container");
|
|
|
|
|
|
|
|
for (int i = 0; i < buildings.size(); ++i) {
|
|
|
|
Ref<Building> building = buildings[i];
|
|
|
|
|
|
|
|
if (!building.is_valid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-14 21:45:25 +01:00
|
|
|
if (i % 2 == 0) {
|
|
|
|
b.div()->cls("row");
|
|
|
|
} else {
|
|
|
|
b.div()->cls("row second");
|
|
|
|
}
|
2021-11-14 21:37:04 +01:00
|
|
|
{
|
2021-11-14 21:45:25 +01:00
|
|
|
b.div()->cls("attr_box")->f()->w(String::num(building->id))->cdiv();
|
|
|
|
b.div()->cls("attr_box")->f()->w(String::num(building->rank))->cdiv();
|
|
|
|
b.div()->cls("attr_box")->f()->w(String::num(building->next_rank))->cdiv();
|
|
|
|
b.div()->cls("name")->f()->w(building->name)->cdiv();
|
|
|
|
b.div()->cls("actionbox")->f()->a()->href(request->get_url_root("edit/" + String::num(building->id)))->f()->w("Edit")->ca()->cdiv();
|
2021-11-14 21:37:04 +01:00
|
|
|
}
|
|
|
|
b.cdiv();
|
|
|
|
}
|
|
|
|
|
|
|
|
b.cdiv();
|
|
|
|
|
|
|
|
request->body += b.result;
|
|
|
|
}
|
|
|
|
|
2021-11-16 17:00:58 +01:00
|
|
|
void BuildingController::admin_render_building(Request *request, Ref<Building> building) {
|
|
|
|
Vector<Ref<Building> > buildings = BuildingModel::get_singleton()->get_all();
|
|
|
|
|
|
|
|
HTMLBuilder b;
|
|
|
|
|
|
|
|
b.div("back")->f()->fa(request->get_url_root_parent(), "<--- Back")->cdiv();
|
|
|
|
b.br();
|
|
|
|
b.fdiv("top_menu", "Building Editor");
|
|
|
|
b.br();
|
|
|
|
b.div("top_menu")->f()->fa(request->get_url_root("new"), "Create New")->cdiv();
|
|
|
|
b.br();
|
|
|
|
}
|
|
|
|
|
2021-11-14 14:19:13 +01:00
|
|
|
void BuildingController::migrate() {
|
|
|
|
BuildingModel::get_singleton()->migrate();
|
|
|
|
}
|
|
|
|
void BuildingController::add_default_data() {
|
|
|
|
BuildingModel::get_singleton()->add_default_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildingController *BuildingController::get_singleton() {
|
|
|
|
return _self;
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildingController::BuildingController() :
|
2021-11-14 21:37:04 +01:00
|
|
|
AdminController() {
|
2021-11-14 14:19:13 +01:00
|
|
|
|
|
|
|
if (_self) {
|
|
|
|
printf("BuildingController::BuildingController(): Error! self is not null!/n");
|
|
|
|
}
|
|
|
|
|
|
|
|
_self = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildingController::~BuildingController() {
|
|
|
|
if (_self == this) {
|
|
|
|
_self = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BuildingController *BuildingController::_self = nullptr;
|