forked from verdnatura/hedera-web
69 lines
1.2 KiB
JavaScript
69 lines
1.2 KiB
JavaScript
|
|
Vn.resource ('js/htk/image-editor.xml');
|
|
Vn.define (function () {
|
|
|
|
/**
|
|
* A form to handle the image database, it allows to add new images or
|
|
* replace it.
|
|
**/
|
|
Htk.ImageEditor = new Class
|
|
({
|
|
Extends: Htk.Widget
|
|
|
|
,initialize: function (props)
|
|
{
|
|
this.builderInit (this.constructor.Xml);
|
|
|
|
var self = this;
|
|
this.$('form').onsubmit = function ()
|
|
{ self.onSubmit (); return false; };
|
|
|
|
this.parent (props);
|
|
}
|
|
|
|
,onNameChange: function ()
|
|
{
|
|
var newValue = this.$('name').value;
|
|
|
|
if (!newValue)
|
|
newValue = null
|
|
|
|
this.signalEmit ('name-changed', newValue);
|
|
}
|
|
|
|
,onSubmit: function ()
|
|
{
|
|
this.$('submit').disabled = true;
|
|
this.$('spinner').start ();
|
|
|
|
var request = new Vn.JsonRequest ();
|
|
request.sendFormMultipart (this.$('form'),
|
|
this.onResponse.bind (this));
|
|
}
|
|
|
|
,onResponse: function (request, json, error)
|
|
{
|
|
this.$('submit').disabled = false;
|
|
this.$('spinner').stop ();
|
|
|
|
if (json)
|
|
{
|
|
Htk.Toast.showMessage (_('ImageAdded'));
|
|
this.signalEmit ('file-uploaded', this.$('name').value);
|
|
}
|
|
else
|
|
Htk.Toast.showError (error.message);
|
|
}
|
|
|
|
,setData: function (image, directory)
|
|
{
|
|
this.$('name').value = image;
|
|
this.$('schema').value = directory;
|
|
}
|
|
}).extend
|
|
({
|
|
Xml: 'js/htk/image-editor.xml'
|
|
});
|
|
|
|
});
|