1 (function ($, rf) {
  2 
  3     rf.ui = rf.ui || {};
  4 
  5     rf.ui.CollapsibleSubTable = function(id, f, options) {
  6         this.id = id;
  7         this.stateInput = options.stateInput;
  8         this.optionsInput = options.optionsInput;
  9         this.expandMode = options.expandMode || rf.ui.CollapsibleSubTable.MODE_CLNT;
 10         this.eventOptions = options.eventOptions;
 11         this.formId = f;
 12 
 13         this.attachToDom();
 14     };
 15 
 16     $.extend(rf.ui.CollapsibleSubTable, {
 17             MODE_AJAX: "ajax",
 18             MODE_SRV: "server",
 19             MODE_CLNT: "client",
 20             collapse: 0,
 21             expand: 1
 22         });
 23 
 24     rf.BaseComponent.extend(rf.ui.CollapsibleSubTable);
 25     var $super = rf.ui.CollapsibleSubTable.$super;
 26 
 27     $.extend(rf.ui.CollapsibleSubTable.prototype, (function () {
 28 
 29         var element = function() {
 30             //use parent tbody as parent dom elem
 31             return $(document.getElementById(this.id)).parent();
 32         };
 33 
 34         var stateInputElem = function() {
 35             return $(document.getElementById(this.stateInput));
 36         };
 37 
 38         var optionsInputElem = function() {
 39             return $(document.getElementById(this.optionsInput));
 40         };
 41 
 42         var ajax = function(e, options) {
 43             this.__switchState();
 44             rf.ajax(this.id, e, options);
 45         };
 46 
 47         var server = function(options) {
 48             this.__switchState();
 49             $(document.getElementById(this.formId)).submit();
 50         };
 51 
 52         var client = function(options) {
 53             if (this.isExpanded()) {
 54                 this.collapse(options);
 55             } else {
 56                 this.expand(options);
 57             }
 58         };
 59 
 60 
 61         return {
 62 
 63             name: "CollapsibleSubTable",
 64 
 65             switchState: function(e, options) {
 66                 if (this.expandMode == rf.ui.CollapsibleSubTable.MODE_AJAX) {
 67                     ajax.call(this, e, this.eventOptions, options);
 68                 } else if (this.expandMode == rf.ui.CollapsibleSubTable.MODE_SRV) {
 69                     server.call(this, options);
 70                 } else if (this.expandMode == rf.ui.CollapsibleSubTable.MODE_CLNT) {
 71                     client.call(this, options);
 72                 }
 73             },
 74 
 75             collapse: function(options) {
 76                 this.setState(rf.ui.CollapsibleSubTable.collapse);
 77                 element.call(this).hide();
 78             },
 79 
 80             expand: function(options) {
 81                 this.setState(rf.ui.CollapsibleSubTable.expand);
 82                 element.call(this).show();
 83             },
 84 
 85             isExpanded: function() {
 86                 return (parseInt(this.getState()) == rf.ui.CollapsibleSubTable.expand);
 87             },
 88 
 89             __switchState: function(options) {
 90                 var state = this.isExpanded() ? rf.ui.CollapsibleSubTable.collapse : rf.ui.CollapsibleSubTable.expand;
 91                 this.setState(state);
 92             },
 93 
 94             getState: function() {
 95                 return stateInputElem.call(this).val();
 96             },
 97 
 98             setState: function(state) {
 99                 stateInputElem.call(this).val(state)
100             },
101 
102             setOption: function(option) {
103                 optionsInputElem.call(this).val(option);
104             },
105 
106             getMode: function() {
107                 return this.expandMode;
108             },
109             destroy: function() {
110                 $super.destroy.call(this);
111             }
112         };
113 
114     })());
115 
116 })(RichFaces.jQuery, window.RichFaces);