Termlists widget creates the individual Facet widgets therein.
[mkws-moved-to-github.git] / src / mkws-widgets.js
index 19f1066..90f1794 100644 (file)
@@ -83,6 +83,13 @@ widget.autosearch = function(widget) {
                if (!query) {
                    alert("This page has a MasterKey widget that needs a query specified by the path-component " + index);
                }
+            } else if (query.match(/^!var!/)) {
+               var name = query.replace(/^!var!/, '');
+               query = window[name]; // It's ridiculous that this works
+               widget.log("obtained query '" + query + "' from variable '" + name + "'");
+               if (!query) {
+                   alert("This page has a MasterKey widget that needs a query specified by the '" + name + "' variable");
+               }
            }
 
            var sortOrder = widget.config.sort;
@@ -118,6 +125,12 @@ mkws.registerWidgetType('Targets', function() {
     var that = this;
     var M = mkws.M;
 
+    $(this.node).html('\
+<div class="mkwsBytarget mkwsTeam_' + this.team.name() + '">\
+No information available yet.\
+</div>');
+    $(this.node).css("display", "none");
+
     this.team.queue("targets").subscribe(function(data) {
        var table ='<table><thead><tr>' +
            '<td>' + M('Target ID') + '</td>' +
@@ -237,6 +250,7 @@ mkws.registerWidgetType('Records', function() {
        var html = [];
        for (var i = 0; i < data.hits.length; i++) {
            var hit = data.hits[i];
+            that.team.queue("record").publish(hit);
            var divId = team.recordElementId(hit.recid[0]);
            html.push('<div class="record mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
            // ### At some point, we may be able to move the
@@ -270,20 +284,18 @@ mkws.registerWidgetType('Navi', function() {
        var filters = that.team.filters();
        var text = "";
 
-       for (var i in filters) {
-           if (text) {
-               text += " | ";
-           }
-           var filter = filters[i];
-           if (filter.id) {
-               text += M('source') + ': <a class="crossout" href="#" onclick="mkws.delimitTarget(\'' + teamName +
-                   "', '" + filter.id + "'" + ');return false;">' + filter.name + '</a>';
-           } else {
-               text += M(filter.field) + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(\'' + teamName +
-                   "', '" + filter.field + "', '" + filter.value + "'" +
-                   ');return false;">' + filter.value + '</a>';
-           }
-       }
+       filters.visitTargets(function(id, name) {
+           if (text) text += " | ";
+           text += M('source') + ': <a class="crossout" href="#" onclick="mkws.delimitTarget(\'' + teamName +
+               "', '" + id + "'" + ');return false;">' + name + '</a>';
+       });
+
+       filters.visitFields(function(field, value) {
+           if (text) text += " | ";
+           text += M(field) + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(\'' + teamName +
+               "', '" + field + "', '" + value + "'" +
+               ');return false;">' + value + '</a>';
+       });
 
        $(that.node).html(text);
     });
@@ -326,3 +338,36 @@ mkws.registerWidgetType('Done', function() {
        $(that.node).html("Search complete: found " + n + " records");
     });
 });
+
+
+mkws.registerWidgetType('Switch', function() {
+    var tname = this.team.name();
+    $(this.node).html('\
+<a href="#" onclick="mkws.switchView(\'' + tname + '\', \'records\')">Records</a><span> \
+| \
+</span><a href="#" onclick="mkws.switchView(\'' + tname + '\', \'targets\')">Targets</a>');
+});
+
+
+mkws.registerWidgetType('Search', function() {
+    var tname = this.team.name();
+    var M = mkws.M;
+
+    $(this.node).html('\
+<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
+  <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + this.config.query_width + '" />\
+  <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
+</form>');
+});
+
+
+mkws.registerWidgetType('SearchForm', function() {
+    var team = this.team;    
+    $(this.node).submit(function() {
+       var val = team.widget('Query').value();
+       team.newSearch(val);
+       return false;
+    });
+});
+
+