2020-12-11 20:29:46 +00:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.3
|
|
|
|
import QtQuick.Dialogs 1.3
|
2021-10-08 12:26:46 +00:00
|
|
|
import utils 1.0
|
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
|
2022-03-07 14:56:05 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
2021-07-07 12:45:11 +00:00
|
|
|
import StatusQ.Controls 0.1
|
2021-08-16 13:46:00 +00:00
|
|
|
import StatusQ.Controls.Validators 0.1
|
2021-07-07 12:45:11 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
|
|
|
StatusModal {
|
|
|
|
id: popup
|
2021-12-21 09:26:13 +00:00
|
|
|
|
2021-05-28 02:55:50 +00:00
|
|
|
property bool isEdit: false
|
2022-01-31 18:57:05 +00:00
|
|
|
property string chatId: ""
|
2022-01-31 13:33:42 +00:00
|
|
|
property string categoryId: ""
|
2021-12-21 09:26:13 +00:00
|
|
|
property string channelName: ""
|
|
|
|
property string channelDescription: ""
|
2022-03-07 14:56:05 +00:00
|
|
|
property string channelEmoji: ""
|
2022-03-10 19:28:37 +00:00
|
|
|
property string channelColor: ""
|
2022-03-07 14:56:05 +00:00
|
|
|
property bool emojiPopupOpened: false
|
|
|
|
property var emojiPopup: null
|
2022-03-10 19:28:37 +00:00
|
|
|
readonly property var communityColorValidator: Utils.Validate.NoEmpty
|
|
|
|
| Utils.Validate.TextHexColor
|
2021-06-29 12:47:28 +00:00
|
|
|
|
2022-05-09 08:40:27 +00:00
|
|
|
readonly property int maxChannelNameLength: 24
|
2021-06-29 12:47:28 +00:00
|
|
|
readonly property int maxChannelDescLength: 140
|
2022-02-09 09:43:23 +00:00
|
|
|
|
2022-03-10 19:28:37 +00:00
|
|
|
signal createCommunityChannel(string chName, string chDescription, string chEmoji,
|
|
|
|
string chColor, string chCategoryId)
|
|
|
|
signal editCommunityChannel(string chName, string chDescription, string chEmoji, string chColor,
|
|
|
|
string chCategoryId)
|
2021-06-02 19:43:33 +00:00
|
|
|
|
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-09-07 13:23:07 +00:00
|
|
|
contentItem.channelName.input.text = ""
|
2022-03-10 17:01:17 +00:00
|
|
|
contentItem.channelName.input.icon.emoji = ""
|
2022-05-09 16:12:17 +00:00
|
|
|
contentItem.channelName.input.edit.forceActiveFocus(Qt.MouseFocusReason)
|
2021-05-28 02:55:50 +00:00
|
|
|
if (isEdit) {
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Edit #%1"
|
2021-12-21 09:26:13 +00:00
|
|
|
header.title = qsTrId("edit---1").arg(popup.channelName);
|
|
|
|
contentItem.channelName.input.text = popup.channelName
|
|
|
|
contentItem.channelDescription.input.text = popup.channelDescription
|
2022-03-21 20:51:54 +00:00
|
|
|
if (popup.channelEmoji) {
|
|
|
|
contentItem.channelName.input.icon.emoji = popup.channelEmoji
|
|
|
|
} else {
|
|
|
|
// Assign a random emoji to channels who down't have one (from old versions)
|
2022-05-09 16:12:17 +00:00
|
|
|
contentItem.channelName.input.icon.emoji =
|
|
|
|
StatusQUtils.Emoji.getRandomEmoji(StatusQUtils.Emoji.size.verySmall)
|
2022-03-21 20:51:54 +00:00
|
|
|
}
|
2022-03-10 17:01:17 +00:00
|
|
|
scrollView.channelColorDialog.color = popup.channelColor
|
2022-05-09 16:12:17 +00:00
|
|
|
} else {
|
|
|
|
contentItem.channelName.input.icon.emoji =
|
|
|
|
StatusQUtils.Emoji.getRandomEmoji(StatusQUtils.Emoji.size.verySmall)
|
2021-05-28 02:55:50 +00:00
|
|
|
}
|
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
|
|
|
|
2022-03-07 14:56:05 +00:00
|
|
|
Connections {
|
|
|
|
enabled: popup.opened && popup.emojiPopupOpened
|
|
|
|
target: emojiPopup
|
|
|
|
|
|
|
|
onEmojiSelected: function (emojiText, atCursor) {
|
2022-05-09 16:12:17 +00:00
|
|
|
scrollView.channelName.input.icon.emoji = emojiText
|
2022-03-07 14:56:05 +00:00
|
|
|
}
|
|
|
|
onClosed: {
|
|
|
|
popup.emojiPopupOpened = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 12:47:28 +00:00
|
|
|
function isFormValid() {
|
2022-01-13 20:48:03 +00:00
|
|
|
return (scrollView.channelName.valid &&
|
2022-03-10 19:28:37 +00:00
|
|
|
scrollView.channelDescription.valid) &&
|
|
|
|
Utils.validateAndReturnError(scrollView.channelColorDialog.color.toString().toUpperCase(),
|
|
|
|
communityColorValidator) === ""
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 14:40:10 +00:00
|
|
|
contentItem: ScrollView {
|
2021-07-07 12:45:11 +00:00
|
|
|
|
|
|
|
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
|
2022-03-10 19:28:37 +00:00
|
|
|
property alias channelColorDialog: colorDialog
|
2021-07-07 12:45:11 +00:00
|
|
|
|
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
|
2022-03-10 17:01:17 +00:00
|
|
|
width: popup.width
|
2021-07-07 12:45:11 +00:00
|
|
|
|
2021-08-16 13:46:00 +00:00
|
|
|
StatusInput {
|
|
|
|
id: nameInput
|
2022-03-10 19:28:37 +00:00
|
|
|
label: qsTr("Channel name")
|
2021-08-16 13:46:00 +00:00
|
|
|
charLimit: popup.maxChannelNameLength
|
2022-05-09 08:40:27 +00:00
|
|
|
input.placeholderText: qsTr("# Name the channel")
|
2021-08-16 13:46:00 +00:00
|
|
|
input.onTextChanged: {
|
|
|
|
input.text = Utils.convertSpacesToDashesAndUpperToLowerCase(input.text);
|
|
|
|
input.cursorPosition = input.text.length
|
2021-03-29 12:28:41 +00:00
|
|
|
}
|
2022-03-10 17:01:17 +00:00
|
|
|
input.isIconSelectable: true
|
|
|
|
input.icon.color: colorDialog.color.toString()
|
2022-05-09 16:12:17 +00:00
|
|
|
input.leftPadding: 16
|
2022-03-10 17:01:17 +00:00
|
|
|
onIconClicked: {
|
|
|
|
popup.emojiPopupOpened = true
|
|
|
|
popup.emojiPopup.open()
|
2022-05-09 16:12:17 +00:00
|
|
|
popup.emojiPopup.emojiSize = StatusQUtils.Emoji.size.verySmall
|
2022-03-10 17:01:17 +00:00
|
|
|
popup.emojiPopup.x = popup.x + Style.current.padding
|
|
|
|
popup.emojiPopup.y = popup.y + nameInput.height + 2*Style.current.xlPadding
|
|
|
|
}
|
2022-01-13 20:48:03 +00:00
|
|
|
validationMode: StatusInput.ValidationMode.Always
|
2022-05-09 08:40:27 +00:00
|
|
|
validators: [
|
|
|
|
StatusMinLengthValidator {
|
|
|
|
minLength: 1
|
|
|
|
errorMessage: Utils.getErrorMessage(nameInput.errors, qsTr("channel name"))
|
|
|
|
}
|
|
|
|
]
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2022-03-10 19:28:37 +00:00
|
|
|
Item {
|
|
|
|
id: spacer1
|
|
|
|
height: 16
|
|
|
|
width: parent.width
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
2022-05-09 16:12:17 +00:00
|
|
|
text: qsTr("Channel colour")
|
2022-03-10 19:28:37 +00:00
|
|
|
font.pixelSize: 15
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 16
|
|
|
|
}
|
|
|
|
|
2022-05-09 16:12:17 +00:00
|
|
|
Item {
|
|
|
|
id: spacer2
|
|
|
|
height: 8
|
|
|
|
width: parent.width
|
|
|
|
}
|
|
|
|
|
2022-03-10 19:28:37 +00:00
|
|
|
Item {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
height: colorSelectorButton.height + 16
|
|
|
|
width: parent.width - 32
|
|
|
|
|
|
|
|
StatusPickerButton {
|
|
|
|
id: colorSelectorButton
|
|
|
|
|
|
|
|
property string validationError: ""
|
|
|
|
|
|
|
|
bgColor: colorDialog.colorSelected ?
|
|
|
|
colorDialog.color : Theme.palette.baseColor2
|
|
|
|
// TODO adjust text color depending on the background color to make it readable
|
|
|
|
// contentColor: colorDialog.colorSelected ? Theme.palette.indirectColor1 : Theme.palette.baseColor1
|
|
|
|
text: colorDialog.colorSelected ?
|
|
|
|
colorDialog.color.toString().toUpperCase() :
|
|
|
|
//% "Pick a color"
|
|
|
|
qsTrId("pick-a-color")
|
|
|
|
|
|
|
|
onClicked: colorDialog.open();
|
|
|
|
onTextChanged: {
|
|
|
|
if (colorDialog.colorSelected) {
|
|
|
|
validationError = Utils.validateAndReturnError(text, communityColorValidator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorDialog {
|
|
|
|
id: colorDialog
|
|
|
|
property bool colorSelected: popup.isEdit && popup.channelColor
|
|
|
|
color: popup.isEdit && popup.channelColor ? popup.channelColor :
|
|
|
|
Theme.palette.primaryColor1
|
|
|
|
onAccepted: colorSelected = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
text: colorSelectorButton.validationError
|
|
|
|
visible: !!text
|
|
|
|
color: Theme.palette.dangerColor1
|
|
|
|
anchors.top: colorSelectorButton.bottom
|
|
|
|
anchors.topMargin: 4
|
|
|
|
anchors.right: colorSelectorButton.right
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
|
|
|
|
2021-08-16 13:46:00 +00:00
|
|
|
StatusInput {
|
|
|
|
id: descriptionTextArea
|
|
|
|
label: qsTr("Description")
|
|
|
|
charLimit: 140
|
|
|
|
|
|
|
|
input.placeholderText: qsTr("Describe the channel")
|
|
|
|
input.multiline: true
|
|
|
|
input.implicitHeight: 88
|
2022-01-13 20:48:03 +00:00
|
|
|
validationMode: StatusInput.ValidationMode.Always
|
2021-09-20 03:00:50 +00:00
|
|
|
validators: [StatusMinLengthValidator {
|
|
|
|
minLength: 1
|
2021-11-03 13:25:56 +00:00
|
|
|
errorMessage: Utils.getErrorMessage(descriptionTextArea.errors, qsTr("channel description"))
|
2021-09-20 03:00:50 +00:00
|
|
|
}]
|
2021-05-28 02:55:50 +00:00
|
|
|
}
|
2021-08-16 13:46:00 +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
|
|
|
/* } */
|
|
|
|
|
2021-09-07 13:23:07 +00:00
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
height: 8
|
|
|
|
}
|
2020-12-11 20:29:46 +00:00
|
|
|
}
|
2021-07-07 12:45:11 +00:00
|
|
|
}
|
2022-02-09 09:43:23 +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 = "";
|
2022-04-04 16:55:56 +00:00
|
|
|
let emoji = StatusQUtils.Emoji.deparseFromParse(popup.contentItem.channelName.input.icon.emoji)
|
2022-03-21 20:51:54 +00:00
|
|
|
|
2021-07-07 12:45:11 +00:00
|
|
|
if (!isEdit) {
|
2022-03-10 19:28:37 +00:00
|
|
|
//popup.contentItem.communityColor.color.toString().toUpperCase()
|
2021-12-21 09:26:13 +00:00
|
|
|
popup.createCommunityChannel(Utils.filterXSS(popup.contentItem.channelName.input.text),
|
2022-01-31 13:33:42 +00:00
|
|
|
Utils.filterXSS(popup.contentItem.channelDescription.input.text),
|
2022-03-21 20:51:54 +00:00
|
|
|
emoji,
|
2022-03-10 19:28:37 +00:00
|
|
|
popup.contentItem.channelColorDialog.color.toString().toUpperCase(),
|
2022-01-31 13:33:42 +00:00
|
|
|
popup.categoryId)
|
2021-07-07 12:45:11 +00:00
|
|
|
} else {
|
2021-12-21 09:26:13 +00:00
|
|
|
popup.editCommunityChannel(Utils.filterXSS(popup.contentItem.channelName.input.text),
|
2022-01-31 18:57:05 +00:00
|
|
|
Utils.filterXSS(popup.contentItem.channelDescription.input.text),
|
2022-03-21 20:51:54 +00:00
|
|
|
emoji,
|
2022-03-10 19:28:37 +00:00
|
|
|
popup.contentItem.channelColorDialog.color.toString().toUpperCase(),
|
2022-01-31 18:57:05 +00:00
|
|
|
popup.categoryId)
|
2021-07-07 12:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|