2022-06-09 15:27:14 +00:00
|
|
|
import QtQuick 2.14
|
2023-01-17 12:22:28 +00:00
|
|
|
import QtQuick.Controls 2.14
|
2022-06-09 15:27:14 +00:00
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
2022-11-25 17:35:30 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
|
2023-02-09 16:18:17 +00:00
|
|
|
import AppLayouts.Chat.helpers 1.0
|
2023-01-17 12:22:28 +00:00
|
|
|
import AppLayouts.Chat.panels.communities 1.0
|
2022-12-06 11:19:20 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
import "../../../Chat/controls/community"
|
|
|
|
|
2022-12-13 13:09:38 +00:00
|
|
|
StatusScrollView {
|
2022-06-09 15:27:14 +00:00
|
|
|
id: root
|
|
|
|
|
2022-12-20 00:54:50 +00:00
|
|
|
property var rootStore
|
2022-11-25 17:35:30 +00:00
|
|
|
property var store
|
2022-12-20 00:54:50 +00:00
|
|
|
|
2022-11-25 17:35:30 +00:00
|
|
|
property int viewWidth: 560 // by design
|
2022-11-24 16:23:54 +00:00
|
|
|
property bool isEditState: false
|
2023-02-10 22:40:07 +00:00
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
readonly property bool dirty:
|
|
|
|
!holdingsModelComparator.equal ||
|
|
|
|
!channelsModelComparator.equal ||
|
|
|
|
root.isPrivate !== d.dirtyValues.isPrivate ||
|
|
|
|
root.permissionType !== d.dirtyValues.permissionType
|
2022-11-24 16:23:54 +00:00
|
|
|
|
2023-02-14 23:53:01 +00:00
|
|
|
readonly property alias dirtyValues: d.dirtyValues
|
|
|
|
|
|
|
|
readonly property bool isFullyFilled:
|
|
|
|
dirtyValues.holdingsModel.count > 0 &&
|
|
|
|
dirtyValues.permissionType !== PermissionTypes.Type.None &&
|
|
|
|
(d.isCommunityPermission || dirtyValues.channelsModel.count > 0)
|
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
property int permissionType: PermissionTypes.Type.None
|
|
|
|
property bool isPrivate: false
|
2023-02-08 10:13:16 +00:00
|
|
|
|
2023-01-12 11:31:08 +00:00
|
|
|
// roles: type, key, name, amount, imageSource
|
2022-11-24 16:23:54 +00:00
|
|
|
property var holdingsModel: ListModel {}
|
|
|
|
|
2023-01-27 09:22:04 +00:00
|
|
|
// roles: itemId, text, emoji, color
|
2022-11-24 16:23:54 +00:00
|
|
|
property var channelsModel: ListModel {}
|
|
|
|
|
2023-02-14 20:39:18 +00:00
|
|
|
property alias duplicationWarningVisible: duplicationPanel.visible
|
|
|
|
|
2023-02-08 23:22:57 +00:00
|
|
|
signal createPermissionClicked
|
|
|
|
|
|
|
|
function resetChanges() {
|
|
|
|
d.loadInitValues()
|
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
|
2023-02-09 22:31:34 +00:00
|
|
|
ModelsComparator {
|
|
|
|
id: holdingsModelComparator
|
|
|
|
|
|
|
|
modelA: root.dirtyValues.holdingsModel
|
|
|
|
modelB: root.holdingsModel
|
|
|
|
|
|
|
|
roles: ["key", "name", "shortName", "amount"]
|
|
|
|
mode: ModelsComparator.CompareMode.Set
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelsComparator {
|
|
|
|
id: channelsModelComparator
|
|
|
|
|
|
|
|
modelA: root.dirtyValues.channelsModel
|
|
|
|
modelB: root.channelsModel
|
|
|
|
|
|
|
|
roles: ["itemId", "text", "emoji", "color"]
|
|
|
|
mode: ModelsComparator.CompareMode.Set
|
|
|
|
}
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
2022-12-20 00:54:50 +00:00
|
|
|
|
2023-01-19 17:36:06 +00:00
|
|
|
readonly property int maxHoldingsItems: 5
|
|
|
|
|
2022-12-20 00:54:50 +00:00
|
|
|
readonly property int dropdownHorizontalOffset: 4
|
|
|
|
readonly property int dropdownVerticalOffset: 1
|
|
|
|
|
2023-01-20 11:15:05 +00:00
|
|
|
readonly property bool isCommunityPermission:
|
2023-02-14 23:53:01 +00:00
|
|
|
PermissionTypes.isCommunityPermission(dirtyValues.permissionType)
|
2023-01-20 11:22:04 +00:00
|
|
|
|
2023-01-20 11:15:05 +00:00
|
|
|
onIsCommunityPermissionChanged: {
|
|
|
|
if (isCommunityPermission) {
|
2023-01-27 09:22:04 +00:00
|
|
|
d.dirtyValues.channelsModel.clear()
|
2023-01-20 11:15:05 +00:00
|
|
|
inSelector.wholeCommunitySelected = true
|
|
|
|
inSelector.itemsModel = inModelCommunity
|
|
|
|
} else {
|
|
|
|
inSelector.itemsModel = 0
|
|
|
|
inSelector.wholeCommunitySelected = false
|
2023-01-27 09:22:04 +00:00
|
|
|
inSelector.itemsModel = d.dirtyValues.channelsModel
|
2023-01-20 11:15:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 23:22:57 +00:00
|
|
|
readonly property QtObject dirtyValues: QtObject {
|
|
|
|
readonly property ListModel holdingsModel: ListModel {}
|
|
|
|
readonly property ListModel channelsModel: ListModel {}
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
property int permissionType: PermissionTypes.Type.None
|
2023-02-08 12:39:47 +00:00
|
|
|
property bool isPrivate: false
|
2022-11-24 16:23:54 +00:00
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
Binding on isPrivate {
|
|
|
|
value: (d.dirtyValues.permissionType === PermissionTypes.Type.Admin) ||
|
|
|
|
(d.dirtyValues.permissionType === PermissionTypes.Type.Moderator)
|
|
|
|
}
|
|
|
|
|
2023-02-09 16:18:17 +00:00
|
|
|
function getHoldingIndex(key) {
|
|
|
|
return ModelUtils.indexOf(holdingsModel, "key", key)
|
2023-01-24 21:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTokenKeysAndAmounts() {
|
2023-02-09 16:18:17 +00:00
|
|
|
return ModelUtils.modelToArray(holdingsModel, ["type", "key", "amount"])
|
|
|
|
.filter(item => item.type !== HoldingTypes.Type.Ens)
|
|
|
|
.map(item => ({ key: item.key, amount: item.amount }))
|
2023-01-24 21:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEnsNames() {
|
2023-02-09 16:18:17 +00:00
|
|
|
return ModelUtils.modelToArray(holdingsModel, ["type", "name"])
|
|
|
|
.filter(item => item.type === HoldingTypes.Type.Ens)
|
|
|
|
.map(item => item.name)
|
2023-01-24 21:49:07 +00:00
|
|
|
}
|
2022-11-24 16:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadInitValues() {
|
|
|
|
// Holdings:
|
|
|
|
d.dirtyValues.holdingsModel.clear()
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2023-02-09 16:18:17 +00:00
|
|
|
d.dirtyValues.holdingsModel.append(
|
2023-02-13 10:40:13 +00:00
|
|
|
ModelUtils.modelToArray(root.holdingsModel, ["type", "key", "amount"]))
|
2022-11-24 16:23:54 +00:00
|
|
|
|
|
|
|
// Permissions:
|
2023-02-11 19:03:57 +00:00
|
|
|
d.dirtyValues.permissionType = root.permissionType
|
2023-01-27 09:22:04 +00:00
|
|
|
|
|
|
|
// Channels
|
|
|
|
d.dirtyValues.channelsModel.clear()
|
|
|
|
|
2023-02-09 16:18:17 +00:00
|
|
|
d.dirtyValues.channelsModel.append(
|
|
|
|
ModelUtils.modelToArray(root.channelsModel,
|
|
|
|
["itemId", "text", "emoji", "color", "operator"]))
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
if (root.channelsModel && (root.channelsModel.count || d.dirtyValues.permissionType === PermissionTypes.Type.None)) {
|
2023-01-27 09:22:04 +00:00
|
|
|
inSelector.wholeCommunitySelected = false
|
|
|
|
inSelector.itemsModel = d.dirtyValues.channelsModel
|
|
|
|
} else {
|
|
|
|
inSelector.wholeCommunitySelected = true
|
|
|
|
inSelector.itemsModel = inModelCommunity
|
|
|
|
}
|
2022-11-24 16:23:54 +00:00
|
|
|
|
|
|
|
// Is private permission
|
2023-02-08 12:39:47 +00:00
|
|
|
d.dirtyValues.isPrivate = root.isPrivate
|
2022-11-24 16:23:54 +00:00
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contentWidth: mainLayout.width
|
|
|
|
contentHeight: mainLayout.height
|
|
|
|
|
2023-02-14 20:39:18 +00:00
|
|
|
onPermissionTypeChanged: Qt.callLater(() => d.loadInitValues())
|
2022-11-24 16:23:54 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
ColumnLayout {
|
|
|
|
id: mainLayout
|
2022-11-25 17:35:30 +00:00
|
|
|
width: root.viewWidth
|
2022-06-09 15:27:14 +00:00
|
|
|
spacing: 0
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
CurveSeparatorWithText {
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
Layout.leftMargin: 14
|
|
|
|
text: qsTr("Anyone")
|
|
|
|
}
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
StatusItemSelector {
|
|
|
|
id: tokensSelector
|
2023-01-18 19:54:14 +00:00
|
|
|
|
2023-01-24 21:49:07 +00:00
|
|
|
property int editedIndex: -1
|
2023-01-18 19:54:14 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
icon: Style.svg("contact_verified")
|
|
|
|
title: qsTr("Who holds")
|
|
|
|
defaultItemText: qsTr("Example: 10 SNT")
|
2022-12-21 13:59:43 +00:00
|
|
|
tagLeftPadding: 2
|
|
|
|
asset.height: 28
|
|
|
|
asset.width: asset.height
|
2023-01-19 17:36:06 +00:00
|
|
|
addButton.visible: itemsModel.count < d.maxHoldingsItems
|
2022-09-07 09:40:25 +00:00
|
|
|
|
2023-02-13 10:40:13 +00:00
|
|
|
itemsModel: HoldingsSelectionModel {
|
|
|
|
sourceModel: d.dirtyValues.holdingsModel
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2023-02-13 10:40:13 +00:00
|
|
|
assetsModel: root.store.assetsModel
|
|
|
|
collectiblesModel: root.store.collectiblesModel
|
2022-09-07 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HoldingsDropdown {
|
2022-06-09 15:27:14 +00:00
|
|
|
id: dropdown
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
store: root.store
|
2022-09-07 09:40:25 +00:00
|
|
|
|
2023-01-12 11:31:08 +00:00
|
|
|
function addItem(type, item, amount) {
|
2022-09-07 09:40:25 +00:00
|
|
|
const key = item.key
|
|
|
|
|
2023-02-13 10:40:13 +00:00
|
|
|
d.dirtyValues.holdingsModel.append({ type, key, amount })
|
2022-09-07 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-24 21:49:07 +00:00
|
|
|
function prepareUpdateIndex(key) {
|
|
|
|
const itemIndex = tokensSelector.editedIndex
|
2023-02-09 16:18:17 +00:00
|
|
|
const existingIndex = d.dirtyValues.getHoldingIndex(key)
|
2023-01-24 21:49:07 +00:00
|
|
|
|
|
|
|
if (itemIndex !== -1 && existingIndex !== -1 && itemIndex !== existingIndex) {
|
|
|
|
const previousKey = d.dirtyValues.holdingsModel.get(itemIndex).key
|
|
|
|
d.dirtyValues.holdingsModel.remove(existingIndex)
|
2023-02-09 16:18:17 +00:00
|
|
|
return d.dirtyValues.getHoldingIndex(previousKey)
|
2023-01-24 21:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (itemIndex === -1) {
|
|
|
|
return existingIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
usedTokens = d.dirtyValues.getTokenKeysAndAmounts()
|
|
|
|
usedEnsNames = d.dirtyValues.getEnsNames().filter(item => item !== ensDomainName)
|
|
|
|
}
|
|
|
|
|
2023-01-12 13:18:52 +00:00
|
|
|
onAddAsset: {
|
2023-01-18 19:54:14 +00:00
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(store.assetsModel, key)
|
2023-01-12 13:18:52 +00:00
|
|
|
addItem(HoldingTypes.Type.Asset, modelItem, amount)
|
2022-09-07 09:40:25 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onAddCollectible: {
|
2023-01-18 19:54:14 +00:00
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(store.collectiblesModel, key)
|
2023-01-12 11:31:08 +00:00
|
|
|
addItem(HoldingTypes.Type.Collectible, modelItem, amount)
|
2022-09-07 09:40:25 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onAddEns: {
|
2023-02-13 10:40:13 +00:00
|
|
|
d.dirtyValues.holdingsModel.append(
|
|
|
|
{ type: HoldingTypes.Type.Ens, key: domain, amount: 1 })
|
2022-09-07 09:40:25 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
2023-01-12 13:18:52 +00:00
|
|
|
onUpdateAsset: {
|
2023-01-24 21:49:07 +00:00
|
|
|
const itemIndex = prepareUpdateIndex(key)
|
2023-01-18 19:54:14 +00:00
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(store.assetsModel, key)
|
2022-09-07 09:40:25 +00:00
|
|
|
|
2023-02-13 10:40:13 +00:00
|
|
|
d.dirtyValues.holdingsModel.set(itemIndex,
|
|
|
|
{ type: HoldingTypes.Type.Asset, key, amount })
|
2022-06-09 15:27:14 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
|
|
onUpdateCollectible: {
|
2023-01-24 21:49:07 +00:00
|
|
|
const itemIndex = prepareUpdateIndex(key)
|
2023-01-18 19:54:14 +00:00
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(store.collectiblesModel, key)
|
2022-09-07 09:40:25 +00:00
|
|
|
|
2023-02-13 10:40:13 +00:00
|
|
|
d.dirtyValues.holdingsModel.set(itemIndex,
|
|
|
|
{ type: HoldingTypes.Type.Collectible, key, amount })
|
2022-09-07 09:40:25 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onUpdateEns: {
|
2023-02-13 10:40:13 +00:00
|
|
|
d.dirtyValues.holdingsModel.set(tokensSelector.editedIndex,
|
|
|
|
{ type: HoldingTypes.Type.Ens, key: domain, amount: 1 })
|
2022-09-07 09:40:25 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onRemoveClicked: {
|
2022-11-24 16:23:54 +00:00
|
|
|
d.dirtyValues.holdingsModel.remove(tokensSelector.editedIndex)
|
2022-09-07 09:40:25 +00:00
|
|
|
dropdown.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addButton.onClicked: {
|
|
|
|
dropdown.parent = tokensSelector.addButton
|
2022-12-20 00:54:50 +00:00
|
|
|
dropdown.x = tokensSelector.addButton.width + d.dropdownHorizontalOffset
|
2022-09-07 09:40:25 +00:00
|
|
|
dropdown.y = 0
|
2023-01-18 19:54:14 +00:00
|
|
|
dropdown.open()
|
2023-01-24 21:49:07 +00:00
|
|
|
|
|
|
|
editedIndex = -1
|
2022-09-07 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onItemClicked: {
|
|
|
|
if (mouse.button !== Qt.LeftButton)
|
|
|
|
return
|
|
|
|
|
|
|
|
dropdown.parent = item
|
2022-12-20 00:54:50 +00:00
|
|
|
dropdown.x = mouse.x + d.dropdownHorizontalOffset
|
|
|
|
dropdown.y = d.dropdownVerticalOffset
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
|
|
const modelItem = tokensSelector.itemsModel.get(index)
|
|
|
|
|
|
|
|
switch(modelItem.type) {
|
2023-01-12 13:18:52 +00:00
|
|
|
case HoldingTypes.Type.Asset:
|
|
|
|
dropdown.assetKey = modelItem.key
|
|
|
|
dropdown.assetAmount = modelItem.amount
|
2022-09-07 09:40:25 +00:00
|
|
|
break
|
|
|
|
case HoldingTypes.Type.Collectible:
|
|
|
|
dropdown.collectibleKey = modelItem.key
|
|
|
|
dropdown.collectibleAmount = modelItem.amount
|
|
|
|
break
|
|
|
|
case HoldingTypes.Type.Ens:
|
2023-02-13 10:40:13 +00:00
|
|
|
dropdown.ensDomainName = modelItem.key
|
2022-09-07 09:40:25 +00:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
console.warn("Unsupported holdings type.")
|
|
|
|
}
|
|
|
|
|
2022-09-15 10:12:38 +00:00
|
|
|
dropdown.setActiveTab(modelItem.type)
|
2023-01-18 19:54:14 +00:00
|
|
|
dropdown.openUpdateFlow()
|
2022-09-15 10:12:38 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
editedIndex = index
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.preferredWidth: 2
|
|
|
|
Layout.preferredHeight: 24
|
|
|
|
color: Style.current.separator
|
|
|
|
}
|
|
|
|
StatusItemSelector {
|
2022-09-09 22:09:37 +00:00
|
|
|
id: permissionsSelector
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
icon: Style.svg("profile/security")
|
|
|
|
iconSize: 24
|
2022-09-09 22:09:37 +00:00
|
|
|
useIcons: true
|
2022-06-09 15:27:14 +00:00
|
|
|
title: qsTr("Is allowed to")
|
|
|
|
defaultItemText: qsTr("Example: View and post")
|
2022-09-09 22:09:37 +00:00
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
QtObject {
|
|
|
|
id: permissionItemModelData
|
|
|
|
|
|
|
|
readonly property int key: d.dirtyValues.permissionType
|
|
|
|
readonly property string text: PermissionTypes.getName(key)
|
|
|
|
readonly property string imageSource: PermissionTypes.getIcon(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
itemsModel: d.dirtyValues.permissionType !== PermissionTypes.Type.None
|
|
|
|
? permissionItemModelData : null
|
|
|
|
|
|
|
|
addButton.visible: d.dirtyValues.permissionType === PermissionTypes.Type.None
|
2022-09-09 22:09:37 +00:00
|
|
|
|
|
|
|
PermissionsDropdown {
|
|
|
|
id: permissionsDropdown
|
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
initialPermissionType: d.dirtyValues.permissionType
|
2023-01-20 11:22:04 +00:00
|
|
|
enableAdminPermission: root.store.isOwner
|
2022-09-09 22:09:37 +00:00
|
|
|
|
|
|
|
onDone: {
|
2023-02-11 19:03:57 +00:00
|
|
|
if (d.dirtyValues.permissionType === permissionType) {
|
2023-01-20 11:15:05 +00:00
|
|
|
permissionsDropdown.close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
d.dirtyValues.permissionType = permissionType
|
2022-09-09 22:09:37 +00:00
|
|
|
permissionsDropdown.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addButton.onClicked: {
|
|
|
|
permissionsDropdown.mode = PermissionsDropdown.Mode.Add
|
|
|
|
permissionsDropdown.parent = permissionsSelector.addButton
|
2022-12-20 00:54:50 +00:00
|
|
|
permissionsDropdown.x = permissionsSelector.addButton.width
|
|
|
|
+ d.dropdownHorizontalOffset
|
2022-09-09 22:09:37 +00:00
|
|
|
permissionsDropdown.y = 0
|
|
|
|
permissionsDropdown.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemClicked: {
|
|
|
|
if (mouse.button !== Qt.LeftButton)
|
|
|
|
return
|
|
|
|
|
|
|
|
permissionsDropdown.mode = PermissionsDropdown.Mode.Update
|
|
|
|
permissionsDropdown.parent = item
|
2022-12-20 00:54:50 +00:00
|
|
|
permissionsDropdown.x = mouse.x + d.dropdownHorizontalOffset
|
|
|
|
permissionsDropdown.y = d.dropdownVerticalOffset
|
2022-09-09 22:09:37 +00:00
|
|
|
permissionsDropdown.open()
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.preferredWidth: 2
|
|
|
|
Layout.preferredHeight: 24
|
|
|
|
color: Style.current.separator
|
|
|
|
}
|
|
|
|
StatusItemSelector {
|
2022-12-20 00:54:50 +00:00
|
|
|
id: inSelector
|
|
|
|
|
2023-01-20 11:15:05 +00:00
|
|
|
readonly property bool editable: !d.isCommunityPermission
|
|
|
|
|
|
|
|
addButton.visible: editable
|
|
|
|
itemsClickable: editable
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
Layout.fillWidth: true
|
2023-01-20 11:15:05 +00:00
|
|
|
icon: d.isCommunityPermission ? Style.svg("communities") : Style.svg("create-category")
|
2022-06-09 15:27:14 +00:00
|
|
|
iconSize: 24
|
|
|
|
title: qsTr("In")
|
|
|
|
defaultItemText: qsTr("Example: `#general` channel")
|
2022-12-20 00:54:50 +00:00
|
|
|
|
|
|
|
useLetterIdenticons: !wholeCommunitySelected || !inDropdown.communityImage
|
|
|
|
|
2023-01-27 09:22:04 +00:00
|
|
|
tagLeftPadding: wholeCommunitySelected ? 2 : 6
|
|
|
|
asset.width: wholeCommunitySelected ? 28 : 20
|
|
|
|
asset.height: asset.width
|
|
|
|
|
2022-12-20 00:54:50 +00:00
|
|
|
property bool wholeCommunitySelected: false
|
|
|
|
|
2023-01-20 11:15:05 +00:00
|
|
|
function openInDropdown(parent, x, y) {
|
|
|
|
inDropdown.parent = parent
|
|
|
|
inDropdown.x = x
|
|
|
|
inDropdown.y = y
|
|
|
|
|
|
|
|
const selectedChannels = []
|
|
|
|
|
|
|
|
if (!inSelector.wholeCommunitySelected)
|
2023-01-27 09:22:04 +00:00
|
|
|
for (let i = 0; i < d.dirtyValues.channelsModel.count; i++)
|
|
|
|
selectedChannels.push(d.dirtyValues.channelsModel.get(i).itemId)
|
2023-01-20 11:15:05 +00:00
|
|
|
|
|
|
|
inDropdown.setSelectedChannels(selectedChannels)
|
|
|
|
inDropdown.open()
|
|
|
|
}
|
|
|
|
|
2022-12-20 00:54:50 +00:00
|
|
|
ListModel {
|
|
|
|
id: inModelCommunity
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
append({
|
|
|
|
imageSource: inDropdown.communityData.image,
|
|
|
|
text: inDropdown.communityData.name,
|
2023-01-27 09:22:04 +00:00
|
|
|
operator: OperatorsUtils.Operators.None,
|
2023-02-15 09:26:48 +00:00
|
|
|
color: inDropdown.communityData.color
|
2022-12-20 00:54:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InDropdown {
|
|
|
|
id: inDropdown
|
|
|
|
|
|
|
|
model: root.rootStore.chatCommunitySectionModule.model
|
|
|
|
|
|
|
|
readonly property var communityData: rootStore.mainModuleInst.activeSection
|
|
|
|
|
|
|
|
communityName: communityData.name
|
|
|
|
communityImage: communityData.image
|
|
|
|
communityColor: communityData.color
|
|
|
|
|
|
|
|
onChannelsSelected: {
|
2023-01-27 09:22:04 +00:00
|
|
|
d.dirtyValues.channelsModel.clear()
|
2022-12-20 00:54:50 +00:00
|
|
|
inSelector.itemsModel = 0
|
|
|
|
inSelector.wholeCommunitySelected = false
|
|
|
|
|
2023-01-27 09:22:04 +00:00
|
|
|
channels.forEach(channel => {
|
|
|
|
d.dirtyValues.channelsModel.append({
|
2022-12-20 00:54:50 +00:00
|
|
|
itemId: channel.itemId,
|
|
|
|
text: "#" + channel.name,
|
|
|
|
emoji: channel.emoji,
|
|
|
|
color: channel.color,
|
|
|
|
operator: OperatorsUtils.Operators.None
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2023-01-27 09:22:04 +00:00
|
|
|
inSelector.itemsModel = d.dirtyValues.channelsModel
|
2022-12-20 00:54:50 +00:00
|
|
|
close()
|
|
|
|
}
|
|
|
|
|
|
|
|
onCommunitySelected: {
|
2023-01-27 09:22:04 +00:00
|
|
|
d.dirtyValues.channelsModel.clear()
|
2022-12-20 00:54:50 +00:00
|
|
|
inSelector.wholeCommunitySelected = true
|
|
|
|
inSelector.itemsModel = inModelCommunity
|
|
|
|
close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addButton.onClicked: {
|
|
|
|
inDropdown.acceptMode = InDropdown.AcceptMode.Add
|
|
|
|
openInDropdown(inSelector.addButton,
|
|
|
|
inSelector.addButton.width + d.dropdownHorizontalOffset, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemClicked: {
|
|
|
|
if (mouse.button !== Qt.LeftButton)
|
|
|
|
return
|
|
|
|
|
|
|
|
inDropdown.acceptMode = InDropdown.AcceptMode.Update
|
|
|
|
openInDropdown(item, mouse.x + d.dropdownHorizontalOffset,
|
|
|
|
d.dropdownVerticalOffset)
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
Separator {
|
|
|
|
Layout.topMargin: 24
|
|
|
|
}
|
2023-02-08 17:13:25 +00:00
|
|
|
|
|
|
|
HidePermissionPanel {
|
2022-06-09 15:27:14 +00:00
|
|
|
Layout.topMargin: 12
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
Layout.rightMargin: Layout.leftMargin
|
2023-02-08 17:13:25 +00:00
|
|
|
|
2023-02-11 19:03:57 +00:00
|
|
|
enabled: d.dirtyValues.permissionType !== PermissionTypes.Type.Admin
|
2023-02-08 17:13:25 +00:00
|
|
|
checked: d.dirtyValues.isPrivate
|
|
|
|
onToggled: d.dirtyValues.isPrivate = checked
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
2023-01-17 12:22:28 +00:00
|
|
|
|
2023-02-08 17:13:25 +00:00
|
|
|
PermissionConflictWarningPanel {
|
2023-01-23 15:50:34 +00:00
|
|
|
id: conflictPanel
|
2023-01-27 09:22:04 +00:00
|
|
|
|
2023-01-23 15:50:34 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: 50 // by desing
|
2023-02-14 23:53:01 +00:00
|
|
|
|
|
|
|
visible: store.permissionConflict.exists
|
2023-01-23 15:50:34 +00:00
|
|
|
holdings: store.permissionConflict.holdings
|
|
|
|
permissions: store.permissionConflict.permissions
|
|
|
|
channels: store.permissionConflict.channels
|
|
|
|
}
|
|
|
|
|
2023-02-14 20:39:18 +00:00
|
|
|
PermissionDuplicationWarningPanel {
|
|
|
|
id: duplicationPanel
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: 50 // by desing
|
2023-02-14 23:53:01 +00:00
|
|
|
|
|
|
|
visible: false
|
2023-02-14 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
StatusButton {
|
|
|
|
Layout.preferredHeight: 44
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.fillWidth: true
|
2023-02-14 23:53:01 +00:00
|
|
|
Layout.topMargin: conflictPanel.visible
|
|
|
|
? conflictPanel.Layout.topMargin
|
|
|
|
: Style.current.bigPadding
|
|
|
|
|
|
|
|
visible: !root.isEditState
|
|
|
|
text: qsTr("Create permission")
|
|
|
|
enabled: root.isFullyFilled && !root.duplicationWarningVisible
|
2023-02-08 23:22:57 +00:00
|
|
|
|
|
|
|
onClicked: root.createPermissionClicked()
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|