Author: Alex.Kolonitsky
Date: 2010-07-09 14:09:13 -0400 (Fri, 09 Jul 2010)
New Revision: 17792
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanelItem.js
Log:
RF-8745 TogglePanel component
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2010-07-09
17:33:53 UTC (rev 17791)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2010-07-09
18:09:13 UTC (rev 17792)
@@ -63,6 +63,7 @@
Map<String, Object> options = new HashMap<String, Object>(2);
options.put("name", panelItem.getName());
+ options.put("togglePanelId", panelItem.getParent().getClientId());
options.put("switchMode", panelItem.getSwitchType());
return options;
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-09
17:33:53 UTC (rev 17791)
+++
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-09
18:09:13 UTC (rev 17792)
@@ -93,6 +93,7 @@
execServer : function (oldPanel, newPanel) {
var continueProcess = oldPanel.leave();
if (!continueProcess) {
+
return false;
}
@@ -190,6 +191,13 @@
/********************* Methods *************************/
+ var ITEMS_META_NAMES = {
+ "@first" : function (comp) { return 0; },
+ "@prev" : function (comp) { return getItemIndex(comp.items,
comp.selectedItem) - 1; },
+ "@next" : function (comp) { return getItemIndex(comp.items,
comp.selectedItem) + 1; },
+ "@last" : function (comp) { return comp.items.length - 1; }
+ };
+
function getItemIndex (items, itemName) {
for (var i = 0; i < items.length; i++) {
if (items[i].getName() === itemName) {
@@ -251,23 +259,48 @@
* @name TogglePanel#switchToItem
*
* @param {String} name - panel item name to switch
- * @return {Boolean} - always false
+ * we can use meta names @first, @prev, @next and @last
+ * @return {Boolean} - false if something wrong and true if all is ok
*/
switchToItem: function (name) {
+ var newPanel = this.getNextItem(name);
+ if (newPanel == null) {
+ rf.log.warn("TogglePanel.switchToItems(" + name + "):
item with name '" + name + "' not found");
+ return false;
+ }
+
var oldPanel = getItemByName(this.items, this.getSelectItem());
- var newPanel = getItemByName(this.items, name || this.nextItem());
var continueProcess = fireBeforeItemChange(this, oldPanel, newPanel);
if (!continueProcess) {
+ rf.log.warn("TogglePanel.switchToItems(" + name + "):
switch has been canceled by beforeItemChange event");
return false
}
- new SwitchItems(this).exec(oldPanel, newPanel);
-
- return false;
+ return new SwitchItems(this).exec(oldPanel, newPanel);
},
/**
+ * @methodOf
+ * @name TogglePanel#getNextItem
+ *
+ * @param {String} name of TogglePanelItem or meta name (@first | @prev |
@next | @last)
+ * @return {TogglePanelItem} null if item not found
+ */
+ getNextItem : function (name) {
+ if (name) {
+ var newItemIndex = ITEMS_META_NAMES[name];
+ if (newItemIndex) {
+ return getItem(this.items, newItemIndex(this));
+ } else {
+ return getItemByName(this.items, name);
+ }
+ } else {
+ return getItemByName(this.items, this.nextItem());
+ }
+ },
+
+ /**
* please, remove this method when client side ajax events will be added
*
* */
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanelItem.js
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanelItem.js 2010-07-09
17:33:53 UTC (rev 17791)
+++
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanelItem.js 2010-07-09
18:09:13 UTC (rev 17792)
@@ -36,6 +36,7 @@
this.options = $.extend({}, DEFAULT_OPTIONS, options);
this.name = this.options.name;
+ this.togglePanelId = this.options.togglePanelId;
this.switchMode = this.options.switchMode;
};
@@ -47,53 +48,83 @@
/***************************** Private Static Methods
*************************************************************/
- function fireLeave ($this) {
+ function fireLeave($this) {
return rf.Event.fireById($this.id, "leave");
}
- function fireEnter ($this) {
- return rf.Event.fireById($this.id, "enter");
+ function fireEnter($this) {
+ return rf.Event.fireById($this.id, "enter");
}
/***************************** Public Methods
********************************************************************/
$.extend(rf.ui.TogglePanelItem.prototype, (function () {
return {
- // class name
- name:"TogglePanelItem",
+ // class name
+ name:"TogglePanelItem",
- // public api
- /**
- * @methodOf
- * @name TogglePanelItem#getName
- *
- * @return {String} panel item name
- */
- getName: function () {
- return this.options.name;
- },
+ // public api
+ /**
+ * @methodOf
+ * @name TogglePanelItem#getName
+ *
+ * @return {String} panel item name
+ */
+ getName: function () {
+ return this.options.name;
+ },
- enter : function () {
- rf.getDomElement(this.id).style.display = "block";
+ /**
+ * @methodOf
+ * @name TogglePanelItem#getTogglePanel
+ *
+ * @return {TogglePanel} parent TogglePanel
+ * */
+ getTogglePanel : function () {
+ return rf.$(this.togglePanelId);
+ },
- return fireEnter(this);
- },
+ /**
+ * @methodOf
+ * @name TogglePanelItem#isSelected
+ *
+ * @return {Boolean} true if this panel item is selected in the parent toggle
panel
+ * */
+ isSelected : function () {
+ return this.getName() == this.getTogglePanel().getSelectItem();
+ },
- leave : function () {
- var continueProcess = fireLeave(this);
- if (!continueProcess) {
- return false;
- }
+ /**
+ * @private
+ *
+ * used in TogglePanel
+ * */
+ enter : function () {
+ rf.getDomElement(this.id).style.display = "block";
- rf.getDomElement(this.id).style.display = "none";
- return true;
- },
+ return fireEnter(this);
+ },
- // class stuff
- destroy: function () {
-// rf.Event.unbindById(this.options.buttonId,
"."+this.namespace);
-// rf.Event.unbindById(this.componentId, "."+this.namespace);
- $super.destroy.call(this);
- }
+ /**
+ * @private
+ *
+ * used in TogglePanel
+ * */
+ leave : function () {
+ var continueProcess = fireLeave(this);
+ if (!continueProcess) {
+ return false;
+ }
+
+ rf.getDomElement(this.id).style.display = "none";
+ return true;
+ },
+
+ // class stuff
+ destroy: function () {
+ // rf.Event.unbindById(this.options.buttonId,
"."+this.namespace);
+ // rf.Event.unbindById(this.componentId,
"."+this.namespace);
+ $super.destroy.call(this);
+ }
};
})());
})(jQuery, RichFaces);