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

67 lines
1.2 KiB
JavaScript
Raw Normal View History

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;
/**
* A form to handle the image database, it allows to add new images or
* replace it.
2022-05-26 06:08:31 +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
*/
conn: {
2016-09-24 14:32:31 +00:00
type: Vn.JsonConnection
}
},
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);
2016-08-25 10:47:09 +00:00
var self = this;
2022-05-28 01:18:06 +00:00
this.$.form.onsubmit = function() {
2022-05-21 21:31:56 +00:00
self._onSubmit(); return false;
};
2015-11-09 08:14:33 +00:00
2022-06-06 16:02:17 +00:00
Component.prototype.initialize.call(this, props);
},
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);
},
2022-11-16 01:46:44 +00:00
_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-05-28 01:18:06 +00:00
this.conn.sendFormMultipart(this.$.form,
this._onResponse.bind(this));
},
2022-11-16 01:46:44 +00:00
_onResponse(json, error) {
2022-05-28 01:18:06 +00:00
this.$.submit.disabled = false;
this.$.spinner.stop();
2015-03-06 23:33:54 +00:00
2016-10-11 14:45:10 +00:00
if (error)
throw error;
Toast.showMessage(_('ImageAdded'));
2022-05-30 01:30:33 +00:00
this.emit('file-uploaded', this.$.name.value);
},
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
}
});