2015-09-25 00:53:59 +00:00
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
var Component = require('./component');
|
|
|
|
var Toast = require('./toast');
|
2022-05-21 21:31:56 +00:00
|
|
|
var Tpl = require('./image-editor.xml').default;
|
2015-09-25 00:53:59 +00:00
|
|
|
|
2015-09-11 09:37:16 +00:00
|
|
|
/**
|
2015-12-19 15:42:38 +00:00
|
|
|
* A form to handle the image database, it allows to add new images or
|
|
|
|
* replace it.
|
2015-09-11 09:37:16 +00:00
|
|
|
**/
|
2018-08-24 13:20:18 +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.
|
|
|
|
**/
|
2018-08-24 13:20:18 +00:00
|
|
|
conn: {
|
2016-09-24 14:32:31 +00:00
|
|
|
type: Vn.JsonConnection
|
|
|
|
}
|
2018-08-24 13:20:18 +00:00
|
|
|
},
|
2015-03-06 23:33:54 +00:00
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
initialize: function(props) {
|
|
|
|
this.builderInitString(Tpl);
|
2015-09-25 00:53:59 +00:00
|
|
|
|
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
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
this.parent(props);
|
|
|
|
},
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
onNameChange: function() {
|
2015-12-10 13:48:43 +00:00
|
|
|
var newValue = this.$('name').value;
|
|
|
|
|
|
|
|
if (!newValue)
|
|
|
|
newValue = null
|
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
this.signalEmit('name-changed', newValue);
|
|
|
|
},
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
_onSubmit: function() {
|
|
|
|
this.$('hidden-name').value = this.$('name').value;
|
2015-03-27 19:10:49 +00:00
|
|
|
this.$('submit').disabled = true;
|
2018-08-24 13:20:18 +00:00
|
|
|
this.$('spinner').start();
|
2016-08-25 10:47:09 +00:00
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
this.conn.sendFormMultipart(this.$('form'),
|
|
|
|
this._onResponse.bind(this));
|
|
|
|
},
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
_onResponse: function(json, error) {
|
2015-03-27 19:10:49 +00:00
|
|
|
this.$('submit').disabled = false;
|
2018-08-24 13:20:18 +00:00
|
|
|
this.$('spinner').stop();
|
2015-03-06 23:33:54 +00:00
|
|
|
|
2016-10-11 14:45:10 +00:00
|
|
|
if (error)
|
|
|
|
throw error;
|
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
Toast.showMessage(_('ImageAdded'));
|
|
|
|
this.signalEmit('file-uploaded', this.$('name').value);
|
|
|
|
},
|
2015-03-06 23:33:54 +00:00
|
|
|
|
2018-08-24 13:20:18 +00:00
|
|
|
setData: function(image, directory) {
|
2015-03-06 23:33:54 +00:00
|
|
|
this.$('name').value = image;
|
|
|
|
this.$('schema').value = directory;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|