From: Thierry Parmentelat Date: Wed, 27 Mar 2013 11:34:17 +0000 (+0100) Subject: additional datatables_options can be passed to hazelnut from the view for any fine... X-Git-Tag: myslice-django-0.1-3~23 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=c6f034023202f3e233956e3eb7fdd020ca45867f additional datatables_options can be passed to hazelnut from the view for any fine-grained tweaks just in case we use this to remove sorting arrows on the checkbox column for now --- diff --git a/plugins/hazelnut/hazelnut.css b/plugins/hazelnut/hazelnut.css index 2439bd15..a72e6a0c 100644 --- a/plugins/hazelnut/hazelnut.css +++ b/plugins/hazelnut/hazelnut.css @@ -14,7 +14,7 @@ div.Hazelnut table.dataTable th { text-align: left; padding: 8px 12px 4px 20px; vertical-align:middle; - background: #CAE8EA url(../img/tablesort-header.jpg) no-repeat; +/* background: #CAE8EA url(../img/tablesort-header.jpg) no-repeat; */ } div.Hazelnut table.dataTable td, div.Hazelnut table.dataTable textarea, div.Hazelnut table.dataTable input [type="text"] { @@ -35,9 +35,16 @@ div.Hazelnut div.dataTables_info { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; } +/* one could think or using repeat-x here but that's not working because of the arrows + * we might need to make these wider some day */ div.Hazelnut table.dataTable thead .sorting { background: url('../img/tablesort-header-sortable.png') no-repeat; } div.Hazelnut table.dataTable thead .sorting_asc { background: url('../img/tablesort-header-up.png') no-repeat; } div.Hazelnut table.dataTable thead .sorting_desc { background: url('../img/tablesort-header-down.png') no-repeat; } -/* former set did not have that exact equivalent - using an approximation for now */ -div.Hazelnut table.dataTable thead .sorting_asc_disabled { background: url('../img/tablesort-header-sortable.png') no-repeat; } -div.Hazelnut table.dataTable thead .sorting_desc_disabled { background: url('../img/tablesort-header-sortable.png') no-repeat; } +/* this icons set does not have that exact equivalent - using an approximation for now */ +div.Hazelnut table.dataTable thead .sorting_asc_disabled { background: url('../img/tablesort-header.png') no-repeat; } +div.Hazelnut table.dataTable thead .sorting_desc_disabled { background: url('../img/tablesort-header.png') no-repeat; } + +/* the footers are not active */ +div.Hazelnut table.dataTable tfoot { background: url('../img/tablesort-header.png') no-repeat; } +/* and when sorting is turned off it's useful to set this on header too */ +div.Hazelnut table.dataTable thead { background: url('../img/tablesort-header.png') no-repeat; } diff --git a/plugins/hazelnut/hazelnut.js b/plugins/hazelnut/hazelnut.js index a5a9ad8e..99e9b96f 100644 --- a/plugins/hazelnut/hazelnut.js +++ b/plugins/hazelnut/hazelnut.js @@ -115,28 +115,23 @@ var object = this; /* Transforms the table into DataTable, and keep a pointer to it */ - this.table = $('#hazelnut-' + options.plugin_uuid).dataTable({ + actual_options = { // Customize the position of Datatables elements (length,filter,button,...) - // inspired from : // http://datatables.net/release-datatables/examples/advanced_init/dom_toolbar.html // http://www.datatables.net/forums/discussion/3914/adding-buttons-to-header-or-footer/p1 - //"sDom": 'lf<"#datatableSelectAll-'+ options.plugin_uuid+'">rtip', sDom: "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>", sPaginationType: 'bootstrap', // Handle the null values & the error : Datatables warning Requested unknown parameter // http://datatables.net/forums/discussion/5331/datatables-warning-...-requested-unknown-parameter/p2 aoColumnDefs: [{sDefaultContent: '',aTargets: [ '_all' ]}], -// bRetrieve: true, // WARNING: this one causes tables in a 'tabs' that are not exposed at the time this is run to show up empty // sScrollX: '100%', /* Horizontal scrolling */ bProcessing: true, /* Loading */ -// this looks like just another ugly hack -// fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { -// $(nRow).attr('id', unfold.get_value(aData[3])); -// return nRow; -// }, fnDrawCallback: function() { hazelnut_draw_callback.call(object, options); } - }); + }; + // the intention here is that options.datatables_options as coming from the python object take precedence + $.extend(actual_options, options.datatables_options ); + this.table = $('#hazelnut-' + options.plugin_uuid).dataTable(actual_options); /* Setup the SelectAll button in the dataTable header */ var oSelectAll = $('#datatableSelectAll-'+ options.plugin_uuid); diff --git a/plugins/hazelnut/hazelnut.py b/plugins/hazelnut/hazelnut.py index b69bcc93..e2b3a7c4 100644 --- a/plugins/hazelnut/hazelnut.py +++ b/plugins/hazelnut/hazelnut.py @@ -5,7 +5,7 @@ class Hazelnut (Plugin): # set checkboxes if a final column with checkboxes is desired # pass columns as the initial set of columns # if None then this is taken from the query's fields - def __init__ (self, query, checkboxes=False, columns=None, **settings): + def __init__ (self, query, checkboxes=False, columns=None, datatables_options={}, **settings): Plugin.__init__ (self, **settings) self.query=query self.checkboxes=checkboxes @@ -13,6 +13,7 @@ class Hazelnut (Plugin): self.columns=columns else: self.columns=self.query.fields + self.datatables_options=datatables_options def template_file (self): return "hazelnut.html" @@ -38,4 +39,4 @@ class Hazelnut (Plugin): return reqs # the list of things passed to the js plugin - def json_settings_list (self): return ['plugin_uuid','query_uuid','checkboxes'] + def json_settings_list (self): return ['plugin_uuid','query_uuid','checkboxes','datatables_options'] diff --git a/trash/sliceview.py b/trash/sliceview.py index d1c93dd0..2811bb6b 100644 --- a/trash/sliceview.py +++ b/trash/sliceview.py @@ -62,6 +62,9 @@ def slice_view (request, slicename=tmp_default_slice): checkboxes=True, # this is the query at the core of the slice list query=main_query, + # this of course should be automatic in hazelnut + # for now we turn off sorting on the checkboxes columns this way + datatables_options = { 'aoColumns' : [ None, None, None, None, {'bSortable': False} ] }, ), ]), Hazelnut (