AddContactView.qml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
  5. *
  6. * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this
  9. * software and associated documentation files (the "Software"), to deal in the Software
  10. * without restriction, including without limitation the rights to use, copy, modify,
  11. * merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  12. * to permit persons to whom the Software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all copies
  16. * or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. import QtQuick 2.9
  26. import QtQuick.Controls 2.4
  27. import qtprotobuf.examples 1.0
  28. StackItem {
  29. id: root
  30. Flickable {
  31. anchors.fill: parent
  32. contentHeight: innerColumn.height + 70 + 10
  33. contentWidth: parent.width
  34. Column {
  35. id: innerColumn
  36. anchors.right: parent.right
  37. anchors.left: parent.left
  38. TextInputRow {
  39. id: firstNameField
  40. label: qsTr("First name")
  41. }
  42. TextInputRow {
  43. id: middleNameField
  44. label: qsTr("Middle name")
  45. }
  46. TextInputRow {
  47. id: lastNameField
  48. label: qsTr("Last name")
  49. }
  50. PhoneInput {
  51. id: homePhone
  52. label: qsTr("Home phone")
  53. PhoneNumber {
  54. id: _homePhoneData
  55. countryCode: homePhone.countryCode
  56. number: parseInt(homePhone.number, 10)
  57. }
  58. }
  59. DropDownColumn {
  60. anchors.right: parent.right
  61. anchors.left: parent.left
  62. width: root.width
  63. header: qsTr("Job")
  64. value: _jobTitle.text
  65. TextInputRow {
  66. id: _jobTitle
  67. label: qsTr("Title")
  68. }
  69. Item {
  70. height: 70
  71. anchors.right: parent.right
  72. anchors.left: parent.left
  73. PrimaryText {
  74. anchors.bottom: parent.bottom
  75. text: qsTr("Address")
  76. }
  77. }
  78. TextInputRow {
  79. id: _jstreetAddress1
  80. label: qsTr("Street address 1")
  81. }
  82. TextInputRow {
  83. id: _jstreetAddress2
  84. label: qsTr("Street address 2")
  85. }
  86. TextInputRow {
  87. id: _jzipCode
  88. label: qsTr("Zip code")
  89. }
  90. TextInputRow {
  91. id: _jstate
  92. label: qsTr("State")
  93. }
  94. TextInputRow {
  95. id: _jCountry
  96. label: qsTr("Country")
  97. }
  98. }
  99. DropDownColumn {
  100. anchors.right: parent.right
  101. anchors.left: parent.left
  102. width: root.width
  103. header: qsTr("Home address")
  104. TextInputRow {
  105. id: _streetAddress1
  106. label: qsTr("Street address 1")
  107. }
  108. TextInputRow {
  109. id: _streetAddress2
  110. label: qsTr("Street address 2")
  111. }
  112. TextInputRow {
  113. id: _zipCode
  114. label: qsTr("Zip code")
  115. }
  116. TextInputRow {
  117. id: _state
  118. label: qsTr("State")
  119. }
  120. TextInputRow {
  121. id: _country
  122. label: qsTr("Country")
  123. }
  124. }
  125. }
  126. }
  127. property Contact newContact: Contact {
  128. firstName: firstNameField.text
  129. middleName: middleNameField.text
  130. lastName: lastNameField.text
  131. job.title: _jobTitle.text
  132. // job.officeAddress.country: _jcountry.text
  133. job.officeAddress.streetAddress1: _jstreetAddress1.text
  134. job.officeAddress.streetAddress2: _jstreetAddress2.text
  135. job.officeAddress.zipCode: parseInt(_jzipCode.text, 10)
  136. job.officeAddress.state: _jstate.text
  137. // address.country: _country.text
  138. address.streetAddress1: _streetAddress1.text
  139. address.streetAddress2: _streetAddress2.text
  140. address.zipCode: parseInt(_zipCode.text, 10)
  141. address.state: _state.text
  142. }
  143. onNewContactChanged: {
  144. firstNameField.text = newContact.firstName
  145. middleNameField.text = newContact.middleName
  146. lastNameField.text = newContact.lastName
  147. _jobTitle.text = newContact.job.title
  148. // newContact.job.officeAddress.country: _jcountry.text
  149. _jstreetAddress1.text = newContact.job.officeAddress.streetAddress1
  150. _jstreetAddress2.text = newContact.job.officeAddress.streetAddress2
  151. _jzipCode.text = newContact.job.officeAddress.zipCode.toString()
  152. _jstate.text = newContact.job.officeAddress.state
  153. // newContact.address.country: _country.text
  154. _streetAddress1.text = newContact.address.streetAddress1
  155. _streetAddress2.text = newContact.address.streetAddress2
  156. _zipCode.text = newContact.address.zipCode.toString()
  157. _state.text = newContact.address.state
  158. var phoneNumber = newContact.phonesData.length > 0 ?
  159. newContact.phonesData[0] : null
  160. if (phoneNumber) {
  161. homePhone.number = phoneNumber.number.toString()
  162. }
  163. }
  164. FloatingRoundButton {
  165. id: addContactButton
  166. enabled: firstNameField.text.length > 0
  167. anchors.right: parent.right
  168. anchors.bottom: parent.bottom
  169. anchors.margins: 10
  170. icon: "qrc:/images/check.png"
  171. onClicked: {
  172. var phones = new Array;
  173. if (homePhone.number.length !== 0) {
  174. phones.push(_homePhoneData);
  175. }
  176. newContact.phonesData = phones;
  177. abEngine.addContact(newContact)
  178. stack.pop()
  179. }
  180. }
  181. }