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 %}
This is an empty link. You should add some facets.
- + {% raw %} +