Author: pyaschenko
Date: 2010-07-21 08:22:40 -0400 (Wed, 21 Jul 2010)
New Revision: 18172
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js
Log:
https://jira.jboss.org/browse/RF-8875
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-07-21
12:15:26 UTC (rev 18171)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoComplete.js 2010-07-21
12:22:40 UTC (rev 18172)
@@ -186,115 +186,116 @@
rf.ajax(this.componentId, event, {parameters: params, error: ajaxError,
complete:ajaxSuccess});
};
+ /*
+ * public API functions definition
+ */
+
+ var selectItem = function(index, isOffset, noAutoFill) {
+ if (this.items.length==0) return;
+
+ if (this.index!=-1) {
+ this.items.eq(this.index).removeClass(this.options.selectedItemClass);
+ }
+
+ if (index==undefined) {
+ this.index = -1;
+ return;
+ }
+
+ if (isOffset) {
+ this.index += index;
+ if ( this.index<0 ) {
+ this.index = this.items.length - 1;
+ } else if (this.index >= this.items.length) {
+ this.index = 0;
+ }
+ } else {
+ if (index<0) {
+ index = 0;
+ } else if (index>=this.items.length) {
+ index = this.items.length - 1;
+ }
+ this.index = index;
+ }
+ var item = this.items.eq(this.index);
+ item.addClass(this.options.selectedItemClass);
+ scrollToSelectedItem.call(this);
+ !noAutoFill && autoFill.call(this, this.inputValue,
this.getSelectedItemValue());
+ };
+
+ var changeValue = function (event, value) {
+ this.selectItem();
+
+ if (typeof value == "undefined") {
+ // called from show method, not actually value changed
+ if (this.items.length==0 && this.inputValue.length>=this.options.minChars
&& this.isFirstAjax) {
+ this.options.ajaxMode && callAjax.call(this, event);
+ }
+ return;
+ }
+
+ // TODO: ajax call here if needed
+ if (( value.toLowerCase().indexOf(this.cache.key.toLowerCase())!=0 ||
this.inputValue.length==0) &&
+ value.length>=this.options.minChars) {
+ this.inputValue = value;
+ this.options.ajaxMode && callAjax.call(this, event);
+ return;
+ }
+
+ var newItems = this.cache.getItems(value);
+ this.items = $(newItems);
+ //TODO: works only with simple markup, not with <tr>
+ $(rf.getDomElement(this.componentId+ID.ITEMS)).empty().append(newItems);
+ this.index = -1;
+ this.inputValue = value;
+ if (this.options.selectFirst) {
+ this.selectItem(0, false, event.which == rf.KEYS.BACKSPACE);
+ }
+ };
+
+ var getSelectedItemValue = function () {
+ if ( this.index>=0) {
+ var element = this.items.eq(this.index);
+ return element.data(DATA_TAG) || getData(element)[0];
+ }
+ return undefined;
+ };
+ /*
+ * Prototype definition
+ */
$.extend(rf.ui.AutoComplete.prototype, (function () {
return {
+ /*
+ * public API functions
+ */
name:"AutoComplete",
- destroy: function () {
- //TODO: add all unbind
- this.items = null;
- this.cache = null;
- rf.Event.unbind(rf.getDomElement(this.componentId+ID.ITEMS).parentNode,
this.namespace);
- $super.destroy.call(this);
- },
- getNamespace: function () {
- return this.namespace;
- },
-
- selectItem: function(index, isOffset, noAutoFill) {
- if (this.items.length==0) return;
-
- if (this.index!=-1) {
- this.items.eq(this.index).removeClass(this.options.selectedItemClass);
- }
-
- if (index==undefined) {
- this.index = -1;
- return;
- }
-
- if (isOffset) {
- this.index += index;
- if ( this.index<0 ) {
- this.index = this.items.length - 1;
- } else if (this.index >= this.items.length) {
- this.index = 0;
- }
- } else {
- if (index<0) {
- index = 0;
- } else if (index>=this.items.length) {
- index = this.items.length - 1;
- }
- this.index = index;
- }
- var item = this.items.eq(this.index);
- item.addClass(this.options.selectedItemClass);
-
- scrollToSelectedItem.call(this);
- !noAutoFill && autoFill.call(this, this.inputValue,
this.getSelectedItemValue());
- },
-
- selectPrevItem: function () {
+ selectItem: selectItem,
+ changeValue: changeValue,
+ getSelectedItemValue: getSelectedItemValue,
+ /*
+ * Protected methods
+ */
+ __onKeyUp: function () {
this.selectItem(-1, true);
},
- selectNextItem: function () {
+ __onKeyDown: function () {
this.selectItem(1, true);
},
- selectPageUp: function () {
+ __onPageUp: function () {
},
- selectPageDown: function () {
+ __onPageDown: function () {
},
- onBeforeShow: function (event) {
+ __onBeforeShow: function (event) {
},
-
- onEnter: function (event) {
+ __onEnter: function (event) {
this.changeValue(event, this.getSelectedItemValue());
rf.getDomElement(this.fieldId).blur();
rf.Selection.setCaretTo(rf.getDomElement(this.fieldId));
rf.getDomElement(this.fieldId).focus();
},
-
- changeValue: function (event, value) {
- this.selectItem();
-
- if (typeof value == "undefined") {
- // called from show method, not actually value changed
- if (this.items.length==0 &&
this.inputValue.length>=this.options.minChars && this.isFirstAjax) {
- this.options.ajaxMode && callAjax.call(this, event);
- }
- return;
- }
-
- // TODO: ajax call here if needed
- if (( value.toLowerCase().indexOf(this.cache.key.toLowerCase())!=0 ||
this.inputValue.length==0) &&
- value.length>=this.options.minChars) {
- this.inputValue = value;
- this.options.ajaxMode && callAjax.call(this, event);
- return;
- }
-
- var newItems = this.cache.getItems(value);
- this.items = $(newItems);
- //TODO: works only with simple markup, not with <tr>
- $(rf.getDomElement(this.componentId+ID.ITEMS)).empty().append(newItems);
- this.index = -1;
- this.inputValue = value;
- if (this.options.selectFirst) {
- this.selectItem(0, false, event.which == rf.KEYS.BACKSPACE);
- }
- },
-
- getSelectedItemValue: function () {
- if ( this.index>=0) {
- var element = this.items.eq(this.index);
- return element.data(DATA_TAG) || getData(element)[0];
- }
- return undefined;
- },
-
- onShow: function (event) {
+ __onShow: function (event) {
if (this.items && this.items.length>0) {
//??TODO it's nessesary only if not changed value
if (this.options.selectFirst) {
@@ -302,9 +303,18 @@
}
}
},
-
- onHide: function () {
+ __onHide: function () {
this.selectItem();
+ },
+ /*
+ * Destructor
+ */
+ destroy: function () {
+ //TODO: add all unbind
+ this.items = null;
+ this.cache = null;
+ rf.Event.unbind(rf.getDomElement(this.componentId+ID.ITEMS).parentNode,
this.namespace);
+ $super.destroy.call(this);
}
};
})());
Modified:
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js
===================================================================
---
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-07-21
12:15:26 UTC (rev 18171)
+++
root/ui-sandbox/inputs/trunk/combobox/src/main/resources/META-INF/resources/org.richfaces/AutoCompleteBase.js 2010-07-21
12:22:40 UTC (rev 18172)
@@ -149,13 +149,13 @@
case rf.KEYS.UP:
event.preventDefault();
if (this.isVisible) {
- this.selectPrevItem();
+ this.__onKeyUp(event);
}
break;
case rf.KEYS.DOWN:
event.preventDefault();
if (this.isVisible) {
- this.selectNextItem();
+ this.__onKeyDown(event);
} else {
onShow.call(this, event);
}
@@ -163,20 +163,20 @@
case rf.KEYS.PAGEUP:
event.preventDefault();
if (this.isVisible) {
- this.selectPageUp();
+ this.__onPageUp(event);
}
break;
case rf.KEYS.PAGEDOWN:
event.preventDefault();
if (this.isVisible) {
- this.selectPageDown();
+ this.__onPageDown(event);
}
break;
case rf.KEYS.TAB:
case rf.KEYS.RETURN:
//TODO draft code, merge with code from combobox.js
event.preventDefault();
- this.onEnter(event);
+ this.__onEnter(event);
/*if( selectCurrentItem() ) {
event.preventDefault();
//TODO: bind form submit event handler to cancel form submit under the opera
@@ -198,72 +198,63 @@
break;
}
}
-
+
+ /*
+ * public API functions definition
+ */
+ var show = function (event) {
+ if (!this.isVisible) {
+ if (this.__onBeforeShow(event)!=false) {
+ this.scrollElements = rf.Event.bindScrollEventHandlers(this.selectId, this.hide,
this, this.namespace);
+ if (this.options.attachToBody) {
+ var element = rf.getDomElement(this.selectId);
+ this.parentElement = element.parentNode;
+ $(element).detach().appendTo("body");
+ }
+ $(rf.getDomElement(this.selectId)).setPosition({id: this.fieldId},
{type:"DROPDOWN", offset:[0,20]}).show();
+ this.isVisible = true;
+ this.__onShow(event);
+ }
+ }
+ };
+ var hide = function (event) {
+ if (this.isVisible) {
+ rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
+ this.scrollElements = null;
+ $(rf.getDomElement(this.selectId)).hide();
+ this.isVisible = false;
+ if (this.options.attachToBody && this.parentElement) {
+ $(rf.getDomElement(this.selectId)).detach().appendTo(this.parentElement);
+ this.parentElement = null;
+ }
+ this.__onHide(event);
+ }
+ };
+
+ /*
+ * Prototype definition
+ */
$.extend(rf.ui.AutoCompleteBase.prototype, (function () {
return {
+ /*
+ * public API functions
+ */
name:"AutoCompleteBase",
- show: function (event) {
- if (!this.isVisible) {
- if (this.onBeforeShow(event)!=false) {
- this.scrollElements = rf.Event.bindScrollEventHandlers(this.selectId, this.hide,
this, this.namespace);
- if (this.options.attachToBody) {
- var element = rf.getDomElement(this.selectId);
- this.parentElement = element.parentNode;
- $(element).detach().appendTo("body");
- }
- $(rf.getDomElement(this.selectId)).setPosition({id: this.fieldId},
{type:"DROPDOWN", offset:[0,20]}).show();
- this.isVisible = true;
- if (this.onShow) {
- this.onShow(event);
- }
- }
- }
- },
- hide: function (event) {
- if (this.isVisible) {
- rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
- this.scrollElements = null;
- $(rf.getDomElement(this.selectId)).hide();
- this.isVisible = false;
- if (this.options.attachToBody && this.parentElement) {
- $(rf.getDomElement(this.selectId)).detach().appendTo(this.parentElement);
- this.parentElement = null;
- }
- if (this.onHide) {
- this.onHide(event);
- }
- }
- },
- destroy: function () {
- //TODO: add all unbind
- this.parentNode = null;
- if (this.scrollElements) {
- rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
- this.scrollElements = null;
- }
- rf.Event.unbindById(this.options.buttonId, this.namespace);
- rf.Event.unbindById(this.fieldId, this.namespace);
- rf.Event.unbindById(this.selectId, this.namespace);
- $super.destroy.call(this);
- },
+ show: show,
+ hide: hide,
getNamespace: function () {
return this.namespace;
},
-
- selectPrevItem: function () {
- },
- selectNextItem: function () {
- },
- selectPageUp: function () {
- },
- selectPageDown: function () {
- },
- onBeforeShow: function () {
- },
getInputValue: function () {
return this.fieldId ? rf.getDomElement(this.fieldId).value : undefined;
},
- updateInputValue: function (value) {
+ setInputValue: function (value) {
+ this.currentValue = this.__updateInputValue(value);
+ },
+ /*
+ * Protected methods
+ */
+ __updateInputValue: function (value) {
if (this.fieldId) {
rf.getDomElement(this.fieldId).value = value;
return value;
@@ -271,8 +262,36 @@
return "";
}
},
- setInputValue: function (value) {
- this.currentValue = this.updateInputValue(value);
+ /*
+ * Protected abstract methods
+ */
+ __onKeyUp: function () {
+ },
+ __onKeyDown: function () {
+ },
+ __onPageUp: function () {
+ },
+ __onPageDown: function () {
+ },
+ __onBeforeShow: function () {
+ },
+ __onShow: function () {
+ },
+ __onHide: function () {
+ },
+ /*
+ * Destructor
+ */
+ destroy: function () {
+ this.parentNode = null;
+ if (this.scrollElements) {
+ rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
+ this.scrollElements = null;
+ }
+ rf.Event.unbindById(this.options.buttonId, this.namespace);
+ rf.Event.unbindById(this.fieldId, this.namespace);
+ rf.Event.unbindById(this.selectId, this.namespace);
+ $super.destroy.call(this);
}
};
})());