2021-05-16 15:16:42 +00:00
|
|
|
|
import QtQuick 2.12
|
|
|
|
|
import QtQuick.Controls 2.3
|
|
|
|
|
import QtQuick.Dialogs 1.3
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
|
|
import utils 1.0
|
2021-05-16 15:16:42 +00:00
|
|
|
|
import "../../../../shared"
|
2021-10-14 10:01:34 +00:00
|
|
|
|
import "../../../../shared/popups"
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
|
import StatusQ.Controls 0.1
|
2021-08-17 09:19:20 +00:00
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
2021-07-09 10:09:03 +00:00
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
|
|
|
|
|
StatusModal {
|
2021-05-16 15:16:42 +00:00
|
|
|
|
property string communityId
|
2021-05-17 15:05:45 +00:00
|
|
|
|
property string categoryId
|
|
|
|
|
property string categoryName: ""
|
|
|
|
|
property var channels: []
|
|
|
|
|
|
|
|
|
|
property bool isEdit: false
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-06-29 12:47:28 +00:00
|
|
|
|
readonly property int maxCategoryNameLength: 30
|
|
|
|
|
readonly property var categoryNameValidator: Utils.Validate.NoEmpty
|
|
|
|
|
| Utils.Validate.TextLength
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
|
|
|
|
id: popup
|
|
|
|
|
|
|
|
|
|
onOpened: {
|
2021-05-17 15:05:45 +00:00
|
|
|
|
if(isEdit){
|
2021-09-07 13:39:10 +00:00
|
|
|
|
popup.contentItem.categoryName.input.text = categoryName
|
2021-05-17 15:05:45 +00:00
|
|
|
|
channels = JSON.parse(chatsModel.communities.activeCommunity.getChatIdsByCategory(categoryId))
|
|
|
|
|
}
|
2021-09-07 13:39:10 +00:00
|
|
|
|
popup.contentItem.categoryName.input.forceActiveFocus(Qt.MouseFocusReason)
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
onClosed: destroy()
|
|
|
|
|
|
2021-06-29 12:47:28 +00:00
|
|
|
|
function isFormValid() {
|
2021-09-07 13:39:10 +00:00
|
|
|
|
return contentItem.categoryName.valid
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
header.title: isEdit ?
|
2021-07-16 20:22:50 +00:00
|
|
|
|
//% "Edit category"
|
|
|
|
|
qsTrId("edit-category") :
|
|
|
|
|
//% "New category"
|
|
|
|
|
qsTrId("new-category")
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-09-02 14:40:10 +00:00
|
|
|
|
contentItem: Column {
|
2021-07-22 11:53:08 +00:00
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
width: popup.width
|
|
|
|
|
property alias categoryName: nameInput
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-08-17 09:19:20 +00:00
|
|
|
|
StatusInput {
|
|
|
|
|
id: nameInput
|
|
|
|
|
charLimit: maxCategoryNameLength
|
|
|
|
|
input.placeholderText: qsTr("Category title")
|
2021-09-20 03:00:50 +00:00
|
|
|
|
validators: [StatusMinLengthValidator {
|
|
|
|
|
minLength: 1
|
|
|
|
|
errorMessage: Utils.getErrorMessage(errors, qsTr("category name"))
|
|
|
|
|
}]
|
2021-07-22 11:53:08 +00:00
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
StatusModalDivider {
|
|
|
|
|
topPadding: 8
|
|
|
|
|
bottomPadding: 8
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
ScrollView {
|
|
|
|
|
id: scrollView
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
width: popup.width
|
|
|
|
|
height: Math.min(content.height, 300)
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
property ScrollBar vScrollBar: ScrollBar.vertical
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
contentHeight: content.height
|
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
|
clip: true
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
function scrollBackUp() {
|
|
|
|
|
vScrollBar.setPosition(0)
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
Item {
|
|
|
|
|
id: content
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: channelsLabel.height + communityChannelList.height
|
2021-07-09 10:09:03 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
Item {
|
|
|
|
|
id: channelsLabel
|
2021-07-09 10:09:03 +00:00
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
width: parent.width - 32
|
2021-07-22 11:53:08 +00:00
|
|
|
|
height: 34
|
|
|
|
|
StatusBaseText {
|
|
|
|
|
//% "Channels"
|
|
|
|
|
text: qsTrId("channels")
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.bottomMargin: 4
|
|
|
|
|
font.pixelSize: 15
|
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
|
id: communityChannelList
|
|
|
|
|
|
|
|
|
|
anchors.top: channelsLabel.bottom
|
|
|
|
|
height: childrenRect.height
|
|
|
|
|
width: parent.width
|
|
|
|
|
model: chatsModel.communities.activeCommunity.chats
|
|
|
|
|
interactive: false
|
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
|
|
delegate: StatusListItem {
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
visible: popup.isEdit ?
|
|
|
|
|
model.categoryId === popup.categoryId || model.categoryId === "" :
|
|
|
|
|
model.categoryId === ""
|
|
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
title: "#" + model.name
|
|
|
|
|
icon.isLetterIdenticon: true
|
|
|
|
|
icon.background.color: model.color
|
|
|
|
|
sensor.onClicked: channelItemCheckbox.checked = !channelItemCheckbox.checked
|
|
|
|
|
|
|
|
|
|
components: [
|
|
|
|
|
StatusCheckBox {
|
|
|
|
|
id: channelItemCheckbox
|
|
|
|
|
checked: popup.isEdit ? popup.channels.indexOf(model.id) > - 1 : false
|
|
|
|
|
onCheckedChanged: {
|
|
|
|
|
var idx = popup.channels.indexOf(model.id)
|
|
|
|
|
if(checked){
|
|
|
|
|
if(idx === -1){
|
|
|
|
|
popup.channels.push(model.id)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if(idx > -1){
|
|
|
|
|
popup.channels.splice(idx, 1);
|
|
|
|
|
}
|
2021-07-09 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
2021-07-22 11:53:08 +00:00
|
|
|
|
]
|
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-22 11:53:08 +00:00
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
StatusModalDivider {
|
|
|
|
|
visible: deleteCategoryButton.visible
|
|
|
|
|
topPadding: 8
|
|
|
|
|
bottomPadding: 8
|
|
|
|
|
}
|
2021-05-17 15:05:45 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
StatusListItem {
|
|
|
|
|
id: deleteCategoryButton
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
visible: isEdit
|
|
|
|
|
|
|
|
|
|
//% "Delete category"
|
|
|
|
|
title: qsTrId("delete-category")
|
|
|
|
|
icon.name: "delete"
|
|
|
|
|
type: StatusListItem.Type.Danger
|
|
|
|
|
sensor.onClicked: {
|
|
|
|
|
openPopup(deleteCategoryConfirmationDialogComponent, {
|
|
|
|
|
//% "Delete %1 category"
|
2021-09-07 13:39:10 +00:00
|
|
|
|
title: qsTrId("delete--1-category").arg(popup.contentItem.categoryName.input.text),
|
2021-07-22 11:53:08 +00:00
|
|
|
|
//% "Are you sure you want to delete %1 category? Channels inside the category won’t be deleted."
|
2021-09-07 13:39:10 +00:00
|
|
|
|
confirmationText: qsTrId("are-you-sure-you-want-to-delete--1-category--channels-inside-the-category-won-t-be-deleted-").arg(popup.contentItem.categoryName.input.text)
|
2021-07-22 11:53:08 +00:00
|
|
|
|
|
|
|
|
|
})
|
2021-07-09 10:09:03 +00:00
|
|
|
|
}
|
2021-07-22 11:53:08 +00:00
|
|
|
|
}
|
2021-05-17 15:05:45 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
Item {
|
|
|
|
|
height: 8
|
|
|
|
|
width: parent.width
|
|
|
|
|
}
|
2021-05-17 15:05:45 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
Component {
|
|
|
|
|
id: deleteCategoryConfirmationDialogComponent
|
|
|
|
|
ConfirmationDialog {
|
|
|
|
|
btnType: "warn"
|
|
|
|
|
showCancelButton: true
|
|
|
|
|
onClosed: {
|
|
|
|
|
destroy()
|
|
|
|
|
}
|
|
|
|
|
onCancelButtonClicked: {
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
onConfirmButtonClicked: function(){
|
|
|
|
|
const error = chatsModel.communities.deleteCommunityCategory(chatsModel.communities.activeCommunity.id, popup.categoryId)
|
|
|
|
|
if (error) {
|
|
|
|
|
creatingError.text = error
|
|
|
|
|
return creatingError.open()
|
2021-05-17 15:05:45 +00:00
|
|
|
|
}
|
2021-07-22 11:53:08 +00:00
|
|
|
|
close();
|
|
|
|
|
popup.close()
|
2021-05-17 15:05:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
rightButtons: [
|
|
|
|
|
StatusButton {
|
|
|
|
|
enabled: isFormValid()
|
|
|
|
|
text: isEdit ?
|
2021-07-16 20:22:50 +00:00
|
|
|
|
//% "Save"
|
|
|
|
|
qsTrId("save") :
|
|
|
|
|
//% "Create"
|
|
|
|
|
qsTrId("create")
|
2021-07-09 10:09:03 +00:00
|
|
|
|
onClicked: {
|
|
|
|
|
if (!isFormValid()) {
|
|
|
|
|
scrollView.scrollBackUp()
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-05-17 15:05:45 +00:00
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
let error = ""
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
if (isEdit) {
|
2021-09-07 13:39:10 +00:00
|
|
|
|
error = chatsModel.communities.editCommunityCategory(communityId, categoryId, Utils.filterXSS(popup.contentItem.categoryName.input.text), JSON.stringify(channels))
|
2021-07-09 10:09:03 +00:00
|
|
|
|
} else {
|
2021-09-07 13:39:10 +00:00
|
|
|
|
error = chatsModel.communities.createCommunityCategory(communityId, Utils.filterXSS(popup.contentItem.categoryName.input.text), JSON.stringify(channels))
|
2021-07-09 10:09:03 +00:00
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
if (error) {
|
|
|
|
|
categoryError.text = error
|
|
|
|
|
return categoryError.open()
|
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
popup.close()
|
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
2021-07-09 10:09:03 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
MessageDialog {
|
|
|
|
|
id: categoryError
|
|
|
|
|
title: isEdit ?
|
2021-07-16 20:22:50 +00:00
|
|
|
|
//% "Error editing the category"
|
|
|
|
|
qsTrId("error-editing-the-category") :
|
|
|
|
|
//% "Error creating the category"
|
|
|
|
|
qsTrId("error-creating-the-category")
|
2021-07-09 10:09:03 +00:00
|
|
|
|
icon: StandardIcon.Critical
|
|
|
|
|
standardButtons: StandardButton.Ok
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|