virtual Evas_Object *onCreate(Evas_Object *parent) override;
virtual void onCreated() override;
virtual void onPageAttached() override;
+ virtual bool onBackPressed() override;
ContactFieldItem *createFieldItem(Model::ContactObject &field);
Ui::GenlistItem *getNextFieldItem(Model::ContactFieldId fieldId);
void onDonePressed(Evas_Object *button, void *eventInfo);
void onCancelPressed(Evas_Object *button, void *eventInfo);
+ bool onCancel();
int m_RecordId;
Model::Contact m_Contact;
virtual void initialize() override;
/**
+ * @see ContactField::isChanged()
+ */
+ virtual bool isChanged() const override;
+
+ /**
* @brief Add new child field.
* @return New child field.
*/
private:
const ContactArrayMetadata &getArrayMetadata() const;
+
+ size_t m_InitialCount;
};
}
}
using ContactField::ContactField;
/**
+ * @see ContactField::initialize()
+ */
+ virtual void initialize() override;
+
+ /**
* @see ContactInputField::reset()
*/
virtual void reset() override;
/**
+ * @see ContactField::isChanged()
+ */
+ virtual bool isChanged() const override;
+
+ /**
* @return Date field value.
*/
tm getValue() const;
private:
static tm convertDate(int value);
static int convertDate(const tm &date);
+
+ time_t m_InitialValue;
};
}
}
using ContactField::ContactField;
/**
+ * @see ContactField::initialize()
+ */
+ virtual void initialize() override;
+
+ /**
* @see ContactField::reset()
*/
virtual void reset() override;
/**
+ * @see ContactField::isChanged()
+ */
+ virtual bool isChanged() const override;
+
+ /**
* @return Array of possible values.
*/
Utils::Range<const int *> getValues() const;
private:
const ContactEnumMetadata &getEnumMetadata() const;
+
+ int m_InitialValue;
};
}
}
virtual bool isFilled() const { return !isEmpty(); }
/**
+ * @return Whether the field value was changed.
+ */
+ virtual bool isChanged() const { return true; }
+
+ /**
* @return Whether the field determines that parent object is filled.
*/
bool isRequired() const;
using ContactField::ContactField;
/**
+ * @see ContactField::reset()
+ */
+ virtual void reset() override;
+
+ /**
* @see ContactField::isEmpty()
*/
virtual bool isEmpty() const override;
virtual bool isFilled() const override;
/**
- * @see ContactField::reset()
+ * @see ContactField::isChanged()
*/
- virtual void reset() override;
+ virtual bool isChanged() const override;
/**
* @return Begin iterator.
*/
ContactField *getField(unsigned index) const;
+ /**
+ * @return Child field count.
+ */
+ size_t getFieldCount() const;
+
protected:
ContactField &addField(contacts_record_h record,
const ContactFieldMetadata &metadata);
#define CONTACTS_MODEL_CONTACT_TEXT_FIELD_H
#include "Contacts/Model/ContactField.h"
+#include <string>
namespace Contacts
{
using ContactField::ContactField;
/**
- * @see ContactField::isEmpty()
+ * @see ContactField::initialize()
*/
- virtual bool isEmpty() const override;
+ virtual void initialize() override;
/**
* @see ContactField::reset()
virtual void reset() override;
/**
+ * @see ContactField::isEmpty()
+ */
+ virtual bool isEmpty() const override;
+
+ /**
+ * @see ContactField::isChanged()
+ */
+ virtual bool isChanged() const override;
+
+ /**
* @return Text field value.
*/
const char *getValue() const;
* @brief Set text field value.
*/
void setValue(const char *value);
+
+ private:
+ std::string m_InitialValue;
};
}
}
virtual void reset() override;
/**
+ * @see ContactField::isChanged()
+ */
+ virtual bool isChanged() const override;
+
+ /**
* @return Field that represents object's type.
*/
ContactEnumField &getTypeField() const;
#include "App/Path.h"
#include "Ui/Genlist.h"
+#include "Ui/Popup.h"
#include "Utils/Callback.h"
#include "Utils/Logger.h"
#include "Utils/Range.h"
page->setContent("title_left_btn", cancelButton);
}
+bool InputView::onBackPressed()
+{
+ return onCancel();
+}
+
ContactFieldItem *InputView::createFieldItem(ContactObject &field)
{
ContactFieldItem *item = nullptr;
void InputView::onCancelPressed(Evas_Object *button, void *eventInfo)
{
- delete this;
+ if (onCancel()) {
+ delete this;
+ }
+}
+
+bool InputView::onCancel()
+{
+ if (!m_Contact.isChanged()) {
+ return true;
+ }
+
+ Ui::Popup *popup = new Ui::Popup();
+ popup->create(getEvasObject());
+ popup->setTitle("IDS_PB_HEADER_DISCARD_CHANGES_ABB");
+ popup->setText("IDS_PB_POP_ALL_CHANGES_WILL_BE_DISCARDED");
+
+ popup->addButton("IDS_PB_BUTTON_CANCEL");
+ popup->addButton("IDS_PB_BUTTON_DISCARD_ABB", [this] {
+ delete this;
+ return true;
+ });
+
+ return false;
}
contacts_record_get_child_record_at_p(getRecord(), getPropertyId(), i, &record);
ContactFieldContainer::addField(record, getArrayMetadata().element);
}
+
+ m_InitialCount = getFieldCount();
+}
+
+bool ContactArray::isChanged() const
+{
+ if (getFieldCount() < m_InitialCount) {
+ return true;
+ }
+
+ return ContactFieldContainer::isChanged();
}
ContactField &ContactArray::addField()
using namespace Contacts::Model;
+void ContactDateField::initialize()
+{
+ tm value = getValue();
+ m_InitialValue = mktime(&value);
+}
+
void ContactDateField::reset()
{
time_t now = time(nullptr);
setValue(*localtime(&now));
}
+bool ContactDateField::isChanged() const
+{
+ tm value = getValue();
+ return difftime(mktime(&value), m_InitialValue) != 0;
+}
+
tm ContactDateField::getValue() const
{
int date = 0;
using namespace Contacts::Model;
+void ContactEnumField::initialize()
+{
+ m_InitialValue = getValue();
+}
+
void ContactEnumField::reset()
{
setValue(getEnumMetadata().defaultValue);
}
+bool ContactEnumField::isChanged() const
+{
+ return m_InitialValue != getValue();
+}
+
Utils::Range<const int *> ContactEnumField::getValues() const
{
return getEnumMetadata().values;
using namespace Contacts::Model;
-bool ContactFieldContainer::isEmpty() const
+void ContactFieldContainer::reset()
{
- bool isEmpty = true;
- for (auto &&field : *this) {
- if (!field.isEmpty()) {
- isEmpty = false;
- break;
- }
+ for (auto &&field : m_Fields) {
+ field->reset();
}
+}
- return isEmpty;
+bool ContactFieldContainer::isEmpty() const
+{
+ return !std::any_of(m_Fields.begin(), m_Fields.end(), [](const ContactFieldPtr &field) {
+ return !field->isEmpty();
+ });
}
bool ContactFieldContainer::isFilled() const
{
- bool isFilled = false;
- for (auto &&field : *this) {
- if (field.isRequired() && field.isFilled()) {
- isFilled = true;
- break;
- }
- }
-
- return isFilled;
+ return std::any_of(m_Fields.begin(), m_Fields.end(), [](const ContactFieldPtr &field) {
+ return field->isRequired() && field->isFilled();
+ });
}
-void ContactFieldContainer::reset()
+bool ContactFieldContainer::isChanged() const
{
- for (auto &&field : *this) {
- field.reset();
- }
+ return std::any_of(m_Fields.begin(), m_Fields.end(), std::mem_fn(&ContactField::isChanged));
}
ContactFieldIterator ContactFieldContainer::begin() const
return nullptr;
}
+size_t ContactFieldContainer::getFieldCount() const
+{
+ return m_Fields.size();
+}
+
ContactField &ContactFieldContainer::addField(contacts_record_h record,
const ContactFieldMetadata &metadata)
{
using namespace Contacts::Model;
-bool ContactTextField::isEmpty() const
+void ContactTextField::initialize()
{
const char *value = getValue();
- return !(value && *value);
+ if (value) {
+ m_InitialValue = value;
+ }
}
void ContactTextField::reset()
setValue("");
}
+bool ContactTextField::isEmpty() const
+{
+ const char *value = getValue();
+ return !(value && *value);
+}
+
+bool ContactTextField::isChanged() const
+{
+ const char *value = getValue();
+ if (!value) {
+ value = "";
+ }
+
+ return m_InitialValue.compare(value) != 0;
+}
+
const char *ContactTextField::getValue() const
{
char *value = nullptr;
m_LabelField->reset();
}
+bool ContactTypedObject::isChanged() const
+{
+ if (ContactObject::isChanged()) {
+ return true;
+ }
+
+ if (!isEmpty()) {
+ if (m_TypeField->isChanged()) {
+ return true;
+ }
+
+ if (getTypeField().hasCustomValue()) {
+ return m_LabelField->isChanged();
+ }
+ }
+
+ return false;
+}
+
ContactEnumField &ContactTypedObject::getTypeField() const
{
return m_TypeField->cast<ContactEnumField>();