mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
chore: revamp permissions panel
This commit is contained in:
parent
575b563c67
commit
b48f911bf2
3 changed files with 98 additions and 64 deletions
|
@ -307,9 +307,6 @@ input + .help-text {
|
||||||
.formbox.with-switch {
|
.formbox.with-switch {
|
||||||
padding-top: 2px;
|
padding-top: 2px;
|
||||||
}
|
}
|
||||||
.formbox select {
|
|
||||||
width: calc(100% - 14px);
|
|
||||||
}
|
|
||||||
fieldset.formbox {
|
fieldset.formbox {
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--color-lightGray);
|
border-top: 1px solid var(--color-lightGray);
|
||||||
|
@ -386,6 +383,10 @@ fieldset legend {
|
||||||
font-size: .9rem;
|
font-size: .9rem;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
}
|
}
|
||||||
|
fieldset.separator {
|
||||||
|
border: none;
|
||||||
|
border-top: 1px solid var(--color-lightGray);
|
||||||
|
}
|
||||||
|
|
||||||
[data-badge] {
|
[data-badge] {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -46,15 +46,8 @@ export class MapPermissions {
|
||||||
return this.map
|
return this.map
|
||||||
}
|
}
|
||||||
|
|
||||||
edit() {
|
_editAnonymous(container) {
|
||||||
if (this.map.options.editMode !== 'advanced') return
|
|
||||||
if (!this.map.options.umap_id) {
|
|
||||||
return Alert.info(translate('Please save the map first'))
|
|
||||||
}
|
|
||||||
const container = DomUtil.create('div', 'permissions-panel')
|
|
||||||
const fields = []
|
const fields = []
|
||||||
DomUtil.createTitle(container, translate('Update permissions'), 'icon-key')
|
|
||||||
if (this.isAnonymousMap()) {
|
|
||||||
if (this.isOwner()) {
|
if (this.isOwner()) {
|
||||||
fields.push([
|
fields.push([
|
||||||
'options.edit_status',
|
'options.edit_status',
|
||||||
|
@ -64,50 +57,10 @@ export class MapPermissions {
|
||||||
selectOptions: this.map.options.edit_statuses,
|
selectOptions: this.map.options.edit_statuses,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (this.isOwner()) {
|
|
||||||
fields.push([
|
|
||||||
'options.edit_status',
|
|
||||||
{
|
|
||||||
handler: 'IntSelect',
|
|
||||||
label: translate('Who can edit'),
|
|
||||||
selectOptions: this.map.options.edit_statuses,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
fields.push([
|
|
||||||
'options.share_status',
|
|
||||||
{
|
|
||||||
handler: 'IntSelect',
|
|
||||||
label: translate('Who can view'),
|
|
||||||
selectOptions: this.map.options.share_statuses,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
fields.push([
|
|
||||||
'options.owner',
|
|
||||||
{ handler: 'ManageOwner', label: translate("Map's owner") },
|
|
||||||
])
|
|
||||||
if (this.map.options.user?.teams?.length) {
|
|
||||||
fields.push([
|
|
||||||
'options.team',
|
|
||||||
{
|
|
||||||
handler: 'ManageTeam',
|
|
||||||
label: translate('Attach map to a team'),
|
|
||||||
teams: this.map.options.user.teams,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fields.push([
|
|
||||||
'options.editors',
|
|
||||||
{ handler: 'ManageEditors', label: translate("Map's editors") },
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
const builder = new U.FormBuilder(this, fields)
|
const builder = new U.FormBuilder(this, fields)
|
||||||
const form = builder.build()
|
const form = builder.build()
|
||||||
container.appendChild(form)
|
container.appendChild(form)
|
||||||
if (this.isAnonymousMap()) {
|
|
||||||
if (this.options.anonymous_edit_url) {
|
if (this.options.anonymous_edit_url) {
|
||||||
DomUtil.createCopiableInput(
|
DomUtil.createCopiableInput(
|
||||||
container,
|
container,
|
||||||
|
@ -133,12 +86,89 @@ export class MapPermissions {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_editWithOwner(container) {
|
||||||
|
const topFields = []
|
||||||
|
const collaboratorsFields = []
|
||||||
|
const fieldset = Utils.loadTemplate(
|
||||||
|
`<fieldset class="separator"><legend>${translate('Map')}</legend></fieldset>`
|
||||||
|
)
|
||||||
|
container.appendChild(fieldset)
|
||||||
|
if (this.isOwner()) {
|
||||||
|
topFields.push([
|
||||||
|
'options.edit_status',
|
||||||
|
{
|
||||||
|
handler: 'IntSelect',
|
||||||
|
label: translate('Who can edit'),
|
||||||
|
selectOptions: this.map.options.edit_statuses,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
topFields.push([
|
||||||
|
'options.share_status',
|
||||||
|
{
|
||||||
|
handler: 'IntSelect',
|
||||||
|
label: translate('Who can view'),
|
||||||
|
selectOptions: this.map.options.share_statuses,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
collaboratorsFields.push([
|
||||||
|
'options.owner',
|
||||||
|
{ handler: 'ManageOwner', label: translate("Map's owner") },
|
||||||
|
])
|
||||||
|
if (this.map.options.user?.teams?.length) {
|
||||||
|
collaboratorsFields.push([
|
||||||
|
'options.team',
|
||||||
|
{
|
||||||
|
handler: 'ManageTeam',
|
||||||
|
label: translate('Attach map to a team'),
|
||||||
|
teams: this.map.options.user.teams,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
collaboratorsFields.push([
|
||||||
|
'options.editors',
|
||||||
|
{ handler: 'ManageEditors', label: translate("Map's editors") },
|
||||||
|
])
|
||||||
|
|
||||||
|
const builder = new U.FormBuilder(this, topFields)
|
||||||
|
const form = builder.build()
|
||||||
|
container.appendChild(form)
|
||||||
|
if (collaboratorsFields.length) {
|
||||||
|
const fieldset = Utils.loadTemplate(
|
||||||
|
`<fieldset class="separator"><legend>${translate('Manage collaborators')}</legend></fieldset>`
|
||||||
|
)
|
||||||
|
container.appendChild(fieldset)
|
||||||
|
const builder = new U.FormBuilder(this, collaboratorsFields)
|
||||||
|
const form = builder.build()
|
||||||
|
container.appendChild(form)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_editDatalayers(container) {
|
||||||
if (this.map.hasLayers()) {
|
if (this.map.hasLayers()) {
|
||||||
DomUtil.add('h4', '', container, translate('Datalayers'))
|
const fieldset = Utils.loadTemplate(
|
||||||
|
`<fieldset class="separator"><legend>${translate('Datalayers')}</legend></fieldset>`
|
||||||
|
)
|
||||||
|
container.appendChild(fieldset)
|
||||||
this.map.eachDataLayer((datalayer) => {
|
this.map.eachDataLayer((datalayer) => {
|
||||||
datalayer.permissions.edit(container)
|
datalayer.permissions.edit(fieldset)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
edit() {
|
||||||
|
if (this.map.options.editMode !== 'advanced') return
|
||||||
|
if (!this.map.options.umap_id) {
|
||||||
|
Alert.info(translate('Please save the map first'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const container = DomUtil.create('div', 'permissions-panel')
|
||||||
|
DomUtil.createTitle(container, translate('Update permissions'), 'icon-key')
|
||||||
|
if (this.isAnonymousMap()) this._editAnonymous(container)
|
||||||
|
else this._editWithOwner(container)
|
||||||
|
this._editDatalayers(container)
|
||||||
this.map.editPanel.open({ content: container, className: 'dark' })
|
this.map.editPanel.open({ content: container, className: 'dark' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,8 +189,9 @@ export class MapPermissions {
|
||||||
for (let i = 0; i < this.options.editors.length; i++)
|
for (let i = 0; i < this.options.editors.length; i++)
|
||||||
formData.append('editors', this.options.editors[i].id)
|
formData.append('editors', this.options.editors[i].id)
|
||||||
}
|
}
|
||||||
if (this.isOwner() || this.isAnonymousMap())
|
if (this.isOwner() || this.isAnonymousMap()) {
|
||||||
formData.append('edit_status', this.options.edit_status)
|
formData.append('edit_status', this.options.edit_status)
|
||||||
|
}
|
||||||
if (this.isOwner()) {
|
if (this.isOwner()) {
|
||||||
formData.append('owner', this.options.owner?.id)
|
formData.append('owner', this.options.owner?.id)
|
||||||
formData.append('team', this.options.team?.id || '')
|
formData.append('team', this.options.team?.id || '')
|
||||||
|
|
|
@ -1029,6 +1029,7 @@ L.FormBuilder.ManageOwner = L.FormBuilder.Element.extend({
|
||||||
const options = {
|
const options = {
|
||||||
className: 'edit-owner',
|
className: 'edit-owner',
|
||||||
on_select: L.bind(this.onSelect, this),
|
on_select: L.bind(this.onSelect, this),
|
||||||
|
placeholder: L._("Type new owner's username"),
|
||||||
}
|
}
|
||||||
this.autocomplete = new U.AjaxAutocomplete(this.parentNode, options)
|
this.autocomplete = new U.AjaxAutocomplete(this.parentNode, options)
|
||||||
const owner = this.toHTML()
|
const owner = this.toHTML()
|
||||||
|
@ -1058,6 +1059,7 @@ L.FormBuilder.ManageEditors = L.FormBuilder.Element.extend({
|
||||||
className: 'edit-editors',
|
className: 'edit-editors',
|
||||||
on_select: L.bind(this.onSelect, this),
|
on_select: L.bind(this.onSelect, this),
|
||||||
on_unselect: L.bind(this.onUnselect, this),
|
on_unselect: L.bind(this.onUnselect, this),
|
||||||
|
placeholder: L._("Type editor's username"),
|
||||||
}
|
}
|
||||||
this.autocomplete = new U.AjaxAutocompleteMultiple(this.parentNode, options)
|
this.autocomplete = new U.AjaxAutocompleteMultiple(this.parentNode, options)
|
||||||
this._values = this.toHTML()
|
this._values = this.toHTML()
|
||||||
|
|
Loading…
Reference in a new issue