From 2555dbb4ea1abea2b120e00752df5e9f7873fafb Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sun, 30 Oct 2011 14:40:33 +0000 Subject: [PATCH] add getMatches option to ListMap --- source/Ox.UI/js/Map/Ox.ListMap.js | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/source/Ox.UI/js/Map/Ox.ListMap.js b/source/Ox.UI/js/Map/Ox.ListMap.js index fab4defa..df3f5f50 100644 --- a/source/Ox.UI/js/Map/Ox.ListMap.js +++ b/source/Ox.UI/js/Map/Ox.ListMap.js @@ -21,6 +21,7 @@ Ox.ListMap = function(options, self) { .defaults({ addPlace: null, editPlace: null, + getMatches: null, height: 256, labels: false, pageLength: 100, @@ -539,6 +540,19 @@ Ox.ListMap = function(options, self) { .css({margin: '4px 0 4px 0'}) .appendTo(self.$placeForm); + if (self.options.getMatches) { + self.$matchesInput = Ox.Input({ + disabled: true, + id: 'matches', + label: 'Matches', + labelWidth: 80, + type: 'int', + width: 240 + }) + .css({margin: '8px 0 4px 0'}) + .appendTo(self.$placeForm); + } + self.$placeStatusbar = Ox.Bar({ size: 24 }); @@ -725,6 +739,9 @@ Ox.ListMap = function(options, self) { }); } }); + if (keys.indexOf('name') > -1 || keys.indexOf('alternativeNames') > -1) { + updateMatches(); + } } function initList(data) { @@ -790,6 +807,7 @@ Ox.ListMap = function(options, self) { self.$placeForm.values(place).show(); self.$areaKmInput.options({value: Ox.formatArea(place.area)}); self.$placeButton.options({title: isResult ? 'Add Place' : 'Remove Place'}).show(); + updateMatches(); } else { self.selectedPlace = null; self.$placeTitle.hide(); @@ -823,6 +841,24 @@ Ox.ListMap = function(options, self) { }); } + function updateMatches() { + var names, place; + if (self.options.getMatches) { + place = self.$placeForm.values(); + names = Ox.filter(Ox.merge([place.name], place.alternativeNames), function(name) { + return name !== ''; + }); + Ox.print('names', names); + if (names.length) { + self.options.getMatches(names, function(matches) { + self.$matchesInput.options({value: matches}); + }); + } else { + self.$matchesInput.options({value: 0}); + } + } + } + /*@ setOption setOption @*/