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

67 lines
1.2 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-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
this.parent(props);
},
onNameChange: function() {
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);
},
_onSubmit: function() {
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));
},
_onResponse: function(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
setData: function(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
}
});