mirror of https://github.com/OCA/web.git
parent
e1fbe67b67
commit
28d85aa32f
|
@ -2,20 +2,19 @@
|
||||||
* Copyright 2017 Komit - <http:///komit-consulting.com>
|
* Copyright 2017 Komit - <http:///komit-consulting.com>
|
||||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||||
odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
function (require) {
|
function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require('web.core');
|
var core = require('web.core');
|
||||||
var form_common = require('web.form_common');
|
var form_common = require('web.form_common');
|
||||||
var formats = require ("web.formats");
|
var formats = require("web.formats");
|
||||||
|
|
||||||
var _lt = core._lt;
|
var _lt = core._lt;
|
||||||
var ListView = require('web.ListView');
|
var ListView = require('web.ListView');
|
||||||
var list_widget_registry = core.list_widget_registry;
|
var list_widget_registry = core.list_widget_registry;
|
||||||
|
|
||||||
var FieldTextMarkDown = form_common.AbstractField.extend(
|
var FieldTextMarkDown = form_common.AbstractField.extend(
|
||||||
form_common.ReinitializeFieldMixin,
|
form_common.ReinitializeFieldMixin, {
|
||||||
{
|
|
||||||
|
|
||||||
template: 'FieldMarkDown',
|
template: 'FieldMarkDown',
|
||||||
display_name: _lt('MarkDown'),
|
display_name: _lt('MarkDown'),
|
||||||
|
@ -24,7 +23,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
'change input': 'store_dom_value'
|
'change input': 'store_dom_value'
|
||||||
},
|
},
|
||||||
|
|
||||||
init: function (field_manager, node) {
|
init: function(field_manager, node) {
|
||||||
this._super(field_manager, node);
|
this._super(field_manager, node);
|
||||||
this.$txt = false;
|
this.$txt = false;
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
return formats.parse_value(val, this, def);
|
return formats.parse_value(val, this, def);
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize_content: function () {
|
initialize_content: function() {
|
||||||
// Gets called at each redraw of widget
|
// Gets called at each redraw of widget
|
||||||
// - switching between read-only mode and edit mode
|
// - switching between read-only mode and edit mode
|
||||||
// - BUT NOT when switching to next object.
|
// - BUT NOT when switching to next object.
|
||||||
|
@ -50,7 +49,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
this.old_value = null; // will trigger a redraw
|
this.old_value = null; // will trigger a redraw
|
||||||
},
|
},
|
||||||
|
|
||||||
store_dom_value: function () {
|
store_dom_value: function() {
|
||||||
if (!this.get('effective_readonly') &&
|
if (!this.get('effective_readonly') &&
|
||||||
this.is_syntax_valid()) {
|
this.is_syntax_valid()) {
|
||||||
// We use internal_set_value because we were called by
|
// We use internal_set_value because we were called by
|
||||||
|
@ -64,18 +63,19 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
commit_value: function () {
|
commit_value: function() {
|
||||||
this.store_dom_value();
|
this.store_dom_value();
|
||||||
return this._super();
|
return this._super();
|
||||||
},
|
},
|
||||||
|
|
||||||
_get_raw_value: function() {
|
_get_raw_value: function() {
|
||||||
if (this.$txt === false)
|
if (this.$txt === false) {
|
||||||
return '';
|
return '';
|
||||||
|
}
|
||||||
return this.$txt.val();
|
return this.$txt.val();
|
||||||
},
|
},
|
||||||
|
|
||||||
render_value: function () {
|
render_value: function() {
|
||||||
// Gets called at each redraw/save of widget
|
// Gets called at each redraw/save of widget
|
||||||
// - switching between read-only mode and edit mode
|
// - switching between read-only mode and edit mode
|
||||||
// - when switching to next object.
|
// - when switching to next object.
|
||||||
|
@ -87,7 +87,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
} else {
|
} else {
|
||||||
// avoids loading markitup...
|
// avoids loading markitup...
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
highlight: function (code) {
|
highlight: function(code) {
|
||||||
return hljs.highlightAuto(code).value;
|
return hljs.highlightAuto(code).value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -95,7 +95,7 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
format_value: function (val, def) {
|
format_value: function(val, def) {
|
||||||
return formats.format_value(val, this, def);
|
return formats.format_value(val, this, def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,18 +109,19 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
**/
|
**/
|
||||||
ListView.Column.include({
|
ListView.Column.include({
|
||||||
|
|
||||||
init: function(){
|
init: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
hljs.initHighlightingOnLoad();
|
hljs.initHighlightingOnLoad();
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
sanitize: true,
|
sanitize: true,
|
||||||
highlight: function (code) {
|
highlight: function(code) {
|
||||||
return hljs.highlightAuto(code).value;
|
return hljs.highlightAuto(code).value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_format: function(row_data, options){
|
_format: function(row_data, options) {
|
||||||
|
if (this.type === "text") {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var markdown_text = marked(
|
var markdown_text = marked(
|
||||||
formats.format_value(
|
formats.format_value(
|
||||||
|
@ -129,8 +130,10 @@ odoo.define("web_widget_text_markdown.bootstrap_markdown",
|
||||||
);
|
);
|
||||||
return markdown_text;
|
return markdown_text;
|
||||||
}
|
}
|
||||||
|
return this._super(row_data, options)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
list_widget_registry.add('field.bootstrap_markdown', ListView.Column);
|
list_widget_registry.add('field.bootstrap_markdown', ListView.Column);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue