Skip to content

Commit

Permalink
added POST method to rest-api
Browse files Browse the repository at this point in the history
  • Loading branch information
drfho committed Nov 17, 2024
1 parent f31ffe8 commit 1219c2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
16 changes: 12 additions & 4 deletions Products/zms/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def __bobo_traverse__(self, TraversalRequest, name):
def __call__(self, REQUEST=None, **kw):
""""""
standard.writeBlock(self.context,'__call__: %s'%str(self.ids))
if self.method == 'POST':
if self.ids == ['get_htmldiff']:
decoration, data = self.get_htmldiff(self.context, content_type=True)
return data
if self.method == 'GET':
decoration, data = {'content_type':'text/plain'}, {}
if self.ids == [] and self.context.meta_type == 'ZMSIndex':
Expand All @@ -196,8 +200,6 @@ def __call__(self, REQUEST=None, **kw):
decoration, data = self.get_tag(self.context, content_type=True)
elif self.ids == ['body_content']:
decoration, data = self.body_content(self.context, content_type=True)
elif self.ids == ['get_htmldiff']:
decoration, data = self.get_htmldiff(self.context, content_type=True)
elif self.ids == [] or self.ids == ['get']:
decoration, data = self.get(self.context, content_type=True)
else:
Expand Down Expand Up @@ -335,6 +337,12 @@ def body_content(self, context):
return '\n'.join(html)

@api(tag="version", pattern="/{path}/get_htmldiff", method="POST", content_type="text/html")
def get_htmldiff(self, context, original='<pre>original</pre>', changed='<pre>changed</pre>'):
def get_htmldiff(self, context):
decoration, data = {'content_type':'text/html'}, {}
request = _get_request(context)
return standard.htmldiff(original, changed)
original = request.get('original','<pre>original</pre>')
changed = request.get('changed','<pre>changed</pre>')
data = standard.htmldiff(original, changed)
ct = decoration['content_type']
request.RESPONSE.setHeader('Content-Type',ct)
return data
18 changes: 10 additions & 8 deletions Products/zms/zpt/versionmanager/manage_undoversionform.zpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
level python:here.getLevel();
obj_versions python:here.getObjVersions();">

<div class="diff-container container">
<div class="diff-container container center">
<div class="row">
<div class="col-sm-6 col-original">
<div class="input-group mb-3" title="original">
Expand Down Expand Up @@ -46,7 +46,7 @@
<pre class="changed json d-none"></pre>
</div>
<div class="col-sm-12">
<pre class="diff preview"></pre>
<div class="diff preview"></div>
<pre class="diff json d-none"></pre>
</div>
</div>
Expand Down Expand Up @@ -92,17 +92,19 @@ function toggle_view(btn,btn_func) {
}
}

function get_htmldiff() {
let href = $ZMI.getPhysicalPath();
let original = $('.diff-container .original.preview').html();
let changed = $('.diff-container .changed.preview').html();
function get_htmldiff(container, qualifier) {
let originalContainer = qualifier + '.original';
let changedContainer = qualifier + '.changed';
let diffContainer = qualifier + '.diff';
let original = $(originalContainer).html();
let changed = $(changedContainer).html();
let data = {
'original':original,
'changed':changed
};
$.ajax({
type: "POST",
url: $ZMI.get_rest_api_url(href)+'/get_htmldiff',
url: $ZMI.get_rest_api_url($ZMI.getPhysicalPath())+'/get_htmldiff',
data: data,
dataType: 'html',
success: function(html) {
Expand Down Expand Up @@ -161,7 +163,7 @@ function diff(container, qualifier) {
$preview.text($(this).val());
$.get($ZMI.get_rest_api_url(href)+"/body_content", {tag:tag}, function(html) {
$preview.html(html);
diff($('.diff-container'),'.preview');
get_htmldiff($('.diff-container'),'.preview');
});
$.get($ZMI.get_rest_api_url(href)+"/get_tag",{tag:tag},function(json) {
var str = JSON.stringify(json, null, 4);
Expand Down

0 comments on commit 1219c2c

Please sign in to comment.