X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fqueryupdater%2Fstatic%2Fjs%2Fqueryupdater.js;h=7718253c7c3c52d096d1d0b53dd3471169691ea7;hb=3a41bf6525b4c0cddaa08998a7279aefaaf7440e;hp=abcd2d7fc833256e2a6a81099011e5110937400c;hpb=ffc68fa6f93c8acfeb7b4a84a8dbf0ff69af9409;p=unfold.git diff --git a/plugins/queryupdater/static/js/queryupdater.js b/plugins/queryupdater/static/js/queryupdater.js index abcd2d7f..7718253c 100644 --- a/plugins/queryupdater/static/js/queryupdater.js +++ b/plugins/queryupdater/static/js/queryupdater.js @@ -11,6 +11,9 @@ (function( $ ){ + var debug=false; + debug=true; + // XXX record selected (multiple selection ?) // XXX record disabled ? // XXX out of sync plugin ? @@ -25,11 +28,15 @@ var QueryUpdater = Plugin.extend({ - init: function(options, element) - { + init: function(options, element) { + this.classname="queryupdater"; this._super(options, element); var self = this; + + this.initial = Array(); + this.selected_resources = Array(); + this.table = this.elmt('table').dataTable({ // the original querytable layout was // sDom: "<'row'<'col-xs-5'l><'col-xs-1'r><'col-xs-6'f>>t<'row'<'col-xs-5'i><'col-xs-7'p>>", @@ -37,7 +44,7 @@ sDom: "<'row'<'col-xs-5'l><'col-xs-1'r><'col-xs-6'f>>t>", // so this does not matter anymore now that the pagination area is turned off // sPaginationType: 'bootstrap', - bAutoWidth: true, + bAutoWidth: true, // bJQueryUI : true, // bRetrieve : true, // sScrollX : '100%', // Horizontal scrolling @@ -53,7 +60,7 @@ }); // XXX This should not be done at init... - this.elmt('update').click(this, this.do_update); + this.elmt('update').click(this, this.do_checksla); this.elmt('refresh').click(this, this.do_refresh); this.elmt('reset').click(this, this.do_reset); this.elmt('clear_annotations').click(this, this.do_clear_annotations); @@ -65,11 +72,218 @@ /***************************** GUI EVENTS *****************************/ - do_update: function(e) - { + do_checksla: function(e) { + var username = e.data.options.username; + var urn = data.value; + var arrayselectedresources = data.selected_resources; + + var accepted_sla = Array(); + var count = 0; + // XXX check that the query is not disabled + + console.log("DATA VALUE: " + data.value); + + //

SLA description

+ //

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime

+ //

SLA description

+ //

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the WiLab2 resources during the sliver lifetime

+ var promt = $('#modal-body'); + + // id="myModalLabel" + var flagVW = false; + var flagWi = false; + + var wilabForm = ""; + var wimessage = '

SLA description

to be deployed

'; + for(var iter = 0; iter < arrayselectedresources.length; iter++){ + var list = '

'+arrayselectedresources[iter].toLowerCase()+'


'; + + + if (arrayselectedresources[iter].toLowerCase().indexOf("wilab2") >= 0){ + + accepted_sla.push({"wilab2":false}); + wilabForm += list; + flagWi = true; + + } + + } + + //var wallmessage = '

SLA description

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime

'; + + var wallForm = ""; + for(var iter = 0; iter < arrayselectedresources.length; iter++){ + var list = ''+arrayselectedresources[iter].toLowerCase()+'


'; + + if (arrayselectedresources[iter].toLowerCase().indexOf("wall2") >= 0){ + + accepted_sla.push({"wall2":false}); + wallForm += list; + flagVW = true; + + } + + } + promt.append(wimessage); + var flagDouble = false; + if(flagWi) + { + flagDouble = true; + promt.append(wilabForm); + } + if(flagVW) + { + //promt.append(wallmessage); + flagDouble = true; + promt.append(wallForm); + } + + + // var wimessage = '

SLA description

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime

' + + $('#sla_dialog').show(); + $('#slamodal-wilab2').modal('show'); + + + $("#accept_sla_wilab2").click(function(){ + console.log("SLA ACCEPTED"); + console.log("With username: " + username); + + // var promt = $('#modal-body'); + // var notchecked = true; + // for (var i=0;i<50;i++) + // { + // var wielement = $('#wi'+i); + // var wallElement = $('#wall'+i); + // if(wielement != null && !wielement.checked) + // { + // notchecked = false; + // } + // if(wallElement!= null && !wallElement.checked) + // { + // notchecked = false; + // } + // } + + + if(flagDouble) + { + $.post("/sla/agreements/simplecreate", + { "template_id": "iMindsServiceWiLab2", + "user": username, + "expiration_time": new Date().toISOString() + }); + $.post("/sla/agreements/simplecreate", + { "template_id": "iMindsServiceVirtualwall", + "user": username, + "expiration_time": new Date().toISOString() + }); + + $('#slamodal-wilab2').modal('hide'); + accepted_sla["wilab2"] = true; + + this.do_update(e); + } + }); + + $("#dismiss_sla_wilab2").click(function(){ + console.log("SLA NOT ACCEPTED"); + $('#slamodal-wilab2').modal('hide'); + }); + + // for(var iter = 0; iter < arrayselectedresources.length; iter++){ + // var list = ''+arrayselectedresources[iter].toLowerCase()+'
'; + // promt.append(list); + // if (arrayselectedresources[iter].toLowerCase().indexOf("wall2") >= 0){ + + + + // accepted_sla.push({"wall2":false}); + + // $('#sla_dialog').show(); + // $('#slamodal-virtualwall').modal('show'); + + + // $("#accept_sla_vwall").click(function(){ + // console.log("SLA ACCEPTED"); + // console.log("With username: " + username); + + // $.post("/sla/agreements/simplecreate", + // { "template_id": "iMindsServiceVirtualwall", + // "user": username, + // "expiration_time": new Date() + // }); + + // $('#slamodal-virtualwall').modal('hide'); + // accepted_sla["wall2"] = true; + // }); + + // $("#dismiss_sla_vwall").click(function(){ + // console.log("SLA NOT ACCEPTED"); + // $('#slamodal-vir').modal('hide'); + // }); + + // } + + // if (arrayselectedresources[iter].toLowerCase().indexOf("wilab2") >= 0){ + + // accepted_sla.push({"wilab2":false}); + + // $('#sla_dialog').show(); + // $('#slamodal-wilab2').modal('show'); + + + // $("#accept_sla_wilab2").click(function(){ + // console.log("SLA ACCEPTED"); + // console.log("With username: " + username); + + // $.post("/sla/agreements/simplecreate", + // { "template_id": "iMindsServiceWiLab2", + // "user": username, + // "expiration_time": new Date() + // }); + + // $('#slamodal-wilab2').modal('hide'); + // accepted_sla["wilab2"] = true; + // }); + + // $("#dismiss_sla_wilab2").click(function(){ + // console.log("SLA NOT ACCEPTED"); + // $('#slamodal-wilab2').modal('hide'); + // }); + + + // } + + // } + + // for(var sla in accepted_sla){ + // if(accepted_sla[sla] == true){ + // count += 1; + // } + // } + + // if(count == accepted_sla.length){ + // this.do_update(e); + // } + }, + + + do_update: function(e) { var self = e.data; + + var username = e.data.options.username; + var urn = data.value; // XXX check that the query is not disabled - manifold.raise_event(self.options.query_uuid, RUN_UPDATE); + + self.spin(); + console.log("do_update"); + // XXX check that the query is not disabled + //manifold.raise_event(self.options.query_uuid, RUN_UPDATE); + + // how to stop the spinning after the event? + // this should be triggered by some on_updatequery_done ? + }, // related buttons are also disabled in the html template @@ -120,6 +334,7 @@ set_state: function(data) { + console.log("function set_state"); var action; var msg; var button = ''; @@ -129,7 +344,9 @@ // make sure the change is visible : toggle on the whole plugin // this might have to be made an 'auto-toggle' option of this plugin.. // also it might be needed to be a little finer-grained here - this.toggle_on(); + + // XXX we don't want to show automaticaly the pending when a checkbox is checked + //this.toggle_on(); switch(data.request) { case FIELD_REQUEST_ADD_RESET: @@ -138,6 +355,8 @@ row = this.find_row(data.value); if (row) this.table.fnDeleteRow(row.nTr); + $("#badge-pending").data('number', $("#badge-pending").data('number') - 1 ); + $("#badge-pending").text($("#badge-pending").data('number')); return; case FIELD_REQUEST_CHANGE: action = 'UPDATE'; @@ -165,10 +384,14 @@ var status = msg + status; + + // find line // if no, create it, else replace it // XXX it's not just about adding lines, but sometimes removing some // XXX how do we handle status reset ? + data.value = JSON.stringify(data.value); + data.selected_resources = this.selected_resources; row = this.find_row(data.value); newline = [ action, @@ -181,6 +404,8 @@ // XXX second parameter refresh = false can improve performance. todo in querytable also this.table.fnAddData(newline); row = this.find_row(data.value); + $("#badge-pending").data('number', $("#badge-pending").data('number') + 1 ); + $("#badge-pending").text($("#badge-pending").data('number')); } else { // Update row text... this.table.fnUpdate(newline, row.nTr); @@ -203,11 +428,15 @@ on_new_record: function(record) { + console.log("query_updater on_new_record"); + console.log(record); + // if (not and update) { // initial['resource'], initial['lease'] ? - this.initial.push(record.urn); + this.initial.push(record); + //this.set_record_state(record, RECORD_STATE_ATTACHED); // We simply add to the table // } else { // \ this.initial_resources @@ -268,6 +497,7 @@ on_query_in_progress: function() { + messages.debug("queryupdater.on_query_in_progress"); this.spin(); }, @@ -283,12 +513,9 @@ this.clear(); }, - on_new_record: function(record) - { - }, - on_query_done: function() { + console.log("on_query_done"); this.unspin(); }, @@ -296,11 +523,14 @@ // NOTE: record_key could be sufficient on_added_record: function(record) { + console.log("on_added_record = ",record); this.set_record_state(record, RECORD_STATE_ADDED); + // update pending number }, on_removed_record: function(record_key) { + console.log("on_removed_record = ",record_key); this.set_record_state(RECORD_STATE_REMOVED); }, @@ -316,6 +546,17 @@ on_field_state_changed: function(result) { + console.log("on_field_state_changed"); + console.log(result); + if(result.request == FIELD_REQUEST_ADD){ + this.selected_resources.push(result.value); + } else if(result.request == FIELD_REQUEST_REMOVE_RESET){ + var i = this.selected_resources.indexOf(result.value); + if(i != -1){ + this.selected_resources.splice(i,1); + } + } + console.log("Resources: " + self.selected_resources); messages.debug(result) /* this.set_state(result.request, result.key, result.value, result.status); */ this.set_state(result); @@ -362,7 +603,7 @@ if (!change) return; // ioi: Refubrished - var initial = this.initial_resources; + var initial = this.initial; //var r_removed = []; // /*----------------------------------------------------------------------- TODO: remove this dirty hack !!!