summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/helpers.cpp14
-rw-r--r--src/ui/ui_contacts.cpp31
-rw-r--r--src/ui/ui_invoices.cpp81
-rw-r--r--src/ui/ui_projects.cpp2
4 files changed, 94 insertions, 34 deletions
diff --git a/src/ui/helpers.cpp b/src/ui/helpers.cpp
index a239f4c..4c6647e 100644
--- a/src/ui/helpers.cpp
+++ b/src/ui/helpers.cpp
@@ -65,20 +65,24 @@ void ui_helper_draw_required_tag()
ImGui::PopStyleColor();
}
-void ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, char* buffer, size_t buf_size,
+int ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, char* buffer, size_t buf_size,
char* suggestions[], int suggestion_count)
{
+ int result = -1;
static bool is_open = false;
ImGui::InputTextWithHint(label, hint, buffer, buf_size);
+ if (buffer[0] == '\0' && is_open) is_open = false;
+ if (suggestion_count == 0 && is_open) is_open = false;
+
bool is_active = ImGui::IsItemActive();
- if (is_active && buffer[0] != '\0')
+ if (is_active && buffer[0] != '\0' && suggestion_count > 0)
{
is_open = true;
}
if (is_open) {
- ImGui::BeginChild("autocomplete_popup", ImVec2(0, 100), true);
+ ImGui::BeginChild("autocomplete_popup", ImVec2(0, 10.0f + suggestion_count*23.0f), true);
{
ImVec2 win_pos = ImGui::GetWindowPos();
ImVec2 win_size = ImGui::GetWindowSize();
@@ -97,7 +101,7 @@ void ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, ch
// Copy selected suggestion to buffer
strops_copy(buffer, suggestions[i], buf_size);
buffer[buf_size - 1] = '\0';
-
+ result = i;
is_open = false;
}
}
@@ -105,4 +109,6 @@ void ui_helper_TextInputWithAutocomplete(const char* label, const char* hint, ch
ImGui::EndChild();
}
}
+ return result;
}
+
diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp
index c381db5..d57776e 100644
--- a/src/ui/ui_contacts.cpp
+++ b/src/ui/ui_contacts.cpp
@@ -18,9 +18,8 @@ void ui_setup_contacts()
memset(&selected_for_removal, 0, sizeof(contact));
}
-void draw_contact_form(contact* buffer, bool viewing_only = false)
+void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false, bool* on_autocomplete = 0)
{
- bool with_autocomplete = false;
const char* selected_country = NULL;
ImGui::Spacing();
@@ -37,12 +36,26 @@ void draw_contact_form(contact* buffer, bool viewing_only = false)
// 2. Full name
ImGui::SetNextItemWidth(widthAvailable*0.5f);
if (with_autocomplete) {
- contact autocomplete_list[5];
- int autocomplete_count = 5;
- char* autocomplete_strings[5] = { "1", "2", "3", "4", "5" };
+ contact autocomplete_list[5];
+ int autocomplete_count = administration_get_contact_recommendations(autocomplete_list, 5, buffer->name);
+ char* autocomplete_strings[5];
+
+ for (int i = 0; i < autocomplete_count; i++)
+ {
+ autocomplete_strings[i] = autocomplete_list[i].name;
+ }
- ui_helper_TextInputWithAutocomplete(localize("contact.form.fullname"), localize("contact.form.fullname"),
+ int autocomplete_index = ui_helper_TextInputWithAutocomplete(localize("contact.form.fullname"), localize("contact.form.fullname"),
buffer->name, IM_ARRAYSIZE(buffer->name), (char**)autocomplete_strings, autocomplete_count);
+
+ if (on_autocomplete) {
+ *on_autocomplete = autocomplete_index != -1;
+ }
+
+ if (autocomplete_index != -1)
+ {
+ memcpy(buffer, &autocomplete_list[autocomplete_index], sizeof(contact));
+ }
}
else ImGui::InputTextWithHint(localize("contact.form.fullname"), localize("contact.form.fullname"), buffer->name, IM_ARRAYSIZE(buffer->name));
ImGui::SameLine();ui_helper_draw_required_tag();
@@ -131,6 +144,12 @@ void draw_contact_form(contact* buffer, bool viewing_only = false)
if (viewing_only) ImGui::EndDisabled();
}
+void draw_contact_form(contact* buffer, bool viewing_only = false)
+{
+ draw_contact_form_ex(buffer, viewing_only, false, 0);
+}
+
+
static void draw_contact_list()
{
const u32 items_per_page = 50;
diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp
index fe4f5a8..8ee099c 100644
--- a/src/ui/ui_invoices.cpp
+++ b/src/ui/ui_invoices.cpp
@@ -1,4 +1,7 @@
#include <stdio.h>
+#include <time.h>
+
+#include "ImGuiDatePicker/ImGuiDatePicker.hpp"
#include "strops.hpp"
#include "ui.hpp"
@@ -9,7 +12,7 @@
static view_state current_view_state = view_state::LIST;
static invoice active_invoice;
-extern void draw_contact_form(contact* buffer, bool viewing_only = false);
+void draw_contact_form_ex(contact* buffer, bool viewing_only = false, bool with_autocomplete = false, bool* on_autocomplete = 0);
void ui_setup_invoices()
{
@@ -17,23 +20,16 @@ void ui_setup_invoices()
active_invoice = administration_create_empty_invoice();
}
-bool draw_invoice_form(invoice* buffer, bool back_button_enabled = true, bool viewing_only = false)
+void draw_invoice_form(invoice* buffer, bool viewing_only = false)
{
- if (back_button_enabled)
- {
- if (ImGui::Button(localize("form.back"))) {
- current_view_state = view_state::LIST;
- return false;
- }
- }
- ImGui::Spacing();
- float widthAvailable = ImGui::GetContentRegionAvail().x;
+ //float widthAvailable = ImGui::GetContentRegionAvail().x;
+ ImGui::BeginDisabled();
// 1. Identifier
- //ImGui::BeginDisabled();
//ImGui::SetNextItemWidth(widthAvailable*0.2f);
//ImGui::InputText(localize("contact.form.identifier"), buffer->id, IM_ARRAYSIZE(buffer->id));
-
+ if (!viewing_only) ImGui::EndDisabled();
+
// 2. Sequential number
ImGui::Text("Invoice number: %s", buffer->sequential_number);
@@ -42,20 +38,54 @@ bool draw_invoice_form(invoice* buffer, bool back_button_enabled = true, bool vi
ImGui::Separator();
+ // 4. Customer information
ImGui::Text("Customer information");
- draw_contact_form(&buffer->customer);
- strops_copy(buffer->customer_id, buffer->customer.id, sizeof(buffer->customer_id));
+ bool on_autocomplete;
+ draw_contact_form_ex(&buffer->customer, false, true, &on_autocomplete);
+
+ if (on_autocomplete) {
+ strops_copy(buffer->customer_id, buffer->customer.id, sizeof(buffer->customer_id));
+ }
ImGui::Separator();
+ // 5. Invoice issued at
+ ImGui::BeginDisabled();
+ tm issued_at_date = *gmtime(&buffer->issued_at);
+ if (ImGui::DatePicker("##issuedAt", issued_at_date))
+ {
+ buffer->issued_at = mktime(&issued_at_date);
+ }
+ ImGui::SameLine();
+ ImGui::Text("Invoice issued at");
+ ImGui::EndDisabled();
+
+ // 6. Invoice expires at
+ ImGui::BeginDisabled();
+ tm expires_at_date = *gmtime(&buffer->expires_at);
+ if (ImGui::DatePicker("##expiresAt", expires_at_date))
+ {
+ buffer->expires_at = mktime(&expires_at_date);
+ }
+ ImGui::SameLine();
+ ImGui::Text("Invoice expires at");
+ ImGui::EndDisabled();
+
+ // 7. Product/service delivered at
+ tm delivered_at_date = *gmtime(&buffer->delivered_at);
+ if (ImGui::DatePicker("##deliveredAt", delivered_at_date))
+ {
+ buffer->delivered_at = mktime(&delivered_at_date);
+ }
+ ImGui::SameLine();
+ ImGui::Text("Product/service delivered at");
+
//ImGui::SetNextItemWidth(widthAvailable*0.5f);
//ImGui::InputTextWithHint("Invoice number", "Invoice number", buffer->sequential_number, IM_ARRAYSIZE(buffer->sequential_number));
//ImGui::SameLine();ui_helper_draw_required_tag();
- //if (!viewing_only) ImGui::EndDisabled();
-
- return false;
+ if (viewing_only) ImGui::EndDisabled();
}
void draw_invoices_list()
@@ -75,12 +105,17 @@ void ui_draw_invoices()
switch(current_view_state)
{
case view_state::LIST: draw_invoices_list(); break;
- case view_state::CREATE:
- if (draw_invoice_form(&active_invoice))
- {
- //administration_create_invoice(active_invoice);
+ case view_state::CREATE:
+
+ if (ImGui::Button(localize("form.back"))) {
current_view_state = view_state::LIST;
- }
+ }
+ draw_invoice_form(&active_invoice);
+
+ //if () {
+ //administration_create_invoice(active_invoice);
+ //current_view_state = view_state::LIST;
+ //}
break;
case view_state::EDIT: break;
case view_state::VIEW: break;
diff --git a/src/ui/ui_projects.cpp b/src/ui/ui_projects.cpp
index 5cb412f..3c550a2 100644
--- a/src/ui/ui_projects.cpp
+++ b/src/ui/ui_projects.cpp
@@ -45,7 +45,7 @@ static void draw_project_form()
if (viewing_only) ImGui::EndDisabled();
if (!viewing_only) {
- bool can_save = strlen(active_project.description) > 0;
+ bool can_save = administration_is_project_valid(active_project);
if (!can_save) ImGui::BeginDisabled();
// Save button