0001-misc-avoid-javascript-in-mini-rich-text-widget-templ.patch
tests/test_widgets.py | ||
---|---|---|
17 | 17 |
FileWithPreviewWidget, |
18 | 18 |
Form, |
19 | 19 |
MapWidget, |
20 |
MiniRichTextWidget, |
|
20 | 21 |
OptGroup, |
21 | 22 |
PasswordEntryWidget, |
22 | 23 |
SingleSelectHintWidget, |
... | ... | |
515 | 516 |
assert widget.parse() == '<p><img src="/test/"></p>' |
516 | 517 | |
517 | 518 | |
519 |
def test_mini_rich_text_widget(): |
|
520 |
widget = MiniRichTextWidget('test') |
|
521 |
form = MockHtmlForm(widget) |
|
522 |
assert 'data-godo="basic"' in form.as_html |
|
523 | ||
524 | ||
518 | 525 |
def test_select_hint_widget(): |
519 | 526 |
widget = SingleSelectHintWidget( |
520 | 527 |
'test', options=[('apple', 'Apple', 'apple'), ('pear', 'Pear', 'pear'), ('peach', 'Peach', 'peach')] |
wcs/qommon/form.py | ||
---|---|---|
2438 | 2438 | |
2439 | 2439 |
def add_media(self): |
2440 | 2440 |
get_response().add_css_include('../xstatic/css/godo.css') |
2441 |
get_response().add_javascript_module('qommon.godo.js') |
|
2441 | 2442 | |
2442 | 2443 | |
2443 | 2444 |
class TableWidget(CompositeWidget): |
wcs/qommon/http_response.py | ||
---|---|---|
25 | 25 | |
26 | 26 |
class HTTPResponse(quixote.http_response.HTTPResponse): |
27 | 27 |
javascript_scripts = None |
28 |
javascript_modules = None |
|
28 | 29 |
javascript_code_parts = None |
29 | 30 |
css_includes = None |
30 | 31 |
after_jobs = None |
... | ... | |
61 | 62 | |
62 | 63 |
def reset_includes(self): |
63 | 64 |
self.javascript_scripts = None |
65 |
self.javascript_modules = None |
|
64 | 66 |
self.javascript_code_parts = None |
65 | 67 |
self.css_includes = None |
66 | 68 | |
... | ... | |
138 | 140 |
self.add_javascript(['jquery.js', '../../i18n.js', 'qommon.forms.js', 'select2.js']) |
139 | 141 |
self.add_css_include('select2.css') |
140 | 142 | |
143 |
def add_javascript_module(self, *modules): |
|
144 |
if not self.javascript_modules: |
|
145 |
self.javascript_modules = [] |
|
146 |
for module in modules: |
|
147 |
if module not in self.javascript_modules: |
|
148 |
self.javascript_modules.append(module) |
|
149 | ||
141 | 150 |
def add_javascript_code(self, code): |
142 | 151 |
if not self.javascript_code_parts: |
143 | 152 |
self.javascript_code_parts = [] |
... | ... | |
146 | 155 | |
147 | 156 |
def get_javascript_for_header(self): |
148 | 157 |
s = '' |
149 |
if self.javascript_scripts: |
|
150 |
from .admin.menu import get_vc_version |
|
158 |
from .admin.menu import get_vc_version |
|
151 | 159 | |
152 |
version_hash = hashlib.md5(force_bytes(get_vc_version())).hexdigest() |
|
153 |
root_url = get_publisher().get_root_url() + get_publisher().qommon_static_dir |
|
160 |
version_hash = hashlib.md5(force_bytes(get_vc_version())).hexdigest() |
|
161 |
root_url = get_publisher().get_root_url() + get_publisher().qommon_static_dir |
|
162 |
if self.javascript_scripts: |
|
154 | 163 |
s += '\n'.join( |
155 | 164 |
[ |
156 | 165 |
'<script type="text/javascript" src="%sjs/%s?%s"></script>' |
... | ... | |
159 | 168 |
] |
160 | 169 |
) |
161 | 170 |
s += '\n' |
171 |
if self.javascript_modules: |
|
172 |
s += '\n'.join( |
|
173 |
[ |
|
174 |
'<script type="module" src="%sjs/%s?%s"></script>' % (root_url, str(x), version_hash) |
|
175 |
for x in self.javascript_modules |
|
176 |
] |
|
177 |
) |
|
178 |
s += '\n' |
|
162 | 179 |
if self.javascript_code_parts: |
163 | 180 |
s += '<script type="text/javascript">' |
164 | 181 |
s += '\n'.join(self.javascript_code_parts) |
wcs/qommon/static/js/qommon.godo.js | ||
---|---|---|
1 |
import Godo from '../xstatic/js/godo.js'; |
|
2 | ||
3 |
$(() => { |
|
4 |
$('textarea[data-godo]').each(function() { |
|
5 |
new Godo(this, {schema: this.getAttribute('data-godo')}); |
|
6 |
}) |
|
7 |
}); |
wcs/qommon/templates/qommon/forms/widgets/mini-rich-text.html | ||
---|---|---|
2 | 2 |
{% block widget-control %} |
3 | 3 |
<textarea style="width: 100%" id="form_{{widget.get_name_for_id}}" name="{{widget.name}}" |
4 | 4 |
{% for attr in widget.attrs.items %}{{attr.0}}="{{attr.1}}" {% endfor %} |
5 |
>{{widget.value|default:""}}</textarea> |
|
6 |
<script type="module"> |
|
7 |
import Godo from "/static/xstatic/js/godo.js?{{version_hash}}"; |
|
8 |
new Godo(document.getElementById('form_{{widget.get_name_for_id}}'), {schema: 'basic'}); |
|
9 |
</script> |
|
5 |
data-godo="basic">{{widget.value|default:""}} |
|
6 |
</textarea> |
|
10 | 7 |
{% endblock %} |
11 |
- |