1 (function ($, rf) {
  2 
  3     rf.ui = rf.ui || {};
  4 
  5     rf.ui.DataTable = function(id, options) {
  6         $super.constructor.call(this, id);
  7         this.options = $.extend(this.options, options || {});
  8         this.attachToDom();
  9 
 10     };
 11 
 12     rf.BaseComponent.extend(rf.ui.DataTable);
 13     var $super = rf.ui.DataTable.$super;
 14 
 15     $.extend(rf.ui.DataTable, {
 16             SORTING: "rich:sorting",
 17             FILTERING: "rich:filtering",
 18             SUBTABLE_SELECTOR:".rf-cst"
 19         });
 20 
 21     $.extend(rf.ui.DataTable.prototype, ( function () {
 22 
 23         var invoke = function(event, attributes) {
 24             rf.ajax(this.id, event, {"parameters" : attributes});
 25         };
 26 
 27         var createParameters = function(type, id, arg1, arg2) {
 28             var parameters = {};
 29             var key = this.id + type;
 30             parameters[key] = (id + ":" + (arg1 || "") + ":" + arg2);
 31 
 32             var eventOptions = this.options.ajaxEventOption;
 33             for (key in eventOptions) {
 34                 if (!parameters[key]) {
 35                     parameters[key] = eventOptions[key];
 36                 }
 37             }
 38             return parameters;
 39         };
 40 
 41 
 42         return {
 43 
 44             name : "RichFaces.ui.DataTable",
 45 
 46             sort: function(columnId, direction, isClear) {
 47                 invoke.call(this, null, createParameters.call(this, rf.ui.DataTable.SORTING, columnId, direction, isClear));
 48             },
 49 
 50             clearSorting: function() {
 51                 this.sort("", "", true);
 52             },
 53 
 54             filter: function(columnId, filterValue, isClear) {
 55                 invoke.call(this, null, createParameters.call(this, rf.ui.DataTable.FILTERING, columnId, filterValue, isClear));
 56             },
 57 
 58             clearFiltering: function() {
 59                 this.filter("", "", true);
 60             },
 61 
 62             expandAllSubTables: function() {
 63                 this.invokeOnSubTables('expand');
 64             },
 65 
 66             collapseAllSubTables: function() {
 67                 this.invokeOnSubTables('collapse');
 68             },
 69 
 70             switchSubTable: function(id) {
 71                 this.getSubTable(id).switchState();
 72             },
 73 
 74             getSubTable: function(id) {
 75                 return rf.component(id);
 76             },
 77 
 78             invokeOnSubTables: function(funcName) {
 79                 var elements = $(document.getElementById(this.id)).children(rf.ui.DataTable.SUBTABLE_SELECTOR);
 80                 var invokeOnComponent = this.invokeOnComponent;
 81                 elements.each(
 82                     function() {
 83                         if (this.firstChild && this.firstChild[rf.RICH_CONTAINER] && this.firstChild[rf.RICH_CONTAINER].component) {
 84                             var component = this.firstChild[rf.RICH_CONTAINER].component;
 85                             if (component instanceof RichFaces.ui.CollapsibleSubTable) {
 86                                 invokeOnComponent(component, funcName);
 87                             }
 88                         }
 89                     }
 90                 );
 91             },
 92 
 93             invokeOnSubTable: function(id, funcName) {
 94                 var subtable = this.getSubTable(id);
 95                 this.invokeOnComponent(subtable, funcName);
 96             },
 97 
 98             invokeOnComponent: function(component, funcName) {
 99                 if (component) {
100                     var func = component[funcName];
101                     if (typeof func == 'function') {
102                         func.call(component);
103                     }
104                 }
105             },
106             destroy: function() {
107                 $super.destroy.call(this);
108             }
109         }
110 
111     })());
112 
113 })(RichFaces.jQuery, window.RichFaces);
114 
115