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
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
|
|
|
StatusModal {
|
|
|
|
id: popup
|
2020-12-11 20:29:46 +00:00
|
|
|
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
|
|
|
|
|
2021-07-22 15:03:59 +00:00
|
|
|
//% "New channel"
|
|
|
|
header.title: qsTrId("create-channel-title")
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
onOpened: {
|
2021-07-07 12:45:11 +00:00
|
|
|
contentComponent.channelName.text = ""
|
2021-05-28 02:55:50 +00:00
|
|
|
if (isEdit) {
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Edit #%1"
|
|
|
|
header.title = qsTrId("edit---1").arg(channel.name);
|
2021-07-15 11:05:17 +00:00
|
|
|
contentComponent.channelName.text = channel.name
|
2021-05-28 02:55:50 +00:00
|
|
|
}
|
2021-07-07 12:45:11 +00:00
|
|
|
contentComponent.channelName.forceActiveFocus(Qt.MouseFocusReason)
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
2021-07-07 12:45:11 +00:00
|
|
|
|
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() {
|
2021-07-07 12:45:11 +00:00
|
|
|
return Utils.validateAndReturnError(contentComponent.channelName.text,
|
2021-06-29 12:47:28 +00:00
|
|
|
channelNameValidator,
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "channel name"
|
|
|
|
qsTrId("channel-name"),
|
2021-06-29 12:47:28 +00:00
|
|
|
maxChannelNameLength) === ""
|
2021-07-07 12:45:11 +00:00
|
|
|
&& Utils.validateAndReturnError(contentComponent.channelDescription.text,
|
2021-06-29 12:47:28 +00:00
|
|
|
channelDescValidator,
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "channel decription"
|
|
|
|
qsTrId("channel-decription"),
|
2021-06-29 12:47:28 +00:00
|
|
|
maxChannelDescLength) === ""
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
content: ScrollView {
|
|
|
|
|
|
|
|
id: scrollView
|
2020-12-11 20:29:46 +00:00
|
|
|
|
|
|
|
property ScrollBar vScrollBar: ScrollBar.vertical
|
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
property alias channelName: nameInput
|
|
|
|
property alias channelDescription: descriptionTextArea
|
|
|
|
|
2020-12-11 20:29:46 +00:00
|
|
|
contentHeight: content.height
|
2021-07-07 12:45:11 +00:00
|
|
|
height: Math.min(content.height, 432)
|
|
|
|
width: popup.width
|
|
|
|
|
2020-12-11 20:29:46 +00:00
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
function scrollBackUp() {
|
|
|
|
vScrollBar.setPosition(0)
|
|
|
|
}
|
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
Column {
|
2020-12-11 20:29:46 +00:00
|
|
|
id: content
|
2021-07-07 12:45:11 +00:00
|
|
|
width: popup.width
|
|
|
|
|
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
height: 76
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: nameInput
|
|
|
|
width: parent.width - 32
|
|
|
|
anchors.centerIn: parent
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Channel name"
|
|
|
|
placeholderText: qsTrId("name-your-channel-placeholder")
|
2021-07-07 12:45:11 +00:00
|
|
|
maxLength: popup.maxChannelNameLength
|
|
|
|
|
|
|
|
onTextEdited: {
|
|
|
|
text = Utils.convertSpacesToDashesAndUpperToLowerCase(text);
|
|
|
|
|
|
|
|
validationError = Utils.validateAndReturnError(text,
|
|
|
|
channelNameValidator,
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "channel name"
|
|
|
|
qsTrId("channel-name"),
|
2021-07-07 12:45:11 +00:00
|
|
|
maxChannelNameLength)
|
2021-03-29 12:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
StatusModalDivider {
|
|
|
|
topPadding: 8
|
|
|
|
bottomPadding: 8
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
Item {
|
|
|
|
height: descriptionTextArea.height + 26
|
|
|
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.leftMargin: 16
|
|
|
|
anchors.rightMargin: 16
|
|
|
|
|
|
|
|
StyledTextArea {
|
|
|
|
id: descriptionTextArea
|
|
|
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 10
|
2021-06-02 19:15:46 +00:00
|
|
|
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Description"
|
|
|
|
label: qsTrId("description")
|
|
|
|
//% "Describe the channel"
|
|
|
|
placeholderText: qsTrId("describe-channel")
|
2021-07-07 12:45:11 +00:00
|
|
|
|
|
|
|
customHeight: 88
|
|
|
|
|
|
|
|
text: popup.isEdit ? popup.channel.description : ""
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
if(text.length > maxChannelDescLength)
|
|
|
|
{
|
|
|
|
textField.remove(maxChannelDescLength, text.length)
|
|
|
|
return
|
2021-06-02 19:15:46 +00:00
|
|
|
}
|
2021-07-07 12:45:11 +00:00
|
|
|
|
|
|
|
validationError = Utils.validateAndReturnError(text,
|
|
|
|
channelDescValidator,
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "channel description"
|
|
|
|
qsTrId("channel-description"),
|
2021-07-07 12:45:11 +00:00
|
|
|
maxChannelDescLength)
|
2021-06-02 19:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
StyledText {
|
|
|
|
id: charLimit
|
|
|
|
text: `${descriptionTextArea.text.length}/${maxChannelDescLength}`
|
|
|
|
anchors.top: descriptionTextArea.top
|
|
|
|
anchors.right: descriptionTextArea.right
|
|
|
|
font.pixelSize: 12
|
|
|
|
color: !descriptionTextArea.validationError ? Theme.palette.baseColor1 : Theme.palette.dangerColor1
|
|
|
|
}
|
2021-05-28 02:55:50 +00:00
|
|
|
}
|
2021-07-07 12:45:11 +00:00
|
|
|
|
|
|
|
/* TODO: use the code below to enable private channels and message limit */
|
|
|
|
/* StatusListItem { */
|
|
|
|
/* width: parent.width */
|
|
|
|
/* height: 56 */
|
|
|
|
/* sensor.enabled: false */
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Private channel"
|
|
|
|
/* title: qsTrId("private-channel") */
|
2021-07-07 12:45:11 +00:00
|
|
|
/* components: [ */
|
|
|
|
/* StatusSwitch { */
|
|
|
|
/* id: privateSwitch */
|
|
|
|
/* } */
|
|
|
|
/* ] */
|
|
|
|
/* } */
|
|
|
|
|
|
|
|
/* StatusBaseText { */
|
|
|
|
/* width: parent.width - 32 */
|
|
|
|
/* anchors.left: parent.left */
|
|
|
|
/* anchors.right: parent.right */
|
|
|
|
/* anchors.rightMargin: 121 */
|
|
|
|
/* anchors.leftMargin: 16 */
|
|
|
|
/* color: Theme.palette.baseColor1 */
|
|
|
|
/* wrapMode: Text.WordWrap */
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "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-07-07 12:45:11 +00:00
|
|
|
/* } */
|
|
|
|
|
|
|
|
/* StatusModalDivider { */
|
|
|
|
/* topPadding: 8 */
|
|
|
|
/* bottomPadding: 8 */
|
|
|
|
/* } */
|
|
|
|
|
|
|
|
/* StatusListItem { */
|
|
|
|
/* width: parent.width */
|
|
|
|
/* height: 56 */
|
|
|
|
/* sensor.enabled: false */
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Message limit"
|
|
|
|
/* title: qsTrId("message-limit") */
|
2021-07-07 12:45:11 +00:00
|
|
|
/* components: [ */
|
|
|
|
/* StatusSwitch {} */
|
|
|
|
/* ] */
|
|
|
|
/* } */
|
|
|
|
|
|
|
|
/* StatusBaseText { */
|
|
|
|
/* width: parent.width - 32 */
|
|
|
|
/* anchors.left: parent.left */
|
|
|
|
/* anchors.right: parent.right */
|
|
|
|
/* anchors.rightMargin: 121 */
|
|
|
|
/* anchors.leftMargin: 16 */
|
|
|
|
/* color: Theme.palette.baseColor1 */
|
|
|
|
/* wrapMode: Text.WordWrap */
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Limit channel members to sending one message per chose time interval"
|
|
|
|
/* text: qsTrId("limit-channel-members-to-sending-one-message-per-chose-time-interval") */
|
2021-07-07 12:45:11 +00:00
|
|
|
/* } */
|
|
|
|
|
|
|
|
StatusListItem {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Pinned messages"
|
|
|
|
title: qsTrId("pinned-messages")
|
2021-07-07 12:45:11 +00:00
|
|
|
icon.name: "pin"
|
|
|
|
label: chatsModel.messageView.pinnedMessagesList.count
|
|
|
|
components: [
|
|
|
|
StatusIcon {
|
|
|
|
icon: "chevron-down"
|
|
|
|
rotation: 270
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
|
|
|
]
|
2020-12-11 20:29:46 +00:00
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
sensor.onClicked: openPopup(pinnedMessagesPopupComponent)
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
StatusModalDivider {
|
|
|
|
topPadding: 8
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
2021-07-07 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rightButtons: [
|
|
|
|
StatusButton {
|
|
|
|
enabled: isFormValid()
|
|
|
|
text: isEdit ?
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Save"
|
|
|
|
qsTrId("save") :
|
|
|
|
//% "Create"
|
|
|
|
qsTrId("create")
|
2021-07-07 12:45:11 +00:00
|
|
|
onClicked: {
|
|
|
|
if (!isFormValid()) {
|
|
|
|
scrollView.scrollBackUp()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let error = "";
|
|
|
|
if (!isEdit) {
|
|
|
|
error = chatsModel.createCommunityChannel(communityId,
|
|
|
|
Utils.filterXSS(popup.contentComponent.channelName.text),
|
|
|
|
Utils.filterXSS(popup.contentComponent.channelDescription.text),
|
|
|
|
categoryId)
|
|
|
|
// TODO: pass the private value when private channels
|
|
|
|
// are implemented
|
|
|
|
//privateSwitch.checked)
|
|
|
|
} else {
|
|
|
|
error = chatsModel.editCommunityChannel(communityId,
|
|
|
|
channel.id,
|
|
|
|
Utils.filterXSS(popup.contentComponent.channelName.text),
|
|
|
|
Utils.filterXSS(popup.contentComponent.channelDescription.text),
|
2021-07-22 13:51:48 +00:00
|
|
|
channel.categoryId)
|
2021-07-07 12:45:11 +00:00
|
|
|
// TODO: pass the private value when private channels
|
|
|
|
// are implemented
|
|
|
|
//privateSwitch.checked)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
const errorJson = JSON.parse(error)
|
|
|
|
creatingError.text = errorJson.error
|
|
|
|
return creatingError.open()
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
// TODO Open the community once we have designs for it
|
|
|
|
popup.close()
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
2021-07-07 12:45:11 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
MessageDialog {
|
|
|
|
id: creatingError
|
|
|
|
//% "Error creating the community"
|
|
|
|
title: qsTrId("error-creating-the-community")
|
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|