Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Document Properties Marker
overridefalse


Short DescriptionModule to provide a filter for a display table macro.
Doctypedocmodulehide
NameFilter Module
Short Name
Parent
Parent Property
property-nameName
hide
Audience
Name List
doctyperole
render-no-hits-as-blanktrue
propertyAudience
empty-as-nonetrue

Subject
Name List
doctypesubject
propertySubject

Categories
Name List
doctypecategory
propertyCategories

Tags
Tag List
propertyTags

Flagshide
Iteration
Iteration
valuefinished

Type
Name List
doctypemodule-type
render-no-hits-as-blanktrue
propertyType

Sort Keyhide



Section
titleDescription

...

Section
titleContent

Below this text is the HTML-Code to be transcluded to provide a filter for a display table macro using the remote controlled feature.

The javascript code uses the variable initialwhere which can be replaced using the transclusion variable replacement feature and be set to the initial where condition used in the display table macro.

Morover two more variables have to be set to provide options for a dropdown.

Full example replacement to put in transclusion box to disable the dropdown:

tableid=fitered
initialwhere=$<DirectAncestorId>=[112494396]
datalistselects=<datalist id="selects"></datalist>
datalistwheredatalistwheres=<datalist id="wheres"></datalist>

Full example replacement to put in transclusion box to set values for the dropdowns:

tableid=filteredinitialwhere=$<DirectAncestorId>=[112494396]
datalistselects=<datalist id="selects"><option value="Name">Name only</option><option value="Name, Short Description, Iteration">With Iteration</option></datalist>
datalistwheredatalistwheres=<datalist id="wheres"><option value="$<Iteration>=[Facade]">Facade</option><option value="$<Iteration>=[Filled]">Filled</option><option value="$<Iteration>=[Finished]">Finished</option></datalist>
Section
hidetrue
titleHide


Section
titleHTML-CODE


HTML
<form id="
filterForm$
filterForm-${tableid}" action="">
  <label for="select">select:</label>
  <input id="
filterSelect$
filterSelect-${tableid}" size="50" type="text" list="
selects$
selects-${tableid}" name="select" autocomplete="on">
  
${datalistselects} where:
<label for="where">where:</label>
  <input id="
