2 Copyright 2017 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 if (typeof dreamer
=== 'undefined') {
22 dreamer
.GraphRequests
= (function(global
) {
27 GraphRequests
.prototype.constructor = GraphRequests
;
32 function GraphRequests(args
) {
37 GraphRequests
.prototype.addNode = function(args
, choice
, success
, error
) {
38 var data
= new FormData();
39 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
41 data
= args_to_formdata(args
, data
);
43 //FIXME questo metodo dovrebbere essere generico
44 if(args
.existing_element
)
45 data
.append('existing_element', args
.existing_element
? args
.existing_element
: false)
47 // data.append('choice', choice);
55 success: function(result
) {
59 error: function(result
) {
62 log("some error: " + result
);
67 GraphRequests
.prototype.removeNode = function(args
, choice
, success
, error
) {
68 var data
= new FormData();
69 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
71 data
= args_to_formdata(args
, data
);
80 success: function(result
) {
84 error: function(result
) {
91 GraphRequests
.prototype.getNodeOverview = function(args
, success
, error
) {
93 var params
= jQuery
.param(args
)
94 console
.log("params", params
)
96 url
: "overviewelement?"+params
,
98 success: function(result
) {
102 error: function(result
) {
109 GraphRequests
.prototype.addLink = function(args
, choice
, success
, error
) {
110 var data
= new FormData();
111 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
112 data
= args_to_formdata(args
, data
);
114 //data.append('destination', JSON.stringify(destination));
116 data
.append('choice', choice
);
118 // data.append('element_desc_id', link.desc_id || '');
126 success: function(result
) {
130 error: function(result
) {
133 log("some error: " + result
);
138 GraphRequests
.prototype.removeLink = function(args
, success
, error
) {
139 var data
= new FormData();
140 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
141 data
= args_to_formdata(args
, data
);
150 success: function(result
) {
154 error: function(result
) {
157 log("some error: " + result
);
163 GraphRequests
.prototype.getAvailableNodes = function(args
, success
, error
){
164 var data
= new FormData();
165 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
167 url
: "availablenodes?layer="+args
.layer
,
169 success: function(result
) {
173 error: function(result
) {
176 log("some error: " + result
);
181 GraphRequests
.prototype.savePositions = function(positions
, success
, error
) {
182 var data
= new FormData();
183 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
184 data
.append('positions', JSON
.stringify(positions
));
192 success: function(result
) {
196 error: function(result
) {
199 log("some error: " + result
);
204 /* START ETSI methods */
205 GraphRequests
.prototype.addVnffg = function(args
, success
, error
) {
206 var data
= new FormData();
207 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
208 /* data.append('group_id', args.info.group[0]);
209 data.append('element_id', args.id);
210 data.append('element_type', args.info.type);*/
211 data
= args_to_formdata(args
, data
);
219 success: function(result
) {
223 error: function(result
) {
226 log("some error: " + result
);
231 GraphRequests
.prototype.addNodeToVnffg = function(args
, success
, error
) {
232 var data
= new FormData();
233 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
234 /* data.append('group_id', args.info.group[0]);
235 data.append('element_id', args.id);
236 data.append('element_type', args.info.type);
237 data.append('vnffg_id', args.vnffgId);*/
238 data
= args_to_formdata(args
, data
);
241 url
: "addnodetovnffg",
247 success: function(result
) {
251 error: function(result
) {
254 log("some error: " + result
);
259 GraphRequests
.prototype.getUnusedVnf = function(nsd_id
, success
, error
) {
260 var data
= new FormData();
261 data
.append('csrfmiddlewaretoken', this.getCookie('csrftoken'));
263 url
: "unusedvnf/" + nsd_id
,
265 success: function(result
) {
269 error: function(result
) {
272 log("some error: " + result
);
277 /* END ETSI methods */
279 GraphRequests
.prototype.getCookie = function(name
) {
280 var cookieValue
= null;
281 if (document
.cookie
&& document
.cookie
!== '') {
282 var cookies
= document
.cookie
.split(';');
283 for (var i
= 0; i
< cookies
.length
; i
++) {
284 var cookie
= jQuery
.trim(cookies
[i
]);
285 // Does this cookie string begin with the name we want?
286 if (cookie
.substring(0, name
.length
+ 1) === (name
+ '=')) {
287 cookieValue
= decodeURIComponent(cookie
.substring(name
.length
+ 1));
295 function args_to_formdata(args
, form_data
){
296 for ( var key
in args
) {
297 form_data
.append(key
, args
[key
]);
308 console
.log("::GraphRequests::", text
);
311 return GraphRequests
;
316 if (typeof module
=== 'object') {
317 module
.exports
= dreamer
.GraphRequests
;