changeset 25ba98274e26 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=25ba98274e26
description:
Add HTML editor
issue8004
review54481002
diffstat:
CHANGELOG | 1 +
src/view/form.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 1 deletions(-)
diffs (106 lines):
diff -r f6eff9a92dea -r 25ba98274e26 CHANGELOG
--- a/CHANGELOG Thu Mar 28 19:33:23 2019 +0100
+++ b/CHANGELOG Sat Mar 30 16:04:45 2019 +0100
@@ -1,3 +1,4 @@
+* Support HTML widget
* Use locale format for data export
* Add day view on calendar
* Add CSV exports into print toolbar
diff -r f6eff9a92dea -r 25ba98274e26 src/view/form.js
--- a/src/view/form.js Thu Mar 28 19:33:23 2019 +0100
+++ b/src/view/form.js Sat Mar 30 16:04:45 2019 +0100
@@ -1150,6 +1150,10 @@
if (!this.translate) {
this.translate = Sao.View.Form.TranslateMixin.translate.bind(this);
}
+ if (!this.translate_dialog) {
+ this.translate_dialog =
+ Sao.View.Form.TranslateMixin.translate_dialog.bind(this);
+ }
if (!this.translate_widget_set_readonly) {
this.translate_widget_set_readonly =
Sao.View.Form.TranslateMixin.translate_widget_set_readonly
@@ -1194,10 +1198,13 @@
'params': params.concat({})
};
Sao.rpc(args, session).then(function(languages) {
- var dialog = new Sao.View.Form.TranslateDialog(languages,
this);
+ this.translate_dialog(languages);
}.bind(this));
}.bind(this));
};
+ Sao.View.Form.TranslateMixin.translate_dialog = function(languages) {
+ new Sao.View.Form.TranslateDialog(languages, this);
+ };
Sao.View.Form.TranslateMixin.translate_widget_set_readonly =
function(el, value) {
el.prop('readonly', value);
@@ -3786,6 +3793,60 @@
}
});
+ Sao.View.Form.HTML = Sao.class_(Sao.View.Form.Widget, {
+ class_: 'form-html',
+ init: function(view, attributes) {
+ Sao.View.Form.HTML._super.init.call(this, view, attributes);
+ Sao.View.Form.TranslateMixin.init.call(this);
+ this.el = jQuery('<div/>', {
+ 'class': this.class_,
+ });
+ this.button = jQuery('<a/>', {
+ 'class': 'btn btn-lnk',
+ 'target': '_blank',
+ }).text(attributes.string).appendTo(this.el);
+ if (attributes.translate) {
+ var button = jQuery('<button/>', {
+ 'class': 'btn btn-default btn-sm',
+ 'type': 'button',
+ 'aria-label': Sao.i18n.gettext('Translate'),
+ }).appendTo(this.el);
+ button.append(
+ Sao.common.ICONFACTORY.get_icon_img('tryton-translate'));
+ button.click(this.translate.bind(this));
+ }
+ },
+ uri: function(language) {
+ var record = this.record,
+ uri;
+ if (!record || (record.id < 0)) {
+ uri = '';
+ } else {
+ uri = '/' + record.model.session.database +
+ '/ir/html/' + record.model.name + '/' + record.id + '/' +
+ this.field_name;
+ uri += '?language=' + encodeURIComponent(
+ language || Sao.i18n.getlang());
+ uri += '&title=' + encodeURIComponent(Sao.config.title);
+ }
+ return uri;
+ },
+ display: function() {
+ Sao.View.Form.HTML._super.display.call(this);
+ this.button.attr('href', this.uri());
+ },
+ translate_dialog: function(languages) {
+ var options = {};
+ languages.forEach(function(language) {
+ options[language.name] = language.code;
+ });
+ Sao.common.selection(Sao.i18n.gettext("Choose a language"),
options)
+ .done(function(language) {
+ window.open(this.uri(language), '_blank');
+ }.bind(this));
+ },
+ });
+
Sao.View.Form.ProgressBar = Sao.class_(Sao.View.Form.Widget, {
class_: 'form-char',
init: function(view, attributes) {
@@ -4413,6 +4474,7 @@
'dict': Sao.View.Form.Dict,
'email': Sao.View.Form.Email,
'float': Sao.View.Form.Float,
+ 'html': Sao.View.Form.HTML,
'image': Sao.View.Form.Image,
'integer': Sao.View.Form.Integer,
'many2many': Sao.View.Form.Many2Many,