filterWhere$
filterWhere-${tableid}" size="50" type="text" list="
wheres$
wheres-${tableid}" name="where"
> ${datalistwheres}
 autocomplete="on">
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</form>
<script> AJS.toInit(function() { var urlParams = new URLSearchParams(window.location.search); var originalSelect = urlParams.get('${tableid}:select'); var originalWhere = urlParams.get('${tableid}customWhere'); var initialWhere = urlParams.get('${tableid}initialWhere'); console.error("####################################"); if (initialWhere != null && initialWhere.trim()) { console.error("*****************************************"); console.error("*****************************************"); console.error("initial where is NOT empty"); console.error("*****************************************"); console.error("*****************************************"); } else { console.error("*****************************************"); console.error("*****************************************"); console.error("initial where is empty"); console.error("*****************************************"); console.error("*****************************************"); initialWhere = $('#${tableid} table').attr('data-projectdoc-query-where'); } console.error("####################################"+initialWhere); $('#filterForm${tableid} datalist').attr('id', function(index, id)





<form id="filterForm${tableid}" action=""> select: <input id="filterSelect${tableid}" size="50" type="text" list="selects${tableid}" name="select" > ${datalistselects} where: <input id="filterWhere${tableid}" size="50" type="text" list="wheres${tableid}" name="where"> ${datalistwheres} <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> <script> AJS.toInit(function() { var urlParams = new URLSearchParams(window.location.search); var originalSelect = urlParams.get('${tableid}:select'); var originalWhere = urlParams.get('${tableid}customWhere'); $('#filterForm${tableid} datalist').attr('id', function(index, id) {

            if ($select.trim()) {
                var $encodedSelect = encodeURI($select);
                var $selectQueryParam = tableId + ":" + "select" + "=" + $encodedSelect;
                $queryString = appendToQueryString($queryString, $selectQueryParam);
            }

            if ($where.trim()) {
                var $encodedCustomWhere = encodeURI($where);
         
return
 
id+"${tableid}";
     
})
 var $customWhereQueryParam = "$
("#filterSelect$
{tableid}
").val(originalSelect); $("#filterWhere${tableid}").val(originalWhere); function appendToQueryString( queryString, queryParam ) {
customWhere" + "=" + $encodedCustomWhere;

          
if(queryString.trim())
      var 
{
$encodedWhere 
queryString
=
queryString +
 "
&
"
+ queryParam
;

       
}
   
else
      
{ queryString="?"+queryParam; }
if (typeof initialWhere == 'undefined' || initialWhere == null) {
       
return
 
queryString;
    
 
};
 
$('#filterForm${tableid}').submit(function(evt)
 
{
  
evt.preventDefault();
   console.debug("Check 3 : 
var
initial 
tableId
where 
=
is empty"
${tableid}"
);
     
var
 
$initialWhere
 
=
 
"${initialwhere}"
  
var
 
$select
 
=
 
$('#filterSelect${tableid}').val();
  
var
 
$where
 
=
 
$('#filterWhere${tableid}').val(); console.debug($select); console.debug
  $encodedWhere = encodeURI($where);
var $queryString=""; if ($select.trim()) { var $encodedSelect = encodeURI($select);
                } else {
                    console.debug("Check 3 
var
: 
$selectQueryParam
initial 
=
where 
tableId
is 
+
not 
":"+"select"+"="+$encodedSelect
empty");
       
$queryString=appendToQueryString($queryString, $selectQueryParam); } if ($where.trim()) {
            
var
 
$encodedCustomWhere
$encodedWhere = encodeURI(initialWhere + " AND " + $where);
          
var
 
$customWhereQueryParam
 
=
 
"${tableid}customWhere"+"="+$encodedCustomWhere;
   
var
}
 
$encodedWhere
 
=
 
encodeURI($initialWhere
 
+
 
"
 
AND
 
"
 
+
 
$where);
       var $whereQueryParam = tableId + ":" + "where" + "=" + $encodedWhere;
                $queryString = appendToQueryString($queryString, $whereQueryParam
);
);
                $queryString = appendToQueryString($queryString, $customWhereQueryParam);
            }
    
$queryString
 
=
 
appendToQueryString($queryString,
 
$customWhereQueryParam
 
);
  
}
  $action = window.location.href.split('?')[0] + $queryString;
            $('#filterForm').attr('action', $action);
            console.debug($action);
            window.location.href = $action;
        });
    }
)
;

</script>
HTML
<form id="filterForm${tableid}" action="">
  <label for="select">select:</label>
  <input id="filterSelect${tableid}" size="50" type="text" list="selects${tableid}" name="select" autocomplete="on">
  ${datalistselects}
  <label for="where">where:</label>
  <input id="filterWhere${tableid}" size="50" type="text" list="wheres${tableid}" name="where" autocomplete="on">
  ${datalistwheres}
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</form>
<script>
AJS.toInit(
    function() {
	 const logToConsole = false;
	  if (logToConsole) AJS.log("[copy-page-id] Registering action 'Copy Page ID to Clipboard' to keydown 'p'...");

        console.debug('${datalistselects}')
        function appendToQueryString(queryString, queryParam) {
            if (queryString.trim()) {
                queryString = queryString + "&" + queryParam;
            } else {
                queryString = "?" + queryParam;
            }
            return queryString;
        };

        var urlParams = new URLSearchParams(window.location.search);
        var originalSelect = urlParams.get('${tableid}:select');
        var originalWhere = urlParams.get('${tableid}customWhere');
        var initialWhere = urlParams.get('${tableid}initialWhere');
        console.debug("From Queryparam : initial where is: " + initialWhere);

        var oldQueryParams = ""
        urlParams.forEach(function(value, key) {
            if (!key.startsWith("${tableid}")) {
                oldQueryParams = appendToQueryString(oldQueryParams, key + "=" + encodeURI(value));
            }
        });

        if (typeof initialWhere == 'undefined' || initialWhere == null) {
            console.debug("Check 1 a: initial where is empty");
            if (initialWhere == originalWhere) {
                console.debug("In Check 1 b : initial where is: " + initialWhere);
                console.debug("In Check 1 b : original where is: " + originalWhere);
            } else {
                initialWhere = $('#${tableid} table').attr('data-projectdoc-query-where');
                console.debug("In Check 1 c: initial where is: " + initialWhere);
                console.debug("In Check 1 c : original where is: " + originalWhere);
            }
            if (typeof initialWhere == 'undefined' || initialWhere == null) {
                console.debug("Check 1 : initial is set to empty string.");
                initialWhere = null;
                console.debug("In Check 1/1 : initial where is: " + initialWhere);
            }
        } else {
            console.debug("Check 1 : initial where is not empty");
            console.debug("In Check 1 : initial where is: " + initialWhere);
        }

        $('#filterForm${tableid} datalist').attr('id', function(index, id) {
            return id + "${tableid}";
        })

        $("#filterSelect${tableid}").val(originalSelect);
        $("#filterWhere${tableid}").val(originalWhere);

        $('#filterForm${tableid}').submit(function(evt) {
            evt.preventDefault();

            var tableId = "${tableid}";
            var $select = $('#filterSelect${tableid}').val();
            var $where = $('#filterWhere${tableid}').val();

            var $queryString = "";
            if (oldQueryParams.trim()) {
                $queryString = appendToQueryString($queryString, oldQueryParams.substr(1));
            }
            if (typeof initialWhere == 'undefined' || initialWhere == null) {
                console.debug("Check 2 : initial where is empty");
            } else {
       
return
 
id+"${tableid}";
     
})
   
$("#filterSelect${tableid}").val(originalSelect); $("#filterWhere${tableid}").val(originalWhere);
console.debug("Check 2 : initial where is not empty");
    
function
 
appendToQueryString(
 
queryString,
 
queryParam
 
)
 
{
       if
(queryString.trim())
 (initialWhere == originalWhere) {
       
{
 
queryString=queryString + "&"
 
+
 
queryParam;
       
}
   
else { queryString="?"+queryParam
console.debug("In Check 2 b : initial where is: " + initialWhere);
       
}
    
return queryString;
    
 
};
 
$('#filterForm${tableid}').submit(function(evt)
 
{
  
evt
console.
preventDefault(); var tableId = "${tableid}";
debug("In Check 2 b : original where is: " + originalWhere);
        
var
 
$initialWhere
 
=
 
"${initialwhere}"
  
var
 
$select
 
=
 
$('#filterSelect${tableid}').val(); var $where = $('#filterWhere${tableid}').val(); var $queryString="";
} else {
                    $queryString = appendToQueryString($queryString, "${tableid}initialWhere=" + encodeURI(
$initialWhere
initialWhere));
     
if
 
($select.trim())
  
{
   
var
 
$encodedSelect
 
=
 
encodeURI($select);
      
var $selectQueryParam = tableId + ":"+"select"+"="+$encodedSelect;
console.debug("In Check 2 c: initial where is: " + initialWhere);
             
$queryString=appendToQueryString($queryString,
 
$selectQueryParam);
  
}
   
if
 
($where
console.
trim()) { var $encodedCustomWhere = encodeURI($where
debug("In Check 2 c : original where is: " + originalWhere);
       
var
 
$customWhereQueryParam = "${tableid}customWhere"+"="+$encodedCustomWhere;
   
var
 
$encodedWhere
 
=
 
encodeURI($initialWhere
 
+
 
"
}
 
AND
 
"
 
+
 
$where);
       
var
 
$whereQueryParam
 
=
 
tableId
 
+
 
":"+"where"+"="+$encodedWhere; $queryString = appendToQueryString($queryString, $whereQueryParam
console.debug("In Check 2 : initial where is: " + initialWhere);
       
$queryString =
 
appendToQueryString($queryString,
 
$customWhereQueryParam
 
);
  
}
  
$action
 
=
 
window.location.href.split('?')[0] + $queryString; $('#filterForm').attr('action', $action); console.debug($action);
console.debug("In Check 2 : querystring is: " + $queryString);
           
window.location.href=$action;
 }
); }); </script>
Section
titleHTML Code
Code Block


Section
titleTranscluded By
Display Table
render-no-hits-as-blanktrue
selectName, Short Description, Doctype
sort-bySort Key, Name
where$<TranscludedDocumentTitles>=[${Space Key}.${Title}]

...