AddCategory.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3. import "Logic.js" as Logic
  4. Page {
  5. id: pageAddCategory
  6. property string __idCategoryEdit: ""
  7. tools: ToolBarLayout {
  8. id: tool_only_back
  9. opacity: userTheme.opacityToolbar
  10. ToolIcon {
  11. id: toolIconBack
  12. //iconId: "toolbar-back"
  13. iconSource: "images/toolbar/back.png"
  14. onClicked: {
  15. pageStack.pop();
  16. }
  17. }
  18. ToolIcon {
  19. id: toolIconOk
  20. //iconId: "toolbar-done"
  21. iconSource: "images/toolbar/ok.png"
  22. onClicked: {
  23. var category = categoryNameInput.text
  24. var descr = categoryCommentInput.text
  25. var str = ""
  26. if( category == "" ) {
  27. str = qsTr("Enter the category name")
  28. dlgSaveCategoryOk.openDlg( str )
  29. } else if ( pageCategoryList.isEditCategory === false ) {
  30. var ri = Logic.addCategory( category, descr )
  31. if(ri) {
  32. pageStack.pop();
  33. pageCategoryList.getAllCategory()
  34. } else {
  35. str = qsTr("Failed to save")
  36. dlgSaveCategoryOk.openDlg( str )
  37. }
  38. } else {
  39. var ru = Logic.updateCategory( pageCategoryList.selCategoryId, category, descr )
  40. if(ru) {
  41. pageStack.pop();
  42. pageCategoryList.getAllCategory()
  43. } else {
  44. str = qsTr("Failed to update")
  45. }
  46. }
  47. }
  48. }
  49. } //ToolBarLayout
  50. /************************************************************************/
  51. function initForm() {
  52. if( pageCategoryList.isEditCategory ) {
  53. categoryNameInput.text = pageCategoryList.selCategoryName
  54. categoryCommentInput.text = pageCategoryList.selCategoryDescr
  55. __idCategoryEdit = pageCategoryList.selCategoryId
  56. }
  57. }
  58. /************************************************************************/
  59. QNMTitle {
  60. id: titlePage
  61. text: pageCategoryList.isEditCategory ? qsTr("Edit category") : qsTr("Add category")
  62. image: "images/categories.png"
  63. busy: false
  64. }
  65. BackgroundPage { }
  66. Flickable {
  67. id: flickArea
  68. anchors {
  69. top: titlePage.bottom
  70. bottom: parent.bottom
  71. left: parent.left
  72. right: parent.right
  73. topMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 5 : 15
  74. leftMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 40 : 20
  75. rightMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 40 : 20
  76. bottomMargin: screen.orientationString == "Landscape" || screen.orientationString == "LandscapeInverted" ? 5 : 15
  77. }
  78. flickableDirection: Flickable.VerticalFlick
  79. width: parent.width
  80. height: parent.height
  81. contentWidth: contentFlickArea.width
  82. contentHeight: contentFlickArea.height
  83. clip: true
  84. Column {
  85. id: contentFlickArea
  86. width: parent.width
  87. spacing: 10
  88. Text {
  89. text: qsTr("Name of category")
  90. font.pixelSize: 30
  91. }
  92. TextField {
  93. id: categoryNameInput
  94. //width: (screen.orientationString == "Portrait") || (screen.orientationString == "PortraitInverted") ? 440 : 810
  95. width: flickArea.width
  96. placeholderText: qsTr("Name of category")
  97. Image {
  98. anchors { right: parent.right; verticalCenter: parent.verticalCenter }
  99. id: clearText
  100. fillMode: Image.PreserveAspectFit
  101. smooth: true;
  102. visible: categoryNameInput.text
  103. source: "image://theme/icon-m-toolbar-backspace"
  104. height: parent.height
  105. //width: parent.height
  106. MouseArea {
  107. id: clear
  108. anchors.fill: parent
  109. onClicked: {
  110. categoryNameInput.text = ""
  111. categoryNameInput.forceActiveFocus()
  112. }
  113. }
  114. }
  115. }
  116. Item { height: 50; width: parent.width }
  117. Text {
  118. text: qsTr("Comment")
  119. font.pixelSize: 30
  120. }
  121. TextArea {
  122. //width: (screen.orientationString == "Portrait") || (screen.orientationString == "PortraitInverted") ? 440 : 810
  123. width: flickArea.width
  124. height: 400
  125. id: categoryCommentInput
  126. placeholderText: qsTr("Write your comment here")
  127. wrapMode: TextEdit.WordWrap
  128. clip: true
  129. }
  130. }
  131. }
  132. Component.onCompleted: { initForm(); }
  133. QueryDialog {
  134. id: dlgSaveCategoryOk
  135. title: Image {
  136. anchors.horizontalCenter: parent.horizontalCenter
  137. //source: "image://theme/icon-l-user-guide"
  138. source: "images/info.png"
  139. }
  140. property alias text: dlgSaveCategoryOk.message
  141. function openDlg( text ) {
  142. dlgSaveCategoryOk.message = text
  143. dlgSaveCategoryOk.open()
  144. }
  145. }
  146. }