]> _ Git - fluidbook-html5.git/commitdiff
wip #2251 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Sep 2018 16:45:11 +0000 (18:45 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 28 Sep 2018 16:45:11 +0000 (18:45 +0200)
js/libs/fluidbook/fluidbook.search.js
js/libs/fluidbook/special/wescosales.js

index 393bda6d46fdbe1f1ad888396859b7ded92a434a..8364cd5d1dfa6889f7edf3d31d9db645e6faa7e3 100644 (file)
@@ -5,6 +5,7 @@ function FluidbookSearch(fluidbook) {
     this.highlights = [];
     this.highlightEnabled = fluidbook.datas.highlightResults;
     this.resultPages = [];
+    this.plugins = [];
 
     this.init();
 }
@@ -87,6 +88,13 @@ FluidbookSearch.prototype = {
             res.push([k, v.t]);
         }
 
+        for (var p in this.plugins) {
+            var plugin = this.plugins[p];
+            var h = plugin.getHints(q);
+            console.log(h);
+            res = res.concat(h);
+        }
+
         res.sort(this.sortHints);
         callback(res.slice(0, 12));
     },
@@ -439,7 +447,11 @@ FluidbookSearch.prototype = {
         }
         this.menuSearchHints.html('');
         $.each(hints, function (k, v) {
-            $this.menuSearchHints.append('<a class="hint" term="' + v[0] + '" href="#/search/' + v[0] + '">' + v[0] + '</a>');
+            var termType = 'word';
+            if (v.length > 2) {
+                termType = v[2];
+            }
+            $this.menuSearchHints.append('<a class="hint" data-termtype="' + termType + '" term="' + v[0] + '" href="#/search/' + termType + '/' + v[0] + '">' + v[0] + '</a>');
         });
         var qoffset = $("#q").offset();
         var top = qoffset.top + $("#q").outerHeight() + 5;
@@ -455,9 +467,11 @@ FluidbookSearch.prototype = {
 
         $("#searchHints").css({top: top, left: left}).show();
     },
+
     killLastSearchHint: function () {
         this.kill();
     },
+
     hideSearchHints: function () {
         this.menuSearchHints.html('').hide(); // Clear and hide all hints
     },
@@ -601,6 +615,9 @@ FluidbookSearch.prototype = {
             minScrollbarLength: 40,
             //maxScrollbarLength: 60
         });
-    }
+    },
+    registerPlugin: function (p) {
+        this.plugins.push(p);
+    },
 };
 
index d51fe8bd6f057950619455098583c8573cfffd4b..403f0b5bb1c7c7ed8fcefe27c3151fc630eec907 100644 (file)
@@ -1,5 +1,6 @@
 var wsref = {};
 var normalizeRefCache = {};
+var allrefs = null;
 
 $(function () {
     if (fluidbook.datas.basket) {
@@ -28,6 +29,8 @@ function initWescoNav() {
 }
 
 function initWesco() {
+    fluidbook.search.registerPlugin(new WescoSalesSearchPlugin());
+
     $(document).on('click', '[data-wescosales-ref]', function (e) {
         setWescoSalesPanel($(this).data('wescosales-ref'), e);
         return false;
@@ -110,6 +113,24 @@ function setWescoSalesPanel(ref, e, updateOnly) {
     setInteractPanel(ref, updateOnly);
 }
 
+function getAllRefs() {
+    if (allrefs === null) {
+        var res = [];
+        for (var country in DATAS.basketReferences) {
+            var sheet = DATAS.basketReferences[country];
+            for (var linenum in sheet) {
+                var line = sheet[linenum];
+                var r = normalizeRef(line[0].toString());
+                if (res.indexOf(r) === -1) {
+                    res.push(r);
+                }
+            }
+        }
+        allrefs = res;
+    }
+    return allrefs;
+}
+
 function setInteractPanel(ref, onlyRect) {
     if (onlyRect === undefined) {
         onlyRect = false;
@@ -255,3 +276,30 @@ function getWescoRef(ref) {
     }
     return wsref[ref];
 }
+
+function WescoSalesSearchPlugin() {
+
+}
+
+WescoSalesSearchPlugin.prototype = {
+    getHints: function (q) {
+        if (!q.match(/(\d\s*)/gm)) {
+            return [];
+        }
+
+        q = q.replace(/\s/gm, '');
+
+        if (q.length > 5) {
+            return [];
+        }
+        var all = getAllRefs();
+        var res = [];
+        $.each(all, function (k, v) {
+            if (v.indexOf(q) === 0) {
+                res.push([v, 100000, 'ref']);
+            }
+        });
+
+        return res;
+    }
+};