Author: abelevich
Date: 2010-11-01 08:19:23 -0400 (Mon, 01 Nov 2010)
New Revision: 19818
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/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/inputBase.js
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js
Log:
RF-9573, add some new API methods for the popup obj
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 2010-11-01
12:14:59 UTC (rev 19817)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceBase.js 2010-11-01
12:19:23 UTC (rev 19818)
@@ -89,6 +89,12 @@
onhide: function() {
},
+ onsave: function() {
+ },
+
+ oncancel: function() {
+ },
+
isValueSaved: function() {
return this.isSaved;
},
@@ -106,6 +112,7 @@
this.__applyChangedStyles();
this.__hide();
+ this.onsave();
},
cancel: function(){
@@ -116,7 +123,12 @@
this.setValue(text);
this.isSaved = true;
this.__hide();
+ this.oncancel();
},
+
+ isEditState: function() {
+ return this.editState;
+ },
__applyChangedStyles: function() {
if(this.isValueChanged()) {
@@ -128,8 +140,8 @@
__show: function() {
this.scrollElements = rf.Event.bindScrollEventHandlers(this.id, this.__scrollHandler,
this);
+ this.editState = true;
this.onshow();
- this.editState = true;
},
__hide: function() {
@@ -137,9 +149,9 @@
rf.Event.unbindScrollEventHandlers(this.scrollElements, this);
this.scrollElements = null;
}
- this.onhide();
this.editState = false;
this.editContainer.addClass(this.noneCss);
+ this.onhide();
},
__editHandler: function(e) {
@@ -151,8 +163,8 @@
this.cancel();
},
- isEditState: function() {
- return this.editState;
+ __setInputFocus: function() {
+ this.input.focus();
},
destroy: function () {
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 2010-11-01
12:14:59 UTC (rev 19817)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-11-01
12:19:23 UTC (rev 19818)
@@ -55,11 +55,11 @@
__keydownHandler: function(e) {
switch(e.keyCode || e.which) {
- case 27:
+ case rf.KEYS.ESC:
e.preventDefault();
this.cancel();
break;
- case 13:
+ case rf.KEYS.RETURN:
e.preventDefault();
this.save();
return false;
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-11-01
12:14:59 UTC (rev 19817)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-11-01
12:19:23 UTC (rev 19818)
@@ -15,6 +15,7 @@
this.list.bind("click", $.proxy(this.__onListClick, this));
this.openOnEdit = options.openOnEdit;
this.saveOnSelect = options.saveOnSelect;
+ this.savedIndex = -1;
}
rf.ui.InplaceInput.extend(rf.ui.InplaceSelect);
@@ -64,39 +65,64 @@
this.popupList.hide();
},
+ onsave: function() {
+ var item = this.popupList.currentSelectItem();
+ if(item) {
+ this.savedIndex = this.popupList.getSelectedItemIndex();
+ var value = this.getItemValue(item);
+ this.saveItemValue(value);
+ }
+ },
+
+ oncancel: function() {
+ var prevItem = this.popupList.getItemByIndex(this.savedIndex);
+ if(prevItem) {
+ var value = this.getItemValue(prevItem);
+ this.saveItemValue(value);
+ }
+ },
+
processItem: function(item) {
- var key = $(item).attr("id");
- var value = this.getItemValue(key);
- this.saveItemValue(value);
- var label = this.getItemLabel(key);
+ var label = this.getItemLabel(item);
this.setValue(label);
- this.__setInputFocus();
+
+ this.__setInputFocus();
this.hidePopup();
+
if(this.saveOnSelect) {
this.save();
}
},
- getItemValue: function(key) {
- for(var i in this.items) {
- var item = this.items[i];
- if(item && item.id == key) {
- return item.value;
- }
- }
+ getItemValue: function(item) {
+ var key = $(item).attr("id");
+
+ var value;
+ $.each(this.items, function(){
+ if (this.id == key) {
+ value = this.value;
+ return false;
+ }
+ });
+
+ return value;
},
saveItemValue: function(value) {
this.selValueInput.val(value);
},
- getItemLabel: function(key) {
- for(var i in this.items) {
- var item = this.items[i];
- if(item && item.id == key) {
- return item.label;
- }
- }
+ getItemLabel: function(item) {
+ var key = $(item).attr("id");
+ var label;
+ $.each(this.items, function(){
+ if (this.id == key) {
+ label = this.label;
+ return false;
+ }
+ });
+
+ return label;
},
__keydownHandler: function(e) {
@@ -150,7 +176,8 @@
__onListClick: function(e) {
window.clearTimeout(this.timeoutId);
- }
+ }
+
}
})());
Modified:
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inputBase.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inputBase.js 2010-11-01
12:14:59 UTC (rev 19817)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inputBase.js 2010-11-01
12:19:23 UTC (rev 19818)
@@ -1,19 +1,3 @@
-(function (rf) {
- rf.KEYS = {
- BACKSPACE: 8,
- TAB: 9,
- RETURN: 13,
- ESC: 27,
- PAGEUP: 33,
- PAGEDOWN: 34,
- LEFT: 37,
- UP: 38,
- RIGHT: 39,
- DOWN: 40,
- DEL: 46
- };
-})(RichFaces);
-
(function ($, rf) {
rf.ui = rf.ui || {};
@@ -66,10 +50,6 @@
__changeHandler: function(e) {
},
- __setInputFocus: function() {
- this.input.focus();
- },
-
getValue: function() {
return this.input.val();
},
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 2010-11-01
12:14:59 UTC (rev 19817)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js 2010-11-01
12:19:23 UTC (rev 19818)
@@ -56,6 +56,22 @@
}
},
+ currentSelectItem: function() {
+ if(this.items && this.index != -1) {
+ return this.items[this.index];
+ }
+ },
+
+ getSelectedItemIndex: function() {
+ return this.index;
+ },
+
+ getItemByIndex: function(i) {
+ if(i >= 0 && i <= this.items.length) {
+ return this.items[i];
+ }
+ },
+
resetItemsSelection: function() {
if(this.items) {
var popup = this;
@@ -82,7 +98,7 @@
__selectByIndex: function(index, isOffset) {
if (this.items.length==0 || (!isOffset && this.index == index)) return;
-
+
var item;
if (this.index != -1) {
item = this.items.eq(this.index);