2 * Description: display a query result in a datatables-powered <table>
3 * Copyright (c) 2012-2013 UPMC Sorbonne Universite - INRIA
12 var UnivbrisVtamForm = Plugin.extend({
14 init: function(options, element) {
15 //console.log("hello....................");
16 this._super(options, element);
17 this.filters = Array();
19 // an internal buffer for records that are 'in' and thus need to be checked
20 this.buffered_records_to_check = [];
21 // an internal buffer for keeping lines and display them in one call to fnAddData
22 this.buffered_lines = [];
27 //var keys = manifold.metadata.get_key(this.object);
28 //this.canonical_key = (keys && keys.length == 1) ? keys[0] : undefined;
30 //this.init_key = this.options.init_key;
31 // have init_key default to canonical_key
32 //this.init_key = this.init_key || this.canonical_key;
34 //if ( ! this.init_key ) messages.warning ("UnivbrisVtamForm : cannot find init_key");
35 //if ( ! this.canonical_key ) messages.warning ("UnivbrisVtamForm : cannot find canonical_key");
36 //if (debug) messages.debug("UnivbrisVtamForm: canonical_key="+this.canonical_key+" init_key="+this.init_key);
38 /* Setup query and record handlers */
39 this.listen_query(options.query_uuid);
40 // this.listen_query(options.query_all_uuid, 'all');
42 /* GUI setup and event binding */
45 $('<button id="cancelvtamform" type="button" style="height: 25px; width: 200px" onclick="fnCancelVtamForm()">Cancel</button>').appendTo('#vtam_form_buttons');
46 $("#cancelvtamform").unbind('click').click(this, this.fnCancelVtamForm);
48 $('<button id="addvtamform" type="button" style="height: 25px; width: 200px" onclick="fnAddVtamForm()">Add VM</button>').appendTo('#vtam_form_buttons');
49 $("#addvtamform").unbind('click').click(this, this.fnAddVtamForm);
51 jQuery("#univbris_vtam_form").hide();
53 $('#uob_testbed_name').on("change", this.testbedChanged);
55 //this.on_new_record("urn:publicid:IDN+i2cat:vtam+node+Rodoreda");
56 //this.on_new_record("urn:publicid:IDN+bristol:vtam+node+March");
57 //this.on_new_record("urn:publicid:IDN+brazil:vtam+node+Verdaguer");
58 //this.on_query_done();
60 // console.log("after");
63 testbedChanged: function(e){
64 console.log($('#uob_testbed_name option:selected').text());
66 $('#uob_virtualization_server')
71 for(var i=0;i<vt_servers_list.length;i++){
72 if(vt_servers_list[i].testbed==$('#uob_testbed_name option:selected').text()){
73 $('#uob_virtualization_server')
74 .append($("<option></option>")
75 .attr("value",vt_servers_list[i].urn)
76 .text(vt_servers_list[i].name));
82 fnCancelVtamForm:function(e){
83 jQuery("#univbris_vtam_form").hide();
84 jQuery("#univbris_vtam").show();
85 console.log("cancel vtam form");
88 fnAddVtamForm:function(e){
89 console.log("add vtam form");
90 var vmNameVal = /^[a-zA-Z0-9]+$/;
91 //console.log($("#uob_vm_name").val());
92 if (vmNameVal.test($("#uob_vm_name").val())){
94 //{"urn:publicid:IDN+vtam.univbris+node+uclalien":[{"name":"toto"}]}
95 var vtam='{"'+$('#uob_virtualization_server option:selected').val()+'":';
96 vtam+='[{"name":"'+$('#uob_vm_name').val()+'"}]}';
97 //var vtam="testbed="+$('#uob_testbed_name option:selected').text();
98 // Use the URN instead of the hostname of the server
99 //vtam +=",vt_server="+$('#uob_virtualization_server option:selected').val();
100 //vtam +=",vm_name="+$("#uob_vm_name").val();
101 var vm_name="<p id='"+vtam+"'>"+$("#uob_vm_name").val()+"</p>";
102 var vtamtable = $("#univbris_vtam__table").dataTable();
103 vtamtable.fnAddData([$('#uob_testbed_name option:selected').text(),$('#uob_virtualization_server option:selected').text(), vm_name,'<a class="delete" href="">Delete</a>']);
104 jQuery("#univbris_vtam_form").hide();
105 jQuery("#univbris_vtam").show();
108 $('#uob_vm_name').addClass('error');
109 jQuery('#uob_vm_name_error').show();
115 on_show: function(e) {
118 on_resize: function(e) {
123 /* GUI MANIPULATION */
125 new_record: function(record)
127 var urn = record['urn'];
128 var pos = urn.search('vtam');
130 ///line =new Array();
132 var com_ay=urn.split("+");
133 vt_server['name']=com_ay[com_ay.length-1];
134 var testbed_ay=com_ay[1].split(":");
135 vt_server['testbed']=testbed_ay[0];
136 vt_server['urn']=urn;
137 this.add_new_vt_server(vt_server);
138 this.add_new_testbed(testbed_ay[0]);
139 //this.vt_servers_list.push(vt_server);
143 clear_table: function()
147 redraw_table: function()
152 add_new_vt_server:function(vt_server){
154 for(var i=0;i<vt_servers_list.length;i++){
155 if(vt_servers_list[i].name==vt_server.name && vt_servers_list[i].testbed==vt_server.testbed){
161 //console.log(found);
164 vt_servers_list.push(vt_server);
168 add_new_testbed:function(testbed){
170 for(var i=0;i<testbeds_list.length;i++){
171 if(testbeds_list[i]==testbed){
177 //console.log(found);
180 testbeds_list.push(testbed);
188 /*************************** QUERY HANDLER ****************************/
190 on_filter_added: function(filter)
194 on_filter_removed: function(filter)
198 on_filter_clear: function()
203 on_field_added: function(field)
205 this.show_column(field);
208 on_field_removed: function(field)
210 this.hide_column(field);
213 on_field_clear: function()
218 /*************************** ALL QUERY HANDLER ****************************/
220 on_all_filter_added: function(filter)
224 on_all_filter_removed: function(filter)
229 on_all_filter_clear: function()
233 on_all_field_added: function(field)
237 on_all_field_removed: function(field)
241 on_all_field_clear: function()
246 /*************************** RECORD HANDLER ***************************/
248 on_new_record: function(record)
251 console.log(record.hostname);
252 if (this.received_all_query) {
255 this.buffered_records_to_check.push(record);
259 on_clear_records: function()
263 // Could be the default in parent
264 on_query_in_progress: function()
269 on_query_done: function()
271 this.received_query = true;
272 for(var i=0;i<this.buffered_records_to_check.length;i++){
273 this.new_record(this.buffered_records_to_check[i]);
277 /*$.each(vt_servers_list, function(key, value) {
278 $('#uob_testbed_name')
279 .append($("<option></option>")
281 .text(value.testbed));
284 $('#uob_testbed_name')
289 for(var t=0;t<testbeds_list.length;t++){
290 $('#uob_testbed_name')
291 .append($("<option></option>")
292 .attr("value",testbeds_list[t])
293 .text(testbeds_list[t]));
296 $('#uob_virtualization_server')
301 for(var i=0;i<vt_servers_list.length;i++){
302 if(vt_servers_list[i].testbed==$('#uob_testbed_name option:selected').text()){
303 $('#uob_virtualization_server')
304 .append($("<option></option>")
305 .attr("value",vt_servers_list[i].urn)
306 .text(vt_servers_list[i].name));
313 on_field_state_changed: function(data)
318 }); //close plugin extend
320 $.plugin('UnivbrisVtamForm', UnivbrisVtamForm);