remove the class from the parent
[mkdru-moved-to-drupal.org.git] / mkdru.theme.js
index 92e1340..ce5fe15 100644 (file)
 Drupal.theme.prototype.mkdruResult = function(hit, num, detailLink) {
   var html = "";
+
+  // OPEN - result list item
   html += '<li class="mkdru-result" id="rec_' + hit.recid + '" >'
-          + '<span>' + num + '. </span>'
-          + '<a href="' + detailLink + '" class="mkdru-result-title">'
-          + hit["md-title"] + '</a> ';
-  if (hit["md-title-remainder"] !== undefined) {
-    html += '<span class="mkdru-result-title-remainder">' 
-            + hit["md-title-remainder"] + ' </span>';
+
+  // thumbnail
+  html += '<div class="picture"></div>';
+
+  // OPEN - record div
+  html += '<div class="record">';
+
+
+  // media type
+  if (hit["md-medium"] && hit["md-medium"][0]) {
+    html += '<div class="types">'
+      + '<ul class="ting-search-collection-types item-list">'
+      + '<li class="available even first last">';
+    switch (hit["md-medium"][0]) {
+      case '(CD)videorecording':
+        html += Drupal.t('CD');
+        break;
+      case '(DVD)videorecording':
+        html += Drupal.t('DVD');
+        break;        
+      case 'article':
+        html += Drupal.t('article');
+        break;      
+      case 'book':
+        html += Drupal.t('book');
+        break;
+      case 'cartographic material':
+        html += Drupal.t('map');
+        break;
+      case 'electronicresource':
+        html += Drupal.t('online');
+        break;
+      case 'Enregistrementsonore':
+        html += Drupal.t('recording');
+        break;
+      case 'enregistrementvidéo':
+        html += Drupal.t('video');
+        break;
+      case 'map':
+        html += Drupal.t('map');
+        break;
+      case 'microform':
+        html += Drupal.t('microform');
+        break;
+      case 'microforme':
+        html += Drupal.t('microform');
+        break;
+      case 'resourceélectronique':
+        html += Drupal.t('online');
+        break;
+      case 'ressourceélectronique':
+        html += Drupal.t('online');
+        break;
+      case 'soundrecording':
+        html += Drupal.t('recording');
+        break;
+      case 'videorecording':
+        html += Drupal.t('video');
+        break;
+      default:
+        html += Drupal.t('other');
+        break;
+    }
+    html += '</li></ul></div>';
+  }
+
+
+  // title and link
+  var link = choose_url(hit);
+  if (!link) link = choose_url(hit['location'][0]);
+
+  html += '<h3 class="title">';
+  if (link) html += '<a href="' + link + '" target="_blank" class="title">';
+  html += hit["md-title"];
+  if (hit["md-title-remainder"])
+    html += ' - ' + hit["md-title-remainder"];
+  if (link) html += '</a>';
+  html += '</h3>';
+
+
+  html += '<div class="meta">';
+  // author
+  if (hit["md-author"]) {
+    html += '<span class="creator">' + Drupal.t('By')
+      + ' <em>' + hit['md-author'] + '</em></span> ';
+  } else if (hit['md-title-responsibility']) {
+    html += '<span class="creator">' + ' <em>' + hit['md-title-responsibility'] + '</em></span>';
+  }
+  // date
+  if (hit['md-date']) {
+    html += '<span class="publication_date"> (<em>'
+      + hit['md-date'] + '</em>)</span>';
+  }
+  html += '</div>';
+
+  // journal title
+  html += '<div class="meta">';
+  if (hit["location"] && hit["location"][0] && hit["location"][0]["md-journal-title"]) {
+    html += hit["location"][0]["md-journal-title"];
+    if (hit["location"][0]["md-journal-subpart"]) {
+      html += '&nbsp;&nbsp;&nbsp;' + hit["location"][0]["md-journal-subpart"];
+    }
+  } else if (hit["md-journal-title"]) {
+    html += hit["md-journal-title"];
+    if (hit["md-journal-subpart"]) {
+      html += '&nbsp;&nbsp;&nbsp;' + hit["md-journal-subpart"];
+    }
   }
-  if (hit["md-title-responsibility"] !== undefined) {
-    html += '<span class="mkdru-result-author"><i>'
-            + hit["md-title-responsibility"]
-            + '</i></span>';
+  html += '</div>';
+  
+  
+  // description
+  if (hit["md-description"]) {
+    html += '<div class="abstract"><p>';
+    // limit description to 400 characters
+    html += hit["md-description"][0].substr(0, 400);
+    html += '</p></div>';
+  }
+
+
+  // subjects
+  if (hit["location"] && hit["location"][0] && hit["location"][0]["md-subject"]) {
+    html += '<div class="subjects"><h4>'
+      + Drupal.t('Subjects') + ':</h4><ul>';
+    for (var i = 0; i < hit["location"][0]["md-subject"].length; i++) {
+      html += '<li>' + hit["location"][0]["md-subject"][i]  + '</li>';
+    }
+    html += '</ul></div>';
   }
+
+  // CLOSE - record div
+  html += '</div>';
+  // CLOSE - result list item
   html += '</li>';
+
   return html;
 };
 
@@ -101,35 +225,68 @@ Drupal.theme.prototype.mkdruPager = function (pages, start, current, total, prev
 };
 
 Drupal.theme.prototype.mkdruCounts = function(first, last, available, total) {
-  return first + Drupal.t(' to ') + last + Drupal.t(' of ') + available
+  if (last > 0)
+    return first + Drupal.t(' to ') + last + Drupal.t(' of ') + available
          + Drupal.t(' available (') + total + Drupal.t(' found)');
+  else
+    return Drupal.t('No results');
 };
 
 Drupal.theme.prototype.mkdruStatus = function(activeClients, clients) {
+  if (Number(activeClients) < 1) {
+    jQuery('a[href="#addon-0-result"]').parent().removeClass('spinning');  
+  }
   return Drupal.t('Waiting on ') + activeClients + Drupal.t(' out of ')
          + clients + Drupal.t(' targets');
 };
 
-Drupal.theme.prototype.mkdruFacet = function (terms, facet, max) {
+Drupal.theme.prototype.mkdruFacet = function (terms, facet, max, selections) {
   var html = "";
   for (var i = 0; i < terms.length && i < max; i++ ) {
-    html += '<a href="';
-    if (facet == 'source')
-      html += mkdru.addLimit(facet, terms[i].id);
-    else 
-      html += mkdru.addLimit(facet, terms[i].name);
-    html += '">' + terms[i].name + '</a><span> (' + terms[i].freq + ')</span><br/>';
+    var term = terms[i];
+    html += '<a href="'+term.toggleLink+'"';
+    if (term.selected) html += ' class="cross"><strong';
+    html += '>'+terms[i].name;
+    if (term.selected) html += "</strong>";
+    html += '</a><span> (' + terms[i].freq
+        + ')</span><br/>';
+  }
+  if (terms.length == 0 && selections && selections.length) {
+    for (var i=0; i<selections.length; i++) {
+      if (selections[i]) {
+        // since we have no target name (only id) go for the basename
+        // FIXME get the proper target name
+        var name = facet == "source" ? selections[i].replace(/.*[\/\\]/, "")
+          .replace(/\?.*/, '')
+          : selections[i];
+        html += '<a class="cross" href="'
+          + mkdru.removeLimit(facet, selections[i])
+          + '"><strong>'+name+'</strong></a><span> (0)</span><br/>';
+      }
+    } 
   }
   return html;
 };
 
-Drupal.theme.prototype.mkdruFacetLimit = function (term, link) {
-  if (term) {
-    return '<p>' + Drupal.t('Only displaying ') + term.name + '</p>'
-      + '<p><a href="' + link + '">' + Drupal.t('Show all...') + '</a></p>';
+Drupal.theme.prototype.mkdruFacetContainer = function (facetsCfg) {
+  var fs = [];
+  for (var fname in facetsCfg) {
+    facetsCfg[fname].originalKey = fname;
+    fs.push(facetsCfg[fname]);
   }
-};
-
-Drupal.theme.prototype.mkdruFacetContainer = function (facets, facetCfg) {
-  return "";
+  fs.sort(function (a,b) { return a.orderWeight - b.orderWeight });
+  var html = '<div class="content"><table class="mkdru-facets-table"><tr>';
+  for (var i=0; i<fs.length; i++) {
+    var f = fs[i];
+    html += '<td><fieldset class="form-wrapper">'
+    html += '<legend><span class="fieldset-legend">'+f.displayName
+      +'</span></legend>';
+    html += '<div class="fieldset-wrapper">';
+    html += '<div class="mkdru-facet-list-container mkdru-facet-'
+      +f.originalKey+'"/>';
+    html += '</div>';
+    html += '</fieldset></td>'
+  }
+  html += '</tr></table></div>';
+  return html;
 };