Part of MKWS-413.
[mkws-moved-to-github.git] / src / mkws-widget.js
index fd51a12..94cd6f6 100644 (file)
@@ -71,9 +71,13 @@ mkws.makeWidget = function($, team, type, node) {
   function expandValue(val) {
     if (val.match(/^!param!/)) {
       var param = val.replace(/^!param!/, '');
+      var optional = param.match(/^\?/);
+      if (optional) {
+        param = param.replace(/^\?/, ''); 
+      }
       val = mkws.getParameterByName(param);
       that.info("obtained val '" + val + "' from param '" + param + "'");
-      if (!val) {
+      if (!val && !optional) {
         alert("This page has a MasterKey widget that needs a val specified by the '" + param + "' parameter");
       }
     } else if (val.match(/^!path!/)) {
@@ -100,42 +104,17 @@ mkws.makeWidget = function($, team, type, node) {
     var that = this;
     var query = this.config.autosearch;
     if (query) {
-      var old = this.team.config.query;
-      if (!old) {
-        // Stash this for subsequent inspection
-        this.team.config.query = query;
-      } else if (old === query) {
-        this.warn("duplicate autosearch: '" + query + "': ignoring");
-        return;
-      } else {
-        this.warn("conflicting autosearch: '" + query + "' vs '" + old + "': ignoring");
-        return;
-      }
+      // Should do this more elegantly with message passing
+      var widget = this.team.widget('query');
+      if (widget) { widget.node.val(query); }
 
       this.team.queue("ready").subscribe(function() {
-        // Postpone testing for the configuration items: these are not
-        // yet set for Record subclass widgets that fill them in in the
-        // subclass, as widget.autosearch is called in the superclass,
-        // before the subclass fiddles with the configuration.
-        var sortOrder = that.config.sort;
-        var maxrecs = that.config.maxrecs;
-        var perpage = that.config.perpage;
-        var limit = that.config.limit;
-        var targets = that.config.targets;
-        var targetfilter = that.config.targetfilter;
-        var target = that.config.target;
-        if (target) targetfilter = 'udb=="' + target + '"';
-
-        var s = "running auto search: '" + query + "'";
-        if (sortOrder) s += " sorted by '" + sortOrder + "'";
-        if (maxrecs) s += " restricted to " + maxrecs + " records";
-        if (perpage) s += " with " + perpage + " per page";
-        if (limit) s += " limited by '" + limit + "'";
-        if (targets) s += " in targets '" + targets + "'";
-        if (targetfilter) s += " constrained by targetfilter '" + targetfilter + "'";
-        that.info(s);
-
-        that.team.newSearch(query, sortOrder, maxrecs, perpage, limit, targets, targetfilter);
+        // Postpone search until the team is ready: configuration
+        // items are not yet set for Record subclass widgets that fill
+        // them in in the subclass, as widget.autosearch is called in
+        // the superclass, before the subclass fiddles with the
+        // configuration.
+        that.team.newSearch(that, query, sortOrder, maxrecs, perpage, limit, targets, targetfilter);
       });
     }
   };
@@ -182,7 +161,7 @@ mkws.makeWidget = function($, team, type, node) {
   if (fn) {
     fn.call(that);
     this.info("made " + type + " widget(node=" + node + ")");
-  } else if (type.match(/-Container-(narrow|wide)$/)) {
+  } else if (type.match(/-[Cc]ontainer-(narrow|wide)$/)) {
     // Not really a widget: no need to log its lack of promotion
   } else {
     this.info("made UNPROMOTED widget(type=" + type + ", node=" + node + ")");