Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / launchpad / src / virtual_links / nsVirtualLinkCreateSource.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 import NSVirtualLinkCreateActions from './nsVirtualLinkCreateActions.js';
19 import $ from 'jquery';
20 var Utils = require('utils/utils.js');
21 let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
22 let HOST = API_SERVER;
23 let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
24 let DEV_MODE = require('utils/rw.js').getSearchParams(window.location).dev_mode || false;
25
26 if (DEV_MODE) {
27 HOST = window.location.protocol + '//' + window.location.hostname;
28 }
29
30
31 export default {
32 createVirtualLink() {
33 return {
34 remote(state, nsrId, payload) {
35 return new Promise(function(resolve, reject) {
36 $.ajax({
37 url: 'api/nsr/' + nsrId + '/vld' + '?api_server=' + API_SERVER,
38 type: 'POST',
39 beforeSend: Utils.addAuthorizationStub,
40 dataType:'json',
41 data: payload,
42 success: function(data) {
43 resolve(data);
44 },
45 error: function(error) {
46 console.log("There was an error creating the virtual link: ", error);
47 return reject();
48 }
49 });
50 })
51 },
52 loading: NSVirtualLinkCreateActions.createVirtualLinkLoading,
53 success: NSVirtualLinkCreateActions.createVirtualLinkSuccess,
54 error: NSVirtualLinkCreateActions.createVirtualLinkError
55 }
56 },
57 deleteVirtualLink() {
58 return {
59 remote(state, nsrId, vldId) {
60 return new Promise(function(resolve, reject) {
61 $.ajax({
62 url: 'api/nsr/' + nsrId + '/vld/' + vldId + '?api_server=' + API_SERVER,
63 type: 'DELETE',
64 beforeSend: Utils.addAuthorizationStub,
65 success: function(data) {
66 resolve(data);
67 },
68 error: function(error) {
69 console.log("There was an error deleting the virtual link: ", error);
70 return reject();
71 }
72 });
73 })
74 },
75 loading: NSVirtualLinkCreateActions.deleteVirtualLinkLoading,
76 success: NSVirtualLinkCreateActions.deleteVirtualLinkSuccess,
77 error: NSVirtualLinkCreateActions.deleteVirtualLinkError
78 }
79 },
80 editVirtualLink() {
81 return {
82 remote(state, nsrId, vldId, vld) {
83 return new Promise(function(resolve, reject) {
84 $.ajax({
85 url: 'api/nsr/' + nsrId + '/vld/' + vldId + '?api_server=' + API_SERVER,
86 type: 'PUT',
87 beforeSend: Utils.addAuthorizationStub,
88 dataType:'json',
89 data: vld,
90 success: function(data) {
91 resolve(data);
92 },
93 error: function(error) {
94 console.log("There was an error editing the virtual link: ", error);
95 return reject();
96 }
97 });
98 })
99 },
100 loading: NSVirtualLinkCreateActions.editVirtualLinkLoading,
101 success: NSVirtualLinkCreateActions.editVirtualLinkSuccess,
102 error: NSVirtualLinkCreateActions.editVirtualLinkError
103 }
104 }
105
106 }