0
1
Fork 0
hedera-web-mindshore/js/htk/image-editor/index.js

67 lines
1.2 KiB
JavaScript

require('./style.scss');
var Component = require('vn/component');
var Toast = require('../toast');
var Tpl = require('./ui.xml').default;
/**
* A form to handle the image database, it allows to add new images or
* replace it.
*/
module.exports = new Class({
Extends: Component,
Properties: {
/**
* The REST connection used to upload the image.
*/
conn: {
type: Vn.JsonConnection
}
},
initialize(props) {
this.loadTemplateFromString(Tpl);
var self = this;
this.$.form.onsubmit = function() {
self._onSubmit(); return false;
};
Component.prototype.initialize.call(this, props);
},
onNameChange() {
var newValue = this.$.name.value;
if (!newValue)
newValue = null
this.emit('name-changed', newValue);
},
_onSubmit() {
this.$.hiddenName.value = this.$.name.value;
this.$.submit.disabled = true;
this.$.spinner.start();
this.conn.sendFormMultipart(this.$.form,
this._onResponse.bind(this));
},
_onResponse(json, error) {
this.$.submit.disabled = false;
this.$.spinner.stop();
if (error)
throw error;
Toast.showMessage(_('ImageAdded'));
this.emit('file-uploaded', this.$.name.value);
},
setData(image, directory) {
this.$.name.value = image;
this.$.schema.value = directory;
}
});