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

75 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Widget = require ('./widget');
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-09-26 09:28:47 +00:00
module.exports = new Class
({
2016-09-26 09:28:47 +00:00
Extends: Widget
2016-09-24 14:32:31 +00:00
,Properties:
{
/**
* The REST connection used to upload the image.
**/
conn:
{
type: Vn.JsonConnection
}
}
2015-03-06 23:33:54 +00:00
,initialize: function (props)
2015-03-06 23:33:54 +00:00
{
2016-09-26 09:28:47 +00:00
this.builderInitString (Tpl);
2016-08-25 10:47:09 +00:00
var self = this;
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 ()
{
2015-12-10 13:48:43 +00:00
var newValue = this.$('name').value;
if (!newValue)
newValue = null
this.signalEmit ('name-changed', newValue);
}
2016-09-24 14:32:31 +00:00
,_onSubmit: function ()
{
this.$('submit').disabled = true;
2016-05-02 13:05:49 +00:00
this.$('spinner').start ();
2016-08-25 10:47:09 +00:00
2016-09-24 14:32:31 +00:00
this.conn.sendFormMultipart (this.$('form'),
this._onResponse.bind (this));
}
2016-09-24 14:32:31 +00:00
,_onResponse: function (request, json, error)
{
this.$('submit').disabled = false;
2016-05-02 13:05:49 +00:00
this.$('spinner').stop ();
2015-03-06 23:33:54 +00:00
2016-08-25 10:47:09 +00:00
if (json)
{
2016-09-26 09:28:47 +00:00
Toast.showMessage (_('ImageAdded'));
2016-08-25 10:47:09 +00:00
this.signalEmit ('file-uploaded', this.$('name').value);
2015-03-06 23:33:54 +00:00
}
2016-08-25 10:47:09 +00:00
else
2016-09-26 09:28:47 +00:00
Toast.showError (error.message);
2015-03-06 23:33:54 +00:00
}
,setData: function (image, directory)
{
this.$('name').value = image;
this.$('schema').value = directory;
}
});