Author: abelevich
Date: 2010-12-07 07:41:00 -0500 (Tue, 07 Dec 2010)
New Revision: 20432
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelectComponent.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
trunk/ui/input/ui/src/main/templates/select.template.xml
Log:
RF-9855, RF-9800
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelectComponent.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelectComponent.java 2010-12-07
11:56:13 UTC (rev 20431)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/component/AbstractSelectComponent.java 2010-12-07
12:41:00 UTC (rev 20432)
@@ -118,8 +118,8 @@
@Attribute(events=@EventName("listkeyup"))
public abstract String getOnlistkeyup();
- @Attribute(events=@EventName("select"))
- public abstract String getOnselect();
+ @Attribute(events=@EventName("selectitem"))
+ public abstract String getOnselectitem();
@Attribute(events=@EventName("change"))
public abstract String getOnchange();
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-12-07
11:56:13 UTC (rev 20431)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-12-07
12:41:00 UTC (rev 20432)
@@ -12,7 +12,8 @@
this.items = mergedOptions.items;
this.selValueInput = $(document.getElementById(id+"selValue"));
this.list = $(document.getElementById(id+"List"));
- this.list.bind("click", $.proxy(this.__onListClick, this));
+ this.list.bind("mousedown", $.proxy(this.__onListMouseDown, this));
+ this.list.bind("mouseup", $.proxy(this.__onListMouseUp, this));
this.openOnEdit = mergedOptions.openOnEdit;
this.saveOnSelect = mergedOptions.saveOnSelect;
this.savedIndex = -1;
@@ -98,7 +99,7 @@
if(this.saveOnSelect) {
this.save();
- }
+ }
},
getItemValue: function(item) {
@@ -169,20 +170,30 @@
},
__blurHandler: function(e) {
- if(this.isEditState()) {
- this.timeoutId = window.setTimeout($.proxy(function(){
- this.onblur();
- }, this), 200);
- }
+ if(!this.isMouseDown) {
+ if(this.isEditState()) {
+ this.timeoutId = window.setTimeout($.proxy(function(){
+ this.onblur();
+ }, this), 200);
+ }
+ } else {
+ this.__setInputFocus();
+ this.isMouseDown = false;
+ }
},
__clickHandler: function(e) {
this.showPopup();
},
- __onListClick: function(e) {
- window.clearTimeout(this.timeoutId);
- }
+ __onListMouseDown: function(e) {
+ this.isMouseDown = true;
+ },
+
+ __onListMouseUp: function(e) {
+ this.isMouseDown = false;
+ this.__setInputFocus();
+ }
}
})());
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2010-12-07
11:56:13 UTC (rev 20431)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/select.js 2010-12-07
12:41:00 UTC (rev 20432)
@@ -115,16 +115,17 @@
if(mergedOptions.showControl) {
this.btn = $(document.getElementById(id+"Button"));
- this.btn.bind("click", $.proxy(this.__clickHandler, this));
- this.btn.mousedown($.proxy(this, function(){
- this.focusin = false;
- }));
+ this.btn.bind("mousedown", $.proxy(this.__onBtnMouseDown, this));
+ this.btn.bind("mouseup", $.proxy(this.__onMouseUp, this));
}
this.selectFirst = mergedOptions.selectFirst;
this.popupList = new rf.ui.PopupList((id+"List"), this,
mergedOptions);
this.listElem = $(document.getElementById(id+"List"));
- this.listElem.bind("click", $.proxy(this.__onListClick, this));
+
+ this.listElem.bind("mousedown", $.proxy(this.__onListMouseDown,
this));
+ this.listElem.bind("mouseup", $.proxy(this.__onMouseUp, this));
+
this.items = this.popupList.__getItems();
this.enableManualInput = mergedOptions.enableManualInput;
@@ -162,16 +163,15 @@
return{
name : "select",
- __clickHandler: function(e) {
+ __onBtnMouseDown: function(e) {
if(!this.popupList.isVisible()) {
this.__updateItems();
this.showPopup();
} else {
this.hidePopup();
}
- this.__setInputFocus();
- window.clearTimeout(this.timeoutId);
- },
+ this.isMouseDown = true;
+ },
__focusHandler: function(e) {
if (!this.focused) {
@@ -259,15 +259,25 @@
},
__blurHandler: function(e) {
- this.timeoutId = window.setTimeout($.proxy(function(){
- this.onblur(e);
- }, this), 200);
+ if(!this.isMouseDown) {
+ this.timeoutId = window.setTimeout($.proxy(function(){
+ this.onblur(e);
+ }, this), 200);
+ } else {
+ this.__setInputFocus();
+ this.isMouseDown = false;
+ }
},
- __onListClick: function(e) {
- window.clearTimeout(this.timeoutId);
+ __onListMouseDown: function(e) {
+ this.isMouseDown = true;
},
+ __onMouseUp: function(e) {
+ this.isMouseDown = false;
+ this.__setInputFocus();
+ },
+
__updateItems: function() {
var newValue = this.getValue();
newValue = (newValue != this.defaultLabel) ? newValue : "";
@@ -287,6 +297,55 @@
}
},
+ __getClientItemFromCache: function(inputLabel) {
+ var value;
+ var label;
+ if(this.enableManualInput) {
+ var items = this.cache.getItems(inputLabel);
+ if(items && items.length > 0) {
+ var first = $(items[0]);
+ $.each(this.clientItems, function() {
+ if(this.id == first.attr("id")) {
+ label = this.label;
+ value = this.value;
+ return false;
+ }
+ });
+ } else {
+ this.field.removeClass("rf-sel-fld-err");
+
+ var prevValue = this.selValueInput.val();
+ if(prevValue && prevValue != "") {
+ $.each(this.clientItems, function() {
+ if(this.value == prevValue) {
+ label = this.label;
+ value = this.value
+ return false;
+ }
+ });
+ }
+ }
+ }
+
+ if(label && value) {
+ return {'label': label, 'value': value};
+ }
+ },
+
+ __getClientItem: function(inputLabel) {
+ var value;
+ var label = inputLabel;
+ $.each(this.clientItems, function(){
+ if(label == this.label) {
+ value = this.value;
+ }
+ });
+
+ if(label && value) {
+ return {'label': label, 'value': value};
+ }
+ },
+
showPopup: function() {
this.popupList.show();
},
@@ -307,38 +366,27 @@
this.setValue(label);
this.hidePopup();
this.__setInputFocus();
+
+ this.invokeEvent.call(this,"selectitem",
document.getElementById(this.id + 'Input'), e);
},
onblur: function(e) {
this.hidePopup();
var value = "";
var label = this.defaultLabel;
+ var clientItem;
var inputLabel = this.getValue();
if(inputLabel && inputLabel != "") {
- var items = this.cache.getItems(inputLabel);
- if(items.length > 0) {
- var first = $(items[0]);
- $.each(this.clientItems, function() {
- if(this.id == first.attr("id")) {
- label = this.label;
- value = this.value;
- return false;
- }
- });
+ if(this.enableManualInput) {
+ clientItem = this.__getClientItemFromCache(inputLabel);
} else {
- this.field.removeClass("rf-sel-fld-err");
-
- var prevValue = this.selValueInput.val();
- if(prevValue && prevValue != "") {
- $.each(this.clientItems, function() {
- if(this.value == prevValue) {
- label = this.label;
- value = this.value
- return false;
- }
- });
- }
+ clientItem = this.__getClientItem(inputLabel);
}
+
+ if(clientItem) {
+ label = clientItem.label;
+ value = clientItem.value;
+ }
}
this.setValue(label);
Modified: trunk/ui/input/ui/src/main/templates/select.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/select.template.xml 2010-12-07 11:56:13 UTC (rev
20431)
+++ trunk/ui/input/ui/src/main/templates/select.template.xml 2010-12-07 12:41:00 UTC (rev
20432)
@@ -23,7 +23,7 @@
<div style="position : relative; overflow : hidden; text-align :
left; padding-right : 18px;">
<input id="#{clientId}selValue" name="#{clientId}"
type="hidden" value="#{getInputValue(facesContext, component)}"/>
<div id="#{clientId}Field" class="rf-sel-fld">
- <input cdk:passThroughWithExclusions="class autocomplete id value
disabled name type readonly"
+ <input cdk:passThroughWithExclusions="class autocomplete id value
disabled name type readonly onchange onblur"
id="#{clientId}Input"
value="#{getSelectLabel(facesContext, component)}"
disabled="#{disabled}"
@@ -70,7 +70,7 @@
<cdk:scriptOption name="itemCss"
value="#{concatClasses('rf-sel-opt',
component.attributes['itemClass'])}" />
<cdk:scriptOption name="selectItemCss"
value="#{concatClasses('rf-sel-sel',
component.attributes['selectItemClass'])}" />
<cdk:scriptOption name="listCss"
value="#{concatClasses('rf-sel-lst-cord',
component.attributes['listClass'])}" />
- <cdk:scriptOption attributes="onchange onselect"
wrapper="eventHandler"/>
+ <cdk:scriptOption attributes="onbegin oncomplete onerror
onbeforedomupdate onchange onblur onselectitem"
wrapper="eventHandler"/>
<cdk:scriptOption attributes="showControl defaultLabel enableManualInput
selectFirst" />
</cdk:scriptObject>
new RichFaces.ui.Select("#{clientId}", #{toScriptArgs(options)});