From: Mike Taylor Date: Thu, 20 Mar 2014 09:49:57 +0000 (+0000) Subject: Widget-promotion switch is now driven by a table. X-Git-Tag: 1.0.0~1295 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=42ca1c4a0ca09e45e4cc56e91f1cf69584839d94;p=mkws-moved-to-github.git Widget-promotion switch is now driven by a table. Avoids repetitive code, and enables external extensions. --- diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 0ff94ff..b6f0e0e 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -158,24 +158,20 @@ function widget($, team, type, node) { var M = mkws.M; - if (type === 'Targets') { - promoteTargets(); - team.debug("made targets widget(node=" + node + ")"); - } else if (type === 'Stat') { - promoteStat(); - team.debug("made stat widget(node=" + node + ")"); - } else if (type === 'Termlists') { - promoteTermlists(); - team.debug("made termlists widget(node=" + node + ")"); - } else if (type === 'Pager') { - promotePager(); - team.debug("made pager widget(node=" + node + ")"); - } else if (type === 'Records') { - promoteRecords(); - team.debug("made records widget(node=" + node + ")"); + var type2fn = { + Targets: promoteTargets, + Stat: promoteStat, + Termlists: promoteTermlists, + Pager: promotePager, + Records: promoteRecords + }; + + var promote = type2fn[type]; + if (promote) { + promote(); + team.debug("made " + type + " widget(node=" + node + ")"); } else { - // ### Handle other types here - team.debug("made unencapsulated widget(type=" + type + ", node=" + node + ")"); + team.debug("made UNENCAPSULATED widget(type=" + type + ", node=" + node + ")"); } return that;