import QtQuick 2.0
Rectangle {
width: parent.width
color: "pink"
property variant contact
Column {
spacing: 8
anchors {
fill: parent
leftMargin: 10
topMargin: 10
}
DetailEditWidget { id: nameField; label: "Name "; value: contact ? contact.name.firstName : " "}
DetailEditWidget { id: emailField; label: "Email Address "; value: contact ? contact.email.emailAddress : " "}
DetailEditWidget { id: phoneField; label: "Phone Number "; value: contact ? contact.phoneNumber.number : " "}
}
function deleteContact() {
contactsModel.removeContact(contactEditor.contact.contactId)
statusBar.updateMsg("contact successfully deleted")
}
function updateContact() {
var values = [nameField.value, emailField.value, phoneField.value]
if (!contact) {
var newContact = Qt.createQmlObject("import QtContacts 5.0; Contact{ }", contactEditor)
setDetailValues(newContact, values)
newContact.save()
contactsModel.saveContact(newContact)
statusBar.updateMsg("new contact successfully created")
} else {
if (contact.modified) {
setDetailValues(contact, values)
contact.save()
statusBar.updateMsg("contact successfully updated")
} else {
statusBar.updateMsg("nothing to update, contact already is up-to-date")
}
}
}
function setDetailValues(c, values) {
c.name.firstName = values[0]
c.email.emailAddress = values[1]
c.phoneNumber.number = values[2]
}
function cancel() {
contact = ""
}
function resetToDefaults() {
nameField.inputFocus = false
emailField.inputFocus = false
phoneField.inputFocus = false
nameField.color = "black"
emailField.color = "black"
phoneField.color = "black"
}
}