Author: pyaschenko
Date: 2010-06-30 07:42:30 -0400 (Wed, 30 Jun 2010)
New Revision: 17684
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
Log:
https://jira.jboss.org/browse/RF-8875 working cache was added + some changes
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js
===================================================================
---
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30
06:27:53 UTC (rev 17683)
+++
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/ComboBox.js 2010-06-30
11:42:30 UTC (rev 17684)
@@ -2,22 +2,37 @@
rf.utils = rf.utils || {};
rf.utils.Cache = function (data, options) {
- this.data = data || [];
- this.values = options.parse && options.parse(this.data) || this.data;
+ this.key = options.key;
+ this.cache = {}
+ this.cache[this.key] = data || [];
+ this.values = options.parse && options.parse(data) || this.cache[this.key];
};
- var getItems = function (str) {
- if (!str || str.length==0) {
- return this.data;
+ var getItems = function (key) {
+ var newCache = [];
+
+ if (this.cache[key]) {
+ newCache = this.cache[key];
+ } else {
+ var itemsCache = this.cache[this.key];
+ for (var i = 0; i<this.values.length; i++) {
+ var value = this.values[i].toLowerCase();
+ var p = value.indexOf(key.toLowerCase());
+ if (p == 0) {
+ newCache.push(itemsCache[i]);
+ }
+ }
+
+ if ((!this.lastKey || key.indexOf(this.lastKey)!=0) && newCache.length > 0)
{
+ console && console.log && console.log("added
key:"+key+" length:" + newCache.length)
+ this.cache[key] = newCache;
+ if (newCache.length==1) {
+ this.lastKey = key;
+ }
+ }
}
- var newData = [];
- for (var i = 0; i<this.values.length; i++) {
- var value = this.values[i].toLowerCase();
- var p = value.indexOf(str.toLowerCase());
- p == 0 && newData.push(this.data[i]);
- }
-
- return newData;
+
+ return newCache;
};
$.extend(rf.utils.Cache.prototype, (function () {
@@ -42,8 +57,8 @@
this.options = $.extend(this.options, defaultOptions, options);
//this.currentValue = rf.getDomElement(this.fieldId).value;
this.index = -1;
- updateItemsList.call(this);
bindEventHandlers.call(this);
+ updateItemsList.call(this, "");
};
var $p ={};
@@ -82,10 +97,11 @@
}
};
- var updateItemsList = function () {
+ var updateItemsList = function (value) {
this.items = $(rf.getDomElement(this.componentId+ID.ITEMS)).children();
this.cache = new rf.utils.Cache(this.items, {
- parse: getData
+ parse: getData,
+ key: value
});
};
@@ -126,6 +142,7 @@
return {
name:"CompoBox",
destroy: function () {
+ //TODO: add all unbind
$super.destroy.call(this);
},
getNamespace: function () {
@@ -176,11 +193,13 @@
selectPageDown: function () {
},
- prepareToShow: function (event) {
-
+ onBeforeShow: function (event) {
},
onChange: function (event, value) {
+ // TODO: ajax call here if needed
+
+
this.selectItem();
var newItems = this.cache.getItems(value);
this.items = $(newItems);
@@ -195,7 +214,7 @@
},
onShow: function () {
- if (this.items.length>0) {
+ if (this.items && this.items.length>0) {
//??TODO it's nessesary only if not changed value
this.selectItem(0);
}
Modified:
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js
===================================================================
---
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30
06:27:53 UTC (rev 17683)
+++
root/ui-sandbox/inputs/trunk/autocomplete/src/main/resources/META-INF/resources/script/SelectBase.js 2010-06-30
11:42:30 UTC (rev 17684)
@@ -48,7 +48,7 @@
this.fieldId = fieldId;
this.options = $.extend({}, defaultOptions, options);
this.namespace = this.namespace || "."+rf.Event.createNamespace(this.name,
this.selectId);
- this.currentValue = rf.getDomElement(this.fieldId).value;
+ this.currentValue = this.getCurrentValue();
bindEventHandlers.call(this);
};
@@ -133,7 +133,7 @@
};
var onChange = function (event) {
- var value = rf.getDomElement(this.fieldId).value;
+ var value = this.getCurrentValue();
var flag = value != this.currentValue;
if (event.which == rf.KEYS.LEFT || event.which == rf.KEYS.RIGHT || flag) {
// TODO: call onchange
@@ -184,10 +184,10 @@
case rf.KEYS.TAB:
case rf.KEYS.RETURN:
event.preventDefault();
- /*if( selectCurrent() ) {
+ /*if( selectCurrentItem() ) {
event.preventDefault();
//TODO: bind form submit event handler to cancel form submit under the opera
- cancelSubmit = true;
+ //cancelSubmit = true;
return false;
}*/
this.hide();
@@ -210,7 +210,7 @@
return {
name:"SelectBase",
show: function (event) {
- if (this.prepareToShow(event)!=false) {
+ if (this.onBeforeShow(event)!=false) {
$(rf.getDomElement(this.selectId)).show();
this.isVisible = true;
this.scrollElements = rf.Event.bindScrollEventHandlers(this.selectId, this.hide,
this, this.namespace);
@@ -245,8 +245,13 @@
},
selectPageDown: function () {
},
- prepareToShow: function () {
+ onBeforeShow: function () {
+ },
+ getCurrentValue: function () {
+ var value = this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;
+ return value;
}
+
};
})());
})(jQuery, RichFaces);
\ No newline at end of file