diff --git a/sourcing/static/js/new_xanalink.js b/sourcing/static/js/new_xanalink.js index a84f1a1..5ffb284 100644 --- a/sourcing/static/js/new_xanalink.js +++ b/sourcing/static/js/new_xanalink.js @@ -1,11 +1,62 @@ -$(function () { - $('#custom-field').hide(); +new Vue({ + el: '#app', + data: { + link_types: ['untyped', 'comment', 'title', 'author'], + address_types: ['xanapage', 'link', 'sourcedoc', 'span'], + link_type: "", + facets: [] + }, + methods: { + suggest_link_type(item) { + this.link_type = item != 'untyped' ? item : ''; + }, + suggest_address_type(item, facet_index, leg_index) { + console.log(item, facet_index, leg_index); + Vue.set(this.facets[facet_index], leg_index, item + ': '); + }, + new_facet(e) { + this.facets.push(['']); + }, + new_leg(facet) { + facet.push(''); + }, + delete_leg(facet_index, leg_index) { + var facet = this.facets[facet_index]; + facet.splice(leg_index, 1); + if (facet.length == 0) { + this.facets.splice(facet_index, 1); + } + }, + delete_facet(facet_index) { + this.facets.splice(facet_index, 1); + }, + save(e) { + var post_data = { + 'link_type': this.link_type, + 'facets': this.facets, + } + fetch(window.location.href, { + method: 'POST', + headers: { + "Content-Type": "application/json; charset=utf-8", + }, + body: JSON.stringify(post_data) + }) + .then(response => response.json()) + .then(json => { + window.location.href = json.url; + }); + }, + }, + computed: { + disable_save() { + return !(this.facets.length && this.facets[0][0] != ''); + }, + link_text() { + var text = 'type=' + this.link_type; + + return text; - $('.link-type-radio').click(function() { - if (this.id == 'btn-custom') { - $('#custom-field').show(); - } else { - $('#custom-field').hide(); } - }); + }, }); diff --git a/sourcing/templates/new_xanalink.html b/sourcing/templates/new_xanalink.html index bb03f2e..f670e7d 100644 --- a/sourcing/templates/new_xanalink.html +++ b/sourcing/templates/new_xanalink.html @@ -1,34 +1,85 @@ {% extends "base.html" %} {% block title %}New xanalink {% endblock %} -{% set link_types = ['untyped', 'title', 'author', 'custom'] %} {% block content %}

{{ self.title() }}

- -

This is an empty link. You should add some facets.

- + {% raw %} +
+
+
+

link type

-
- {% for link_type in link_types %} - - {% endfor %} -
-

custom link type:

-

new facet

+ link type: + +  |  + {{ item }} + +

+ +

- +

facets

- +
+
facet {{ facet_index + 1 }} + delete +
+ leg: + +  |  + {{ item }} + +
+
+ +
+
+ delete +
+
+
+

new leg

+
+
+ +

new facet

+ + +
+ +
+
+
+
+ Link source code preview +
+
+
+ type={{ link_type }}
+ + + facet=
+ + {{ leg }}
+
+
+
+
+
+
+
+
+
+ {% endraw %} {% endblock %} {% block scripts %} + {% endblock %} diff --git a/sourcing/view.py b/sourcing/view.py index 3264b24..ebfe9df 100644 --- a/sourcing/view.py +++ b/sourcing/view.py @@ -373,9 +373,9 @@ def new_sourcedoc(): return redirect(doc.url) return render_template('new.html', form=form, item_type='source document') -@bp.route('/new/xanalink', methods=['GET', 'POST']) +@bp.route('/new/xanalink/raw', methods=['GET', 'POST']) @login_required -def new_xanalink(): +def new_xanalink_raw(): form = ItemForm() if form.validate_on_submit(): obj = XanaLink(user=current_user) @@ -386,6 +386,24 @@ def new_xanalink(): return redirect(obj.url) return render_template('new.html', form=form, item_type='xanalink') +@bp.route('/new/xanalink', methods=['GET', 'POST']) +@login_required +def new_xanalink(): + if request.method != 'POST': + return render_template('new_xanalink.html') + + data = request.get_json() + lines = ['type=' + data['link_type']] + for facet in data['facets']: + lines += ['facet='] + facet + text = ''.join(line + '\n' for line in lines) + print(text) + obj = XanaLink(user=current_user, text=text) + session.add(obj) + session.commit() + flash('New xanalink saved.') + return jsonify(url=obj.url) + @bp.route('/new/xanadoc', methods=['GET', 'POST']) @login_required def new_xanadoc():