<commit_before>
/* 
 * EntitiesList DataTable
 */


YUI.add('madb-tables', function(Y) {
  Y.namespace('madb_tables');

//    Y.yui2().use('datatable', 'paginator', function() {


      function EntitiesTable() {
        EntitiesTable.superclass.constructor.apply(this,arguments);
      }

      Y.mix(EntitiesTable,{ 
        NAME: 'entitiestable',
        FILTER_SELECT_LABEL_TEMPLATE : '<span><%= t("madb_filter_on") %> </span>',
        FILTER_SELECT_TEMPLATE : '<select>{{filter_options}}</select>',
        FILTER_FIELD_LABEL_TEMPLATE : '<span> <%= t("madb_with_value")%> </span>',
        FILTER_FIELD_TEMPLATE : '<input type="text" name="value_filter"/>',
        FILTER_SUBMIT_TEMPLATE : '<button><%= t("madb_submit") %></button>',
        FILTER_RESET_TEMPLATE : '<button><%= t("madb_reset") %></button>',
        FILTER_CSV_ICON_TEMPLATE : '<%=image_tag("icon/big/floppy.png", :alt =>t("madb_export"), :title =>t("madb_export") ,   :class => "icon") %>',
        ATTRS : {
                  identifier : {
                    validator: Y.Lang.isString
                  },
                  column_headers : {
                    validator: Y.Lang.isArray
                  },
                  actions : {
                    value : [],
                    validator: Y.Lang.isArray
                  },
                  source : {
                    value: null
                  },
                  fields_definition : {
                    validator: Y.Lang.isArray
                  },
                  entity_name: {
                    validator: Y.Lang.isString
                  },
                  entity_id: {
                    validator: Y.Lang.isNumeric
                  },
                  filter_options: {
                    value: "",
                    validator: Y.Lang.isString
                  },
                  dynamic_data: {
                    value: true,
                    validator: Y.Lang.isBoolean
                  },
                  data : {
                    value: {},
                    validator: Y.Lang.isObject
                    }



                }
      });

      Y.extend(EntitiesTable, Y.Widget, {
        _filter_select_label : null,
        _filter_select: null,
        _filter_field_label: null,
        _filter_field: null,
        _filter_submit: null,
        _filter_reset: null,
        _filter_csv_icon: null,
        _filter_container: null,
        _detail_filter: "",
        _value_filter: "",
        _column_set : null,
        _datatable_config: null,
        _filter_container: null,
        _datatable_container: null,
        _datatable_container_id: null,
        _datatable: null,
        _data_source:null,
        _view_formatter: function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/view.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id } ); 
        }, 
// datasource utf-8 fix
        _edit_formatter : function(cell, record, column, data) {
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/edit.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        _delete_formatter : function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/delete.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        _link_formatter : function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/use.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        _unlink_formatter : function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/unlink.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        getDataTable: function(){
          return this._datatable;
        },
        initializer: function(){
          Y.publish('madb:table_refreshed', {broadcast: 2});

          var available_actions = { "view" : {  "width": 35, "key": "view_action_column",  "label": "<%=t("madb_view")%>", "className": "action_cell", "formatter": this._view_formatter },
                                    "edit": { "width" :35, "key": "edit_action_column",  "label": "<%=t("madb_edit")%>", "className" : "action_cell", "formatter": this._edit_formatter  },
                                    "delete": { "width" :35, "key": "delete_action_column",  "label" : "<%=t("madb_delete")%>", "className" : "action_cell", "formatter": this._delete_formatter  },
                                    "link": { "width" :35, "key": "link_action_column",  "label" : "<%=t("madb_use")%>" , "className" : "action_cell", "formatter": this._link_formatter },
                                    "unlink": { "width" :35, "key": "unlink_action_column",  "label" : "<%=t("madb_unlink")%>" , "className" : "action_cell", "formatter": this._unlink_formatter }};

          var actions = [];
          Y.each( this.get("actions"), function(val, key, arr) {
            actions.push(available_actions[val]);
          });
          // used to reference ourself when in an object definition
          var self = this;
          this._filter_select_label = Y.Node.create(EntitiesTable.FILTER_SELECT_LABEL_TEMPLATE);
          this._filter_select = Y.Node.create(Y.substitute( EntitiesTable.FILTER_SELECT_TEMPLATE, { filter_options: this.get('filter_options') })) ;
          this._filter_field_label =Y.Node.create(EntitiesTable.FILTER_FIELD_LABEL_TEMPLATE);
          this._filter_field = Y.Node.create(EntitiesTable.FILTER_FIELD_TEMPLATE);
          this._filter_submit = Y.Node.create(EntitiesTable.FILTER_SUBMIT_TEMPLATE);
          this._filter_reset = Y.Node.create(EntitiesTable.FILTER_RESET_TEMPLATE);
          this._filter_csv_icon = Y.Node.create(EntitiesTable.FILTER_CSV_ICON_TEMPLATE);

          var contentBox= this.get('contentBox');
          this._filter_container = Y.Node.create('<div></div>');
          contentBox.append(this._filter_container);

          this._datatable_container = Y.Node.create('<div></div>');
          this._datatable_container_id = Y.guid();
          this._datatable_container.set('id', this._datatable_container_id);
          contentBox.append(this._datatable_container);

          this._column_set = new YAHOO.widget.ColumnSet( this.get('column_headers').concat(actions));
          if (this.get('dynamic_data'))
          {
            this._data_source = new YAHOO.util.DataSource(this.get('source'));
            this._data_source.responseType = YAHOO.util.DataSource.TYPE_JSON;
            this._data_source.responseSchema = {
              resultsList: "records",
              metaFields: { totalRecords: "totalRecords" },
            // we have the id here, enabling initial sorting by id
              fields: this.get('fields_definition').concat([ {"key": "id"} ] )
            };
            // set the instance id in the row's record_id attribute. 
            // Used in selenium tests
            this.formatRow=function(elTr, oRecord) {
// datasource utf-8 fix
                var record_id;
                if (oRecord.getData().id)
                   record_id = oRecord.getData().id;
                else
                  record_id = oRecord.getData()["['id']"];
                elTr.setAttribute("record_id", record_id);
                return true;
            }; 


            this._datatable_config = {
              formatRow: this.formatRow,
              //caption:"Example: Inline Editing",
              paginator: new YAHOO.widget.Paginator({ rowsPerPage: <%= MadbSettings.list_length %>, 
                                                      template              : "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} | {CurrentPageReport} | <%= I18n.t 'entities_table.rows_per_page' %>: {RowsPerPageDropdown}",
                                                      pageReportTemplate    : "<%= I18n.t 'entities_table.page_x_of_y'%>",
                                                      firstPageLinkLabel    : "<%= I18n.t 'entities_table.first' %>",
                                                      lastPageLinkLabel     : "<%= I18n.t 'entities_table.last' %>",
                                                      previousPageLinkLabel : "<%= I18n.t 'entities_table.previous' %>",
                                                      nextPageLinkLabel     : "<%= I18n.t 'entities_table.next' %>",
                                                      rowsPerPageOptions    : [10,20,30,50,100]
                    }), 
              dynamicData: true,
              sortedBy: {
                  // eventually replace this with the second line
                  key: "id",
                  //key: this._column_set[0].key
                  dir: YAHOO.widget.DataTable.CLASS_ASC
              },
              // eventually replace this list with the commented one. 
              // Temporarily leaving asis for selenium tests
              initialRequest: "&sort=id&dir=asc&startIndex=0&results=<%=MadbSettings.list_length%>",
              //initialRequest: "sort=<%# @ordered_fields[0] %>&dir=asc&startIndex=0&results=<%=MadbSettings.list_length%>",
              generateRequest: Y.bind(self._requestBuilder, self)
            }
          }
          else {
            this._data_source = new YAHOO.util.DataSource(this.get('source'));
            this._data_source.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
            this._data_source.responseSchema = {
              fields: this.get('fields_definition').concat([ {"key": "id"} ] )
            };

            this._datatable_config = {
              formatRow: this.formatRow,
              //caption:"Example: Inline Editing",
              paginator: new YAHOO.widget.Paginator({ rowsPerPage: <%= MadbSettings.list_length %>, 
                                                      template              : "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} | {CurrentPageReport} | <%= I18n.t 'entities_table.rows_per_page' %>: {RowsPerPageDropdown}",
                                                      pageReportTemplate    : "<%= I18n.t 'entities_table.page_x_of_y'%>",
                                                      firstPageLinkLabel    : "<%= I18n.t 'entities_table.first' %>",
                                                      lastPageLinkLabel     : "<%= I18n.t 'entities_table.last' %>",
                                                      previousPageLinkLabel : "<%= I18n.t 'entities_table.previous' %>",
                                                      nextPageLinkLabel     : "<%= I18n.t 'entities_table.next' %>",
                                                      rowsPerPageOptions    : [10,20,30,50,100]
                    }), 
              dynamicData: false,
              sortedBy: {
                  // eventually replace this with the second line
                  key: "id",
                  //key: this._column_set[0].key
                  dir: YAHOO.widget.DataTable.CLASS_ASC
              },
              // eventually replace this list with the commented one. 
              // Temporarily leaving asis for selenium tests
              //initialRequest: "sort=<%# @ordered_fields[0] %>&dir=asc&startIndex=0&results=<%=MadbSettings.list_length%>",
            }
          }
        },
        renderUI: function() {
          this._renderFilter();
          this._renderDataTable();
        },
        _renderFilter: function() {
          this._filter_container.append(this._filter_select_label).append(this._filter_select).append(this._filter_field_label).append(this._filter_field).append(this._filter_submit).append(this._filter_reset);
          if (this.get("dynamic_data")) {
            this._filter_container.append(this._filter_csv_icon);
          }

        },
/*
  this method is used to define the action listeners in the _renderDatatable function
  the event listener get a hash as argument
*/

        _define_action_listener: function(action, f) {
            self = this;
            this._datatable.subscribe('cellClickEvent',function (oArgs) {
              var datatable = this;
              var target = oArgs.target;
              var record = datatable.getRecord(target);
              var column = datatable.getColumn(target);
              var record_id;
// datasource utf-8 fix
              if (record.getData().id)
                 record_id = record.getData().id;
              else
                record_id = record.getData()["['id']"];
              if (column.key===action+'_action_column') {
                Y.bind(f, this)({ record_id: record_id , record: record, target:target, column:column, target: target});
              }
          });
        },
        _renderDataTable: function() {
          // ATTENTION YUI2
          //this._datatable = new YAHOO.widget.DataTable(Y.Node.getDOMNode(this._datatable_container), this._column_set, this._data_source, this._datatable_config);
          this._datatable = new YAHOO.widget.DataTable(this._datatable_container_id, this._column_set, this._data_source, this._datatable_config);
          this._datatable.handleDataReturnPayload = function (oRequest, oResponse, oPayload) {
            oPayload.totalRecords = oResponse.meta.totalRecords;
            return oPayload; 
          }
          // Define the delete listener only if that action is displayed
          datatable = this._datatable;
          if (Y.Array.find(this.get("actions"), function(value, key, arr) { if (value=="delete") {return true; } }) )
          {
            this._define_action_listener("delete", function(h) {
                var first_column = this.getColumnSet().keys[0].key; 
  // datasource utf-8 fix
                var first_value = h.record.getData("['"+this.getColumnSet().keys[0].key+"']");
                if (confirm(Y.madb.translate("<%= t("madb_really_delete_entity_question") %>", { entity: self.get('entity_name') , title: first_column  , value: first_value}  ))) {
                  var url = '<%= url_for  :controller => "entities", :action => "delete"%>/'+h.record_id+'.js';
                  var datatable = this;
                  var config = { method: 'POST', 
                                 on: { success : function() { this.deleteRow(h.target); },
                                       failure : function() { alert("<%= t('madb_an_error_occured')%>");}
                                 },
                                 context: datatable
                  };
                  Y.io(url, config);
                }
            })
          }
          // Define the view listener only if that action is displayed
          if (Y.Array.find(this.get("actions"), function(value, key, arr) { if (value=="view") {return true; } }) )
          {
            this._define_action_listener("view", function(h) {
                window.location='<%= url_for({ :controller => "entities", :action => "view"})%>/'+ h.record_id ;
            })

          }
          // Define the edit listener only if that action is displayed
          if (Y.Array.find(this.get("actions"), function(value, key, arr) { if (value=="edit") {return true; } }) )<commit_msg>ie8 fix asit does not see Y.madb<commit_after>
/* 
 * EntitiesList DataTable
 */


YUI.add('madb-tables', function(Y) {
  Y.namespace('madb_tables');

//    Y.yui2().use('datatable', 'paginator', function() {


      function EntitiesTable() {
        EntitiesTable.superclass.constructor.apply(this,arguments);
      }

      Y.mix(EntitiesTable,{ 
        NAME: 'entitiestable',
        FILTER_SELECT_LABEL_TEMPLATE : '<span><%= t("madb_filter_on") %> </span>',
        FILTER_SELECT_TEMPLATE : '<select>{{filter_options}}</select>',
        FILTER_FIELD_LABEL_TEMPLATE : '<span> <%= t("madb_with_value")%> </span>',
        FILTER_FIELD_TEMPLATE : '<input type="text" name="value_filter"/>',
        FILTER_SUBMIT_TEMPLATE : '<button><%= t("madb_submit") %></button>',
        FILTER_RESET_TEMPLATE : '<button><%= t("madb_reset") %></button>',
        FILTER_CSV_ICON_TEMPLATE : '<%=image_tag("icon/big/floppy.png", :alt =>t("madb_export"), :title =>t("madb_export") ,   :class => "icon") %>',
        ATTRS : {
                  identifier : {
                    validator: Y.Lang.isString
                  },
                  column_headers : {
                    validator: Y.Lang.isArray
                  },
                  actions : {
                    value : [],
                    validator: Y.Lang.isArray
                  },
                  source : {
                    value: null
                  },
                  fields_definition : {
                    validator: Y.Lang.isArray
                  },
                  entity_name: {
                    validator: Y.Lang.isString
                  },
                  entity_id: {
                    validator: Y.Lang.isNumeric
                  },
                  filter_options: {
                    value: "",
                    validator: Y.Lang.isString
                  },
                  dynamic_data: {
                    value: true,
                    validator: Y.Lang.isBoolean
                  },
                  data : {
                    value: {},
                    validator: Y.Lang.isObject
                    }



                }
      });

      Y.extend(EntitiesTable, Y.Widget, {
        _filter_select_label : null,
        _filter_select: null,
        _filter_field_label: null,
        _filter_field: null,
        _filter_submit: null,
        _filter_reset: null,
        _filter_csv_icon: null,
        _filter_container: null,
        _detail_filter: "",
        _value_filter: "",
        _column_set : null,
        _datatable_config: null,
        _filter_container: null,
        _datatable_container: null,
        _datatable_container_id: null,
        _datatable: null,
        _data_source:null,
        _view_formatter: function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/view.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id } ); 
        }, 
// datasource utf-8 fix
        _edit_formatter : function(cell, record, column, data) {
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/edit.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        _delete_formatter : function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/delete.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        _link_formatter : function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/use.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        _unlink_formatter : function(cell, record, column, data) {
// datasource utf-8 fix
          var record_id;
          if (record.getData().id)
             record_id = record.getData().id;
          else
            record_id = record.getData()["['id']"];
          cell.innerHTML=Y.substitute('<%=image_tag("icon/big/unlink.png", :border =>0,  :record_id => "{record_id}")%>', { record_id: record_id} ); 
        },
        getDataTable: function(){
          return this._datatable;
        },
        initializer: function(){
          Y.publish('madb:table_refreshed', {broadcast: 2});

          var available_actions = { "view" : {  "width": 35, "key": "view_action_column",  "label": "<%=t("madb_view")%>", "className": "action_cell", "formatter": this._view_formatter },
                                    "edit": { "width" :35, "key": "edit_action_column",  "label": "<%=t("madb_edit")%>", "className" : "action_cell", "formatter": this._edit_formatter  },
                                    "delete": { "width" :35, "key": "delete_action_column",  "label" : "<%=t("madb_delete")%>", "className" : "action_cell", "formatter": this._delete_formatter  },
                                    "link": { "width" :35, "key": "link_action_column",  "label" : "<%=t("madb_use")%>" , "className" : "action_cell", "formatter": this._link_formatter },
                                    "unlink": { "width" :35, "key": "unlink_action_column",  "label" : "<%=t("madb_unlink")%>" , "className" : "action_cell", "formatter": this._unlink_formatter }};

          var actions = [];
          Y.each( this.get("actions"), function(val, key, arr) {
            actions.push(available_actions[val]);
          });
          // used to reference ourself when in an object definition
          var self = this;
          this._filter_select_label = Y.Node.create(EntitiesTable.FILTER_SELECT_LABEL_TEMPLATE);
          this._filter_select = Y.Node.create(Y.substitute( EntitiesTable.FILTER_SELECT_TEMPLATE, { filter_options: this.get('filter_options') })) ;
          this._filter_field_label =Y.Node.create(EntitiesTable.FILTER_FIELD_LABEL_TEMPLATE);
          this._filter_field = Y.Node.create(EntitiesTable.FILTER_FIELD_TEMPLATE);
          this._filter_submit = Y.Node.create(EntitiesTable.FILTER_SUBMIT_TEMPLATE);
          this._filter_reset = Y.Node.create(EntitiesTable.FILTER_RESET_TEMPLATE);
          this._filter_csv_icon = Y.Node.create(EntitiesTable.FILTER_CSV_ICON_TEMPLATE);

          var contentBox= this.get('contentBox');
          this._filter_container = Y.Node.create('<div></div>');
          contentBox.append(this._filter_container);

          this._datatable_container = Y.Node.create('<div></div>');
          this._datatable_container_id = Y.guid();
          this._datatable_container.set('id', this._datatable_container_id);
          contentBox.append(this._datatable_container);

          this._column_set = new YAHOO.widget.ColumnSet( this.get('column_headers').concat(actions));
          if (this.get('dynamic_data'))
          {
            this._data_source = new YAHOO.util.DataSource(this.get('source'));
            this._data_source.responseType = YAHOO.util.DataSource.TYPE_JSON;
            this._data_source.responseSchema = {
              resultsList: "records",
              metaFields: { totalRecords: "totalRecords" },
            // we have the id here, enabling initial sorting by id
              fields: this.get('fields_definition').concat([ {"key": "id"} ] )
            };
            // set the instance id in the row's record_id attribute. 
            // Used in selenium tests
            this.formatRow=function(elTr, oRecord) {
// datasource utf-8 fix
                var record_id;
                if (oRecord.getData().id)
                   record_id = oRecord.getData().id;
                else
                  record_id = oRecord.getData()["['id']"];
                elTr.setAttribute("record_id", record_id);
                return true;
            }; 


            this._datatable_config = {
              formatRow: this.formatRow,
              //caption:"Example: Inline Editing",
              paginator: new YAHOO.widget.Paginator({ rowsPerPage: <%= MadbSettings.list_length %>, 
                                                      template              : "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} | {CurrentPageReport} | <%= I18n.t 'entities_table.rows_per_page' %>: {RowsPerPageDropdown}",
                                                      pageReportTemplate    : "<%= I18n.t 'entities_table.page_x_of_y'%>",
                                                      firstPageLinkLabel    : "<%= I18n.t 'entities_table.first' %>",
                                                      lastPageLinkLabel     : "<%= I18n.t 'entities_table.last' %>",
                                                      previousPageLinkLabel : "<%= I18n.t 'entities_table.previous' %>",
                                                      nextPageLinkLabel     : "<%= I18n.t 'entities_table.next' %>",
                                                      rowsPerPageOptions    : [10,20,30,50,100]
                    }), 
              dynamicData: true,
              sortedBy: {
                  // eventually replace this with the second line
                  key: "id",
                  //key: this._column_set[0].key
                  dir: YAHOO.widget.DataTable.CLASS_ASC
              },
              // eventually replace this list with the commented one. 
              // Temporarily leaving asis for selenium tests
              initialRequest: "&sort=id&dir=asc&startIndex=0&results=<%=MadbSettings.list_length%>",
              //initialRequest: "sort=<%# @ordered_fields[0] %>&dir=asc&startIndex=0&results=<%=MadbSettings.list_length%>",
              generateRequest: Y.bind(self._requestBuilder, self)
            }
          }
          else {
            this._data_source = new YAHOO.util.DataSource(this.get('source'));
            this._data_source.responseType = YAHOO.util.DataSource.TYPE_JSARRAY; 
            this._data_source.responseSchema = {
              fields: this.get('fields_definition').concat([ {"key": "id"} ] )
            };

            this._datatable_config = {
              formatRow: this.formatRow,
              //caption:"Example: Inline Editing",
              paginator: new YAHOO.widget.Paginator({ rowsPerPage: <%= MadbSettings.list_length %>, 
                                                      template              : "{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} | {CurrentPageReport} | <%= I18n.t 'entities_table.rows_per_page' %>: {RowsPerPageDropdown}",
                                                      pageReportTemplate    : "<%= I18n.t 'entities_table.page_x_of_y'%>",
                                                      firstPageLinkLabel    : "<%= I18n.t 'entities_table.first' %>",
                                                      lastPageLinkLabel     : "<%= I18n.t 'entities_table.last' %>",
                                                      previousPageLinkLabel : "<%= I18n.t 'entities_table.previous' %>",
                                                      nextPageLinkLabel     : "<%= I18n.t 'entities_table.next' %>",
                                                      rowsPerPageOptions    : [10,20,30,50,100]
                    }), 
              dynamicData: false,
              sortedBy: {
                  // eventually replace this with the second line
                  key: "id",
                  //key: this._column_set[0].key
                  dir: YAHOO.widget.DataTable.CLASS_ASC
              },
              // eventually replace this list with the commented one. 
              // Temporarily leaving asis for selenium tests
              //initialRequest: "sort=<%# @ordered_fields[0] %>&dir=asc&startIndex=0&results=<%=MadbSettings.list_length%>",
            }
          }
        },
        renderUI: function() {
          this._renderFilter();
          this._renderDataTable();
        },
        _renderFilter: function() {
          this._filter_container.append(this._filter_select_label).append(this._filter_select).append(this._filter_field_label).append(this._filter_field).append(this._filter_submit).append(this._filter_reset);
          if (this.get("dynamic_data")) {
            this._filter_container.append(this._filter_csv_icon);
          }

        },
/*
  this method is used to define the action listeners in the _renderDatatable function
  the event listener get a hash as argument
*/

        _define_action_listener: function(action, f) {
            var self = this;
            this._datatable.subscribe('cellClickEvent',function (oArgs) {
              var datatable = this;
              var target = oArgs.target;
              var record = datatable.getRecord(target);
              var column = datatable.getColumn(target);
              var record_id;
// datasource utf-8 fix
              if (record.getData().id)
                 record_id = record.getData().id;
              else
                record_id = record.getData()["['id']"];
              if (column.key===action+'_action_column') {
                Y.bind(f, this)({ record_id: record_id , record: record, target:target, column:column, target: target});
              }
          });
        },
        _renderDataTable: function() {
          // ATTENTION YUI2
          //this._datatable = new YAHOO.widget.DataTable(Y.Node.getDOMNode(this._datatable_container), this._column_set, this._data_source, this._datatable_config);
          this._datatable = new YAHOO.widget.DataTable(this._datatable_container_id, this._column_set, this._data_source, this._datatable_config);
          this._datatable.handleDataReturnPayload = function (oRequest, oResponse, oPayload) {
            oPayload.totalRecords = oResponse.meta.totalRecords;
            return oPayload; 
          }
          // Define the delete listener only if that action is displayed
          var datatable = this._datatable;
          var self = this;
          if (Y.Array.find(this.get("actions"), function(value, key, arr) { if (value=="delete") {return true; } }) )
          {
            Y.log('will define delete listener');
            this._define_action_listener("delete", function(h) {
                Y.log('start define delete listener');
                var first_column = this.getColumnSet().keys[0].key; 
  // datasource utf-8 fix
                var first_value = h.record.getData("['"+this.getColumnSet().keys[0].key+"']");
                // FIX for IE8: Y.madb not available
                Y.log('will display confirmation request');
                var msg;
                if (Y.madb){
                  msg = Y.madb.translate("<%= t("madb_really_delete_entity_question") %>", { entity: self.get('entity_name') , title: first_column  , value: first_value}  );
                  Y.log('Y.madb is available!')
                  Y.log(Y.madb);
                }
                else {
                  Y.log('Y.madb is NOT available!')
                  msg = "confirm?";
                }
                if (confirm(msg)) {
                  var url = '<%= url_for  :controller => "entities", :action => "delete"%>/'+h.record_id+'.js';
                  var datatable = this;
                  var config = { method: 'POST', 
                                 on: { success : function() { this.deleteRow(h.target); },
                                       failure : function() { alert("<%= t('madb_an_error_occured')%>");}
                                 },
                                 context: datatable
                  };
                  Y.log('will send delete request');
                  Y.io(url, config);
                }
            })
          }
          // Define the view listener only if that action is displayed
          if (Y.Array.find(this.get("actions"), function(value, key, arr) { if (value=="view") {return true; } }) )
          {
            this._define_action_listener("view", function(h) {
                window.location='<%= url_for({ :controller => "entities", :action => "view"})%>/'+ h.record_id ;
            })

          }
          // Define the edit listener only if that action is displayed
          if (Y.Array.find(this.get("actions"), function(value, key, arr) { if (value=="edit") {return true; } }) )
{'fraction_non_alphanumeric': 0.13209987966305656, 'fraction_numerical': 0.0049338146811070994, 'mean_word_length': 1.753790075387292, 'pattern_counts': {'":': 40, '<': 109, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 70, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3296841', 'n_tokens_mistral': 9373, 'n_tokens_neox': 8998, 'n_words': 1620}