X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fqueryupdater%2Fstatic%2Fjs%2Fqueryupdater.js;h=252d349c434a1e1a3deb6c54c6c50d0abfda2971;hb=ba476841726dc818c0efd3ed25e42955a39fc504;hp=7d7de24f40007e2a52e51b49b6849df625e99b79;hpb=d1197c134b70bda643a752bdaf891190cb5a15e7;p=unfold.git diff --git a/plugins/queryupdater/static/js/queryupdater.js b/plugins/queryupdater/static/js/queryupdater.js index 7d7de24f..252d349c 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,14 @@ 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.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>>", @@ -65,11 +71,65 @@ /***************************** GUI EVENTS *****************************/ - do_update: function(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); + + console.log("DATA VALUE: " + data.value); + + if (data.value.toLowerCase().indexOf("iminds") >= 0){ + + $('#sla_dialog').show(); + $('#slamodal').modal('show'); + + $(document).ready(function() { + $("#accept_sla").click(function(){ + console.log("SLA ACCEPTED"); + console.log("With username: " + username); + if(urn.toLowerCase().indexOf("wall2") >= 0){ + $.post("/sla/agreements/simplecreate", + { "template_id": "iMindsServiceVirtualwall", + "user": username, + "expiration_time": new Date() // jgarcia: FIXME + }); + } else if(urn.toLowerCase().indexOf("wilab2") >= 0){ + $.post("/sla/agreements/simplecreate", + { "template_id":"iMindsServiceWiLab2", + "user":username, + "expiration_time": new Date() // jgarcia: FIXME + }); + } + $('#slamodal').modal('hide'); + self.spin(); + console.log("Executing do_update after sending SLA"); + // 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 ? + }); + }); + + $(document).ready(function() { + $("#dismiss_sla").click(function(){ + console.log("SLA NOT ACCEPTED"); + $('#slamodal').modal('hide'); + }); + }); + + } else { + 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 +180,7 @@ set_state: function(data) { + console.log("function set_state"); var action; var msg; var button = ''; @@ -127,9 +188,11 @@ var row; // make sure the change is visible : toggle on the whole plugin - // this might hae to be made an 'auto-toggle' option of this 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 +201,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 +230,13 @@ 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); row = this.find_row(data.value); newline = [ action, @@ -181,6 +249,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 +273,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 +342,7 @@ on_query_in_progress: function() { + messages.debug("queryupdater.on_query_in_progress"); this.spin(); }, @@ -283,12 +358,9 @@ this.clear(); }, - on_new_record: function(record) - { - }, - on_query_done: function() { + console.log("on_query_done"); this.unspin(); }, @@ -296,11 +368,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,7 +391,9 @@ on_field_state_changed: function(result) { - console.log(result) + console.log("on_field_state_changed"); + console.log(result); + messages.debug(result) /* this.set_state(result.request, result.key, result.value, result.status); */ this.set_state(result); }, @@ -350,7 +427,7 @@ update_resources: function(resources, change) { - console.log("update_resources"); + messages.debug("update_resources"); var my_oTable = this.table.dataTable(); var prev_resources = this.current_resources; @@ -362,7 +439,7 @@ if (!change) return; // ioi: Refubrished - var initial = this.initial_resources; + var initial = this.initial; //var r_removed = []; // /*----------------------------------------------------------------------- TODO: remove this dirty hack !!!