Skip to content

Commit

Permalink
Allow editing event type (fixes #146)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Oct 19, 2023
1 parent ef1e0ea commit 68909b4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
36 changes: 35 additions & 1 deletion src/components/GrampsjsEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '@material/mwc-icon'
import {GrampsjsObject} from './GrampsjsObject.js'
import './GrampsjsFormEditEventDetails.js'
import './GrampsjsFormEditTitle.js'
import './GrampsjsTooltip.js'
import {fireEvent} from '../util.js'

const BASE_DIR = ''
Expand All @@ -29,7 +30,22 @@ export class GrampsjsEvent extends GrampsjsObject {

renderProfile() {
return html`
<h2>${this._renderTitle()}</h2>
<h2>
${this._renderTitle()}
${this.edit
? html`
<mwc-icon-button
id="btn-edit-type"
icon="edit"
class="edit"
@click="${this._handleEditType}"
></mwc-icon-button>
<grampsjs-tooltip for="btn-edit-type"
>${this._('Edit event type')}</grampsjs-tooltip
>
`
: ''}
</h2>
${this.data.description || this.edit
? html` <dl>
<div>
Expand Down Expand Up @@ -167,6 +183,24 @@ export class GrampsjsEvent extends GrampsjsObject {
e.stopPropagation()
this.dialogContent = ''
}

_handleEditType() {
this.dialogContent = html`
<grampsjs-form-edit-type
dialogTitle="${this._('Edit event type')}"
formId="event-type"
typeName="event_types"
@object:save="${this._handleSaveType}"
@object:cancel="${this._handleCancelDialog}"
.strings=${this.strings}
.data=${{
type: this.data?.type?.string || this.data?.type || '',
}}
prop="value"
>
</grampsjs-form-edit-type>
`
}
}

window.customElements.define('grampsjs-event', GrampsjsEvent)
11 changes: 0 additions & 11 deletions src/components/GrampsjsNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {GrampsjsObject} from './GrampsjsObject.js'
import './GrampsjsNoteContent.js'
import './GrampsjsEditor.js'
import './GrampsjsFormEditType.js'
import {fireEvent} from '../util.js'

export class GrampsjsNote extends GrampsjsObject {
static get styles() {
Expand Down Expand Up @@ -69,16 +68,6 @@ export class GrampsjsNote extends GrampsjsObject {
</grampsjs-form-edit-type>
`
}

_handleSaveType(e) {
fireEvent(this, 'edit:action', {
action: 'updateProp',
data: e.detail.data,
})
e.preventDefault()
e.stopPropagation()
this.dialogContent = ''
}
}

window.customElements.define('grampsjs-note', GrampsjsNote)
10 changes: 10 additions & 0 deletions src/components/GrampsjsObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,16 @@ export class GrampsjsObject extends GrampsjsTranslateMixin(LitElement) {
this.dialogContent = ''
}

_handleSaveType(e) {
fireEvent(this, 'edit:action', {
action: 'updateProp',
data: e.detail.data,
})
e.preventDefault()
e.stopPropagation()
this.dialogContent = ''
}

_getZoomFromBounds(bounds) {
const xMin = bounds[0][0]
const yMin = bounds[0][1]
Expand Down
11 changes: 1 addition & 10 deletions src/components/GrampsjsPlace.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class GrampsjsPlace extends GrampsjsObject {
_handleEditType() {
this.dialogContent = html`
<grampsjs-form-edit-type
dialogTitle="${this._('Edit place type')}"
formId="place-type"
typeName="place_types"
@object:save="${this._handleSaveType}"
Expand All @@ -127,16 +128,6 @@ export class GrampsjsPlace extends GrampsjsObject {
`
}

_handleSaveType(e) {
fireEvent(this, 'edit:action', {
action: 'updateProp',
data: e.detail.data,
})
e.preventDefault()
e.stopPropagation()
this.dialogContent = ''
}

_handleSaveName(e) {
fireEvent(this, 'edit:action', {
action: 'updateProp',
Expand Down
4 changes: 3 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,7 @@
"Attachments": "Attachments",
"Event Year": "Event Year",
"Common ancestors": "Common ancestors",
"Blocked": "Blocked"
"Blocked": "Blocked",
"Edit event type": "Edit event type",
"Edit place type": "Edit place type"
}

0 comments on commit 68909b4

Please sign in to comment.