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
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2022-07-05 10:12:27 +00:00
|
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
2021-07-09 10:09:03 +00:00
|
|
|
|
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
|
|
|
|
|
|
2021-10-25 14:33:41 +00:00
|
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
|
import shared.popups 1.0
|
2021-10-25 14:33:41 +00:00
|
|
|
|
|
2022-09-27 08:51:53 +00:00
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
2021-07-09 10:09:03 +00:00
|
|
|
|
StatusModal {
|
2021-10-22 20:49:47 +00:00
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
property var store
|
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
|
|
|
|
|
2022-05-09 08:40:27 +00:00
|
|
|
|
readonly property int maxCategoryNameLength: 24
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
|
|
|
|
onOpened: {
|
2021-05-17 15:05:45 +00:00
|
|
|
|
if(isEdit){
|
2021-10-22 20:49:47 +00:00
|
|
|
|
root.contentItem.categoryName.input.text = categoryName
|
2022-02-01 15:31:05 +00:00
|
|
|
|
root.channels = []
|
|
|
|
|
root.store.prepareEditCategoryModel(categoryId);
|
2021-05-17 15:05:45 +00:00
|
|
|
|
}
|
2022-09-27 21:26:26 +00:00
|
|
|
|
root.contentItem.categoryName.input.edit.forceActiveFocus()
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 12:46:16 +00:00
|
|
|
|
headerSettings.title: isEdit ? qsTr("Edit category") : qsTr("New category")
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-09-02 14:40:10 +00:00
|
|
|
|
contentItem: Column {
|
2022-05-26 15:46:02 +00:00
|
|
|
|
property alias categoryName: nameInput
|
2022-02-09 09:43:23 +00:00
|
|
|
|
|
2021-10-22 20:49:47 +00:00
|
|
|
|
width: root.width
|
2022-05-26 15:46:02 +00:00
|
|
|
|
topPadding: 16
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-08-17 09:19:20 +00:00
|
|
|
|
StatusInput {
|
|
|
|
|
id: nameInput
|
2022-05-26 15:46:02 +00:00
|
|
|
|
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.leftMargin: 16
|
|
|
|
|
|
2022-08-16 10:21:39 +00:00
|
|
|
|
input.edit.objectName: "createOrEditCommunityCategoryNameInput"
|
2022-09-27 21:26:26 +00:00
|
|
|
|
input.clearable: true
|
2022-05-26 15:46:02 +00:00
|
|
|
|
label: qsTr("Category title")
|
2021-08-17 09:19:20 +00:00
|
|
|
|
charLimit: maxCategoryNameLength
|
2022-07-22 10:28:04 +00:00
|
|
|
|
placeholderText: qsTr("Name the category")
|
2021-09-20 03:00:50 +00:00
|
|
|
|
validators: [StatusMinLengthValidator {
|
|
|
|
|
minLength: 1
|
2022-01-28 00:02:06 +00:00
|
|
|
|
errorMessage: Utils.getErrorMessage(nameInput.errors, qsTr("category name"))
|
2021-09-20 03:00:50 +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 {
|
|
|
|
|
topPadding: 8
|
|
|
|
|
bottomPadding: 8
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 08:51:53 +00:00
|
|
|
|
Item {
|
2021-10-22 20:49:47 +00:00
|
|
|
|
width: root.width
|
2022-09-27 08:51:53 +00:00
|
|
|
|
height: Math.min(communityChannelList.contentHeight, 300)
|
2021-05-16 15:16:42 +00:00
|
|
|
|
|
2021-07-22 11:53:08 +00:00
|
|
|
|
Item {
|
2022-09-27 08:51:53 +00:00
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: -8
|
|
|
|
|
clip: true
|
2021-07-22 11:53:08 +00:00
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
|
StatusListView {
|
2021-07-22 11:53:08 +00:00
|
|
|
|
id: communityChannelList
|
2022-08-16 10:21:39 +00:00
|
|
|
|
objectName: "createOrEditCommunityCategoryChannelList"
|
2021-07-22 11:53:08 +00:00
|
|
|
|
|
2022-09-27 08:51:53 +00:00
|
|
|
|
anchors.fill: parent
|
|
|
|
|
anchors.margins: -parent.anchors.margins
|
|
|
|
|
displayMarginBeginning: anchors.margins
|
|
|
|
|
displayMarginEnd: anchors.margins
|
|
|
|
|
clip: false
|
|
|
|
|
|
|
|
|
|
model: SortFilterProxyModel {
|
|
|
|
|
sourceModel: root.isEdit ? root.store.chatCommunitySectionModule.editCategoryChannelsModel
|
|
|
|
|
: root.store.chatCommunitySectionModule.model
|
2023-01-27 15:24:00 +00:00
|
|
|
|
// filter out channels with categories
|
2022-09-27 08:51:53 +00:00
|
|
|
|
filters: ValueFilter {
|
2023-01-27 15:24:00 +00:00
|
|
|
|
enabled: !root.isEdit
|
|
|
|
|
roleName: "categoryId"
|
|
|
|
|
value: ""
|
2022-09-27 08:51:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
header: Item {
|
|
|
|
|
id: channelsLabel
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
width: parent.width - 32
|
|
|
|
|
height: 34
|
|
|
|
|
StatusBaseText {
|
|
|
|
|
text: qsTr("Channels")
|
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
anchors.bottomMargin: 4
|
|
|
|
|
font.pixelSize: 15
|
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-22 11:53:08 +00:00
|
|
|
|
|
2023-01-27 15:24:00 +00:00
|
|
|
|
delegate: Loader {
|
|
|
|
|
active: model.type !== Constants.chatType.category
|
|
|
|
|
|
|
|
|
|
sourceComponent: StatusListItem {
|
|
|
|
|
readonly property bool checked: channelItemCheckbox.checked
|
2023-03-02 20:18:26 +00:00
|
|
|
|
objectName: "category_item_name_" + model.name
|
2023-01-27 15:24:00 +00:00
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2023-04-03 20:21:50 +00:00
|
|
|
|
anchors.horizontalCenterOffset: 16
|
2023-01-27 15:24:00 +00:00
|
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
title: "#" + model.name
|
2023-04-03 20:21:50 +00:00
|
|
|
|
asset.width: 40
|
|
|
|
|
asset.height: 40
|
2023-01-27 15:24:00 +00:00
|
|
|
|
asset.emoji: model.emoji
|
|
|
|
|
asset.color: model.color
|
|
|
|
|
asset.imgIsIdenticon: false
|
|
|
|
|
asset.name: model.icon
|
|
|
|
|
asset.isImage: !!model.icon
|
|
|
|
|
ringSettings.ringSpecModel: model.colorHash
|
|
|
|
|
asset.isLetterIdenticon: true
|
|
|
|
|
asset.bgColor: model.color
|
|
|
|
|
onClicked: channelItemCheckbox.checked = !channelItemCheckbox.checked
|
|
|
|
|
|
|
|
|
|
components: [
|
|
|
|
|
StatusCheckBox {
|
|
|
|
|
id: channelItemCheckbox
|
|
|
|
|
checked: root.isEdit ? model.categoryId === root.categoryId : false
|
|
|
|
|
onCheckedChanged: {
|
|
|
|
|
if(checked){
|
|
|
|
|
var idx = root.channels.indexOf(model.itemId)
|
|
|
|
|
if(idx === -1){
|
|
|
|
|
root.channels.push(model.itemId)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
root.channels = root.channels.filter(el => el !== model.itemId);
|
2021-07-22 11:53:08 +00:00
|
|
|
|
}
|
2021-07-09 10:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-27 15:24:00 +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
|
|
|
|
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(){
|
2021-10-22 20:49:47 +00:00
|
|
|
|
const error = root.store.deleteCommunityCategory(root.categoryId);
|
2021-07-22 11:53:08 +00:00
|
|
|
|
if (error) {
|
2022-02-01 00:32:53 +00:00
|
|
|
|
categoryError.text = error
|
|
|
|
|
return categoryError.open()
|
2021-05-17 15:05:45 +00:00
|
|
|
|
}
|
2021-07-22 11:53:08 +00:00
|
|
|
|
close();
|
2021-10-22 20:49:47 +00:00
|
|
|
|
root.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: [
|
2023-04-03 20:21:50 +00:00
|
|
|
|
StatusButton {
|
|
|
|
|
visible: isEdit
|
|
|
|
|
type: StatusBaseButton.Type.Danger
|
|
|
|
|
text: qsTr("Delete Category")
|
|
|
|
|
onClicked: {
|
|
|
|
|
Global.openPopup(deleteCategoryConfirmationDialogComponent, {
|
2023-05-23 12:46:16 +00:00
|
|
|
|
"headerSettings.title": qsTr("Delete '%1' category").arg(nameInput.text),
|
2023-04-03 20:21:50 +00:00
|
|
|
|
confirmationText: qsTr("Are you sure you want to delete '%1' category? Channels inside the category won’t be deleted.").arg(nameInput.text)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-07-09 10:09:03 +00:00
|
|
|
|
StatusButton {
|
2022-08-16 10:21:39 +00:00
|
|
|
|
objectName: "createOrEditCommunityCategoryBtn"
|
2021-07-09 10:09:03 +00:00
|
|
|
|
enabled: isFormValid()
|
|
|
|
|
text: isEdit ?
|
2022-04-04 11:26:30 +00:00
|
|
|
|
qsTr("Save") :
|
|
|
|
|
qsTr("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 = ""
|
|
|
|
|
if (isEdit) {
|
2022-07-05 10:12:27 +00:00
|
|
|
|
error = root.store.editCommunityCategory(root.categoryId, StatusQUtils.Utils.filterXSS(root.contentItem.categoryName.input.text), JSON.stringify(channels));
|
2021-07-09 10:09:03 +00:00
|
|
|
|
} else {
|
2022-07-05 10:12:27 +00:00
|
|
|
|
error = root.store.createCommunityCategory(StatusQUtils.Utils.filterXSS(root.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-10-22 20:49:47 +00:00
|
|
|
|
root.close()
|
2021-07-09 10:09:03 +00:00
|
|
|
|
}
|
2021-05-16 15:16:42 +00:00
|
|
|
|
}
|
2021-07-09 10:09:03 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
MessageDialog {
|
|
|
|
|
id: categoryError
|
2022-02-09 09:43:23 +00:00
|
|
|
|
title: isEdit ?
|
2022-04-04 11:26:30 +00:00
|
|
|
|
qsTr("Error editing the category") :
|
|
|
|
|
qsTr("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
|
|
|
|
}
|
|
|
|
|
}
|