refactor mkws_html_all()
authorWolfram Schneider <wosch@indexdata.dk>
Thu, 20 Jun 2013 13:27:23 +0000 (13:27 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Thu, 20 Jun 2013 13:27:23 +0000 (13:27 +0000)
experiments/spclient/mkws.js

index 9e14bdb..d8f43e3 100644 (file)
@@ -394,7 +394,48 @@ function mkws_html_all(data) {
        config[k] = data[k];
     }
 
+    mkws_html_switch(config);
 
+    // For some reason, doing this programmatically results in
+    // document.search.query being undefined, hence the raw HTML.
+    $("#mkwsSearch").html('\
+    <form id="searchForm" name="search">\
+      <input id="query" type="text" size="50" />\
+      <input id="button" type="submit" value="Search" />\
+    </form>');
+
+    $("#mkwsRecords").html('\
+      <table width="100%" border="0" cellpadding="6" cellspacing="0">\
+        <tr>\
+          <td width="250" valign="top">\
+            <div id="termlist"></div>\
+          </td>\
+          <td valign="top">\
+            <div id="ranking">\
+              <form name="select" id="select">\
+        Sort by' + mkws_html_sort(config) + '\
+        and show ' + mkws_html_perpage(config) + '\
+        per page.\
+       </form>\
+            </div>\
+            <div id="pager"></div>\
+            <div id="navi"></div>\
+            <div id="results"></div>\
+          </td>\
+        </tr>\
+      </table>\
+    </div>');
+
+    $("#mkwsTargets").html('\
+      <div id="bytarget">\
+       No information available yet.\
+      </div>');
+    $("#mkwsTargets").css("display", "none");
+
+    domReady();
+}
+
+function mkws_html_switch(config) {
     $("#mkwsSwitch").html($("<a/>", {
        href: '#',
        onclick: "switchView(\'records\')",
@@ -410,8 +451,11 @@ function mkws_html_all(data) {
     if (!config.mkws_switch) {
         $("#mkwsSwitch").css("display", "none");
     }
+}
 
+function mkws_html_sort(config) {
     var sort_html = '<select name="sort" id="sort">';
+
     for(var i = 0; i < config.sort.length; i++) {
        var key = config.sort[i][0];
        var val = config.sort[i].length == 1 ? config.sort[i][0] : config.sort[i][1];
@@ -424,7 +468,12 @@ function mkws_html_all(data) {
     }
     sort_html += '</select>';
 
+    return sort_html;
+}
+
+function mkws_html_perpage(config) {
     var perpage_html = '<select name="perpage" id="perpage">';
+
     for(var i = 0; i < config.perpage.length; i++) {
        var key = config.perpage[i];
 
@@ -436,43 +485,7 @@ function mkws_html_all(data) {
     }
     perpage_html += '</select>';
 
-    // For some reason, doing this programmatically results in
-    // document.search.query being undefined, hence the raw HTML.
-    $("#mkwsSearch").html('\
-    <form id="searchForm" name="search">\
-      <input id="query" type="text" size="50" />\
-      <input id="button" type="submit" value="Search" />\
-    </form>');
-
-    $("#mkwsRecords").html('\
-      <table width="100%" border="0" cellpadding="6" cellspacing="0">\
-        <tr>\
-          <td width="250" valign="top">\
-            <div id="termlist"></div>\
-          </td>\
-          <td valign="top">\
-            <div id="ranking">\
-              <form name="select" id="select">\
-        Sort by' + sort_html + '\
-        and show ' + perpage_html + '\
-        per page.\
-       </form>\
-            </div>\
-            <div id="pager"></div>\
-            <div id="navi"></div>\
-            <div id="results"></div>\
-          </td>\
-        </tr>\
-      </table>\
-    </div>');
-
-    $("#mkwsTargets").html('\
-      <div id="bytarget">\
-       No information available yet.\
-      </div>');
-    $("#mkwsTargets").css("display", "none");
-
-    domReady();
+    return perpage_html;
 }
 
 /*