X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Funivbrisfvfo%2Fstatic%2Fjs%2Funivbrisfvfo.js;fp=plugins%2Funivbrisfvfo%2Fstatic%2Fjs%2Funivbrisfvfo.js;h=7d502a854d022f490f3912854efe6dd4501b3bc8;hb=6a3f5d4949171451d5df2df5d0f96e9eb396f29c;hp=0000000000000000000000000000000000000000;hpb=583c62239bbf6be5222e170609e547349389c1c1;p=myslice.git diff --git a/plugins/univbrisfvfo/static/js/univbrisfvfo.js b/plugins/univbrisfvfo/static/js/univbrisfvfo.js new file mode 100644 index 00000000..7d502a85 --- /dev/null +++ b/plugins/univbrisfvfo/static/js/univbrisfvfo.js @@ -0,0 +1,1266 @@ +/** + * Description: display a query result in a datatables-powered + * Copyright (c) 2012-2013 UPMC Sorbonne Universite - INRIA + * License: GPLv3 + */ + +(function($){ + + var debug=false; + debug=true; + + + var UnivbrisFvfo = Plugin.extend({ + + init: function(options, element) { + //alert("foam init called"); + this.classname="univbrisfvfo"; + this._super(options, element); + + //alert(this.options.hidden_columns); + /* Member variables */ + // in general we expect 2 queries here + // query_uuid refers to a single object (typically a slice) + // query_all_uuid refers to a list (typically resources or users) + // these can return in any order so we keep track of which has been received yet + //this.received_all_query = false; + //this.received_query = false; + + // We need to remember the active filter for datatables filtering + this.filters = Array(); + + // an internal buffer for records that are 'in' and thus need to be checked + this.buffered_records_to_check = []; + // an internal buffer for keeping lines and display them in one call to fnAddData + this.buffered_lines = []; + + /* Events */ + // xx somehow non of these triggers at all for now + //this.elmt().on('show', this, this.on_show); + //this.elmt().on('shown.bs.tab', this, this.on_show); + //this.elmt().on('resize', this, this.on_resize); + + //var query = manifold.query_store.find_analyzed_query(this.options.query_uuid); + //this.object = query.object; + + //// we need 2 different keys + // * canonical_key is the primary key as derived from metadata (typically: urn) + // and is used to communicate about a given record with the other plugins + // * init_key is a key that both kinds of records + // (i.e. records returned by both queries) must have (typically: hrn or hostname) + // in general query_all will return well populated records, but query + // returns records with only the fields displayed on startup + var keys = manifold.metadata.get_key(this.object); + this.canonical_key = (keys && keys.length == 1) ? keys[0] : undefined; + // + this.init_key = this.options.init_key; + // have init_key default to canonical_key + this.init_key = this.init_key || this.canonical_key; + // sanity check + if ( ! this.init_key ) messages.warning ("UnivbrisFvfo : cannot find init_key"); + if ( ! this.canonical_key ) messages.warning ("UnivbrisFvfo : cannot find canonical_key"); + if (debug) messages.debug("UnivbrisFvfo: canonical_key="+this.canonical_key+" init_key="+this.init_key); + + /* 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(); + //alert("init fvf"); + jQuery("#uob_ofv_table_form").hide(); + + //$('').appendTo('#fvf_table_button'); + + //$('').appendTo('#fvf_table_button'); + + this._querytable_draw_callback(); + }, + + /* PLUGIN EVENTS */ + + on_show: function(e) { + if (debug) messages.debug("univbrisfvfo.on_show"); + var self = e.data; + self.table.fnAdjustColumnSizing(); + }, + + on_resize: function(e) { + if (debug) messages.debug("univbrisfvfo.on_resize"); + var self = e.data; + self.table.fnAdjustColumnSizing(); + }, + + /* GUI EVENTS */ + + /* GUI MANIPULATION */ + + initialize_table: function() + { + /* Transforms the table into DataTable, and keep a pointer to it */ + var self = this; + var 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'<'col-xs-5'l><'col-xs-1'r><'col-xs-6'f>>t<'row'<'col-xs-5'i><'col-xs-7'p>>", + //sDom: "<'row'<'col-xs-2'l><'col-xs-9'r><'col-xs-2'f>>t<'row'<'col-xs-5'i><'col-xs-5'p>><'next'>", + sDom: "<'row'<'col-xs-9'r>t<'buttons'>", + // XXX as of sept. 2013, I cannot locate a bootstrap3-friendly mode for now + // hopefully this would come with dataTables v1.10 ? + // in any case, search for 'sPaginationType' all over the code for more comments + 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: false, /* Loading */ + fnDrawCallback: function() { self._querytable_draw_callback.call(self);} + //fnFooterCallback: function() {self._univbrisfvf_footer_callback.call(self,nFoot, aData, iStart, iEnd, aiDisplay)};} + // 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 + // xxx turned back on by Thierry - this is the code that takes python-provided options into account + // check your datatables_options tag instead + // however, we have to accumulate in aoColumnDefs from here (above) + // and from the python wrapper (checkboxes management, plus any user-provided aoColumnDefs) + if ( 'aoColumnDefs' in this.options.datatables_options) { + actual_options['aoColumnDefs']=this.options.datatables_options['aoColumnDefs'].concat(actual_options['aoColumnDefs']); + delete this.options.datatables_options['aoColumnDefs']; + } + $.extend(actual_options, this.options.datatables_options ); + this.table = $("#univbris_flowspace_form__table").dataTable(actual_options); + + //alert(this.table); + + /* Setup the SelectAll button in the dataTable header */ + /* xxx not sure this is still working */ + var oSelectAll = $('#datatableSelectAll-'+ this.options.plugin_uuid); + oSelectAll.html("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 != self.options.plugin_uuid + '__table') + return true; + return self._querytable_filter.call(self, oSettings, aData, iDataIndex); + }); + + //alert(this.options.hidden_columns); + + /* Processing hidden_columns */ + $.each(this.options.hidden_columns, function(i, field) { + //manifold.raise_event(self.options.query_all_uuid, FIELD_REMOVED, field); + //alert (field); + self.hide_column(field); + //self.hide_column(field); + }); + + }, // initialize_table + + + fnCancel:function(e){ + //var sData=$("#uob_fv_table_form").find("input").serialize(); + //alert("add flowspace:" + sData); + //alert("cancel"); + + jQuery("#uob_ofv_table_form").hide(); + jQuery( "#univbris_foam_ports_selection" ).hide(); + jQuery( "#univbris_flowspace_selection" ).show(); + jQuery('#topo_plugin').hide(); + /*var port_table=$("#univbris_foam_ports_selection__table").dataTable(); + var nodes = $('input',port_table.fnGetNodes()); + for(var i=0;i "+$("#flowspace_name").val()+"

"; + this.table.fnAddData([string, 'Edit', 'Delete']); + jQuery( "#univbris_foam_ports_selection" ).hide(); + jQuery( "#univbris_flowspace_selection" ).show(); + jQuery('#topo_plugin').hide(); + } + else{ + alert("validation failed"); + jQuery("#uob_ofv_table_form").show(); + jQuery( "#univbris_foam_ports_selection" ).show(); + } + } + else{ + jQuery("#uob_fv_table_form").hide(); + var sData=$("#uob_fv_table_form").find("input").serialize(); + var form =serializeAnything("#uob_fv_table_form"); + //var form2=serializeAnything("#uob_form"); + + var port_table=$("#univbris_foam_ports_selection__table").dataTable(); + var form2=$('input',port_table.fnGetNodes()).serialize(); + this.table = $("#univbris_flowspace_selection__table").dataTable(); + flowspace=sData; + var m_form=form+","+form2; + var string = "

"+$("#flowspace_name").val()+"

"; + this.table.fnDeleteRow(fvf_nrow); + this.table.fnAddData([string, 'Edit', 'Delete']); + + jQuery( "#univbris_foam_ports_selection" ).hide(); + jQuery( "#univbris_flowspace_selection" ).show(); + jQuery('#topo_plugin').hide(); + + } + }, + + + /** + * @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 + + // create a checkbox tag + // computes 'id' attribute from canonical_key + // computes 'init_id' from init_key for initialization phase + // no need to used convoluted ids with plugin-uuid or others, since + // we search using table.$ which looks only in this table + checkbox_html : function (record) { + var result=""; + // Prefix id with plugin_uuid + result += "