From 17120e6aec897fd9b7dfafcbc3c59163b0f744c4 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 19 May 2014 01:22:41 +0200 Subject: [PATCH] Ox.Filter: fix value reset on clicking (+) or (-), fix default value for item type --- source/Ox.UI/js/Form/Filter.js | 57 ++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/source/Ox.UI/js/Form/Filter.js b/source/Ox.UI/js/Form/Filter.js index 01c5a36c..0193603c 100644 --- a/source/Ox.UI/js/Form/Filter.js +++ b/source/Ox.UI/js/Form/Filter.js @@ -337,7 +337,9 @@ Ox.Filter = function(options, self) { ['string', 'text'].indexOf(oldConditionType) == -1 || ['string', 'text'].indexOf(newConditionType) == -1 ) { - condition.value = self.defaultValue[newFindKey.type]; + condition.value = newFindKey.type == 'item' + ? newFindKey.values[0].id + : self.defaultValue[newFindKey.type]; } renderConditions(); } @@ -456,24 +458,28 @@ Ox.Filter = function(options, self) { .css({margin: '0 4px 0 ' + (isGroup ? '292px' : '8px')}) // fixme: 296 is probably correct, but labels seem to be too wide .bindEvent({ click: function(data) { - var key; - if (self.options.value.conditions.length == 1) { - key = self.options.findKeys[0]; - self.options.value.conditions = [{ - key: key.id, - value: '', - operator: self.conditionOperators[key.type][0].id - }]; - renderConditions(); - triggerChangeEvent(); - } else if (this.$element.parent().data('subposition') == -1) { - removeCondition(this.$element.parent().data('position')); - } else { - removeCondition( - this.$element.parent().data('position'), - this.$element.parent().data('subposition') - ); - } + var key, that = this; + that.$element.focus(); // make input trigger change + setTimeout(function() { + Ox.print(self.options.value.conditions.length, that.$element.parent().data('subposition') == -1); + if (self.options.value.conditions.length == 1) { + key = self.options.findKeys[0]; + self.options.value.conditions = [{ + key: key.id, + value: '', + operator: self.conditionOperators[key.type][0].id + }]; + renderConditions(); + triggerChangeEvent(); + } else if (that.$element.parent().data('subposition') == -1) { + removeCondition(that.$element.parent().data('position')); + } else { + removeCondition( + that.$element.parent().data('position'), + that.$element.parent().data('subposition') + ); + } + }); } }), Ox.Button({ @@ -486,10 +492,8 @@ Ox.Filter = function(options, self) { .bindEvent({ click: function(data) { var that = this; - // timeout needed so that input change registers - // before all conditions are re-rendered - setTimeout(function() { - Ox.Log('Form', 'add...', data, that.$element.parent().data('position'), that.$element.parent().data('subposition')) + that.$element.focus(); // make input trigger change + setTimeout(function() { if (that.$element.parent().data('subposition') == -1) { addCondition(that.$element.parent().data('position') + 1); } else { @@ -512,8 +516,9 @@ Ox.Filter = function(options, self) { .bindEvent({ click: function(data) { var that = this; + that.$element.focus(); // make input trigger change setTimeout(function() { - addCondition(that.$element.parent().data('position') + 1, -1, true) + addCondition(that.$element.parent().data('position') + 1, -1, true); }); } }) @@ -684,6 +689,8 @@ Ox.Filter = function(options, self) { if (type == 'boolean') { $input = Ox.Select({ items: ['true', 'false'], + max: 1, + min: 1, value: value ? 'true' : 'false', width: 288 }); @@ -699,6 +706,8 @@ Ox.Filter = function(options, self) { } else if (type == 'item') { $input = Ox.Select({ items: findKey.values, + max: 1, + min: 1, value: value, width: 288 });