123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /*
- * PropertyDialog.js
- *
- * @author realor
- */
- import { Dialog } from './Dialog.js'
- class PropertyDialog extends Dialog {
- constructor(application, object, dictionary) {
- super('title.object_properties')
- this.application = application
- this.object = object
- this.dictionary = dictionary
- this.setI18N(this.application.i18n)
- this.setSize(240, 210)
- this.nameElem = this.addTextField('propertyName', 'label.property_name', '')
- this.nameElem.setAttribute('spellcheck', false)
- this.typeElem = this.addSelectField('propertyType', 'label.property_type', ['string', 'number', 'boolean', 'object'])
- this.valueElem = this.addTextField('propertyValue', 'label.property_value', '')
- this.acceptButton = this.addButton('accept', 'button.accept', () => this.onAccept())
- this.acceptButton.disabled = true
- this.cancelButton = this.addButton('cancel', 'button.cancel', () => this.onCancel())
- this.nameElem.addEventListener('input', () => {
- this.nameElem.value = this.nameElem.value.replace(/\s/g, '')
- this.acceptButton.disabled = this.nameElem.value.length === 0
- })
- }
- onShow() {
- this.nameElem.focus()
- }
- onAccept() {
- const propertyName = this.nameElem.value
- const propertyType = this.typeElem.value
- const propertyValue = this.valueElem.value
- const dictionary = this.dictionary
- this.hide()
- switch (propertyType) {
- case 'string':
- dictionary[propertyName] = propertyValue
- break
- case 'number':
- dictionary[propertyName] = Number(propertyValue)
- break
- case 'boolean':
- dictionary[propertyName] = Boolean(propertyValue)
- break
- case 'object':
- dictionary[propertyName] = {}
- break
- }
- this.application.notifyObjectsChanged(this.object, this)
- }
- onCancel() {
- this.hide()
- }
- }
- export { PropertyDialog }
|