Hardcode the Ding1 theme
[mkdru-moved-to-drupal.org.git] / mkdru.theme.js
1 Drupal.theme.prototype.mkdruResult = function(hit, num, detailLink) {
2   var link = choose_url(hit);
3   if (!link) link = choose_url(hit['location'][0]);
4   var html = "";
5   html += '<li class="search-result" id="rec_' + hit.recid + '" >'
6     + '<h3 class="title">';
7   if (link) html += '<a href="'+link+'" target="_blank" >';
8   html += hit["md-title"];
9   if (link) html += '</a>';
10   html += '</h3>';
11   html += '<div class="search-snippet-info">'
12      + '<p class="search-snippet"></p>'
13      + '<div class="ting-object clearfix">'
14       + '<div class="ting-overview clearfix">'
15         + '<div class="left-column left">'
16           + '<div class="picture"></div>'
17         + '</div>'
18         + '<div class="right-column left">';
19   if (hit["md-author"]) {
20     html += '<div class="creator"><span class="byline">By </span>'
21       + '<a class="author" href="/search/meta/'+hit['md-author']+'">'
22       + hit['md-author']+'</a>';
23     if (hit['md-date']) {
24       html += '<span class="date"> ('+hit['md-date']+')</span>';
25     }
26     html += '</div><p></p>';
27   }
28   html += "</div>";
29   if (hit["md-description"]) {
30     // limit description to 400 characters
31     html += hit["md-description"][0].substr(0, 400);
32   }
33   html += '</div>'
34   html += '</div>'
35   html += '</div>'
36   html += '</li>';
37   return html;
38 };
39
40 Drupal.theme.prototype.mkdruDetail = function(data, linkBack) {
41   var html = '<table id="det_' + data.recid +'">';
42   if (data["md-title"] != undefined) {
43     html += '<tr><th>' + Drupal.t("Title") + '</th><td><strong>:</strong> '
44             + data["md-title"];
45     if (data["md-title-remainder"] !== undefined) {
46       html += ' : <span>' + data["md-title-remainder"] + ' </span>';
47     }
48     if (data["md-title-responsibility"] !== undefined) {
49       html += ' <span><i>'+ data["md-title-responsibility"] +'</i></span>';
50     }
51     html += '</td></tr>';
52   }
53   if (data["md-date"] != undefined)
54     html += '<tr><th>' + Drupal.t("Date") + '</th><td><strong>:</strong> '
55             + data["md-date"] + '</td></tr>';
56   if (data["md-author"] != undefined)
57     html += '<tr><th>' + Drupal.t("Author") + '</th><td><strong>:</strong> '
58             + data["md-author"] + '</td></tr>';
59   if (data["md-electronic-url"] != undefined)
60     html += '<tr><th>URL</th><td><strong>:</strong> <a href="'
61             + data["md-electronic-url"] + '" target="_blank">'
62             + data["md-electronic-url"] + '</a>' + '</td></tr>';
63   if (data["location"][0]["md-subject"] != undefined)
64     html += '<tr><th>' + Drupal.t("Subject") + '</th><td><strong>:</strong> '
65             + data["location"][0]["md-subject"] + '</td></tr>';
66   if (data["location"][0]["@name"] != undefined)
67     html += '<tr><th>' + Drupal.t("Location") + '</th></td><td><strong>:</strong> '
68             + data["location"][0]["@name"] + " (" + data["location"][0]["@id"] + ")"
69             + '</td></tr>';
70   html += '</table></div>';
71   html += '<a href="' + linkBack + '">Return to result list...</a>';
72   return html;
73 };
74
75 /**
76  * Pager theme
77  *
78  * @param pages
79  *   Array of hrefs for page links.
80  * @param start
81  *   Number of first page.
82  * @param current
83  *   Number of current page.
84  * @param total
85  *   Total number of pages.
86  * @param prev
87  *   Href for previous page.
88  * @param next
89  *   Href for next page.
90  */
91 Drupal.theme.prototype.mkdruPager = function (pages, start, current, total, prev, next) {
92   var html = "";
93   if (prev) 
94     html += '<a href="' + prev + '" class="mkdru-pager-prev">&#60;&#60; '
95             + Drupal.t("Prev") + '</a> | ';
96   else
97     html += '<span class="mkdru-pager-prev">&#60;&#60; ' + Drupal.t("Prev")
98             + '</span> | ';
99
100   if (start > 1)
101     html += '...';
102
103   for (var i = 0; i < pages.length; i++) {
104     if (i + start == current)
105       html += ' <span class="mkdru-pager-current">' + (i + start) + '</span>';
106     else
107       html += ' <a href="' + pages[i] + '">' + (i + start) + '</a>';
108   }
109
110   if (total > i)
111     html += ' ...';
112
113   if (next)
114     html += ' | <a href="' + next + '" class="mkdru-pager-next">'
115       + Drupal.t("Next") + ' &#62;&#62;</a>';
116   else
117     html += ' | <span class="mkdru-pager-next">' + Drupal.t("Next")
118             + ' &#62;&#62;</span>';
119
120   return html;
121 };
122
123 Drupal.theme.prototype.mkdruCounts = function(first, last, available, total) {
124   if (last > 0)
125     return first + Drupal.t(' to ') + last + Drupal.t(' of ') + available
126          + Drupal.t(' available (') + total + Drupal.t(' found)');
127   else
128     return Drupal.t('No results');
129 };
130
131 Drupal.theme.prototype.mkdruStatus = function(activeClients, clients) {
132   return Drupal.t('Waiting on ') + activeClients + Drupal.t(' out of ')
133          + clients + Drupal.t(' targets');
134 };
135
136 Drupal.theme.prototype.mkdruFacet = function (terms, facet, max, selections) {
137   var html = "";
138   for (var i = 0; i < terms.length && i < max; i++ ) {
139     var term = terms[i];
140     html += '<a href="'+term.toggleLink+'"';
141     if (term.selected) html += ' class="cross"><strong';
142     html += '>'+terms[i].name;
143     if (term.selected) html += "</strong>";
144     html += '</a><span> (' + terms[i].freq
145         + ')</span><br/>';
146   }
147   if (terms.length == 0 && selections && selections.length) {
148     for (var i=0; i<selections.length; i++) {
149       if (selections[i]) {
150         // since we have no target name (only id) go for the basename
151         // FIXME get the proper target name
152         var name = facet == "source" ? selections[i].replace(/.*[\/\\]/, "")
153           .replace(/\?.*/, '')
154           : selections[i];
155         html += '<a class="cross" href="'
156           + mkdru.removeLimit(facet, selections[i])
157           + '"><strong>'+name+'</strong></a><span> (0)</span><br/>';
158       }
159     } 
160   }
161   return html;
162 };
163
164 Drupal.theme.prototype.mkdruFacetContainer = function (facetsCfg) {
165     var fs = [];
166   for (var fname in facetsCfg) {
167     facetsCfg[fname].originalKey = fname;
168     fs.push(facetsCfg[fname]);
169   }
170   fs.sort(function (a,b) { return a.orderWeight - b.orderWeight });
171   var html = '<div class="content"><table class="mkdru-facets-table"><tr>';
172   for (var i=0; i<fs.length; i++) {
173     var f = fs[i];
174     html += '<td><fieldset class="form-wrapper">'
175     html += '<legend><span class="fieldset-legend">'+f.displayName
176       +'</span></legend>';
177     html += '<div class="fieldset-wrapper">';
178     html += '<div class="mkdru-facet-'+f.originalKey+'"/>';
179     html += '</div>';
180     html += '</fieldset></td>'
181   }
182   html += '</tr></table></div>';
183   return html;
184 };