refactor(Communities): use StatusQ's StatusInput in create category popup

This commit is contained in:
Pascal Precht 2021-08-17 11:19:20 +02:00 committed by Pascal Precht
parent abb44cb1ec
commit a40fe71767
1 changed files with 14 additions and 35 deletions

View File

@ -1,6 +1,5 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtGraphicalEffects 1.13
import QtQuick.Dialogs 1.3 import QtQuick.Dialogs 1.3
import "../../../../imports" import "../../../../imports"
import "../../../../shared" import "../../../../shared"
@ -9,6 +8,7 @@ import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1 import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1 import StatusQ.Components 0.1
import StatusQ.Controls 0.1 import StatusQ.Controls 0.1
import StatusQ.Controls.Validators 0.1
import StatusQ.Popups 0.1 import StatusQ.Popups 0.1
StatusModal { StatusModal {
@ -27,19 +27,15 @@ StatusModal {
onOpened: { onOpened: {
if(isEdit){ if(isEdit){
popup.contentComponent.categoryName.text = categoryName popup.contentComponent.categoryName.input.text = categoryName
channels = JSON.parse(chatsModel.communities.activeCommunity.getChatIdsByCategory(categoryId)) channels = JSON.parse(chatsModel.communities.activeCommunity.getChatIdsByCategory(categoryId))
} }
popup.contentComponent.categoryName.forceActiveFocus(Qt.MouseFocusReason) popup.contentComponent.categoryName.input.forceActiveFocus(Qt.MouseFocusReason)
} }
onClosed: destroy() onClosed: destroy()
function isFormValid() { function isFormValid() {
return Utils.validateAndReturnError(popup.contentComponent.categoryName.text, return contentComponent.categoryName.valid
categoryNameValidator,
//% "category name"
qsTrId("category-name"),
maxCategoryNameLength) === ""
} }
header.title: isEdit ? header.title: isEdit ?
@ -53,29 +49,12 @@ StatusModal {
width: popup.width width: popup.width
property alias categoryName: nameInput property alias categoryName: nameInput
Item { StatusInput {
width: parent.width id: nameInput
height: 76 charLimit: maxCategoryNameLength
Input { input.placeholderText: qsTr("Category title")
id: nameInput validators: [StatusMinLengthValidator { minLength: 1 }]
width: parent.width -32 onTextChanged: errorMessage = Utils.getErrorMessage(errors, "category name")
anchors.centerIn: parent
anchors.left: undefined
anchors.right: undefined
//% "Category title"
placeholderText: qsTrId("category-title")
maxLength: maxCategoryNameLength
onTextEdited: {
validationError = Utils.validateAndReturnError(text,
categoryNameValidator,
//% "category name"
qsTrId("category-name"),
maxCategoryNameLength)
}
}
} }
StatusModalDivider { StatusModalDivider {
@ -182,9 +161,9 @@ StatusModal {
sensor.onClicked: { sensor.onClicked: {
openPopup(deleteCategoryConfirmationDialogComponent, { openPopup(deleteCategoryConfirmationDialogComponent, {
//% "Delete %1 category" //% "Delete %1 category"
title: qsTrId("delete--1-category").arg(popup.contentComponent.categoryName.text), title: qsTrId("delete--1-category").arg(popup.contentComponent.categoryName.input.text),
//% "Are you sure you want to delete %1 category? Channels inside the category wont be deleted." //% "Are you sure you want to delete %1 category? Channels inside the category wont be deleted."
confirmationText: qsTrId("are-you-sure-you-want-to-delete--1-category--channels-inside-the-category-won-t-be-deleted-").arg(popup.contentComponent.categoryName.text) confirmationText: qsTrId("are-you-sure-you-want-to-delete--1-category--channels-inside-the-category-won-t-be-deleted-").arg(popup.contentComponent.categoryName.input.text)
}) })
} }
@ -237,9 +216,9 @@ StatusModal {
let error = "" let error = ""
if (isEdit) { if (isEdit) {
error = chatsModel.communities.editCommunityCategory(communityId, categoryId, Utils.filterXSS(popup.contentComponent.categoryName.text), JSON.stringify(channels)) error = chatsModel.communities.editCommunityCategory(communityId, categoryId, Utils.filterXSS(popup.contentComponent.categoryName.input.text), JSON.stringify(channels))
} else { } else {
error = chatsModel.communities.createCommunityCategory(communityId, Utils.filterXSS(popup.contentComponent.categoryName.text), JSON.stringify(channels)) error = chatsModel.communities.createCommunityCategory(communityId, Utils.filterXSS(popup.contentComponent.categoryName.input.text), JSON.stringify(channels))
} }
if (error) { if (error) {