Vertical ws
[mkws-moved-to-github.git] / src / mkws-widgets.js
index b5d1373..cd9e45d 100644 (file)
@@ -10,7 +10,7 @@ function widget($, team, type, node) {
        team: team,
        type: type,
        node: node,
-       config: Object.create(team.config())
+       config: mkws.objectInheritingFrom(team.config())
     };
 
     function log(s) {
@@ -22,6 +22,10 @@ function widget($, team, type, node) {
        return '[Widget ' + team.name() + ':' + type + ']';
     };
 
+    that.value = function() {
+        return node.value;
+    }
+
     for (var i = 0; i < node.attributes.length; i++) {
        var a = node.attributes[i];
        if (a.name === 'data-mkws-config') {
@@ -181,24 +185,24 @@ mkws.registerWidgetType('Pager', function() {
                ? firstClkbl + 2*onsides
                : pages;
 
-           var prev = '<span class="mkwsPrev">&#60;&#60; ' + M('Prev') + '</span><b> | </b>';
+           var prev = '<span class="mkwsPrev">&#60;&#60; ' + M('Prev') + '</span> | ';
            if (currentPage > 1)
                prev = '<a href="#" class="mkwsPrev" onclick="mkws.pagerPrev(\'' + teamName + '\');">'
-               +'&#60;&#60; ' + M('Prev') + '</a><b> | </b>';
+               +'&#60;&#60; ' + M('Prev') + '</a> | ';
 
            var middle = '';
            for(var i = firstClkbl; i <= lastClkbl; i++) {
                var numLabel = i;
                if(i == currentPage)
-                   numLabel = '<b>' + i + '</b>';
+                   numLabel = '<span class="mkwsSelected">' + i + '</span>';
 
                middle += '<a href="#" onclick="mkws.showPage(\'' + teamName + '\', ' + i + ')"> '
                    + numLabel + ' </a>';
            }
 
-           var next = '<b> | </b><span class="mkwsNext">' + M('Next') + ' &#62;&#62;</span>';
+           var next = ' | <span class="mkwsNext">' + M('Next') + ' &#62;&#62;</span>';
            if (pages - currentPage > 0)
-               next = '<b> | </b><a href="#" class="mkwsNext" onclick="mkws.pagerNext(\'' + teamName + '\')">'
+               next = ' | <a href="#" class="mkwsNext" onclick="mkws.pagerNext(\'' + teamName + '\')">'
                + M('Next') + ' &#62;&#62;</a>';
 
            var predots = '';
@@ -218,6 +222,13 @@ mkws.registerWidgetType('Pager', function() {
 });
 
 
+mkws.registerWidgetType('Results', function() {
+    // Nothing to do apart from act as an autosearch trigger
+    // Contained elements do all the real work
+    widget.autosearch(this);
+});
+
+
 mkws.registerWidgetType('Records', function() {
     var that = this;
     var team = this.team;
@@ -259,20 +270,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);
     });
@@ -288,7 +297,6 @@ mkws.registerWidgetType('Sort', function() {
     $(this.node).change(function() {
        that.team.set_sortOrder($(that.node).val());
        if (that.team.submitted()) {
-           that.team.resetPage();
            that.team.reShow();
        }
        return false;
@@ -302,9 +310,17 @@ mkws.registerWidgetType('Perpage', function() {
     $(this.node).change(function() {
        that.team.set_perpage($(that.node).val());
        if (that.team.submitted()) {
-           that.team.resetPage();
            that.team.reShow();
        }
        return false;
     });
 });
+
+
+mkws.registerWidgetType('Done', function() {
+    var that = this;
+
+    this.team.queue("complete").subscribe(function(n) {
+       $(that.node).html("Search complete: found " + n + " records");
+    });
+});