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
|
|
|
|
|
2022-12-06 11:19:20 +00:00
|
|
|
|
import AppLayouts.Chat.helpers 1.0
|
2022-06-09 15:27:14 +00:00
|
|
|
|
import utils 1.0
|
|
|
|
|
import shared.panels 1.0
|
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
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
|
|
|
|
|
property bool dirty: {
|
|
|
|
|
|
|
|
|
|
let trick = d.triggerDirtyTool // Trick: Used to force the reevaluation of dirty when an item of the list is updated
|
|
|
|
|
|
|
|
|
|
// Holdings:
|
|
|
|
|
const dirtyHoldingsList = d.checkIfHoldingsDirty()
|
|
|
|
|
|
|
|
|
|
// Permissions:
|
|
|
|
|
let dirtyPermissionObj = false
|
|
|
|
|
if(root.permissionObject && d.dirtyValues.permissionObject.key !== null) {
|
|
|
|
|
dirtyPermissionObj = (d.dirtyValues.permissionObject.key !== root.permissionObject.key) ||
|
|
|
|
|
(d.dirtyValues.permissionObject.text !== root.permissionObject.text) ||
|
|
|
|
|
(d.dirtyValues.permissionObject.imageSource !== root.permissionObject.imageSource)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dirtyPermissionObj = d.dirtyValues.permissionObject.key !== null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Channels:
|
|
|
|
|
let dirtyChannelsList = false
|
|
|
|
|
|
|
|
|
|
return dirtyHoldingsList || dirtyPermissionObj || dirtyChannelsList || d.dirtyValues.isPrivateDirty
|
|
|
|
|
}
|
|
|
|
|
property bool saveChanges: false
|
|
|
|
|
property bool resetChanges: false
|
|
|
|
|
|
|
|
|
|
property int permissionIndex
|
|
|
|
|
|
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 {}
|
|
|
|
|
|
|
|
|
|
// roles: key, text, imageSource
|
|
|
|
|
property var permissionObject
|
|
|
|
|
|
|
|
|
|
// TODO roles:
|
|
|
|
|
property var channelsModel: ListModel {}
|
|
|
|
|
|
|
|
|
|
property bool isPrivate
|
2022-08-23 08:46:37 +00:00
|
|
|
|
|
2022-11-25 17:35:30 +00:00
|
|
|
|
signal permissionCreated()
|
2022-08-23 08:46:37 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
2022-09-09 22:09:37 +00:00
|
|
|
|
property int permissionType: PermissionTypes.Type.None
|
2022-11-24 16:23:54 +00:00
|
|
|
|
property bool triggerDirtyTool: false // Trick: Used to force the reevaluation of dirty when an item of the list is updated
|
|
|
|
|
|
|
|
|
|
property QtObject dirtyValues: QtObject {
|
|
|
|
|
property ListModel holdingsModel: ListModel {}
|
|
|
|
|
property QtObject permissionObject: QtObject {
|
|
|
|
|
property var key: null
|
|
|
|
|
property string text: ""
|
|
|
|
|
property string imageSource: ""
|
|
|
|
|
}
|
|
|
|
|
property bool isPrivateDirty: false
|
|
|
|
|
|
|
|
|
|
// TODO: Channels
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveChanges() {
|
|
|
|
|
|
|
|
|
|
root.store.editPermission(root.permissionIndex,
|
|
|
|
|
d.dirtyValues.holdingsModel,
|
|
|
|
|
d.dirtyValues.permissionObject,
|
|
|
|
|
root.channelsModel,
|
|
|
|
|
d.dirtyValues.isPrivateDirty ? !root.isPrivate : root.isPrivate)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadInitValues() {
|
|
|
|
|
// Holdings:
|
|
|
|
|
d.dirtyValues.holdingsModel.clear()
|
|
|
|
|
if(root.holdingsModel) {
|
|
|
|
|
for(let i = 0; i < root.holdingsModel.count; i++) {
|
|
|
|
|
let item = root.holdingsModel.get(i)
|
|
|
|
|
let initItem = null
|
|
|
|
|
if(item.shortName) {
|
|
|
|
|
initItem = {
|
|
|
|
|
type: item.type,
|
|
|
|
|
key: item.key,
|
|
|
|
|
name: item.name,
|
|
|
|
|
shortName: item.shortName,
|
|
|
|
|
amount: item.amount,
|
2023-01-12 11:31:08 +00:00
|
|
|
|
imageSource: item.imageSource
|
2022-11-24 16:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
initItem = {
|
|
|
|
|
type: item.type,
|
|
|
|
|
key: item.key,
|
|
|
|
|
name: item.name,
|
|
|
|
|
amount: item.amount,
|
2023-01-12 11:31:08 +00:00
|
|
|
|
imageSource: item.imageSource
|
2022-11-24 16:23:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d.dirtyValues.holdingsModel.append(initItem)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Permissions:
|
|
|
|
|
d.dirtyValues.permissionObject.key = root.permissionObject ? root.permissionObject.key : null
|
|
|
|
|
d.dirtyValues.permissionObject.text = root.permissionObject ? root.permissionObject.text : ""
|
|
|
|
|
d.dirtyValues.permissionObject.imageSource = root.permissionObject ? root.permissionObject.imageSource : ""
|
|
|
|
|
|
|
|
|
|
// TODO: Channels
|
|
|
|
|
|
|
|
|
|
// Is private permission
|
|
|
|
|
d.dirtyValues.isPrivateDirty = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkIfHoldingsDirty() {
|
|
|
|
|
let dirty = false
|
|
|
|
|
if(root.holdingsModel) {
|
|
|
|
|
if(root.holdingsModel.count !== d.dirtyValues.holdingsModel.count) {
|
|
|
|
|
dirty = true
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Check element by element
|
|
|
|
|
let equals = 0
|
|
|
|
|
for(let i = 0; i < root.holdingsModel.count; i++) {
|
|
|
|
|
const item1 = root.holdingsModel.get(i)
|
|
|
|
|
for(let j = 0; j < d.dirtyValues.holdingsModel.count; j++) {
|
|
|
|
|
let item2 = d.dirtyValues.holdingsModel.get(j)
|
2023-01-12 11:31:08 +00:00
|
|
|
|
// key, name, shortName, amount
|
2022-11-24 16:23:54 +00:00
|
|
|
|
if((item1.key === item2.key) &&
|
|
|
|
|
(item1.name === item2.name) &&
|
|
|
|
|
(item1.shortName === item2.shortName) &&
|
2023-01-12 11:31:08 +00:00
|
|
|
|
(item1.amount === item2.amount)) {
|
2022-11-24 16:23:54 +00:00
|
|
|
|
equals = equals + 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dirty = (equals !== root.holdingsModel.count)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dirty = (d.dirtyValues.holdingsModel.count !== 0)
|
|
|
|
|
}
|
|
|
|
|
return dirty
|
|
|
|
|
}
|
2023-01-18 19:54:14 +00:00
|
|
|
|
|
|
|
|
|
function holdingsTextFormat(type, name, amount) {
|
|
|
|
|
return CommunityPermissionsHelpers.setHoldingsTextFormat(type, name, amount)
|
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contentWidth: mainLayout.width
|
|
|
|
|
contentHeight: mainLayout.height
|
|
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
|
onSaveChangesChanged: if(saveChanges) d.saveChanges()
|
|
|
|
|
onResetChangesChanged: if(resetChanges) d.loadInitValues()
|
|
|
|
|
onPermissionObjectChanged: d.loadInitValues()
|
|
|
|
|
|
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
|
|
|
|
|
CurveSeparatorWithText {
|
|
|
|
|
Layout.alignment: Qt.AlignLeft
|
|
|
|
|
Layout.leftMargin: 14
|
|
|
|
|
text: qsTr("Anyone")
|
|
|
|
|
}
|
|
|
|
|
StatusItemSelector {
|
|
|
|
|
id: tokensSelector
|
2023-01-18 19:54:14 +00:00
|
|
|
|
|
|
|
|
|
property int editedIndex
|
|
|
|
|
|
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
|
|
|
|
itemsModel: SortFilterProxyModel {
|
2022-11-24 16:23:54 +00:00
|
|
|
|
sourceModel: d.dirtyValues.holdingsModel
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
|
|
|
|
proxyRoles: ExpressionRole {
|
|
|
|
|
name: "text"
|
2023-01-18 19:54:14 +00:00
|
|
|
|
// Direct call for singleton function is not handled properly by SortFilterProxyModel that's why `holdingsTextFormat` is used instead.
|
|
|
|
|
expression: d.holdingsTextFormat(model.type, model.name, model.amount)
|
2022-09-07 09:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HoldingsDropdown {
|
2022-06-09 15:27:14 +00:00
|
|
|
|
id: dropdown
|
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
|
2022-11-25 17:35:30 +00:00
|
|
|
|
const name = item.shortName ? item.shortName : item.name
|
2022-09-07 09:40:25 +00:00
|
|
|
|
const imageSource = item.iconSource.toString()
|
|
|
|
|
|
2023-01-12 11:31:08 +00:00
|
|
|
|
d.dirtyValues.holdingsModel.append({ type, key, name, amount, imageSource })
|
2022-09-07 09:40:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-01-17 23:03:08 +00:00
|
|
|
|
const key = "ENS"
|
2023-01-17 22:56:58 +00:00
|
|
|
|
const icon = Style.svg("profile/ensUsernames")
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
2023-01-17 23:03:08 +00:00
|
|
|
|
d.dirtyValues.holdingsModel.append({type: HoldingTypes.Type.Ens, key, name: domain, amount: 1, imageSource: icon })
|
2022-09-07 09:40:25 +00:00
|
|
|
|
dropdown.close()
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:18:52 +00:00
|
|
|
|
onUpdateAsset: {
|
2023-01-18 19:54:14 +00:00
|
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(store.assetsModel, key)
|
2022-11-25 17:35:30 +00:00
|
|
|
|
const name = modelItem.shortName ? modelItem.shortName : modelItem.name
|
2022-09-07 09:40:25 +00:00
|
|
|
|
const imageSource = modelItem.iconSource.toString()
|
|
|
|
|
|
2023-01-12 13:18:52 +00:00
|
|
|
|
d.dirtyValues.holdingsModel.set(tokensSelector.editedIndex, { type: HoldingTypes.Type.Asset, key, name, amount, imageSource })
|
2022-11-24 16:23:54 +00:00
|
|
|
|
d.triggerDirtyTool = !d.triggerDirtyTool
|
2022-06-09 15:27:14 +00:00
|
|
|
|
dropdown.close()
|
|
|
|
|
}
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
|
|
|
|
onUpdateCollectible: {
|
2023-01-18 19:54:14 +00:00
|
|
|
|
const modelItem = CommunityPermissionsHelpers.getTokenByKey(store.collectiblesModel, key)
|
2022-09-07 09:40:25 +00:00
|
|
|
|
const name = modelItem.name
|
|
|
|
|
const imageSource = modelItem.iconSource.toString()
|
|
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
|
d.dirtyValues.holdingsModel.set(tokensSelector.editedIndex, { type: HoldingTypes.Type.Collectible, key, name, amount, imageSource })
|
|
|
|
|
d.triggerDirtyTool = !d.triggerDirtyTool
|
2022-09-07 09:40:25 +00:00
|
|
|
|
dropdown.close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onUpdateEns: {
|
2023-01-17 23:03:08 +00:00
|
|
|
|
const key = "ENS"
|
2023-01-17 22:56:58 +00:00
|
|
|
|
const icon = Style.svg("profile/ensUsernames")
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
2023-01-17 23:03:08 +00:00
|
|
|
|
d.dirtyValues.holdingsModel.set(tokensSelector.editedIndex, { type: HoldingTypes.Type.Ens, key, name: domain, amount: 1, imageSource: icon })
|
2022-11-24 16:23:54 +00:00
|
|
|
|
d.triggerDirtyTool = !d.triggerDirtyTool
|
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()
|
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:
|
|
|
|
|
dropdown.ensDomainName = modelItem.name
|
|
|
|
|
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-11-24 16:23:54 +00:00
|
|
|
|
itemsModel: d.dirtyValues.permissionObject.key ? d.dirtyValues.permissionObject : null
|
2022-09-09 22:09:37 +00:00
|
|
|
|
|
2022-11-24 16:23:54 +00:00
|
|
|
|
addButton.visible: !root.permissionObject
|
2022-09-09 22:09:37 +00:00
|
|
|
|
|
|
|
|
|
PermissionsDropdown {
|
|
|
|
|
id: permissionsDropdown
|
|
|
|
|
|
|
|
|
|
initialPermissionType: d.permissionType
|
|
|
|
|
|
|
|
|
|
onDone: {
|
|
|
|
|
d.permissionType = permissionType
|
2022-11-24 16:23:54 +00:00
|
|
|
|
d.dirtyValues.permissionObject.key = permissionType
|
|
|
|
|
d.dirtyValues.permissionObject.text = title
|
|
|
|
|
d.dirtyValues.permissionObject.imageSource = asset
|
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
|
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
icon: Style.svg("create-category")
|
|
|
|
|
iconSize: 24
|
|
|
|
|
title: qsTr("In")
|
|
|
|
|
defaultItemText: qsTr("Example: `#general` channel")
|
2022-12-20 00:54:50 +00:00
|
|
|
|
|
|
|
|
|
useLetterIdenticons: !wholeCommunitySelected || !inDropdown.communityImage
|
|
|
|
|
|
|
|
|
|
property bool wholeCommunitySelected: false
|
|
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
|
id: inModelCommunity
|
|
|
|
|
|
|
|
|
|
readonly property string colorWorkaround: inDropdown.communityData.color
|
|
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
|
append({
|
|
|
|
|
imageSource: inDropdown.communityData.image,
|
|
|
|
|
text: inDropdown.communityData.name,
|
|
|
|
|
operator: OperatorsUtils.Operators.None
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
setProperty(0, "color", colorWorkaround)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
|
id: inModelChannels
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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: {
|
|
|
|
|
inModelChannels.clear()
|
|
|
|
|
inSelector.itemsModel = 0
|
|
|
|
|
inSelector.wholeCommunitySelected = false
|
|
|
|
|
|
|
|
|
|
channels.map(channel => {
|
|
|
|
|
inModelChannels.append({
|
|
|
|
|
itemId: channel.itemId,
|
|
|
|
|
text: "#" + channel.name,
|
|
|
|
|
emoji: channel.emoji,
|
|
|
|
|
color: channel.color,
|
|
|
|
|
operator: OperatorsUtils.Operators.None
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
inSelector.itemsModel = inModelChannels
|
|
|
|
|
close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onCommunitySelected: {
|
|
|
|
|
inModelChannels.clear()
|
|
|
|
|
inSelector.wholeCommunitySelected = true
|
|
|
|
|
inSelector.itemsModel = inModelCommunity
|
|
|
|
|
close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openInDropdown(parent, x, y) {
|
|
|
|
|
inDropdown.parent = parent
|
|
|
|
|
inDropdown.x = x
|
|
|
|
|
inDropdown.y = y
|
|
|
|
|
|
|
|
|
|
const selectedChannels = []
|
|
|
|
|
|
|
|
|
|
if (!inSelector.wholeCommunitySelected)
|
|
|
|
|
for (let i = 0; i < inModelChannels.count; i++)
|
|
|
|
|
selectedChannels.push(inModelChannels.get(i).itemId)
|
|
|
|
|
|
|
|
|
|
inDropdown.setSelectedChannels(selectedChannels)
|
|
|
|
|
inDropdown.open()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
RowLayout {
|
|
|
|
|
Layout.topMargin: 12
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.leftMargin: 16
|
|
|
|
|
Layout.rightMargin: Layout.leftMargin
|
|
|
|
|
spacing: 16
|
|
|
|
|
StatusRoundIcon {
|
2022-08-11 11:55:08 +00:00
|
|
|
|
asset.name: "hide"
|
2022-06-09 15:27:14 +00:00
|
|
|
|
}
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
StatusBaseText {
|
|
|
|
|
text: qsTr("Private")
|
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
|
font.pixelSize: 15
|
|
|
|
|
}
|
|
|
|
|
StatusBaseText {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
text: qsTr("Make this permission private to hide it from members who don’t meet it’s requirements")
|
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
|
font.pixelSize: 15
|
|
|
|
|
lineHeight: 1.2
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
elide: Text.ElideRight
|
|
|
|
|
clip: true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
StatusSwitch {
|
2022-11-24 16:23:54 +00:00
|
|
|
|
checked: d.dirtyValues.isPrivateDirty ? !root.isPrivate : root.isPrivate
|
|
|
|
|
onToggled: d.dirtyValues.isPrivateDirty = (root.isPrivate !== checked)
|
2022-06-09 15:27:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-17 12:22:28 +00:00
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
|
StatusButton {
|
2022-11-24 16:23:54 +00:00
|
|
|
|
visible: !root.isEditState
|
2022-06-09 15:27:14 +00:00
|
|
|
|
Layout.topMargin: 24
|
|
|
|
|
text: qsTr("Create permission")
|
2022-11-24 16:23:54 +00:00
|
|
|
|
enabled: d.dirtyValues.holdingsModel && d.dirtyValues.holdingsModel.count > 0 && d.dirtyValues.permissionObject.key !== null
|
2022-06-09 15:27:14 +00:00
|
|
|
|
Layout.preferredHeight: 44
|
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
Layout.fillWidth: true
|
2022-08-23 08:46:37 +00:00
|
|
|
|
onClicked: {
|
2022-11-24 16:23:54 +00:00
|
|
|
|
root.store.createPermission(d.dirtyValues.holdingsModel,
|
|
|
|
|
d.dirtyValues.permissionObject,
|
|
|
|
|
d.dirtyValues.isPrivateDirty ? !root.isPrivate : root.isPrivate,
|
|
|
|
|
root.channelsModel)
|
2022-11-25 17:35:30 +00:00
|
|
|
|
root.permissionCreated()
|
2022-08-23 08:46:37 +00:00
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|