hedera-web/js/htk/image-editor.js

72 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Toast = require ('./toast');
var Tpl = require ('./image-editor.xml');
/**
* A form to handle the image database, it allows to add new images or
* replace it.
2016-12-20 09:32:17 +00:00
*/
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
2017-10-18 16:01:21 +00:00
Extends: Vn.Component
2016-09-24 14:32:31 +00:00
,Properties:
{
/**
* The REST connection used to upload the image.
2016-12-20 09:32:17 +00:00
*/
2016-09-24 14:32:31 +00:00
conn:
{
type: Vn.JsonConnection
}
}
2015-03-06 23:33:54 +00:00
,initialize: function (props)
2015-03-06 23:33:54 +00:00
{
2017-10-18 16:01:21 +00:00
this.loadTemplateFromString (Tpl);
2016-08-25 10:47:09 +00:00
var self = this;
2017-10-20 17:09:06 +00:00
this.$.form.onsubmit = function ()
2016-09-24 14:32:31 +00:00
{ self._onSubmit (); return false; };
2015-11-09 08:14:33 +00:00
this.parent (props);
}
,onNameChange: function ()
{
2017-10-20 17:09:06 +00:00
var newValue = this.$.name.value;
2015-12-10 13:48:43 +00:00
if (!newValue)
newValue = null
2017-04-19 06:16:37 +00:00
this.emit ('name-changed', newValue);
}
2016-09-24 14:32:31 +00:00
,_onSubmit: function ()
{
2017-10-20 17:09:06 +00:00
this.$.submit.disabled = true;
this.$.spinner.start ();
2016-08-25 10:47:09 +00:00
2017-10-20 17:09:06 +00:00
this.conn.sendFormMultipart (this.$.form,
2016-09-24 14:32:31 +00:00
this._onResponse.bind (this));
}
2016-10-11 14:45:10 +00:00
,_onResponse: function (json, error)
{
2017-10-20 17:09: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'));
2017-10-20 17:09:06 +00:00
this.emit ('file-uploaded', this.$.name.value);
2015-03-06 23:33:54 +00:00
}
,setData: function (image, directory)
{
2017-10-20 17:09:06 +00:00
this.$.name.value = image;
this.$.schema.value = directory;
2015-03-06 23:33:54 +00:00
}
});