X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fsladialog%2Fstatic%2Fjs%2Fsladialog.js;h=01eb0afd3f87b3628684b8ce3aeb6931bc5ab44d;hb=deee82377a1f72626cede01fdfec5e9d7cc274ce;hp=c11874359bb78965e4bb655f18a8ee6edb2239ad;hpb=b0773f0d25acb85176f11ac2f91ee25baecea20d;p=myslice.git diff --git a/plugins/sladialog/static/js/sladialog.js b/plugins/sladialog/static/js/sladialog.js index c1187435..01eb0afd 100644 --- a/plugins/sladialog/static/js/sladialog.js +++ b/plugins/sladialog/static/js/sladialog.js @@ -1,13 +1,10 @@ /** - * MyPlugin: demonstration plugin - * Version: 0.1 - * Description: Template for writing new plugins and illustrating the different - * possibilities of the plugin API. - * This file is part of the Manifold project + * SlaDialog + * Description: Plugin to allow SLA acceptance and creation to MySlice portal + * in Fed4FIRE * Requires: js/plugin.js - * URL: http://www.myslice.info - * Author: Jordan Augé - * Copyright: Copyright 2012-2013 UPMC Sorbonne Universités + * Author: Javier García Lloreda + * Copyright: Copyright Atos Spain S.A. * License: GPLv3 */ @@ -16,18 +13,10 @@ var SlaDialog = Plugin.extend({ accepted_slas: {}, + queries: [], - /** XXX to check - * @brief Plugin constructor - * @param options : an associative array of setting values - * @param element : - * @return : a jQuery collection of objects on which the plugin is - * applied, which allows to maintain chainability of calls - */ init: function(options, element) { - // for debugging tools - this.classname="SlaDialog"; - // Call the parent constructor, see FAQ when forgotten + this.classname = "SlaDialog"; this._super(options, element); /* Member variables */ @@ -35,33 +24,66 @@ /* Plugin events */ /* Setup query and record handlers */ - - // Explain this will allow query events to be handled - // What happens when we don't define some events ? - // Some can be less efficient this.listen_query(options.query_uuid); /* GUI setup and event binding */ - // call function - this.button_binding(); + // Get testbeds with sla and store them in localStorage + this.get_testbeds_with_sla(); + // call function + //this.button_binding(); }, - find_row: function(key) - { - // key in third position, column id = 2 - var KEY_POS = 2; - - var cols = $.grep(this.table.fnSettings().aoData, function(col) { - return (col._aData[KEY_POS] == key); - } ); + get_testbeds_with_sla: function () { + var self = this; + return $.get('/sla/testbeds/', function(data) { + if (typeof(Storage) !== "undefined") { + if (!localStorage.getItem("sla_testbeds")) { + var testbeds = data; + localStorage.setItem("sla_testbeds", testbeds); + } + } + }).done(function(data) { + self.get_sla_templates(data); + }); + }, - if (cols.length == 0) - return null; - if (cols.length > 1) - throw "Too many same-key rows in ResourceSelected plugin"; + get_sla_templates: function (testbeds) { + var self = this; - return cols[0]; + testbeds.forEach(function(testbed, index, array) { + + if(testbed=="omf:netmode") { // TODO: Remove + + $.ajax('/sla/agreements/templates/' + testbed) + .always(function(data) { + $(".modal-body #sla_template").html(data.responseText.replace(/<|>/g, "")); + + var content = + ""; + + $("#sla_offers").append(content); + + self.button_binding(); + }); + } + }); }, check_template_status: function() { @@ -73,8 +95,6 @@ }, /* PLUGIN EVENTS */ - // on_show like in querytable - /* GUI EVENTS */ @@ -86,11 +106,28 @@ self.accepted_slas[id] = true; var is_ok = self.check_template_status(); + $(".sla-alert").show(); + $(this).button("complete"); + $(this).prop("disabled", true); + if (is_ok) { // remove warnings - // var warnings = manifold.query_store.get_record_state(resource_query.query_uuid, resource_key, STATE_WARNINGS); + $('#' + id).data("urns").forEach(function (urn, index, array) { + data = { + state: STATE_SET, + key : "resource", + op : STATE_SET_REMOVE, + value: urn + } + + manifold.raise_event(self.query_uuid, STATUS_REMOVE_WARNING, data); + }); } }); + + $(".sla-alert-close").click(function() { + $(this).closest(".sla-alert").hide(); + }); }, create_sla: function(record) { @@ -98,16 +135,17 @@ var urns = []; - record.resource.forEach(function(r) { - if ($.inArray(r.component_id, record.resource) == -1) { // if not already selected - urns.push(r.component_id); - } - }); + if (record.resource.length != 0 && typeof record.resource[0] === "object") { + + record.resource.forEach(function(r) { + if ($.inArray(r.component_id, record.resource) == -1) { // if not already selected + urns.push(r.component_id); + } + }); - if (record.resource.length != 0 && typeof record.resource[0] !== "undefined") { var data = { "SLIVER_INFO_AGGREGATE_URN": record.resource[0].component_manager_id, - "SLIVER_INFO_EXPIRATION": record.lease[0].end_time, // FIXME: only working with leases + "SLIVER_INFO_EXPIRATION": record.lease[0].end_time, // FIXME: only working with leases "SLIVER_INFO_SLICE_URN": record.slice_urn, "SLIVER_INFO_CREATOR_URN": record.users[0], "SLIVER_INFO_URN": urns, @@ -131,43 +169,6 @@ // }); }, - // a function to bind events here: click change - // how to raise manifold events - set_state: function(data, username) - { - - }, - - post_agreement: function() - { - console.log(this.options.user); - }, - - /* GUI MANIPULATION */ - - // We advise you to write function to change behaviour of the GUI - // Will use naming helpers to access content _inside_ the plugin - // always refer to these functions in the remaining of the code - - show_hide_button: function() - { - // this.id, this.el, this.cl, this.elts - // same output as a jquery selector with some guarantees - }, - - /* TEMPLATES */ - - // see in the html template - // How to load a template, use of mustache - - /* QUERY HANDLERS */ - - // How to make sure the plugin is not desynchronized - // He should manifest its interest in filters, fields or records - // functions triggered only if the proper listen is done - - // no prefix - on_filter_added: function(filter) { @@ -176,6 +177,10 @@ on_field_state_changed: function(data) { var self = this; + self.query_uuid = self.options.query_uuid; + + var testbeds = localStorage.getItem("sla_testbeds").split(","); + var urn_regexp = /\+(.*?)\+/; // this.set_state(result, this.options.username); switch(data.state) { @@ -184,46 +189,40 @@ case STATE_SET_IN_PENDING: if (typeof(data.value) == 'string') { // data.value = urn - this._supports_sla(data.value) - .done( function(testbeds) { - var urn_regexp = /\+(.*?)\+/; - var urn = urn_regexp.exec(data.value)[1]; - var pos = $.inArray(urn, testbeds); - if ( pos != -1) { - var id_ref = testbeds[pos].replace(/\.|:/g, "-"); - $("#" + id_ref).data("urns").push(data.value); - $("#" + id_ref).show(); - self.accepted_slas[id_ref] = false; - //$( "#sla_offers_list" ).append( - // $("
  • ").text("Testbed " + testbeds[pos] + " offers SLA for its resources") - //); - } - }); + var urn = urn_regexp.exec(data.value)[1]; + var pos = $.inArray(urn, testbeds); + if ( pos != -1) { + var id_ref = testbeds[pos].replace(/\.|:/g, "-"); + $("#" + id_ref).data("urns").push(data.value); + $("#" + id_ref).show(); + self.accepted_slas[id_ref] = false; + //$( "#sla_offers_list" ).append( + // $("
  • ").text("Testbed " + testbeds[pos] + " offers SLA for its resources") + //); + } } break; case STATE_SET_OUT: // data.value = urn if (typeof(data.value) == 'string') { // data.value = urn - this._supports_sla(data.value) - .done( function(testbeds) { - var urn_regexp = /\+(.*?)\+/; - var urn = urn_regexp.exec(data.value)[1]; - var pos = $.inArray(urn, testbeds); - if ( pos != -1) { - var id_ref = testbeds[pos].replace(/\.|:/g, "-"); - var array = $("#" + id_ref).data("urns"); - array.splice(array.indexOf(data.value), 1); - - if ($("#" + id_ref).data("urns").length == 0) { - $("#" + id_ref).hide(); - delete self.accepted_slas[id_ref]; - } - //$( "#sla_offers_list" ).append( - // $("
  • ").text("Testbed " + testbeds[pos] + " offers SLA for its resources") - //); - } - }); + var urn = urn_regexp.exec(data.value)[1]; + var pos = $.inArray(urn, testbeds); + if ( pos != -1) { + var id_ref = testbeds[pos].replace(/\.|:/g, "-"); + var array = $("#" + id_ref).data("urns"); + array.splice(array.indexOf(data.value), 1); + + if ($("#" + id_ref).data("urns").length == 0) { + $("#" + id_ref).hide(); + delete self.accepted_slas[id_ref]; + $(".sla-accept-button").button("reset"); + $(".sla-accept-button").prop("disabled", false); + } + //$( "#sla_offers_list" ).append( + // $("
  • ").text("Testbed " + testbeds[pos] + " offers SLA for its resources") + //); + } } break; } @@ -238,8 +237,6 @@ } }, - // ... be sure to list all events here - /* RECORD HANDLERS */ on_all_new_record: function(record) { @@ -252,16 +249,11 @@ }, /* INTERNAL FUNCTIONS */ - _dummy: function() { - // only convention, not strictly enforced at the moment - }, _supports_sla: function(resource_urn) { return $.ajax("/sla/testbeds/"); }, - - _getUUID: function() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8); @@ -274,6 +266,4 @@ /* Plugin registration */ $.plugin('SlaDialog', SlaDialog); - // TODO Here use cases for instanciating plugins in different ways like in the pastie. - })(jQuery);