From 7cf4791000a133522253a69dfd0e95e32e6b5661 Mon Sep 17 00:00:00 2001
From: inducedNCS <kidkinster@gmail.com>
Date: Fri, 11 May 2018 21:06:26 -0600
Subject: [PATCH] induced NCS, Quicklist penthouse tabs

Had a rethink and just put some filters on the tabbed content, so that
it only activates on the 'All' tab (which is the default tab).  The idea
is if you're clicking on the other tabs, you've already narrowed your
selection, but in the 'All' tab, the quick list will appear and work as
expected.

-	new file:   src/js/hTagMacroJS.tw
-	modified:   src/uncategorized/slaveSummary.tw
---
 src/js/hTagMacroJS.tw             | 47 +++++++++++++++++++++++++++++++
 src/uncategorized/slaveSummary.tw | 27 ++++++++++--------
 2 files changed, 63 insertions(+), 11 deletions(-)
 create mode 100644 src/js/hTagMacroJS.tw

diff --git a/src/js/hTagMacroJS.tw b/src/js/hTagMacroJS.tw
new file mode 100644
index 00000000000..9e8c566b7eb
--- /dev/null
+++ b/src/js/hTagMacroJS.tw
@@ -0,0 +1,47 @@
+:: HTAG Macro JS [script]
+
+/*
+ * <<htag>> macro
+ * A simple macro which allows to create wrapping html elements with dynamic IDs.
+ *      idea blatantly robbed from the spanMacroJS.tw  but expanded to a more generic 
+ *      case, allowing <div>, <button> or whatever you want. elements, default is for
+ *      the div though.  In addition, you can pass an object in as the first argument 
+ *      instead of an id, and each of the object's attributes will become attributes
+ *      of the generate tag.
+ *
+ * Usage: <<htag id>>...<</htag>>    
+ * Usage: <<htag id tag>>...<</htag>>    
+ * Usage: <<htag atributes>>...<</htag>>    
+ * Usage: <<htag atributes tag>>...<</htag>>    
+ */
+Macro.add('htag', {
+	tags     : null,
+		
+        munge(val, key) { return  key + '="' + val + '"'; },
+	handler() {
+		const payload   =   this.payload[0].contents.replace(/(^\n+|\n+$)/, '');
+		let htag        =   'div';
+		let attributes;
+		
+                if  (1  >  this.args.length) {
+			return  this.error('invalid syntax, format: <<htag [id [ tag ] | attributes [ tag ] >>');
+		}
+                if (1 <  this.args.length) {
+                        htag    =   String(this.args[1]).trim();
+                }
+                if  (typeof this.args[0] === "object") {
+                        attributes  =   //$.map(this.args[0], munge).join(" ");
+                                $.map(
+                                        this.args[0],
+                                        function (val, key) { return  key + '="' + val + '"'; })
+                                .join(" ");
+                } else {
+                        attributes  =   'id="' + String(this.args[0]).trim() + '"';
+                }
+		Config.debug && this.debugView.modes({block: true});
+		
+		jQuery('<' + htag + ' ' + attributes + ' />')
+			.wiki(payload)
+			.appendTo(this.output);
+	}
+});
diff --git a/src/uncategorized/slaveSummary.tw b/src/uncategorized/slaveSummary.tw
index ba4cb47ea18..823b5f19a17 100644
--- a/src/uncategorized/slaveSummary.tw
+++ b/src/uncategorized/slaveSummary.tw
@@ -94,7 +94,7 @@
         /* Useful for finding weird combinations -- usages of this passage that don't yet generate the quick index.
         *   <<print 'pass/count/indexed/flag::[' + _Pass + '/' + _Count + '/' + _indexed + '/' + $Flag + ']'>>
         */
-        <<if ((_Count > 1) && (_indexed == 0) && (((_Pass == 'Main') && (ndef $Flag)) || ($Flag == 1)))>>
+        <<if ((_Count > 1) && (_indexed == 0) && (((_Pass == 'Main') && (ndef $Flag) && (($useSlaveSummaryTabs == 0) || ($slaveAssignmentTab == "all"))) || ($Flag == 1)))>>
                 <<set _indexed = 1, _counter = 0, _buttons = [], _offset = -50>>
                 <<if (/Select/i.test(_Pass))>>
                         <<set _offset = -25>>
@@ -116,13 +116,16 @@
 		<br />
                 <<set _tableCount = _tableCount || 0>>
                 <<set _tableCount++>>
-                <<set _quickList = '<button data-quick-index="' + _tableCount + '">Quick Index</button>'>>
-                <<set _listDivOpen = '<div id="list_index' + _tableCount + '" class="hidden">'>>
-                <<set _listDivClose = '</div><!-- ' + _tableCount + ' -->'>>
-                _quickList
-/%		<button data-quick-index="<<print _tableCount>>">Quick Index</button> %/
-                _listDivOpen
-/%              <div id="list_index<<print _tableCount>>" class="hidden"> %/
+                /*
+                 *  we want <button data-quick-index="<<= _tableCount>>"> ...
+                 */
+                <<set _buttonAttributes = { 'data-quick-index': _tableCount }>>
+                <<htag _buttonAttributes 'button'>>Quick Index<</htag>>
+                /*
+                 *  we want <div id="list_index3" class=" hidden">...
+                 */
+                <<set _divAttributes = { id: 'list_index' + _tableCount, class: 'hidden'}>>
+                <<htag _divAttributes>>
                 <<for !_.isUndefined(_ssii = _indexSlavesIdxs.shift())>>
                         <<set _IndexSlave = $slaves[_ssii]>>
                         <<if $surnameOrder != 1>>
@@ -177,8 +180,7 @@
 				});
                         </script>
                 <</if>>
-                _listDivClose
-/%              </div> %/
+                <</htag>>
         <</if>>
 <</if>>
 <<switch _Pass>>
@@ -756,7 +758,10 @@ will
 
 <</if>> /* closes _numFacilities */
 
-<<print '<span id="slave-' + $slaves[_ssi].ID + '">&nbsp;</span><br/>'>>
+<<if ((_Pass != 'Main') || (def $Flag) || ($useSlaveSummaryTabs == 0) || ($slaveAssignmentTab == "all"))>>
+        <<print '<span id="slave-' + $slaves[_ssi].ID + '">&nbsp;</span>'>>
+<</if>>
+<br/>
 <<if $seeImages != 1 || $seeSummaryImages != 1 || $imageChoice == 1>>&nbsp;&nbsp;&nbsp;&nbsp;<</if>>
 
 <<SlaveSummary _Slave>>
-- 
GitLab