summaryrefslogtreecommitdiffstats
path: root/server/index.html
blob: 5767a0a7feab7c36fa3b87c0fc82b7a3a177fd8f (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="fr">
 <head>
  <meta charset="utf-8"/>
  <link rel="stylesheet" type="text/css" media="all" href="style.css"/>
  <script src="js/jquery-1.7.2.min.js"></script>
  <title>Recherche</title>
  <script type="text/javascript">
var NUM_RESULTS = 25;

function display_results(data) {
  console.log('got results', data);
  var items = [];
  $('#debug').html(data['qtime']);
  $.each(data['results'], function(key, val) {
     if (val['id'].indexOf('N-') == 0) {
       url = 'pdfs-N/' + val['id'];
     } else {
       url = 'pdfs/' + val['id'];
     }
     items.push('<li><span class="score">' + Math.min(5, parseInt(val['score']*5)) + '</span> <a href="' + url + '">' + val['id'] + '</a></li>');
  });
  $('#results').html($('<ul/>', {html: items.join('')}));
  var orig_offset = $('#offset').val()*1;
  if ($('#offset').val()*1 > 0) {
    var prev_start = $('#offset').val()*1 - NUM_RESULTS;
    $('#offset').val(prev_start);
    link = '<a class="nav prev" href="?' + $('form').serialize() + '">Résultats précédents</a>';
    $('#results').append(link);
    $('#results .nav').last().data('offset', prev_start);
  } else {
    if (data['hits'] >= NUM_RESULTS) {
      link = '<span class="nav prev" href="#">Résultats précédents</span>';
      $('#results').append(link);
    }
  }
  $('#offset').val(orig_offset);
  if ($('#offset').val()*1 + $('#count').val()*1 < data['hits']*1) {
    var next_start = $('#offset').val()*1 + NUM_RESULTS;
    $('#offset').val(next_start);
    link = '<a class="nav next" href="?' + $('form').serialize() + '">Résultats suivants</a>';
    $('#results').append(link);
    $('#results .nav').last().data('offset', next_start);
  }
  $('#offset').val(orig_offset);

  $('#info').html('Nombre de résultats: ' + data['hits'] +
                  ' - page ' + ((orig_offset/NUM_RESULTS)+1) +
                  ' de ' + Math.max(1, parseInt((((data['hits']-1)/NUM_RESULTS)+1))));


  $('#results ul a').hover(
    function() { /* on hover */
      $('#preview').attr('src', 'about:blank');
      $('#preview').attr('src', 'search/' + $(this).attr('href'));
      $('#preview').show();
    },
    function () {
      $('#preview').hide();
    }
  );
  $('#results a.nav').click(function() {
    var this_link = $(this);
    $('#results a.nav').hide();
    $.getJSON('search/' + $(this).attr('href'), function(data) {
      $('#offset').val($(this_link).data('offset'));
      display_results(data);
    });
    return false;
  });
}

$(function() {
  $('form').submit(function() {
    $('#results').html('');
    $('#info').html('');
    $('#count').val(NUM_RESULTS);
    $('#offset').val(0);
    $('#preview').hide();
    $.getJSON('search/?' + $(this).serialize(), function(data) {
      display_results(data);
    });
    return false;
  });
});
  </script>
 </head>
 <body>

  <div id="wrap">
    <div id="header">
      <h1>PFWB</h1>
      <span>Prototype</span>
    </div>
    <div id="splash">
    </div>
    <div id="content">

    <div id="appbar">
    <h2>Prototype de moteur de recherche - GED PFWB</h2>
    <a href="upload.html">Ajouter un fichier</a>
    </div>

  <form>
   <input name="count" id="count" type="hidden"/>
   <input name="offset" id="offset" type="hidden"/>
   <input name="q" size="40"/>
   <input type="submit" value="Rechercher"/>
  </form>

  <div id="info">
  </div>

  <div id="results">
  </div>

  <img id="preview"/>

  <div id="debug">
  </div>

    <div id="footer">
        Entr'ouvert — 2012
    </div>
  </div>


 </body>
</html>