1 (function ($, rf) {
  2 
  3     rf.ui = rf.ui || {};
  4 
  5     rf.ui.CollapsibleSubTableToggler = function(id, options) {
  6         this.id = id;
  7         this.eventName = options.eventName;
  8         this.expandedControl = options.expandedControl;
  9         this.collapsedControl = options.collapsedControl;
 10         this.forId = options.forId;
 11         this.element = $(document.getElementById(this.id));
 12 
 13         if (this.element && this.eventName) {
 14             this.element.bind(this.eventName, $.proxy(this.switchState, this));
 15         }
 16     };
 17 
 18     $.extend(rf.ui.CollapsibleSubTableToggler.prototype, (function () {
 19 
 20         var getElementById = function(id) {
 21             return $(document.getElementById(id))
 22         }
 23 
 24         return {
 25 
 26             switchState: function(e) {
 27                 var subtable = rf.component(this.forId);
 28                 if (subtable) {
 29                     var mode = subtable.getMode();
 30 
 31                     if (rf.ui.CollapsibleSubTable.MODE_CLNT == mode) {
 32                         this.toggleControl(subtable.isExpanded());
 33                     }
 34 
 35                     subtable.setOption(this.id);
 36                     subtable.switchState(e);
 37                 }
 38             },
 39 
 40             toggleControl: function(collapse) {
 41                 var expandedControl = getElementById(this.expandedControl);
 42                 var collapsedControl = getElementById(this.collapsedControl);
 43 
 44                 if (collapse) {
 45                     expandedControl.hide();
 46                     collapsedControl.show();
 47                 } else {
 48                     collapsedControl.hide();
 49                     expandedControl.show();
 50                 }
 51             }
 52         };
 53     })());
 54 
 55 })(RichFaces.jQuery, window.RichFaces);