2022-06-06 08:53:59 +00:00
|
|
|
require('./style.scss');
|
2022-06-06 12:49:18 +00:00
|
|
|
var Component = require('vn/component');
|
2022-06-06 08:53:59 +00:00
|
|
|
var Toast = require('../toast');
|
|
|
|
var Tpl = require('./ui.xml').default;
|
2015-09-25 00:53:59 +00:00
|
|
|
|
2015-09-11 09:37:16 +00:00
|
|
|
/**
|
2015-12-19 15:42:38 +00:00
|
|
|
* A form to handle the image database, it allows to add new images or
|
|
|
|
* replace it.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2018-08-24 13:20:18 +00:00
|
|
|
module.exports = new Class({
|
|
|
|
Extends: Component,
|
|
|
|
Properties: {
|
2016-09-24 14:32:31 +00:00
|
|
|
/**
|
|
|
|
* The REST connection used to upload the image.
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2018-08-24 13:20:18 +00:00
|
|
|
conn: {
|
2016-09-24 14:32:31 +00:00
|
|
|
type: Vn.JsonConnection
|
|
|
|
}
|
2018-08-24 13:20:18 +00:00
|
|
|
},
|
2015-03-06 23:33:54 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
initialize(props) {
|
2022-06-06 12:49:18 +00:00
|
|
|
this.loadTemplateFromString(Tpl);
|
2015-09-25 00:53:59 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
this.$.form.onsubmit = () => {
|
|
|
|
this._onSubmit(); return false;
|
2022-05-21 21:31:56 +00:00
|
|
|
};
|
2015-11-09 08:14:33 +00:00
|
|
|
|
2022-06-06 16:02:17 +00:00
|
|
|
Component.prototype.initialize.call(this, props);
|
2018-08-24 13:20:18 +00:00
|
|
|
},
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onNameChange() {
|
2022-05-28 01:18:06 +00:00
|
|
|
var newValue = this.$.name.value;
|
2015-12-10 13:48:43 +00:00
|
|
|
|
|
|
|
if (!newValue)
|
|
|
|
newValue = null
|
|
|
|
|
2022-05-30 01:30:33 +00:00
|
|
|
this.emit('name-changed', newValue);
|
2018-08-24 13:20:18 +00:00
|
|
|
},
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
async _onSubmit() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.hiddenName.value = this.$.name.value;
|
|
|
|
this.$.submit.disabled = true;
|
|
|
|
this.$.spinner.start();
|
2016-08-25 10:47:09 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
try {
|
|
|
|
await this.conn.sendFormMultipart(this.$.form);
|
|
|
|
Toast.showMessage(_('ImageAdded'));
|
|
|
|
this.emit('file-uploaded', this.$.name.value);
|
|
|
|
} finally {
|
|
|
|
this.$.submit.disabled = false;
|
|
|
|
this.$.spinner.stop();
|
|
|
|
}
|
2018-08-24 13:20:18 +00:00
|
|
|
},
|
2015-03-06 23:33:54 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
setData(image, directory) {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.name.value = image;
|
|
|
|
this.$.schema.value = directory;
|
2015-03-06 23:33:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|