Author: pyaschenko
Date: 2011-02-02 13:14:00 -0500 (Wed, 02 Feb 2011)
New Revision: 21398
Modified:
trunk/examples/input-demo/src/main/webapp/examples/inplaceInput.xhtml
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceBase.js
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
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/popupList.js
trunk/ui/input/ui/src/test/java/org/richfaces/renderkit/InplaceInputRendererTest.java
Log:
https://jira.jboss.org/browse/RF-10341
Modified: trunk/examples/input-demo/src/main/webapp/examples/inplaceInput.xhtml
===================================================================
--- trunk/examples/input-demo/src/main/webapp/examples/inplaceInput.xhtml 2011-02-02
17:08:33 UTC (rev 21397)
+++ trunk/examples/input-demo/src/main/webapp/examples/inplaceInput.xhtml 2011-02-02
18:14:00 UTC (rev 21398)
@@ -15,6 +15,8 @@
<in:inplaceInput showControls="true" value="New York">
</in:inplaceInput>
<h:commandButton value="submit"/>
+ <in:inplaceInput showControls="true" defaultLabel="click to enter
your name" saveOnBlur="true"
onblur="RichFaces.$('form:ii').cancel()" id="ii">
+ </in:inplaceInput>
</h:form>
</h:body>
</html>
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceBase.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceBase.js 2011-02-02
17:08:33 UTC (rev 21397)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceBase.js 2011-02-02
18:14:00 UTC (rev 21398)
@@ -63,6 +63,7 @@
var value = this.__getValue()
if(value.length > 0) {
this.setLabel(value);
+ this.useDefaultLabel = false;
} else {
this.setLabel(this.defaultLabel);
this.useDefaultLabel = true;
@@ -77,8 +78,8 @@
cancel: function(){
var text = "";
if(!this.useDefaultLabel) {
- text = this.getLabel()
- }
+ text = this.getLabel();
+ }
this.__setValue(text);
this.isSaved = true;
this.oncancel();
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2011-02-02
17:08:33 UTC (rev 21397)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2011-02-02
18:14:00 UTC (rev 21398)
@@ -8,7 +8,8 @@
this.label = $(document.getElementById(id+"Label"));
var labelText = this.label.text();
var inputLabel = this.__getValue();
- this.initialValue = (labelText == inputLabel) ? labelText : "";
+ this.initialLabel = (labelText == inputLabel) ? labelText : "";
+ this.useDefaultLabel = labelText != inputLabel
this.saveOnBlur = mergedOptions.saveOnBlur;
this.showControls = mergedOptions.showControls;
this.getInput().bind("focus", $.proxy(this.__editHandler, this));
@@ -102,7 +103,7 @@
},
isValueChanged: function () {
- return (this.__getValue() != this.initialValue);
+ return (this.__getValue() != this.initialLabel);
},
onshow: function(){
@@ -153,7 +154,11 @@
__isFocused: function() {
return this.focused;
- }
+ },
+ setValue: function(value) {
+ this.__setValue(value);
+ this.save();
+ }
}
})());
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 2011-02-02
17:08:33 UTC (rev 21397)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2011-02-02
18:14:00 UTC (rev 21398)
@@ -11,6 +11,7 @@
this.popupList = new rf.ui.PopupList(id+"List", this, mergedOptions);
this.items = mergedOptions.items;
this.selValueInput = $(document.getElementById(id+"selValue"));
+ this.initialValue = this.selValueInput.val();
this.list = $(document.getElementById(id+"List"));
this.list.bind("mousedown", $.proxy(this.__onListMouseDown, this));
this.list.bind("mouseup", $.proxy(this.__onListMouseUp, this));
@@ -79,19 +80,42 @@
this.popupList.hide();
this.__showLabel();
},
+
+ __selectItemByValue: function(value) {
+ var item;
+ for (var i=0; i<this.items.length; i++) {
+ item = this.items[i];
+ if (item.value == value) {
+ this.popupList.__selectByIndex(i);
+ return;
+ }
+ }
+ this.popupList.resetSelection();
+ },
+
onsave: function() {
var item = this.popupList.currentSelectItem();
if(item) {
- this.savedIndex = this.popupList.getSelectedItemIndex();
- var value = this.getItemValue(item);
- this.saveItemValue(value);
+ var index = this.popupList.getSelectedItemIndex();
+ if (this.items[index].label == this.__getValue()) {
+ this.savedIndex = index;
+ var value = this.getItemValue(item);
+ this.saveItemValue(value);
+ this.popupList.__selectByIndex(this.savedIndex);
+ } else {
+ this.__selectItemByValue(this.getValue());
+ }
}
},
oncancel: function() {
var prevItem = this.popupList.getItemByIndex(this.savedIndex);
- if(prevItem) {
+ if (prevItem) {
var value = this.getItemValue(prevItem);
this.saveItemValue(value);
+ this.popupList.__selectByIndex(this.savedIndex);
+ } else {
+ this.saveItemValue(this.initialValue);
+ this.__selectItemByValue(this.initialValue);
}
},
onblur: function(e) {
@@ -226,8 +250,8 @@
item = this.items[i];
if (item.value == value) {
this.__setValue(item.label);
+ this.popupList.__selectByIndex(i);
this.save();
- this.popupList.__selectByIndex(i);
break;
}
}
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js 2011-02-02
17:08:33 UTC (rev 21397)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js 2011-02-02
18:14:00 UTC (rev 21398)
@@ -98,7 +98,7 @@
item.removeClass(this.selectItemCss);
}
},
-
+
currentSelectItem: function() {
if(this.items && this.index != -1) {
return this.items[this.index];
@@ -110,19 +110,17 @@
},
getItemByIndex: function(i) {
- if(i >= 0 && i <= this.items.length) {
+ if(i >= 0 && i < this.items.length) {
return this.items[i];
}
},
- resetItemsSelection: function() {
- if(this.items) {
- var popup = this;
- this.items.each(function(i,item){
- popup.unselectItem($(item));
- }
- );
+ resetSelection: function() {
+ var item = this.currentSelectItem();
+ if(item) {
+ this.unselectItem($(item));
}
+ this.index = -1;
},
isPopupList: function(target) {
@@ -172,7 +170,7 @@
item = this.items.eq(this.index);
this.selectItem(item);
},
-
+
__selectCurrent: function() {
var item;
if(this.items && this.index >= 0) {
Modified:
trunk/ui/input/ui/src/test/java/org/richfaces/renderkit/InplaceInputRendererTest.java
===================================================================
---
trunk/ui/input/ui/src/test/java/org/richfaces/renderkit/InplaceInputRendererTest.java 2011-02-02
17:08:33 UTC (rev 21397)
+++
trunk/ui/input/ui/src/test/java/org/richfaces/renderkit/InplaceInputRendererTest.java 2011-02-02
18:14:00 UTC (rev 21398)
@@ -62,7 +62,7 @@
HtmlElement span = page.getFirstByXPath("//*[@id = '"+
withControlsComponentId +"']");
assertNotNull(span);
- assertEquals("rf-ii-d-s rf-ii-c-s",
span.getAttribute(HtmlConstants.CLASS_ATTRIBUTE));
+ assertEquals("rf-ii-d-s",
span.getAttribute(HtmlConstants.CLASS_ATTRIBUTE));
edit(page, withControlsComponentId, "Another Test String");