Add 'use as xanapage' to source document view.

This commit is contained in:
Edward Betts 2019-04-26 11:19:24 +01:00
parent 7ace452d43
commit 3adf364e64
3 changed files with 46 additions and 0 deletions

View file

@ -384,5 +384,13 @@ class SourceDoc(Item):
return start + first_line
return start + self.hashid
@property
def create_xanapage_url(self):
return self.view_url('create_xanapage_from_sourcedoc')
@property
def entire_span(self):
return self.external_url + f',start=0,length={len(self.text)}'
configure_mappers()

View file

@ -36,6 +36,31 @@
</div>
</div>
{% if doc.type == "sourcedoc" %}
<div class="modal fade" id="xanapage-modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Create new xanapage</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form method="POST" action="{{ doc.create_xanapage_url }}">
<div class="modal-body">
<p>Do you want to create a xanapage that contains this entire source document?</p>
<p>You need to create a xanapage if you want to make a xanaedit.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">cancel</button>
<button type="submit" class="btn btn-primary">create xanapage</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
{% if can_delete %}
<div class="modal fade" id="delete-modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
@ -139,6 +164,7 @@
<a class="btn btn-primary" href="{{ request.url }}/raw">raw</a>
<button id="show-span-selector" class="btn btn-primary">show span selector</button>
<button id="select-all" class="btn btn-primary">get entire document span</button>
<button id="create-xanapage-all" class="btn btn-success" data-toggle="modal" data-target="#xanapage-modal">use as xanapage</button>
<p id="span-selector" class="d-none">span: <span id="span"></span></p>
{% endif %}

View file

@ -401,6 +401,18 @@ def history(username, hashid):
item = get_item(username, hashid)
return render_template('history.html', doc=item)
@bp.route('/<username>/<hashid>/as_xanapage', methods=['POST'])
def create_xanapage_from_sourcedoc(username, hashid):
src_doc = get_source_doc(username, hashid)
edl = src_doc.entire_span + '\n'
page = XanaPage(user=current_user, text=edl)
session.add(page)
session.commit()
flash('New xanapage created.')
return redirect(page.url)
@bp.route('/<username>/<hashid>/xanaedit')
def xanaedit_item(username, hashid):
doc = get_xanapage(username, hashid)