summaryrefslogtreecommitdiffstats
path: root/src/collective/dms/thesaurus/browser/dmsthesaurus_view.pt
blob: f4c1897fac32d30beb706a6cbe8f2993af9a50d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="plone.app.dexterity">
<body>

<metal:main fill-slot="main">

    <tal:contents_header condition="python: 'ajax_load' not in request.form.keys()">
    <h1 class="documentFirstHeading" tal:content="context/Title" /> 
    <div tal:replace="structure provider:plone.belowcontenttitle" />
    </tal:contents_header>

    <div id="dmskeywords-navigation"
         tal:attributes="data-thesaurus-url context/absolute_url">

    <form id="thesaurus-search-form" tal:content="structure view/renderForm">
    </form>

    <div id="dmsthesaurus-entry-points-field"
        class="field"
        tal:define="widget python:view.widgets.get('entry_points')">
        <label tal:content="widget/label" />
        <br />
        <div tal:content="structure widget/render" />
    </div>

<script type="text/javascript" tal:condition="python: 'ajax_load' not in request.form.keys()">
function autocomplete_ready(event, data, formatted) {
  window.location=window.location+'/'+data[1];
}

$(document).ready(function() {
    $('.keyword-search').autocomplete('listKeywords', {
                'cacheLength': 0, 'matchContains': true, 'scroll': true, 'max': 30}).result(autocomplete_ready);
});
</script>


<script type="text/javascript" tal:condition="python: 'ajax_load' in request.form.keys()">
function prep_thesaurus_overlay() {
  $('.overlay-ajax a').click(function() {
    var urlsplit = $(this).attr('href').split('/');
    var keyword_id = urlsplit[urlsplit.length-1];
    $(this).parents('.overlay-ajax').data('keyword-id', keyword_id);
    $('.pb-ajax > div').load($(this).attr('href') + '?ajax_load=123 #content>*', prep_thesaurus_overlay);
    return false;
  });
  $('.overlay-ajax button').click(function() {
    overlay_id = $(this).parents('.overlay-ajax').attr('id');
    var id = $(this).parents('.overlay-ajax').data('keyword-id');
    var title = $(this).parents('.overlay-ajax').find('h1').text();

    /* when used as a field widget */
    field = $('a[rel="#' + overlay_id + '"]').parents('.field');
    if (field) {
      $(field).find('select').append('<option id="' + id + '" selected="selected" value="' + id + '"></option>');
      $(field).find('.selected-options').append('<span class="selected-option" data-term-id="' + id + '">' +
          '<span>' + title + '</span>' +
          '<span class="remove">×</span></span>\n');

      $('span.remove').unbind('click').click(function() {
        var field = $(this).parents('.field');
        var term_id = $(this).parent().attr('data-term-id');
        $(field).find('select option[id=' + term_id + ']').remove();
        $(this).parent().remove();
      });
    }

    /* when used as a criteria widget */
    criteria = $('a[rel="#' + overlay_id + '"]').parents('.criteria');
    if (criteria) {
      $(criteria).find('input.queryvalue').val(id);
      $(criteria).find('input.querylabel').val(title);
      $.querywidget.updateSearch();
    }

    $(this).parents('.overlay-ajax').find('.close').click();
    return false;
  });
}

prep_thesaurus_overlay();

function autocomplete_ready(event, data, formatted) {
    var keyword_id = data[1];
    $(this).parents('.overlay-ajax').data('keyword-id', keyword_id);
    thesaurus_url = $('#dmskeywords-navigation').data('thesaurus-url');
    $('.pb-ajax > div').load(thesaurus_url+'/'+data[1] + '?ajax_load=123 #content>*', prep_thesaurus_overlay);
}

thesaurus_url = $('#dmskeywords-navigation').data('thesaurus-url');
$('.keyword-search').autocomplete(thesaurus_url + '/listKeywords', {
                'cacheLength': 0, 'matchContains': true, 'scroll': true, 'max': 30}).result(autocomplete_ready);


</script>

    </div>
</metal:main>

</body>
</html>