--- /dev/null
+from unfold.composite import Composite
+
+class Tabs (Composite):
+
+ def requirements (self):
+ return { 'js_files' : ['js/tabs.js', 'js/bootstrap.js'],
+ 'css_files' : ['css/bootstrap.css', 'css/tabs.css', ]
+ }
+
+ def template_file (self):
+ return "tabs.html"
+
+ # see Composite.py for the details of template_env, that exposes global
+ # 'sons' as a list of sons with each a set of a few attributes
+ def json_settings_list (self):
+ return []
+
+ def export_json_settings(self):
+ return True
--- /dev/null
+div.Tabs {
+/* border-style: solid;
+ border-color: #aaa; */
+ padding: 10px;
+}
--- /dev/null
+(function($){
+
+ $.fn.Tabs = function( method ) {
+
+ $('a[data-toggle="tab"]').on('shown', function (e) {
+ // find the plugin object inside the tab content referenced by the current tabs
+ $('.plugin', $($(e.target).attr('href'))).trigger('show');
+ });
+
+ };
+
+})( jQuery );
--- /dev/null
+<ul class="nav nav-tabs" id='tabs-{{ domid }}'>
+{% for son in sons %}
+<li{% if son.is_active %} class='active'{% endif %}> <a href="#tab-{{ son.domid }}" data-toggle="tab">{{ son.title }}</a> </li>
+{% endfor %}
+</ul><!--nav-tabs-->
+<div class="tab-content">
+{% for son in sons %}
+<div class="tab-pane fade in{% if son.is_active %} active{% endif %}" id="tab-{{ son.domid }}">
+{{ son.rendered }}
+</div><!--tab-pane-->
+{% endfor %}
+</div><!--tab-content-->
--- /dev/null
+from unfold.plugin import Plugin
+
+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=None, query_all=None, checkboxes=False, columns=None, datatables_options={}, **settings):
+ Plugin.__init__ (self, **settings)
+ self.query = query
+ # Until we have a proper way to access queries in Python
+ self.query_all = query_all
+ self.query_all_uuid = query_all.query_uuid if query_all else None
+ self.checkboxes=checkboxes
+ # XXX We need to have some hidden columns until we properly handle dynamic queries
+ if columns is not None:
+ self.columns=columns
+ self.hidden_columns = []
+ elif self.query:
+ self.columns = self.query.fields
+ if query_all:
+ # We need a list because sets are not JSON-serilizable
+ self.hidden_columns = list(self.query_all.fields - self.query.fields)
+ else:
+ self.hidden_columns = []
+ else:
+ self.columns = []
+ self.hidden_columns = []
+ self.datatables_options=datatables_options
+
+ def template_file (self):
+ return "hazelnut.html"
+
+ def template_env (self, request):
+ env={}
+ env.update(self.__dict__)
+ env['columns']=self.columns
+ return env
+
+ def requirements (self):
+ reqs = {
+ 'js_files' : [ "js/hazelnut.js",
+ "js/manifold.js", "js/manifold-query.js",
+ #"js/dataTables.js", "js/with-datatables.js",
+ "js/dataTables.js", "js/dataTables.bootstrap.js", "js/with-datatables.js",
+ "js/datatables-bs3.js",
+ "js/spin.presets.js", "js/spin.min.js", "js/jquery.spin.js",
+ "js/unfold-helper.js",
+ ] ,
+ 'css_files': [ "css/hazelnut.css" ,
+ "css/dataTables.bootstrap.css",
+ ],
+ }
+ return reqs
+
+ # the list of things passed to the js plugin
+ def json_settings_list (self):
+ return ['plugin_uuid', 'domid', 'query_uuid', 'query_all_uuid', 'checkboxes', 'datatables_options', 'hidden_columns']
--- /dev/null
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * General page setup
+ */
+#dt_example {
+ font: 80%/1.45em "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
+ margin: 0;
+ padding: 0;
+ color: #333;
+ background-color: #fff;
+}
+
+
+#dt_example #container {
+ width: 800px;
+ margin: 30px auto;
+ padding: 0;
+}
+
+
+#dt_example #footer {
+ margin: 50px auto 0 auto;
+ padding: 0;
+}
+
+#dt_example #demo {
+ margin: 30px auto 0 auto;
+}
+
+#dt_example .demo_jui {
+ margin: 30px auto 0 auto;
+}
+
+#dt_example .big {
+ font-size: 1.3em;
+ font-weight: bold;
+ line-height: 1.6em;
+ color: #4E6CA3;
+}
+
+#dt_example .spacer {
+ height: 20px;
+ clear: both;
+}
+
+#dt_example .clear {
+ clear: both;
+}
+
+#dt_example pre {
+ padding: 15px;
+ background-color: #F5F5F5;
+ border: 1px solid #CCCCCC;
+}
+
+#dt_example h1 {
+ margin-top: 2em;
+ font-size: 1.3em;
+ font-weight: normal;
+ line-height: 1.6em;
+ color: #4E6CA3;
+ border-bottom: 1px solid #B0BED9;
+ clear: both;
+}
+
+#dt_example h2 {
+ font-size: 1.2em;
+ font-weight: normal;
+ line-height: 1.6em;
+ color: #4E6CA3;
+ clear: both;
+}
+
+#dt_example a {
+ color: #0063DC;
+ text-decoration: none;
+}
+
+#dt_example a:hover {
+ text-decoration: underline;
+}
+
+#dt_example ul {
+ color: #4E6CA3;
+}
+
+.css_right {
+ float: right;
+}
+
+.css_left {
+ float: left;
+}
\ No newline at end of file
--- /dev/null
+.table {
+ width: 100% !important;
+}
+
+div.hazelnut-spacer {
+ height:10px;
+ clear: both;
+}
+
+div.Hazelnut table.dataTable th {
+ font: bold 12px/22px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+ color: #4f6b72;
+ border-right: 1px solid #C1DAD7;
+ border-bottom: 1px solid #C1DAD7;
+ border-top: 1px solid #C1DAD7;
+ letter-spacing: 1px;
+ text-transform: uppercase;
+ text-align: left;
+ padding: 8px 12px 4px 20px;
+ vertical-align:middle;
+/* 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"] {
+ font: normal 12px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+ border-right: 1px solid #C1DAD7;
+ border-bottom: 1px solid #C1DAD7;
+}
+div.Hazelnut table.dataTable td {
+ padding: 4px 8px 4px 8px;
+ /* this applies on even rows only, odd ones have a setting in bootstrap of rbg 249.249.249 */
+ background-color: #f4f4f4;
+}
+div.Hazelnut table.dataTable td a {
+ font-weight:normal;
+}
+/* these come from bootstrap */
+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
+ * and/or to add background-color: #caebea
+ * which would look less conspicuous in case of overflow
+*/
+
+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; }
+/* 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;
+ background-color: #caebea;
+}
+/* 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;
+ background-color: #caebea;
+}
--- /dev/null
+<div id='main-{{ domid }}'>
+ <table class='table table-striped table-bordered dataTable' id='{{domid}}__table'>
+ <thead>
+ <tr>
+ {% for column in columns %}
+ <th>{{ column }}</th>
+ {% endfor %}
+ {% for column in hidden_columns %}
+ <th>{{ column }}</th>
+ {% endfor %}
+ {% if checkboxes %}
+ <th>+/-</th>
+ {% endif %}
+ </tr>
+ </thead>
+ <tbody>
+ </tbody>
+ <tfoot>
+ <tr>
+ {% for column in columns %}
+ <th>{{ column }}</th>
+ {% endfor %}
+ {% for column in hidden_columns %}
+ <th>{{ column }}</th>
+ {% endfor %}
+ {% if checkboxes %}
+ <th>+/-</th>
+ {% endif %}
+ </tr>
+ </tfoot>
+ </table>
+</div>
+<div class="hazelnut-spacer"></div>
--- /dev/null
+these styling elements come from plekit with a simple transition to png
+they're currently not all used in myslice
--- /dev/null
+/**
+ * Description: display a query result in a datatables-powered <table>
+ * Copyright (c) 2012-2013 UPMC Sorbonne Universite - INRIA
+ * License: GPLv3
+ */
+
+(function($){
+
+ // TEMP
+ var debug=false;
+ debug=true
+
+ var Hazelnut = Plugin.extend({
+
+ init: function(options, element)
+ {
+ this._super(options, element);
+
+ /* Member variables */
+ // query status
+ this.received_all = false;
+ this.received_set = false;
+ this.in_set_buffer = Array();
+
+ /* XXX Events XXX */
+ // this.$element.on('show.Datatables', this.on_show);
+ this.elmt().on('show', this, this.on_show);
+ // Unbind all events using namespacing
+ // TODO in destructor
+ // $(window).unbind('Hazelnut');
+
+ var query = manifold.query_store.find_analyzed_query(this.options.query_uuid);
+ this.method = query.object;
+
+ var keys = manifold.metadata.get_key(this.method);
+ this.key = (keys && keys.length == 1) ? keys[0] : null;
+
+ /* Setup query and record handlers */
+ this.listen_query(options.query_uuid);
+ this.listen_query(options.query_all_uuid, 'all');
+
+ /* GUI setup and event binding */
+ this.initialize_table();
+ },
+
+ default_options: {
+ 'checkboxes': false
+ },
+
+ /* PLUGIN EVENTS */
+
+ on_show: function(e)
+ {
+ var self = e.data;
+
+ self.table.fnAdjustColumnSizing()
+
+ /* Refresh dataTabeles if click on the menu to display it : fix dataTables 1.9.x Bug */
+ /* temp disabled... useful ? -- jordan
+ $(this).each(function(i,elt) {
+ if (jQuery(elt).hasClass('dataTables')) {
+ var myDiv=jQuery('#hazelnut-' + this.id).parent();
+ if(myDiv.height()==0) {
+ var oTable=$('#hazelnut-' + this.id).dataTable();
+ oTable.fnDraw();
+ }
+ }
+ });
+ */
+ }, // on_show
+
+ /* GUI EVENTS */
+
+ /* GUI MANIPULATION */
+
+ initialize_table: function()
+ {
+ /* Transforms the table into DataTable, and keep a pointer to it */
+ var self = this;
+ actual_options = {
+ // Customize the position of Datatables elements (length,filter,button,...)
+ // we use a fluid row on top and another on the bottom, making sure we take 12 grid elt's each time
+ sDom: "<'row-fluid'<'span5'l><'span1'r><'span6'f>>t<'row-fluid'<'span5'i><'span7'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' ]}],
+ // 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 */
+ fnDrawCallback: function() { self._hazelnut_draw_callback.call(self); }
+ // XXX use $.proxy here !
+ };
+ // the intention here is that options.datatables_options as coming from the python object take precedence
+ // XXX DISABLED by jordan: was causing errors in datatables.js $.extend(actual_options, options.datatables_options );
+ this.table = this.elmt('table').dataTable(actual_options);
+
+ /* Setup the SelectAll button in the dataTable header */
+ /* xxx not sure this is still working */
+ var oSelectAll = $('#datatableSelectAll-'+ this.options.plugin_uuid);
+ oSelectAll.html("<span class='ui-icon ui-icon-check' style='float:right;display:inline-block;'></span>Select All");
+ oSelectAll.button();
+ oSelectAll.css('font-size','11px');
+ oSelectAll.css('float','right');
+ oSelectAll.css('margin-right','15px');
+ oSelectAll.css('margin-bottom','5px');
+ oSelectAll.unbind('click');
+ oSelectAll.click(this._selectAll);
+
+ /* Add a filtering function to the current table
+ * Note: we use closure to get access to the 'options'
+ */
+ $.fn.dataTableExt.afnFiltering.push(function( oSettings, aData, iDataIndex ) {
+ /* No filtering if the table does not match */
+ if (oSettings.nTable.id != "hazelnut-" + self.options.plugin_uuid)
+ return true;
+ return this._hazelnut_filter.call(self, oSettings, aData, iDataIndex);
+ });
+
+ /* Processing hidden_columns */
+ $.each(this.options.hidden_columns, function(i, field) {
+ self.hide_column(field);
+ });
+ }, // initialize_table
+
+ /**
+ * @brief Determine index of key in the table columns
+ * @param key
+ * @param cols
+ */
+ getColIndex: function(key, cols) {
+ var tabIndex = $.map(cols, function(x, i) { if (x.sTitle == key) return i; });
+ return (tabIndex.length > 0) ? tabIndex[0] : -1;
+ }, // getColIndex
+
+ // UNUSED ? // this.update_plugin = function(e, rows) {
+ // UNUSED ? // // e.data is what we passed in second argument to subscribe
+ // UNUSED ? // // so here it is the jquery object attached to the plugin <div>
+ // UNUSED ? // var $plugindiv=e.data;
+ // UNUSED ? // if (debug)
+ // UNUSED ? // messages.debug("entering hazelnut.update_plugin on id '" + $plugindiv.attr('id') + "'");
+ // UNUSED ? // // clear the spinning wheel: look up an ancestor that has the need-spin class
+ // UNUSED ? // // do this before we might return
+ // UNUSED ? // $plugindiv.closest('.need-spin').spin(false);
+ // UNUSED ? //
+ // UNUSED ? // var options = this.options;
+ // UNUSED ? // var hazelnut = this;
+ // UNUSED ? //
+ // UNUSED ? // /* if we get no result, or an error, try to make that clear, and exit */
+ // UNUSED ? // if (rows.length==0) {
+ // UNUSED ? // if (debug)
+ // UNUSED ? // messages.debug("Empty result on hazelnut " + this.options.domid);
+ // UNUSED ? // var placeholder=$(this.table).find("td.dataTables_empty");
+ // UNUSED ? // console.log("placeholder "+placeholder);
+ // UNUSED ? // if (placeholder.length==1)
+ // UNUSED ? // placeholder.html(unfold.warning("Empty result"));
+ // UNUSED ? // else
+ // UNUSED ? // this.table.html(unfold.warning("Empty result"));
+ // UNUSED ? // return;
+ // UNUSED ? // } else if (typeof(rows[0].error) != 'undefined') {
+ // UNUSED ? // // we now should have another means to report errors that this inline/embedded hack
+ // UNUSED ? // if (debug)
+ // UNUSED ? // messages.error ("undefined result on " + this.options.domid + " - should not happen anymore");
+ // UNUSED ? // this.table.html(unfold.error(rows[0].error));
+ // UNUSED ? // return;
+ // UNUSED ? // }
+ // UNUSED ? //
+ // UNUSED ? // /*
+ // UNUSED ? // * fill the dataTables object
+ // UNUSED ? // * we cannot set html content directly here, need to use fnAddData
+ // UNUSED ? // */
+ // UNUSED ? // var lines = new Array();
+ // UNUSED ? //
+ // UNUSED ? // this.current_resources = Array();
+ // UNUSED ? //
+ // UNUSED ? // $.each(rows, function(index, row) {
+ // UNUSED ? // // this models a line in dataTables, each element in the line describes a cell
+ // UNUSED ? // line = new Array();
+ // UNUSED ? //
+ // UNUSED ? // // go through table headers to get column names we want
+ // UNUSED ? // // in order (we have temporarily hack some adjustments in names)
+ // UNUSED ? // var cols = object.table.fnSettings().aoColumns;
+ // UNUSED ? // var colnames = cols.map(function(x) {return x.sTitle})
+ // UNUSED ? // var nb_col = cols.length;
+ // UNUSED ? // /* if we've requested checkboxes, then forget about the checkbox column for now */
+ // UNUSED ? // if (options.checkboxes) nb_col -= 1;
+ // UNUSED ? //
+ // UNUSED ? // /* fill in stuff depending on the column name */
+ // UNUSED ? // for (var j = 0; j < nb_col; j++) {
+ // UNUSED ? // if (typeof colnames[j] == 'undefined') {
+ // UNUSED ? // line.push('...');
+ // UNUSED ? // } else if (colnames[j] == 'hostname') {
+ // UNUSED ? // if (row['type'] == 'resource,link')
+ // UNUSED ? // //TODO: we need to add source/destination for links
+ // UNUSED ? // line.push('');
+ // UNUSED ? // else
+ // UNUSED ? // line.push(row['hostname']);
+ // UNUSED ? // } else {
+ // UNUSED ? // if (row[colnames[j]])
+ // UNUSED ? // line.push(row[colnames[j]]);
+ // UNUSED ? // else
+ // UNUSED ? // line.push('');
+ // UNUSED ? // }
+ // UNUSED ? // }
+ // UNUSED ? //
+ // UNUSED ? // /* catch up with the last column if checkboxes were requested */
+ // UNUSED ? // if (options.checkboxes) {
+ // UNUSED ? // var checked = '';
+ // UNUSED ? // // xxx problem is, we don't get this 'sliver' thing set apparently
+ // UNUSED ? // if (typeof(row['sliver']) != 'undefined') { /* It is equal to null when <sliver/> is present */
+ // UNUSED ? // checked = 'checked ';
+ // UNUSED ? // hazelnut.current_resources.push(row[ELEMENT_KEY]);
+ // UNUSED ? // }
+ // UNUSED ? // // Use a key instead of hostname (hard coded...)
+ // UNUSED ? // line.push(hazelnut.checkbox(options.plugin_uuid, row[ELEMENT_KEY], row['type'], checked, false));
+ // UNUSED ? // }
+ // UNUSED ? //
+ // UNUSED ? // lines.push(line);
+ // UNUSED ? //
+ // UNUSED ? // });
+ // UNUSED ? //
+ // UNUSED ? // this.table.fnClearTable();
+ // UNUSED ? // if (debug)
+ // UNUSED ? // messages.debug("hazelnut.update_plugin: total of " + lines.length + " rows");
+ // UNUSED ? // this.table.fnAddData(lines);
+ // UNUSED ? //
+ // UNUSED ? // }, // update_plugin
+
+ checkbox: function (key, value)
+ {
+ var result="";
+ // Prefix id with plugin_uuid
+ result += "<input";
+ result += " class='hazelnut-checkbox'";
+ result += " id='" + this.id('checkbox', this.id_from_key(key, value)) + "'";
+ result += " name='" + key + "'";
+ result += " type='checkbox'";
+ result += " autocomplete='off'";
+ result += " value='" + value + "'";
+ result += "></input>";
+ return result;
+ }, // checkbox
+
+
+ new_record: function(record)
+ {
+ // this models a line in dataTables, each element in the line describes a cell
+ line = new Array();
+
+ // go through table headers to get column names we want
+ // in order (we have temporarily hack some adjustments in names)
+ var cols = this.table.fnSettings().aoColumns;
+ var colnames = cols.map(function(x) {return x.sTitle})
+ var nb_col = cols.length;
+ /* if we've requested checkboxes, then forget about the checkbox column for now */
+ if (this.options.checkboxes) nb_col -= 1;
+
+ /* fill in stuff depending on the column name */
+ for (var j = 0; j < nb_col; j++) {
+ if (typeof colnames[j] == 'undefined') {
+ line.push('...');
+ } else if (colnames[j] == 'hostname') {
+ if (record['type'] == 'resource,link')
+ //TODO: we need to add source/destination for links
+ line.push('');
+ else
+ line.push(record['hostname']);
+ } else {
+ if (record[colnames[j]])
+ line.push(record[colnames[j]]);
+ else
+ line.push('');
+ }
+ }
+
+ /* catch up with the last column if checkboxes were requested */
+ if (this.options.checkboxes)
+ // Use a key instead of hostname (hard coded...)
+ // XXX remove the empty checked attribute
+ line.push(this.checkbox(this.key, record[this.key]));
+
+ // XXX Is adding an array of lines more efficient ?
+ this.table.fnAddData(line);
+
+ },
+
+ clear_table: function()
+ {
+ this.table.fnClearTable();
+ },
+
+ redraw_table: function()
+ {
+ this.table.fnDraw();
+ },
+
+ show_column: function(field)
+ {
+ var oSettings = this.table.fnSettings();
+ var cols = oSettings.aoColumns;
+ var index = this.getColIndex(field,cols);
+ if (index != -1)
+ this.table.fnSetColumnVis(index, true);
+ },
+
+ hide_column: function(field)
+ {
+ var oSettings = this.table.fnSettings();
+ var cols = oSettings.aoColumns;
+ var index = this.getColIndex(field,cols);
+ if (index != -1)
+ this.table.fnSetColumnVis(index, false);
+ },
+
+ set_checkbox: function(record, checked)
+ {
+ /* Default: checked = true */
+ if (typeof checked === 'undefined')
+ checked = true;
+
+ var key_value;
+ /* The function accepts both records and their key */
+ switch (manifold.get_type(record)) {
+ case TYPE_VALUE:
+ key_value = record;
+ break;
+ case TYPE_RECORD:
+ /* XXX Test the key before ? */
+ key_value = record[this.key];
+ break;
+ default:
+ throw "Not implemented";
+ break;
+ }
+
+
+ var checkbox_id = this.id('checkbox', this.id_from_key(this.key, key_value));
+ checkbox_id = '#' + checkbox_id.replace(/\./g, '\\.');
+
+ var element = $(checkbox_id, this.table.fnGetNodes());
+
+ element.attr('checked', checked);
+ },
+
+ /*************************** QUERY HANDLER ****************************/
+
+ on_filter_added: function(filter)
+ {
+ // XXX
+ this.redraw_table();
+ },
+
+ on_filter_removed: function(filter)
+ {
+ // XXX
+ this.redraw_table();
+ },
+
+ on_filter_clear: function()
+ {
+ // XXX
+ this.redraw_table();
+ },
+
+ on_field_added: function(field)
+ {
+ this.show_column(field);
+ },
+
+ on_field_removed: function(field)
+ {
+ this.hide_column(field);
+ },
+
+ on_field_clear: function()
+ {
+ alert('Hazelnut::clear_fields() not implemented');
+ },
+
+ /*************************** RECORD HANDLER ***************************/
+
+ on_new_record: function(record)
+ {
+ /* NOTE in fact we are doing a join here */
+ if (this.received_all)
+ // update checkbox for record
+ this.set_checkbox(record, true);
+ else
+ // store for later update of checkboxes
+ this.in_set_buffer.push(record);
+ },
+
+ on_clear_records: function()
+ {
+ },
+
+ // Could be the default in parent
+ on_query_in_progress: function()
+ {
+ this.spin();
+ },
+
+ on_query_done: function()
+ {
+ if (this.received_all)
+ this.unspin();
+ this.received_set = true;
+ },
+
+ on_field_state_changed: function(data)
+ {
+ switch(data.request) {
+ case FIELD_REQUEST_ADD:
+ case FIELD_REQUEST_ADD_RESET:
+ this.set_checkbox(data.value, true);
+ break;
+ case FIELD_REQUEST_REMOVE:
+ case FIELD_REQUEST_REMOVE_RESET:
+ this.set_checkbox(data.value, false);
+ break;
+ default:
+ break;
+ }
+ },
+
+ // all
+
+ on_all_new_record: function(record)
+ {
+ this.new_record(record);
+ },
+
+ on_all_clear_records: function()
+ {
+ this.clear_table();
+
+ },
+
+ on_all_query_in_progress: function()
+ {
+ // XXX parent
+ this.spin();
+ }, // on_all_query_in_progress
+
+ on_all_query_done: function()
+ {
+ var self = this;
+ if (this.received_set) {
+ /* XXX needed ? XXX We uncheck all checkboxes ... */
+ $("[id^='datatables-checkbox-" + this.options.plugin_uuid +"']").attr('checked', false);
+
+ /* ... and check the ones specified in the resource list */
+ $.each(this.in_set_buffer, function(i, record) {
+ self.set_checkbox(record, true);
+ });
+
+ this.unspin();
+ }
+ this.received_all = true;
+
+ }, // on_all_query_done
+
+ /************************** PRIVATE METHODS ***************************/
+
+ /**
+ * @brief Hazelnut filtering function
+ */
+ _hazelnut_filter: function(oSettings, aData, iDataIndex)
+ {
+ var cur_query = this.current_query;
+ if (!cur_query) return true;
+ var ret = true;
+
+ /* We have an array of filters : a filter is an array (key op val)
+ * field names (unless shortcut) : oSettings.aoColumns = [ sTitle ]
+ * can we exploit the data property somewhere ?
+ * field values (unless formatting) : aData
+ * formatting should leave original data available in a hidden field
+ *
+ * The current line should validate all filters
+ */
+ $.each (cur_query.filters, function(index, filter) {
+ /* XXX How to manage checkbox ? */
+ var key = filter[0];
+ var op = filter[1];
+ var value = filter[2];
+
+ /* Determine index of key in the table columns */
+ var col = $.map(oSettings.aoColumns, function(x, i) {if (x.sTitle == key) return i;})[0];
+
+ /* Unknown key: no filtering */
+ if (typeof(col) == 'undefined')
+ return;
+
+ col_value=unfold.get_value(aData[col]);
+ /* Test whether current filter is compatible with the column */
+ if (op == '=' || op == '==') {
+ if ( col_value != value || col_value==null || col_value=="" || col_value=="n/a")
+ ret = false;
+ }else if (op == '!=') {
+ if ( col_value == value || col_value==null || col_value=="" || col_value=="n/a")
+ ret = false;
+ } else if(op=='<') {
+ if ( parseFloat(col_value) >= value || col_value==null || col_value=="" || col_value=="n/a")
+ ret = false;
+ } else if(op=='>') {
+ if ( parseFloat(col_value) <= value || col_value==null || col_value=="" || col_value=="n/a")
+ ret = false;
+ } else if(op=='<=' || op=='≤') {
+ if ( parseFloat(col_value) > value || col_value==null || col_value=="" || col_value=="n/a")
+ ret = false;
+ } else if(op=='>=' || op=='≥') {
+ if ( parseFloat(col_value) < value || col_value==null || col_value=="" || col_value=="n/a")
+ ret = false;
+ }else{
+ // How to break out of a loop ?
+ alert("filter not supported");
+ return false;
+ }
+
+ });
+ return ret;
+ },
+
+ _hazelnut_draw_callback: function()
+ {
+ /*
+ * Handle clicks on checkboxes: reassociate checkbox click every time
+ * the table is redrawn
+ */
+ this.elts('hazelnut-checkbox').unbind('click').click(this, this._check_click);
+
+ if (!this.table)
+ return;
+
+ /* Remove pagination if we show only a few results */
+ var wrapper = this.table; //.parent().parent().parent();
+ var rowsPerPage = this.table.fnSettings()._iDisplayLength;
+ var rowsToShow = this.table.fnSettings().fnRecordsDisplay();
+ var minRowsPerPage = this.table.fnSettings().aLengthMenu[0];
+
+ if ( rowsToShow <= rowsPerPage || rowsPerPage == -1 ) {
+ $('.hazelnut_paginate', wrapper).css('visibility', 'hidden');
+ } else {
+ $('.hazelnut_paginate', wrapper).css('visibility', 'visible');
+ }
+
+ if ( rowsToShow <= minRowsPerPage ) {
+ $('.hazelnut_length', wrapper).css('visibility', 'hidden');
+ } else {
+ $('.hazelnut_length', wrapper).css('visibility', 'visible');
+ }
+ },
+
+ _check_click: function(e)
+ {
+ e.stopPropagation();
+
+ var self = e.data;
+
+ // XXX this.value = key of object to be added... what about multiple keys ?
+ manifold.raise_event(self.options.query_uuid, this.checked?SET_ADD:SET_REMOVED, this.value);
+ //return false; // prevent checkbox to be checked, waiting response from manifold plugin api
+
+ },
+
+ _selectAll: function()
+ {
+ // requires jQuery id
+ var uuid=this.id.split("-");
+ var oTable=$("#hazelnut-"+uuid[1]).dataTable();
+ // Function available in Hazelnut 1.9.x
+ // Filter : displayed data only
+ var filterData = oTable._('tr', {"filter":"applied"});
+ /* TODO: WARNING if too many nodes selected, use filters to reduce nuber of nodes */
+ if(filterData.length<=100){
+ $.each(filterData, function(index, obj) {
+ var last=$(obj).last();
+ var key_value=unfold.get_value(last[0]);
+ if(typeof($(last[0]).attr('checked'))=="undefined"){
+ $.publish('selected', 'add/'+key_value);
+ }
+ });
+ }
+ },
+
+ });
+
+ $.plugin('Hazelnut', Hazelnut);
+
+})(jQuery);
--- /dev/null
+<ul class="nav nav-tabs" id='tabs-{{ domid }}'>
+{% for son in sons %}
+<li{% if son.is_active %} class='active'{% endif %}> <a href="#tab-{{ son.domid }}" data-toggle="tab">{{ son.title }}</a> </li>
+{% endfor %}
+</ul><!--nav-tabs-->
+<div class="tab-content">
+{% for son in sons %}
+<div class="tab-pane fade in{% if son.is_active %} active{% endif %}" id="tab-{{ son.domid }}">
+{{ son.rendered }}
+</div><!--tab-pane-->
+{% endfor %}
+</div><!--tab-content-->
--- /dev/null
+from unfold.composite import Composite
+
+class Tabs (Composite):
+
+ def requirements (self):
+ return { 'js_files' : ['js/tabs.js', 'js/bootstrap.js'],
+ 'css_files' : ['css/bootstrap.css', 'css/tabs.css', ]
+ }
+
+ def template_file (self):
+ return "tabs.html"
+
+ # see Composite.py for the details of template_env, that exposes global
+ # 'sons' as a list of sons with each a set of a few attributes
+ def json_settings_list (self):
+ return []
+
+ def export_json_settings(self):
+ return True
--- /dev/null
+# Create your views here.
+
+from django.template import RequestContext
+from django.shortcuts import render_to_response
+#from django.contrib.auth.decorators import login_required
+#from django.http import HttpResponseRedirect
+
+from unfold.loginrequired import LoginRequiredAutoLogoutView
+
+from unfold.page import Page
+from manifold.core.query import Query, AnalyzedQuery
+from manifold.manifoldresult import ManifoldException
+from manifold.metadata import MetaData as Metadata
+#from myslice.viewutils import quickfilter_criterias, topmenu_items, the_user
+from myslice.viewutils import topmenu_items, the_user
+
+from plugins.raw.raw import Raw
+from plugins.stack.stack import Stack
+from plugins.tabs.tabs import Tabs
+from plugins.lists.slicelist import SliceList
+from plugins.hazelnut import Hazelnut
+from plugins.resources_selected import ResourcesSelected
+from plugins.googlemap import GoogleMap
+from plugins.senslabmap.senslabmap import SensLabMap
+from plugins.querycode.querycode import QueryCode
+from plugins.query_editor import QueryEditor
+from plugins.active_filters import ActiveFilters
+from plugins.quickfilter.quickfilter import QuickFilter
+from plugins.messages.messages import Messages
+#from plugins.updater import Updater
+
+tmp_default_slice='ple.upmc.myslicedemo'
+debug = True
+
+class SliceView (LoginRequiredAutoLogoutView):
+
+ def get (self,request, slicename=tmp_default_slice):
+ page = Page(request)
+ page.add_css_files ('css/slice-view.css')
+ page.expose_js_metadata()
+
+ metadata = page.get_metadata()
+ resource_md = metadata.details_by_object('resource')
+ resource_fields = [column['name'] for column in resource_md['column']]
+
+ user_md = metadata.details_by_object('user')
+ user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
+
+ # TODO The query to run is embedded in the URL
+ main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
+ main_query.select(
+ 'slice_hrn',
+ 'resource.hrn', 'resource.hostname', 'resource.type', 'resource.network_hrn',
+ #'lease.urn',
+ 'user.user_hrn',
+ #'application.measurement_point.counter'
+ )
+
+ query_resource_all = Query.get('resource').select(resource_fields)
+ query_user_all = Query.get('user').select(user_fields)
+
+ # Temporarily filter users which is slow
+ query_user_all = query_user_all.filter_by('authority_hrn', '==', 'ple.upmc')
+
+ aq = AnalyzedQuery(main_query, metadata=metadata)
+ page.enqueue_query(main_query, analyzed_query=aq)
+ page.enqueue_query(query_resource_all)
+ page.enqueue_query(query_user_all)
+
+ # Prepare the display according to all metadata
+ # (some parts will be pending, others can be triggered by users).
+ #
+ # For example slice measurements will not be requested by default...
+
+ # Create the base layout (Stack)...
+ main_stack = Stack (
+ page=page,
+ title="Slice %s"%slicename,
+ sons=[],
+ )
+
+ # ... responsible for the slice properties...
+
+
+ main_stack.insert (
+ Raw (page=page,togglable=False, toggled=True,html="<h2> Slice page for %s</h2>"%slicename)
+ )
+
+ main_stack.insert(
+ Raw (page=page,togglable=False, toggled=True,html='<b>Description:</b> TODO')
+ )
+
+ sq_plugin = Tabs (
+ page=page,
+ title="Slice view for %s"%slicename,
+ togglable=False,
+ sons=[],
+ )
+
+
+ # ... and for the relations
+ # XXX Let's hardcode resources for now
+ sq_resource = aq.subquery('resource')
+ sq_user = aq.subquery('user')
+ sq_lease = aq.subquery('lease')
+ sq_measurement = aq.subquery('measurement')
+
+
+ ############################################################################
+ # RESOURCES
+ #
+ # A stack inserted in the subquery tab that will hold all operations
+ # related to resources
+ #
+
+ stack_resources = Stack(
+ page = page,
+ title = 'Resources',
+ sons=[],
+ )
+
+ resource_query_editor = QueryEditor(
+ page = page,
+ query = sq_resource,
+ )
+ stack_resources.insert(resource_query_editor)
+
+ resource_active_filters = ActiveFilters(
+ page = page,
+ query = sq_resource,
+ )
+ stack_resources.insert(resource_active_filters)
+
+ # --------------------------------------------------------------------------
+ # Different displays = DataTables + GoogleMaps
+ #
+ tab_resource_plugins = Tabs(
+ page = page,
+ sons = []
+ )
+
+ tab_resource_plugins.insert(Hazelnut(
+ page = page,
+ title = 'List',
+ domid = 'checkboxes',
+ # this is the query at the core of the slice list
+ query = sq_resource,
+ query_all = query_resource_all,
+ checkboxes = True,
+ datatables_options = {
+ # for now we turn off sorting on the checkboxes columns this way
+ # this of course should be automatic in hazelnut
+ 'aoColumns' : [None, None, None, None, {'bSortable': False}],
+ 'iDisplayLength' : 25,
+ 'bLengthChange' : True,
+ },
+ ))
+
+ tab_resource_plugins.insert(GoogleMap(
+ page = page,
+ title = 'Geographic view',
+ domid = 'gmap',
+ # tab's sons preferably turn this off
+ togglable = False,
+ query = sq_resource,
+ query_all = query_resource_all,
+ checkboxes = True,
+ # center on Paris
+ latitude = 49.,
+ longitude = 2.2,
+ zoom = 3,
+ ))
+
+ stack_resources.insert(tab_resource_plugins)
+
+ sq_plugin.insert(stack_resources)
+
+ ############################################################################
+ # USERS
+ #
+
+ tab_users = Tabs(
+ page = page,
+ title = 'Users',
+ domid = 'thetabs2',
+ # activeid = 'checkboxes',
+ active_domid = 'checkboxes2',
+ )
+ sq_plugin.insert(tab_users)
+
+ tab_users.insert(Hazelnut(
+ page = page,
+ title = 'List',
+ domid = 'checkboxes2',
+ # tab's sons preferably turn this off
+ togglable = False,
+ # this is the query at the core of the slice list
+ query = sq_user,
+ query_all = query_user_all,
+ checkboxes = True,
+ datatables_options = {
+ # for now we turn off sorting on the checkboxes columns this way
+ # this of course should be automatic in hazelnut
+ 'aoColumns' : [None, None, None, None, {'bSortable': False}],
+ 'iDisplayLength' : 25,
+ 'bLengthChange' : True,
+ },
+ ))
+
+ tab_measurements = Tabs (
+ page = page,
+ title = 'Measurements',
+ domid = 'thetabs3',
+ # activeid = 'checkboxes',
+ active_domid = 'checkboxes3',
+ )
+ sq_plugin.insert(tab_measurements)
+
+ tab_measurements.insert(Hazelnut(
+ page = page,
+ title = 'List',
+ domid = 'checkboxes3',
+ # tab's sons preferably turn this off
+ togglable = False,
+ # this is the query at the core of the slice list
+ query = sq_measurement,
+ checkboxes = True,
+ datatables_options = {
+ # for now we turn off sorting on the checkboxes columns this way
+ # this of course should be automatic in hazelnut
+ 'aoColumns' : [None, None, None, None, {'bSortable': False}],
+ 'iDisplayLength' : 25,
+ 'bLengthChange' : True,
+ },
+ ))
+
+ main_stack.insert(sq_plugin)
+
+ # --------------------------------------------------------------------------
+ # ResourcesSelected
+ #
+ main_stack.insert(ResourcesSelected(
+ page = page,
+ title = 'Pending operations',
+ query = main_query,
+ togglable = True,
+ ))
+
+ main_stack.insert(Messages(
+ page = page,
+ title = "Runtime messages for slice %s"%slicename,
+ domid = "msgs-pre",
+ levels = "ALL",
+ ))
+ # main_stack.insert(Updater(
+ # page = page,
+ # title = "wont show up as non togglable by default",
+ # query = main_query,
+ # label = "Update slice",
+ # ))
+
+
+
+ # variables that will get passed to the view-unfold1.html template
+ template_env = {}
+
+ # define 'unfold1_main' to the template engine - the main contents
+ template_env [ 'unfold1_main' ] = main_stack.render(request)
+
+ # more general variables expected in the template
+ template_env [ 'title' ] = 'Test view that combines various plugins'
+ # the menu items on the top
+ template_env [ 'topmenu_items' ] = topmenu_items('Slice', request)
+ # so we can sho who is logged
+ template_env [ 'username' ] = the_user (request)
+
+ # don't forget to run the requests
+ page.expose_queries ()
+
+ # xxx create another plugin with the same query and a different layout (with_datatables)
+ # show that it worls as expected, one single api call to backend and 2 refreshed views
+
+ # the prelude object in page contains a summary of the requirements() for all plugins
+ # define {js,css}_{files,chunks}
+ prelude_env = page.prelude_env()
+ template_env.update(prelude_env)
+ result=render_to_response ('view-unfold1.html',template_env,
+ context_instance=RequestContext(request))
+ return result
--- /dev/null
+/* Set the defaults for DataTables initialisation */
+$.extend( true, $.fn.dataTable.defaults, {
+ "sDom": "<'row'<'col-sm-12'<'pull-right'f><'pull-left'l>r<'clearfix'>>>t<'row'<'col-sm-12'<'pull-left'i><'pull-right'p><'clearfix'>>>",
+ "sPaginationType": "bs_normal",
+ "oLanguage": {
+ "sLengthMenu": "Show _MENU_ Rows",
+ "sSearch": ""
+ }
+} );
+
+/* Default class modification */
+$.extend( $.fn.dataTableExt.oStdClasses, {
+ "sWrapper": "dataTables_wrapper form-inline"
+} );
+
+/* API method to get paging information */
+$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
+{
+ return {
+ "iStart": oSettings._iDisplayStart,
+ "iEnd": oSettings.fnDisplayEnd(),
+ "iLength": oSettings._iDisplayLength,
+ "iTotal": oSettings.fnRecordsTotal(),
+ "iFilteredTotal": oSettings.fnRecordsDisplay(),
+ "iPage": oSettings._iDisplayLength === -1 ?
+ 0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
+ "iTotalPages": oSettings._iDisplayLength === -1 ?
+ 0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
+ };
+};
+
+/* Bootstrap style pagination control */
+$.extend( $.fn.dataTableExt.oPagination, {
+ "bs_normal": {
+ "fnInit": function( oSettings, nPaging, fnDraw ) {
+ var oLang = oSettings.oLanguage.oPaginate;
+ var fnClickHandler = function ( e ) {
+ e.preventDefault();
+ if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
+ fnDraw( oSettings );
+ }
+ };
+ $(nPaging).append(
+ '<ul class="pagination">'+
+ '<li class="prev disabled"><a href="#"><span class="glyphicon glyphicon-chevron-left"></span> '+oLang.sPrevious+'</a></li>'+
+ '<li class="next disabled"><a href="#">'+oLang.sNext+' <span class="glyphicon glyphicon-chevron-right"></span></a></li>'+
+ '</ul>'
+ );
+ var els = $('a', nPaging);
+ $(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
+ $(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
+ },
+ "fnUpdate": function ( oSettings, fnDraw ) {
+ var iListLength = 5;
+ var oPaging = oSettings.oInstance.fnPagingInfo();
+ var an = oSettings.aanFeatures.p;
+ var i, ien, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
+ if ( oPaging.iTotalPages < iListLength) {
+ iStart = 1;
+ iEnd = oPaging.iTotalPages;
+ }
+ else if ( oPaging.iPage <= iHalf ) {
+ iStart = 1;
+ iEnd = iListLength;
+ } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
+ iStart = oPaging.iTotalPages - iListLength + 1;
+ iEnd = oPaging.iTotalPages;
+ } else {
+ iStart = oPaging.iPage - iHalf + 1;
+ iEnd = iStart + iListLength - 1;
+ }
+ for ( i=0, ien=an.length ; i<ien ; i++ ) {
+ $('li:gt(0)', an[i]).filter(':not(:last)').remove();
+ for ( j=iStart ; j<=iEnd ; j++ ) {
+ sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
+ $('<li '+sClass+'><a href="#">'+j+'</a></li>')
+ .insertBefore( $('li:last', an[i])[0] )
+ .bind('click', function (e) {
+ e.preventDefault();
+ oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
+ fnDraw( oSettings );
+ } );
+ }
+ if ( oPaging.iPage === 0 ) {
+ $('li:first', an[i]).addClass('disabled');
+ } else {
+ $('li:first', an[i]).removeClass('disabled');
+ }
+
+ if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
+ $('li:last', an[i]).addClass('disabled');
+ } else {
+ $('li:last', an[i]).removeClass('disabled');
+ }
+ }
+ }
+ },
+ "bs_two_button": {
+ "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
+ {
+ var oLang = oSettings.oLanguage.oPaginate;
+ var oClasses = oSettings.oClasses;
+ var fnClickHandler = function ( e ) {
+ if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
+ {
+ fnCallbackDraw( oSettings );
+ }
+ };
+ var sAppend = '<ul class="pagination">'+
+ '<li class="prev"><a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="glyphicon glyphicon-chevron-left"></span> '+oLang.sPrevious+'</a></li>'+
+ '<li class="next"><a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sNext+' <span class="glyphicon glyphicon-chevron-right"></span></a></li>'+
+ '</ul>';
+ $(nPaging).append( sAppend );
+ var els = $('a', nPaging);
+ var nPrevious = els[0],
+ nNext = els[1];
+ oSettings.oApi._fnBindAction( nPrevious, {action: "previous"}, fnClickHandler );
+ oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
+ if ( !oSettings.aanFeatures.p )
+ {
+ nPaging.id = oSettings.sTableId+'_paginate';
+ nPrevious.id = oSettings.sTableId+'_previous';
+ nNext.id = oSettings.sTableId+'_next';
+ nPrevious.setAttribute('aria-controls', oSettings.sTableId);
+ nNext.setAttribute('aria-controls', oSettings.sTableId);
+ }
+ },
+ "fnUpdate": function ( oSettings, fnCallbackDraw )
+ {
+ if ( !oSettings.aanFeatures.p )
+ {
+ return;
+ }
+ var oPaging = oSettings.oInstance.fnPagingInfo();
+ var oClasses = oSettings.oClasses;
+ var an = oSettings.aanFeatures.p;
+ var nNode;
+ for ( var i=0, iLen=an.length ; i<iLen ; i++ )
+ {
+ if ( oPaging.iPage === 0 ) {
+ $('li:first', an[i]).addClass('disabled');
+ } else {
+ $('li:first', an[i]).removeClass('disabled');
+ }
+
+ if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
+ $('li:last', an[i]).addClass('disabled');
+ } else {
+ $('li:last', an[i]).removeClass('disabled');
+ }
+ }
+ }
+ },
+ "bs_four_button": {
+ "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
+ {
+ var oLang = oSettings.oLanguage.oPaginate;
+ var oClasses = oSettings.oClasses;
+ var fnClickHandler = function ( e ) {
+ if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
+ {
+ fnCallbackDraw( oSettings );
+ }
+ };
+ $(nPaging).append(
+ '<ul class="pagination">'+
+ '<li class="disabled"><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'"><span class="glyphicon glyphicon-backward"></span> '+oLang.sFirst+'</a></li>'+
+ '<li class="disabled"><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'"><span class="glyphicon glyphicon-chevron-left"></span> '+oLang.sPrevious+'</a></li>'+
+ '<li><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+' <span class="glyphicon glyphicon-chevron-right"></span></a></li>'+
+ '<li><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+' <span class="glyphicon glyphicon-forward"></span></a></li>'+
+ '</ul>'
+ );
+ var els = $('a', nPaging);
+ var nFirst = els[0],
+ nPrev = els[1],
+ nNext = els[2],
+ nLast = els[3];
+ oSettings.oApi._fnBindAction( nFirst, {action: "first"}, fnClickHandler );
+ oSettings.oApi._fnBindAction( nPrev, {action: "previous"}, fnClickHandler );
+ oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
+ oSettings.oApi._fnBindAction( nLast, {action: "last"}, fnClickHandler );
+ if ( !oSettings.aanFeatures.p )
+ {
+ nPaging.id = oSettings.sTableId+'_paginate';
+ nFirst.id =oSettings.sTableId+'_first';
+ nPrev.id =oSettings.sTableId+'_previous';
+ nNext.id =oSettings.sTableId+'_next';
+ nLast.id =oSettings.sTableId+'_last';
+ }
+ },
+ "fnUpdate": function ( oSettings, fnCallbackDraw )
+ {
+ if ( !oSettings.aanFeatures.p )
+ {
+ return;
+ }
+ var oPaging = oSettings.oInstance.fnPagingInfo();
+ var oClasses = oSettings.oClasses;
+ var an = oSettings.aanFeatures.p;
+ var nNode;
+ for ( var i=0, iLen=an.length ; i<iLen ; i++ )
+ {
+ if ( oPaging.iPage === 0 ) {
+ $('li:eq(0)', an[i]).addClass('disabled');
+ $('li:eq(1)', an[i]).addClass('disabled');
+ } else {
+ $('li:eq(0)', an[i]).removeClass('disabled');
+ $('li:eq(1)', an[i]).removeClass('disabled');
+ }
+
+ if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
+ $('li:eq(2)', an[i]).addClass('disabled');
+ $('li:eq(3)', an[i]).addClass('disabled');
+ } else {
+ $('li:eq(2)', an[i]).removeClass('disabled');
+ $('li:eq(3)', an[i]).removeClass('disabled');
+ }
+ }
+ }
+ },
+ "bs_full": {
+ "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
+ {
+ var oLang = oSettings.oLanguage.oPaginate;
+ var oClasses = oSettings.oClasses;
+ var fnClickHandler = function ( e ) {
+ if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
+ {
+ fnCallbackDraw( oSettings );
+ }
+ };
+ $(nPaging).append(
+ '<ul class="pagination">'+
+ '<li class="disabled"><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'">'+oLang.sFirst+'</a></li>'+
+ '<li class="disabled"><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'">'+oLang.sPrevious+'</a></li>'+
+ '<li><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+'</a></li>'+
+ '<li><a tabindex="'+oSettings.iTabIndex+'" class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+'</a></li>'+
+ '</ul>'
+ );
+ var els = $('a', nPaging);
+ var nFirst = els[0],
+ nPrev = els[1],
+ nNext = els[2],
+ nLast = els[3];
+ oSettings.oApi._fnBindAction( nFirst, {action: "first"}, fnClickHandler );
+ oSettings.oApi._fnBindAction( nPrev, {action: "previous"}, fnClickHandler );
+ oSettings.oApi._fnBindAction( nNext, {action: "next"}, fnClickHandler );
+ oSettings.oApi._fnBindAction( nLast, {action: "last"}, fnClickHandler );
+ if ( !oSettings.aanFeatures.p )
+ {
+ nPaging.id = oSettings.sTableId+'_paginate';
+ nFirst.id =oSettings.sTableId+'_first';
+ nPrev.id =oSettings.sTableId+'_previous';
+ nNext.id =oSettings.sTableId+'_next';
+ nLast.id =oSettings.sTableId+'_last';
+ }
+ },
+ "fnUpdate": function ( oSettings, fnCallbackDraw )
+ {
+ if ( !oSettings.aanFeatures.p )
+ {
+ return;
+ }
+ var oPaging = oSettings.oInstance.fnPagingInfo();
+ var iPageCount = $.fn.dataTableExt.oPagination.iFullNumbersShowPages;
+ var iPageCountHalf = Math.floor(iPageCount / 2);
+ var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
+ var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
+ var sList = "";
+ var iStartButton, iEndButton, i, iLen;
+ var oClasses = oSettings.oClasses;
+ var anButtons, anStatic, nPaginateList, nNode;
+ var an = oSettings.aanFeatures.p;
+ var fnBind = function (j) {
+ oSettings.oApi._fnBindAction( this, {"page": j+iStartButton-1}, function(e) {
+ oSettings.oApi._fnPageChange( oSettings, e.data.page );
+ fnCallbackDraw( oSettings );
+ e.preventDefault();
+ } );
+ };
+ if ( oSettings._iDisplayLength === -1 )
+ {
+ iStartButton = 1;
+ iEndButton = 1;
+ iCurrentPage = 1;
+ }
+ else if (iPages < iPageCount)
+ {
+ iStartButton = 1;
+ iEndButton = iPages;
+ }
+ else if (iCurrentPage <= iPageCountHalf)
+ {
+ iStartButton = 1;
+ iEndButton = iPageCount;
+ }
+ else if (iCurrentPage >= (iPages - iPageCountHalf))
+ {
+ iStartButton = iPages - iPageCount + 1;
+ iEndButton = iPages;
+ }
+ else
+ {
+ iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1;
+ iEndButton = iStartButton + iPageCount - 1;
+ }
+ for ( i=iStartButton ; i<=iEndButton ; i++ )
+ {
+ sList += (iCurrentPage !== i) ?
+ '<li><a tabindex="'+oSettings.iTabIndex+'">'+oSettings.fnFormatNumber(i)+'</a></li>' :
+ '<li class="active"><a tabindex="'+oSettings.iTabIndex+'">'+oSettings.fnFormatNumber(i)+'</a></li>';
+ }
+ for ( i=0, iLen=an.length ; i<iLen ; i++ )
+ {
+ nNode = an[i];
+ if ( !nNode.hasChildNodes() )
+ {
+ continue;
+ }
+ $('li:gt(1)', an[i]).filter(':not(li:eq(-2))').filter(':not(li:eq(-1))').remove();
+ if ( oPaging.iPage === 0 ) {
+ $('li:eq(0)', an[i]).addClass('disabled');
+ $('li:eq(1)', an[i]).addClass('disabled');
+ } else {
+ $('li:eq(0)', an[i]).removeClass('disabled');
+ $('li:eq(1)', an[i]).removeClass('disabled');
+ }
+ if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
+ $('li:eq(-1)', an[i]).addClass('disabled');
+ $('li:eq(-2)', an[i]).addClass('disabled');
+ } else {
+ $('li:eq(-1)', an[i]).removeClass('disabled');
+ $('li:eq(-2)', an[i]).removeClass('disabled');
+ }
+ $(sList)
+ .insertBefore('li:eq(-2)', an[i])
+ .bind('click', function (e) {
+ e.preventDefault();
+ oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
+ fnCallbackDraw( oSettings );
+ });
+ }
+ }
+ }
+} );
+
+
+/*
+ * TableTools Bootstrap compatibility
+ * Required TableTools 2.1+
+ */
+if ( $.fn.DataTable.TableTools ) {
+ // Set the classes that TableTools uses to something suitable for Bootstrap
+ $.extend( true, $.fn.DataTable.TableTools.classes, {
+ "container": "DTTT btn-group",
+ "buttons": {
+ "normal": "btn",
+ "disabled": "disabled"
+ },
+ "collection": {
+ "container": "DTTT_dropdown dropdown-menu",
+ "buttons": {
+ "normal": "",
+ "disabled": "disabled"
+ }
+ },
+ "print": {
+ "info": "DTTT_print_info modal"
+ },
+ "select": {
+ "row": "active"
+ }
+ } );
+
+ // Have the collection use a bootstrap compatible dropdown
+ $.extend( true, $.fn.DataTable.TableTools.DEFAULTS.oTags, {
+ "collection": {
+ "container": "ul",
+ "button": "li",
+ "liner": "a"
+ }
+ } );
+}