2020-12-11 20:29:46 +00:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.3
|
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
import QtQuick.Dialogs 1.3
|
2020-12-11 20:38:10 +00:00
|
|
|
import "../../../../imports"
|
2021-06-02 19:15:46 +00:00
|
|
|
import "../components"
|
2020-12-11 20:38:10 +00:00
|
|
|
import "../../../../shared"
|
|
|
|
import "../../../../shared/status"
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
ModalPopup {
|
|
|
|
property string communityId
|
2021-05-28 02:55:50 +00:00
|
|
|
property QtObject channel
|
|
|
|
property bool isEdit: false
|
2021-05-16 15:16:42 +00:00
|
|
|
property string categoryId: ""
|
2021-06-29 12:47:28 +00:00
|
|
|
|
|
|
|
readonly property int maxChannelNameLength: 30
|
|
|
|
readonly property var channelNameValidator: Utils.Validate.NoEmpty
|
|
|
|
| Utils.Validate.TextLength
|
|
|
|
| Utils.Validate.TextLowercaseLettersNumberAndDashes
|
|
|
|
|
|
|
|
readonly property int maxChannelDescLength: 140
|
|
|
|
readonly property var channelDescValidator: Utils.Validate.NoEmpty
|
|
|
|
| Utils.Validate.TextLength
|
2021-06-02 19:43:33 +00:00
|
|
|
|
|
|
|
property Component pinnedMessagesPopupComponent
|
|
|
|
|
2020-12-11 20:29:46 +00:00
|
|
|
id: popup
|
2021-06-02 19:15:46 +00:00
|
|
|
height: 475
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
nameInput.text = "";
|
2021-05-28 02:55:50 +00:00
|
|
|
if (isEdit) {
|
|
|
|
nameInput.text = channel.name;
|
2021-06-21 00:44:29 +00:00
|
|
|
title = qsTr("Edit #%1").arg(channel.name);
|
2021-05-28 02:55:50 +00:00
|
|
|
descriptionTextArea.text = channel.description;
|
|
|
|
// TODO: re-enable once private channels are implemented
|
|
|
|
// privateSwitch.checked = channel.private
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
nameInput.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
2021-03-29 12:28:41 +00:00
|
|
|
onClosed: destroy()
|
2020-12-11 20:29:46 +00:00
|
|
|
|
2021-06-29 12:47:28 +00:00
|
|
|
function isFormValid() {
|
|
|
|
return Utils.validateAndReturnError(nameInput.text,
|
|
|
|
channelNameValidator,
|
|
|
|
qsTr("channel name"),
|
|
|
|
maxChannelNameLength) === ""
|
|
|
|
&& Utils.validateAndReturnError(descriptionTextArea.text,
|
|
|
|
channelDescValidator,
|
|
|
|
qsTr("channel decription"),
|
|
|
|
maxChannelDescLength) === ""
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "New channel"
|
|
|
|
title: qsTrId("new-channel")
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
ScrollView {
|
|
|
|
property ScrollBar vScrollBar: ScrollBar.vertical
|
|
|
|
|
|
|
|
id: scrollView
|
|
|
|
anchors.fill: parent
|
|
|
|
rightPadding: Style.current.padding
|
|
|
|
anchors.rightMargin: - Style.current.halfPadding
|
|
|
|
contentHeight: content.height
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
function scrollBackUp() {
|
|
|
|
vScrollBar.setPosition(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: content
|
|
|
|
height: childrenRect.height
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: nameInput
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "A cool name"
|
|
|
|
placeholderText: qsTrId("a-cool-name")
|
2021-06-29 12:47:28 +00:00
|
|
|
maxLength: popup.maxChannelNameLength
|
2021-03-29 12:28:41 +00:00
|
|
|
|
|
|
|
onTextEdited: {
|
2021-06-29 12:47:28 +00:00
|
|
|
text = Utils.convertSpacesToDashesAndUpperToLowerCase(text);
|
2021-03-29 12:28:41 +00:00
|
|
|
|
2021-06-29 12:47:28 +00:00
|
|
|
validationError = Utils.validateAndReturnError(text,
|
|
|
|
channelNameValidator,
|
|
|
|
qsTr("channel name"),
|
|
|
|
maxChannelNameLength)
|
2021-03-29 12:28:41 +00:00
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledTextArea {
|
|
|
|
id: descriptionTextArea
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Channel description"
|
|
|
|
label: qsTrId("channel-description")
|
|
|
|
//% "What your channel is about"
|
|
|
|
placeholderText: qsTrId("what-your-channel-is-about")
|
2021-06-29 12:47:28 +00:00
|
|
|
|
2020-12-11 20:29:46 +00:00
|
|
|
anchors.top: nameInput.bottom
|
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
customHeight: 88
|
2021-03-29 12:28:41 +00:00
|
|
|
|
2021-06-29 12:47:28 +00:00
|
|
|
onTextChanged: {
|
|
|
|
if(text.length > maxChannelDescLength)
|
|
|
|
{
|
|
|
|
textField.remove(maxChannelDescLength, text.length)
|
|
|
|
return
|
2021-03-29 12:28:41 +00:00
|
|
|
}
|
2021-06-29 12:47:28 +00:00
|
|
|
|
|
|
|
validationError = Utils.validateAndReturnError(text,
|
|
|
|
channelDescValidator,
|
|
|
|
qsTr("channel decription"),
|
|
|
|
maxChannelDescLength)
|
2021-03-29 12:28:41 +00:00
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: charLimit
|
2021-06-29 12:47:28 +00:00
|
|
|
text: `${descriptionTextArea.text.length}/${maxChannelDescLength}`
|
2020-12-11 20:29:46 +00:00
|
|
|
anchors.top: descriptionTextArea.bottom
|
|
|
|
anchors.topMargin: !descriptionTextArea.validationError ? 5 : - Style.current.smallPadding
|
|
|
|
anchors.right: descriptionTextArea.right
|
|
|
|
font.pixelSize: 12
|
|
|
|
color: !descriptionTextArea.validationError ? Style.current.textColor : Style.current.danger
|
|
|
|
}
|
|
|
|
|
2021-05-28 02:55:50 +00:00
|
|
|
// Separator {
|
|
|
|
// id: separator1
|
|
|
|
// anchors.top: charLimit.bottom
|
|
|
|
// anchors.topMargin: Style.current.bigPadding
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TODO: use the switch below to enable private channels
|
|
|
|
// Item {
|
|
|
|
// id: privateSwitcher
|
|
|
|
// height: privateSwitch.height
|
|
|
|
// width: parent.width
|
|
|
|
// anchors.top: separator1.bottom
|
|
|
|
// anchors.topMargin: Style.current.smallPadding * 2
|
|
|
|
|
|
|
|
// StyledText {
|
|
|
|
// //% "Private channel"
|
|
|
|
// text: qsTrId("private-channel")
|
|
|
|
// anchors.verticalCenter: parent.verticalCenter
|
|
|
|
// }
|
|
|
|
|
|
|
|
// StatusSwitch {
|
|
|
|
// id: privateSwitch
|
|
|
|
// anchors.right: parent.right
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// StyledText {
|
|
|
|
// id: privateExplanation
|
|
|
|
// anchors.top: privateSwitcher.bottom
|
|
|
|
// color: Style.current.secondaryText
|
|
|
|
// wrapMode: Text.WordWrap
|
|
|
|
// anchors.topMargin: Style.current.smallPadding * 2
|
|
|
|
// width: parent.width
|
|
|
|
// //% "By making a channel private, only members with selected permission will be able to access it"
|
|
|
|
// text: qsTrId("by-making-a-channel-private--only-members-with-selected-permission-will-be-able-to-access-it")
|
|
|
|
// }
|
2021-06-02 19:15:46 +00:00
|
|
|
|
|
|
|
CommunityPopupButton {
|
|
|
|
id: memberBtn
|
|
|
|
label: qsTr("Pinned messages")
|
|
|
|
iconName: "../pin"
|
|
|
|
txtColor: Style.current.textColor
|
|
|
|
onClicked: openPopup(pinnedMessagesPopupComponent)
|
|
|
|
anchors.top: charLimit.bottom
|
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
|
|
|
|
Item {
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
width: childrenRect.width
|
|
|
|
height: memberBtn.height
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: nbPinMessagesText
|
2021-06-21 19:35:32 +00:00
|
|
|
text: chatsModel.messageView.pinnedMessagesList.count
|
2021-06-02 19:15:46 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
padding: 0
|
|
|
|
font.pixelSize: 15
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGImage {
|
|
|
|
id: caret
|
|
|
|
anchors.left: nbPinMessagesText.right
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
source: "../../../img/caret.svg"
|
|
|
|
width: 13
|
|
|
|
height: 7
|
|
|
|
rotation: -90
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: parent
|
|
|
|
source: parent
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
footer: StatusButton {
|
2021-06-29 12:47:28 +00:00
|
|
|
enabled: isFormValid()
|
2021-05-28 02:55:50 +00:00
|
|
|
text: isEdit ?
|
|
|
|
qsTr("Save") :
|
|
|
|
//% "Create"
|
|
|
|
qsTrId("create")
|
2020-12-11 20:29:46 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
onClicked: {
|
2021-06-29 12:47:28 +00:00
|
|
|
if (!isFormValid()) {
|
2020-12-11 20:29:46 +00:00
|
|
|
scrollView.scrollBackUp()
|
|
|
|
return
|
|
|
|
}
|
2021-05-28 02:55:50 +00:00
|
|
|
let error = "";
|
|
|
|
if (!isEdit) {
|
|
|
|
error = chatsModel.createCommunityChannel(communityId,
|
2020-12-11 20:29:46 +00:00
|
|
|
Utils.filterXSS(nameInput.text),
|
2021-05-16 15:16:42 +00:00
|
|
|
Utils.filterXSS(descriptionTextArea.text),
|
2021-05-28 02:55:50 +00:00
|
|
|
categoryId)
|
|
|
|
// TODO: pass the private value when private channels
|
|
|
|
// are implemented
|
|
|
|
//privateSwitch.checked)
|
|
|
|
} else {
|
|
|
|
error = chatsModel.editCommunityChannel(communityId,
|
|
|
|
channel.id,
|
|
|
|
Utils.filterXSS(nameInput.text),
|
|
|
|
Utils.filterXSS(descriptionTextArea.text),
|
|
|
|
categoryId)
|
|
|
|
// TODO: pass the private value when private channels
|
|
|
|
// are implemented
|
|
|
|
//privateSwitch.checked)
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
if (error) {
|
2021-05-28 02:55:50 +00:00
|
|
|
const errorJson = JSON.parse(error)
|
|
|
|
creatingError.text = errorJson.error
|
2020-12-11 20:29:46 +00:00
|
|
|
return creatingError.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Open the community once we have designs for it
|
|
|
|
popup.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageDialog {
|
|
|
|
id: creatingError
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Error creating the community"
|
|
|
|
title: qsTrId("error-creating-the-community")
|
2020-12-11 20:29:46 +00:00
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|