summaryrefslogtreecommitdiff
path: root/src/ui/ui_contacts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/ui_contacts.cpp')
-rw-r--r--src/ui/ui_contacts.cpp92
1 files changed, 52 insertions, 40 deletions
diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp
index 3115a77..fd9907f 100644
--- a/src/ui/ui_contacts.cpp
+++ b/src/ui/ui_contacts.cpp
@@ -6,44 +6,51 @@
#include "administration.hpp"
#include "locales.hpp"
-static view_state current_view_state = LIST;
+static view_state current_view_state = view_state::LIST;
static contact selected_for_removal;
static contact active_contact;
-static void draw_contact_form()
+void ui_setup_contacts()
{
- static const char* selected_country = NULL;
+ current_view_state = view_state::LIST;
+ memset(&active_contact, 0, sizeof(contact));
+ memset(&selected_for_removal, 0, sizeof(contact));
+}
- if (ImGui::Button(localize("form.back"))) {
- current_view_state = view_state::LIST;
- memset(&active_contact, 0, sizeof(contact));
- selected_country = 0;
- return;
+bool draw_contact_form(contact* buffer, bool back_button_enabled = true, bool viewing_only = false)
+{
+ const char* selected_country = NULL;
+
+ if (back_button_enabled)
+ {
+ if (ImGui::Button(localize("form.back"))) {
+ current_view_state = view_state::LIST;
+ selected_country = 0;
+ return false;
+ }
}
ImGui::Spacing();
- bool viewing_only = (current_view_state == view_state::VIEW);
-
ImGui::BeginDisabled();
float widthAvailable = ImGui::GetContentRegionAvail().x;
ImGui::SetNextItemWidth(widthAvailable*0.2f);
- ImGui::InputText(localize("contact.form.identifier"), active_contact.id, IM_ARRAYSIZE(active_contact.id));
+ ImGui::InputText(localize("contact.form.identifier"), buffer->id, IM_ARRAYSIZE(buffer->id));
if (!viewing_only) ImGui::EndDisabled();
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.fullname"), localize("contact.form.fullname"), active_contact.name, IM_ARRAYSIZE(active_contact.name));
- ImGui::SameLine();view_draw_required_tag();
+ ImGui::InputTextWithHint(localize("contact.form.fullname"), localize("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name));
+ ImGui::SameLine();ui_helper_draw_required_tag();
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.address1"), localize("contact.form.address1"), active_contact.address1, IM_ARRAYSIZE(active_contact.address1));
- ImGui::SameLine();view_draw_required_tag();
+ ImGui::InputTextWithHint(localize("contact.form.address1"), localize("contact.form.address1"), buffer->address.address1, IM_ARRAYSIZE(buffer->address.address1));
+ ImGui::SameLine();ui_helper_draw_required_tag();
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.address2"), localize("contact.form.address2"), active_contact.address2, IM_ARRAYSIZE(active_contact.address2));
- ImGui::SameLine();view_draw_required_tag();
+ ImGui::InputTextWithHint(localize("contact.form.address2"), localize("contact.form.address2"), buffer->address.address2, IM_ARRAYSIZE(buffer->address.address2));
+ ImGui::SameLine();ui_helper_draw_required_tag();
ImGui::SetNextItemWidth(widthAvailable*0.5f);
@@ -52,7 +59,7 @@ static void draw_contact_form()
if (selected_country == 0) {
for (int i = 0; i < country_count; i++)
{
- if (strcmp(countries[i], active_contact.country) == 0)
+ if (strcmp(countries[i], buffer->address.country) == 0)
{
selected_country = countries[i];
break;
@@ -71,50 +78,43 @@ static void draw_contact_form()
ImGui::EndCombo();
}
if (selected_country) {
- strops_copy(active_contact.country, selected_country, IM_ARRAYSIZE(active_contact.country));
+ strops_copy(buffer->address.country, selected_country, IM_ARRAYSIZE(buffer->address.country));
}
- ImGui::SameLine();view_draw_required_tag();
+ ImGui::SameLine();ui_helper_draw_required_tag();
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.taxnumber"), localize("contact.form.taxnumber"), active_contact.taxid, IM_ARRAYSIZE(active_contact.taxid));
+ ImGui::InputTextWithHint(localize("contact.form.taxnumber"), localize("contact.form.taxnumber"), buffer->taxid, IM_ARRAYSIZE(buffer->taxid));
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.businessnumber"), localize("contact.form.businessnumber"), active_contact.businessid, IM_ARRAYSIZE(active_contact.businessid));
+ ImGui::InputTextWithHint(localize("contact.form.businessnumber"), localize("contact.form.businessnumber"), buffer->businessid, IM_ARRAYSIZE(buffer->businessid));
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.email"), localize("contact.form.email"), active_contact.email, IM_ARRAYSIZE(active_contact.email));
+ ImGui::InputTextWithHint(localize("contact.form.email"), localize("contact.form.email"), buffer->email, IM_ARRAYSIZE(buffer->email));
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.phonenumber"), localize("contact.form.phonenumber"), active_contact.phone_number, IM_ARRAYSIZE(active_contact.phone_number));
+ ImGui::InputTextWithHint(localize("contact.form.phonenumber"), localize("contact.form.phonenumber"), buffer->phone_number, IM_ARRAYSIZE(buffer->phone_number));
ImGui::SetNextItemWidth(widthAvailable*0.5f);
- ImGui::InputTextWithHint(localize("contact.form.bankaccount"), localize("contact.form.bankaccount"), active_contact.bank_account, IM_ARRAYSIZE(active_contact.bank_account));
+ ImGui::InputTextWithHint(localize("contact.form.bankaccount"), localize("contact.form.bankaccount"), buffer->bank_account, IM_ARRAYSIZE(buffer->bank_account));
if (viewing_only) ImGui::EndDisabled();
if (!viewing_only) {
- bool can_save = strlen(active_contact.name) > 0 && strlen(active_contact.address1) > 0 &&
- strlen(active_contact.address2) > 0 && strlen(active_contact.country) > 0;
+ bool can_save = strlen(buffer->name) > 0 && strlen(buffer->address.address1) > 0 &&
+ strlen(buffer->address.address2) > 0 && strlen(buffer->address.country) > 0;
if (!can_save) ImGui::BeginDisabled();
// Save button
ImGui::Spacing();
if (ImGui::Button(localize("form.save"))) {
- if (current_view_state == view_state::CREATE)
- administration_create_contact(active_contact);
-
- else if (current_view_state == view_state::EDIT)
- administration_update_contact(active_contact);
-
- memset(&active_contact, 0, sizeof(contact));
- current_view_state = view_state::LIST;
- selected_country = 0;
+ return true;
}
if (!can_save) ImGui::EndDisabled();
}
else {
// TODO list invoices connected to contact.
}
+ return false;
}
static void draw_contact_list()
@@ -168,7 +168,7 @@ static void draw_contact_list()
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::Text(c.id);
ImGui::TableSetColumnIndex(1); ImGui::Text(c.name);
- ImGui::TableSetColumnIndex(2); ImGui::Text("%s %s", c.address1, c.address2);
+ ImGui::TableSetColumnIndex(2); ImGui::Text("%s %s", c.address.address1, c.address.address2);
ImGui::TableSetColumnIndex(3);
@@ -221,8 +221,20 @@ void ui_draw_contacts()
switch(current_view_state)
{
case view_state::LIST: draw_contact_list(); break;
- case view_state::CREATE: draw_contact_form(); break;
- case view_state::EDIT: draw_contact_form(); break;
- case view_state::VIEW: draw_contact_form(); break;
+ case view_state::CREATE:
+ if (draw_contact_form(&active_contact))
+ {
+ administration_create_contact(active_contact);
+ current_view_state = view_state::LIST;
+ }
+ break;
+ case view_state::EDIT:
+ if (draw_contact_form(&active_contact))
+ {
+ administration_update_contact(active_contact);
+ current_view_state = view_state::LIST;
+ }
+ break;
+ case view_state::VIEW: draw_contact_form(&active_contact, true, true); break;
}
} \ No newline at end of file