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

67 lines
1.3 KiB
JavaScript
Raw Normal View History

var Component = require('./component');
var Toast = require('./toast');
2022-05-21 21:31:56 +00:00
var Tpl = require('./image-editor.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
initialize: function(props) {
this.builderInitString(Tpl);
2016-08-25 10:47:09 +00:00
var self = this;
2022-05-21 21:31:56 +00:00
this.$('form').onsubmit = function() {
self._onSubmit(); return false;
};
2015-11-09 08:14:33 +00:00
this.parent(props);
},
onNameChange: function() {
2015-12-10 13:48:43 +00:00
var newValue = this.$('name').value;
if (!newValue)
newValue = null
this.signalEmit('name-changed', newValue);
},
_onSubmit: function() {
this.$('hidden-name').value = this.$('name').value;
this.$('submit').disabled = true;
this.$('spinner').start();
2016-08-25 10:47:09 +00:00
this.conn.sendFormMultipart(this.$('form'),
this._onResponse.bind(this));
},
_onResponse: function(json, error) {
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'));
this.signalEmit('file-uploaded', this.$('name').value);
},
2015-03-06 23:33:54 +00:00
setData: function(image, directory) {
2015-03-06 23:33:54 +00:00
this.$('name').value = image;
this.$('schema').value = directory;
}
});