remove the class from the parent
[mkdru-moved-to-drupal.org.git] / mkdru.theme.js
1 Drupal.theme.prototype.mkdruResult = function(hit, num, detailLink) {
2   var html = "";
3
4   // OPEN - result list item
5   html += '<li class="mkdru-result" id="rec_' + hit.recid + '" >'
6
7   // thumbnail
8   html += '<div class="picture"></div>';
9
10   // OPEN - record div
11   html += '<div class="record">';
12
13
14   // media type
15   if (hit["md-medium"] && hit["md-medium"][0]) {
16     html += '<div class="types">'
17       + '<ul class="ting-search-collection-types item-list">'
18       + '<li class="available even first last">';
19     switch (hit["md-medium"][0]) {
20       case '(CD)videorecording':
21         html += Drupal.t('CD');
22         break;
23       case '(DVD)videorecording':
24         html += Drupal.t('DVD');
25         break;        
26       case 'article':
27         html += Drupal.t('article');
28         break;      
29       case 'book':
30         html += Drupal.t('book');
31         break;
32       case 'cartographic material':
33         html += Drupal.t('map');
34         break;
35       case 'electronicresource':
36         html += Drupal.t('online');
37         break;
38       case 'Enregistrementsonore':
39         html += Drupal.t('recording');
40         break;
41       case 'enregistrementvidéo':
42         html += Drupal.t('video');
43         break;
44       case 'map':
45         html += Drupal.t('map');
46         break;
47       case 'microform':
48         html += Drupal.t('microform');
49         break;
50       case 'microforme':
51         html += Drupal.t('microform');
52         break;
53       case 'resourceélectronique':
54         html += Drupal.t('online');
55         break;
56       case 'ressourceélectronique':
57         html += Drupal.t('online');
58         break;
59       case 'soundrecording':
60         html += Drupal.t('recording');
61         break;
62       case 'videorecording':
63         html += Drupal.t('video');
64         break;
65       default:
66         html += Drupal.t('other');
67         break;
68     }
69     html += '</li></ul></div>';
70   }
71
72
73   // title and link
74   var link = choose_url(hit);
75   if (!link) link = choose_url(hit['location'][0]);
76
77   html += '<h3 class="title">';
78   if (link) html += '<a href="' + link + '" target="_blank" class="title">';
79   html += hit["md-title"];
80   if (hit["md-title-remainder"])
81     html += ' - ' + hit["md-title-remainder"];
82   if (link) html += '</a>';
83   html += '</h3>';
84
85
86   html += '<div class="meta">';
87   // author
88   if (hit["md-author"]) {
89     html += '<span class="creator">' + Drupal.t('By')
90       + ' <em>' + hit['md-author'] + '</em></span> ';
91   } else if (hit['md-title-responsibility']) {
92     html += '<span class="creator">' + ' <em>' + hit['md-title-responsibility'] + '</em></span>';
93   }
94   // date
95   if (hit['md-date']) {
96     html += '<span class="publication_date"> (<em>'
97       + hit['md-date'] + '</em>)</span>';
98   }
99   html += '</div>';
100
101   // journal title
102   html += '<div class="meta">';
103   if (hit["location"] && hit["location"][0] && hit["location"][0]["md-journal-title"]) {
104     html += hit["location"][0]["md-journal-title"];
105     if (hit["location"][0]["md-journal-subpart"]) {
106       html += '&nbsp;&nbsp;&nbsp;' + hit["location"][0]["md-journal-subpart"];
107     }
108   } else if (hit["md-journal-title"]) {
109     html += hit["md-journal-title"];
110     if (hit["md-journal-subpart"]) {
111       html += '&nbsp;&nbsp;&nbsp;' + hit["md-journal-subpart"];
112     }
113   }
114   html += '</div>';
115   
116   
117   // description
118   if (hit["md-description"]) {
119     html += '<div class="abstract"><p>';
120     // limit description to 400 characters
121     html += hit["md-description"][0].substr(0, 400);
122     html += '</p></div>';
123   }
124
125
126   // subjects
127   if (hit["location"] && hit["location"][0] && hit["location"][0]["md-subject"]) {
128     html += '<div class="subjects"><h4>'
129       + Drupal.t('Subjects') + ':</h4><ul>';
130     for (var i = 0; i < hit["location"][0]["md-subject"].length; i++) {
131       html += '<li>' + hit["location"][0]["md-subject"][i]  + '</li>';
132     }
133     html += '</ul></div>';
134   }
135
136   // CLOSE - record div
137   html += '</div>';
138   // CLOSE - result list item
139   html += '</li>';
140
141   return html;
142 };
143
144 Drupal.theme.prototype.mkdruDetail = function(data, linkBack) {
145   var html = '<table id="det_' + data.recid +'">';
146   if (data["md-title"] != undefined) {
147     html += '<tr><th>' + Drupal.t("Title") + '</th><td><strong>:</strong> '
148             + data["md-title"];
149     if (data["md-title-remainder"] !== undefined) {
150       html += ' : <span>' + data["md-title-remainder"] + ' </span>';
151     }
152     if (data["md-title-responsibility"] !== undefined) {
153       html += ' <span><i>'+ data["md-title-responsibility"] +'</i></span>';
154     }
155     html += '</td></tr>';
156   }
157   if (data["md-date"] != undefined)
158     html += '<tr><th>' + Drupal.t("Date") + '</th><td><strong>:</strong> '
159             + data["md-date"] + '</td></tr>';
160   if (data["md-author"] != undefined)
161     html += '<tr><th>' + Drupal.t("Author") + '</th><td><strong>:</strong> '
162             + data["md-author"] + '</td></tr>';
163   if (data["md-electronic-url"] != undefined)
164     html += '<tr><th>URL</th><td><strong>:</strong> <a href="'
165             + data["md-electronic-url"] + '" target="_blank">'
166             + data["md-electronic-url"] + '</a>' + '</td></tr>';
167   if (data["location"][0]["md-subject"] != undefined)
168     html += '<tr><th>' + Drupal.t("Subject") + '</th><td><strong>:</strong> '
169             + data["location"][0]["md-subject"] + '</td></tr>';
170   if (data["location"][0]["@name"] != undefined)
171     html += '<tr><th>' + Drupal.t("Location") + '</th></td><td><strong>:</strong> '
172             + data["location"][0]["@name"] + " (" + data["location"][0]["@id"] + ")"
173             + '</td></tr>';
174   html += '</table></div>';
175   html += '<a href="' + linkBack + '">Return to result list...</a>';
176   return html;
177 };
178
179 /**
180  * Pager theme
181  *
182  * @param pages
183  *   Array of hrefs for page links.
184  * @param start
185  *   Number of first page.
186  * @param current
187  *   Number of current page.
188  * @param total
189  *   Total number of pages.
190  * @param prev
191  *   Href for previous page.
192  * @param next
193  *   Href for next page.
194  */
195 Drupal.theme.prototype.mkdruPager = function (pages, start, current, total, prev, next) {
196   var html = "";
197   if (prev) 
198     html += '<a href="' + prev + '" class="mkdru-pager-prev">&#60;&#60; '
199             + Drupal.t("Prev") + '</a> | ';
200   else
201     html += '<span class="mkdru-pager-prev">&#60;&#60; ' + Drupal.t("Prev")
202             + '</span> | ';
203
204   if (start > 1)
205     html += '...';
206
207   for (var i = 0; i < pages.length; i++) {
208     if (i + start == current)
209       html += ' <span class="mkdru-pager-current">' + (i + start) + '</span>';
210     else
211       html += ' <a href="' + pages[i] + '">' + (i + start) + '</a>';
212   }
213
214   if (total > i)
215     html += ' ...';
216
217   if (next)
218     html += ' | <a href="' + next + '" class="mkdru-pager-next">'
219       + Drupal.t("Next") + ' &#62;&#62;</a>';
220   else
221     html += ' | <span class="mkdru-pager-next">' + Drupal.t("Next")
222             + ' &#62;&#62;</span>';
223
224   return html;
225 };
226
227 Drupal.theme.prototype.mkdruCounts = function(first, last, available, total) {
228   if (last > 0)
229     return first + Drupal.t(' to ') + last + Drupal.t(' of ') + available
230          + Drupal.t(' available (') + total + Drupal.t(' found)');
231   else
232     return Drupal.t('No results');
233 };
234
235 Drupal.theme.prototype.mkdruStatus = function(activeClients, clients) {
236   if (Number(activeClients) < 1) {
237     jQuery('a[href="#addon-0-result"]').parent().removeClass('spinning');  
238   }
239   return Drupal.t('Waiting on ') + activeClients + Drupal.t(' out of ')
240          + clients + Drupal.t(' targets');
241 };
242
243 Drupal.theme.prototype.mkdruFacet = function (terms, facet, max, selections) {
244   var html = "";
245   for (var i = 0; i < terms.length && i < max; i++ ) {
246     var term = terms[i];
247     html += '<a href="'+term.toggleLink+'"';
248     if (term.selected) html += ' class="cross"><strong';
249     html += '>'+terms[i].name;
250     if (term.selected) html += "</strong>";
251     html += '</a><span> (' + terms[i].freq
252         + ')</span><br/>';
253   }
254   if (terms.length == 0 && selections && selections.length) {
255     for (var i=0; i<selections.length; i++) {
256       if (selections[i]) {
257         // since we have no target name (only id) go for the basename
258         // FIXME get the proper target name
259         var name = facet == "source" ? selections[i].replace(/.*[\/\\]/, "")
260           .replace(/\?.*/, '')
261           : selections[i];
262         html += '<a class="cross" href="'
263           + mkdru.removeLimit(facet, selections[i])
264           + '"><strong>'+name+'</strong></a><span> (0)</span><br/>';
265       }
266     } 
267   }
268   return html;
269 };
270
271 Drupal.theme.prototype.mkdruFacetContainer = function (facetsCfg) {
272   var fs = [];
273   for (var fname in facetsCfg) {
274     facetsCfg[fname].originalKey = fname;
275     fs.push(facetsCfg[fname]);
276   }
277   fs.sort(function (a,b) { return a.orderWeight - b.orderWeight });
278   var html = '<div class="content"><table class="mkdru-facets-table"><tr>';
279   for (var i=0; i<fs.length; i++) {
280     var f = fs[i];
281     html += '<td><fieldset class="form-wrapper">'
282     html += '<legend><span class="fieldset-legend">'+f.displayName
283       +'</span></legend>';
284     html += '<div class="fieldset-wrapper">';
285     html += '<div class="mkdru-facet-list-container mkdru-facet-'
286       +f.originalKey+'"/>';
287     html += '</div>';
288     html += '</fieldset></td>'
289   }
290   html += '</tr></table></div>';
291   return html;
292 };