Author: abelevich
Date: 2010-10-14 05:58:10 -0400 (Thu, 14 Oct 2010)
New Revision: 19565
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.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/popup.js
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js
Log:
implement attachToBody
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2010-10-14
08:33:01 UTC (rev 19564)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceSelectBaseRenderer.java 2010-10-14
09:58:10 UTC (rev 19565)
@@ -51,6 +51,7 @@
@ResourceDependency(name = "jquery.js"),
@ResourceDependency(name = "jquery.position.js"),
@ResourceDependency(name = "richfaces.js"),
+ @ResourceDependency(name = "jquery.position.js"),
@ResourceDependency(name = "richfaces-event.js"),
@ResourceDependency(name = "richfaces-base-component.js"),
@ResourceDependency(name = "richfaces-selection.js"),
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-10-14
08:33:01 UTC (rev 19564)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceSelect.js 2010-10-14
09:58:10 UTC (rev 19565)
@@ -4,7 +4,11 @@
rf.ui.InplaceSelect = function(id, options) {
$super.constructor.call(this, id, options)
+
+ options['attachTo'] = id;
+ options['attachToBody'] = true;
this.select = new rf.ui.SelectList(options.listCord, this, options);
+
this.selectItems = options.selectItems;
this.selValueInput = $(document.getElementById(options.selValueInput));
this.openPopup = false;
@@ -45,15 +49,12 @@
this.openPopup = false;
},
- processItem: function(event, element) {
- if(element) {
- var key = $(element).attr("id");
- var value = this.getItemValue(key);
- this.saveItemValue(value);
- var label = this.getItemLabel(key);
- //inplace label
- this.setValue(label);
- }
+ processItem: function(item) {
+ var key = $(item).attr("id");
+ var value = this.getItemValue(key);
+ this.saveItemValue(value);
+ var label = this.getItemLabel(key);
+ this.setValue(label);
this.select.hide();
this.openPopup = false;
@@ -96,19 +97,19 @@
switch(code) {
case rf.KEYS.DOWN:
e.preventDefault();
- this.select.__onKeyDown(e);
+ this.select.__selectNext();
this.__setInputFocus();
break;
case rf.KEYS.UP:
e.preventDefault();
- this.select.__onKeyUp(e);
+ this.select.__selectPrev();
this.__setInputFocus();
break;
case rf.KEYS.RETURN:
e.preventDefault();
- this.select.__onEnter(e);
+ this.select.__selectCurrent();
return false;
break;
}
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popup.js
===================================================================
---
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popup.js 2010-10-14
08:33:01 UTC (rev 19564)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popup.js 2010-10-14
09:58:10 UTC (rev 19565)
@@ -7,7 +7,10 @@
this.attachToDom(id);
this.popup = $(document.getElementById(id));
- this.visible = options.visible;;
+ this.visible = options.visible;
+ this.attachTo = options.attachTo;
+ this.attachToBody = options.attachToBody;
+
this.popup.bind("mouseover", $.proxy(this.__onMouseOver, this));
this.popup.bind("click", $.proxy(this.__onClick, this));
};
@@ -22,15 +25,25 @@
name : "popup",
show: function() {
- this.popup.css('display', '');
- //add attachToBody logic
- this.visible = true;
+ if(!this.visible) {
+ if(this.attachToBody) {
+ this.parentElement = this.popup.parent();
+ this.popup.detach().appendTo("body");
+ }
+ this.popup.setPosition({id: this.attachTo}, {type:"DROPDOWN",
offset:[0,20]}).show();
+ this.visible = true;
+ }
},
hide: function() {
- this.popup.css('display', 'none');
- //add attachToBody logic
- this.visible = false;
+ if(this.visible) {
+ this.popup.hide();
+ this.visible = false;
+ if (this.attachToBody && this.parentElement) {
+ this.popup.detach().appendTo(this.parentElement);
+ this.parentElement = null;
+ }
+ }
},
isVisible: function() {
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-10-14
08:33:01 UTC (rev 19564)
+++
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/popupList.js 2010-10-14
09:58:10 UTC (rev 19565)
@@ -4,7 +4,9 @@
var INTERFACE = {
SelectListener : {
- processItem: function(e, element){}
+ processItem: function(item){},
+ selectItem: function(item){},
+ unselectItem: function(item){}
}
};
@@ -13,8 +15,7 @@
this.selectListener = listener;
this.selectItemCss = options.selectItemCss;
this.itemCss = options.itemCss;
-
- //TODO: from option map?
+
this.index = -1;
this.__updateItemsList();
};
@@ -23,26 +24,34 @@
var $super = rf.ui.PopupList.$super;
$.extend(rf.ui.PopupList.prototype, ( function () {
-
- var isSelectListener = function(obj) {
- for (var method in INTERFACE.SelectListener) {
- if ( (typeof obj[method] != typeof INTERFACE.SelectListener[method]) ) {
- return false;
- }
- }
- return true;
- };
return{
name : "popupList",
-
- processItem: function(e, element) {
- if(isSelectListener(this.selectListener)) {
- this.selectListener.processItem(e, element);
+
+
+ processItem: function(item) {
+ if(this.selectListener.processItem && typeof
this.selectListener.processItem == 'function') {
+ this.selectListener.processItem(item);
}
},
+ selectItem: function(item) {
+ if(this.selectListener.selectItem && typeof
this.selectListener.selectItem == 'function') {
+ this.selectListener.selectItem(item);
+ } else {
+ item.addClass(this.selectItemCss);
+ }
+ },
+
+ unselectItem: function(item) {
+ if(this.selectListener.unselectItem && typeof
this.selectListener.unselectItem == 'function') {
+ this.selectListener.unselectItem(item);
+ } else {
+ item.removeClass(this.selectItemCss);
+ }
+ },
+
__updateItemsList: function () {
this.items = this.popup.find("."+this.itemCss);
},
@@ -58,7 +67,7 @@
var item;
if (this.index != -1) {
item = this.items.eq(this.index);
- this.__unSelectItem(item);
+ this.unselectItem(item);
}
if (index==undefined) {
@@ -83,33 +92,22 @@
}
item = this.items.eq(this.index);
- this.__selectItem(item);
+ this.selectItem(item);
},
- __selectItem: function(item) {
- item.addClass(this.selectItemCss);
- },
-
- __unSelectItem: function(item) {
- item.removeClass(this.selectItemCss);
- },
-
- //remove event, rename ???
- __onEnter: function(e) {
+ __selectCurrent: function() {
var item;
- if(this.items) {
+ if(this.items && this.index >= 0) {
item = this.items.eq(this.index);
- this.processItem(e, item);
+ this.processItem(item);
}
},
- //remove event, rename
- __onKeyUp: function(e) {
+ __selectPrev: function() {
this.__selectByIndex(-1, true);
},
- //remove event, rename
- __onKeyDown: function(e) {
+ __selectNext: function() {
this.__selectByIndex(1, true);
},
@@ -122,7 +120,7 @@
__onClick: function(e) {
var item = this.__getItem(e);
- this.processItem(e, item);
+ this.processItem(item);
this.__select(item);
},