mockup/thet-relitemsfix: Fix filtering of non-selectable items

Johannes Raggam <jenkins-z4DKO/[email protected]> Thu, 27 Jul 2017 14:21:15 -0700 (PDT)
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: mockup
Branch: refs/heads/thet-relitemsfix
Date: 2017-07-27T22:18:05+02:00
Author: Johannes Raggam (thet) <[email protected]>
Commit: https://github.com/plone/mockup/commit/4157a186a6fe4d69ba8ca4bec3aff7bf38a6c097

Fix filtering of non-selectable items
Do not filter out already selected items in search mode but make them non-selectable.
Also change the filtering logic where select2 kept filtered out items as empty list elements in the result list and making selecting items impossible in some cases.

Files changed:
M CHANGES.rst
M mockup/patterns/relateditems/pattern.js

diff --git a/CHANGES.rst b/CHANGES.rst
index a5f16fbb..36f949fa 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -15,7 +15,9 @@ Incompatibile changes:
 
 Bug fixes:
 
-- * Add item here *
+- Do not filter out already selected items in search mode but make them non-selectable.
+  Also change the filtering logic where select2 kept filtered out items as empty list elements in the result list and making selecting items impossible in some cases.
+  [thet]
 
 
 2.5.0 (2017-07-03)
diff --git a/mockup/patterns/relateditems/pattern.js b/mockup/patterns/relateditems/pattern.js
index f10d3145..28aecc03 100644
--- a/mockup/patterns/relateditems/pattern.js
+++ b/mockup/patterns/relateditems/pattern.js
@@ -239,6 +239,18 @@ define([
           var more = (page * this.options.pageSize) < data.total;
           var results = data.results;
 
+          // Filter out non-selectable and non-folderish while browsing.
+          if (this.browsing) {
+            results = results.filter(
+              function (item) {
+                if (!item.is_folderish && !this.isSelectable(item)) {
+                  return false;
+                }
+                return true;
+              }.bind(this)
+            );
+          }
+
           // Extend ``data`` with a ``oneLevelUp`` item when browsing
           var path = this.currentPath.split('/');
           if (page === 1 &&           // Show level up only on top.
@@ -493,17 +505,6 @@ define([
             item.selectable = false;
           }
         }
-        if (
-          !item.selectable && (
-            !self.browsing ||
-            self.browsing && !item.is_folderish
-          )
-        ) {
-          // Filter out non-selectable and non-folderish while browsing.
-          // or
-          // Exclude already selected items while searching.
-          return;
-        }
         var result = $(self.applyTemplate('result', item));
 
         $('.pattern-relateditems-result-select', result).on('click', function(event) {



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot