|
15 | 15 | // specific language governing permissions and limitations |
16 | 16 | // under the License. |
17 | 17 | (function($, cloudStack) { |
| 18 | + var addTierDialog = function(args) { |
| 19 | + var $placeholder = args.$placeholder; |
| 20 | + var context = args.context; |
| 21 | + var addAction = cloudStack.vpc.tiers.actions.add; |
| 22 | + |
| 23 | + cloudStack.dialog.createForm({ |
| 24 | + context: context, |
| 25 | + form: addAction.createForm, |
| 26 | + after: function(args) { |
| 27 | + var $loading = $('<div>').addClass('loading-overlay') |
| 28 | + .prependTo($placeholder); |
| 29 | + |
| 30 | + addAction.action({ |
| 31 | + context: context, |
| 32 | + data: args.data, |
| 33 | + response: { |
| 34 | + success: function(args) { |
| 35 | + cloudStack.ui.notifications.add( |
| 36 | + // Notification |
| 37 | + { |
| 38 | + desc: addAction.label |
| 39 | + }, |
| 40 | + |
| 41 | + // Success |
| 42 | + function(args) { |
| 43 | + $loading.remove(); |
| 44 | + $placeholder.closest('.vpc-network-chart').trigger('reload'); |
| 45 | + }, |
| 46 | + |
| 47 | + {}, |
| 48 | + |
| 49 | + // Error |
| 50 | + function(args) { |
| 51 | + $loading.remove(); |
| 52 | + } |
| 53 | + ); |
| 54 | + }, |
| 55 | + error: function(errorMsg) { |
| 56 | + cloudStack.dialog.notice({ message: _s(errorMsg) }); |
| 57 | + $loading.remove(); |
| 58 | + } |
| 59 | + } |
| 60 | + }); |
| 61 | + } |
| 62 | + }); |
| 63 | + }; |
| 64 | + |
18 | 65 | var elems = { |
19 | 66 | tier: function(args) { |
20 | 67 | var tier = args.tier; |
|
74 | 121 | }, |
75 | 122 | dashboardItems: args.dashboardItems |
76 | 123 | }).addClass('router'); |
77 | | - |
| 124 | + |
78 | 125 | $router.find('.info, .detail-link').remove(); |
79 | 126 | $router.find('.header').prepend($('<span></span>').addClass('icon').html(' ')); |
80 | | - |
| 127 | + |
81 | 128 | return $router; |
82 | 129 | }, |
83 | 130 |
|
|
87 | 134 |
|
88 | 135 | $placeholder.append($('<span>').append('Create network')); |
89 | 136 | $placeholder.click(function() { |
90 | | - var addAction = cloudStack.vpc.tiers.actions.add; |
91 | | - var form = cloudStack.dialog.createForm({ |
| 137 | + addTierDialog({ |
92 | 138 | context: context, |
93 | | - form: addAction.createForm, |
94 | | - after: function(args) { |
95 | | - var $loading = $('<div>').addClass('loading-overlay') |
96 | | - .prependTo($placeholder); |
97 | | - |
98 | | - addAction.action({ |
99 | | - context: context, |
100 | | - data: args.data, |
101 | | - response: { |
102 | | - success: function(args) { |
103 | | - var tier = args.data; |
104 | | - |
105 | | - cloudStack.ui.notifications.add( |
106 | | - // Notification |
107 | | - { |
108 | | - desc: addAction.label |
109 | | - }, |
110 | | - |
111 | | - // Success |
112 | | - function(args) { |
113 | | - $loading.remove(); |
114 | | - $placeholder.closest('.vpc-network-chart').trigger('reload'); |
115 | | - |
116 | | - // addNewTier({ |
117 | | - // ipAddresses: ipAddresses, |
118 | | - // $browser: $browser, |
119 | | - // tierDetailView: tierDetailView, |
120 | | - // context: $.extend(true, {}, context, { |
121 | | - // networks: [tier] |
122 | | - // }), |
123 | | - // tier: tier, |
124 | | - // acl: acl, |
125 | | - // $tiers: $tiers, |
126 | | - // actions: actions, |
127 | | - // actionPreFilter: actionPreFilter, |
128 | | - // vmListView: vmListView |
129 | | - // }); |
130 | | - }, |
131 | | - |
132 | | - {}, |
133 | | - |
134 | | - // Error |
135 | | - function(args) { |
136 | | - $loading.remove(); |
137 | | - } |
138 | | - ); |
139 | | - }, |
140 | | - error: function(errorMsg) { |
141 | | - cloudStack.dialog.notice({ message: _s(errorMsg) }); |
142 | | - $loading.remove(); |
143 | | - } |
144 | | - } |
145 | | - }); |
146 | | - } |
| 139 | + $placeholder: $placeholder |
147 | 140 | }); |
148 | 141 | }); |
149 | | - |
| 142 | + |
150 | 143 | return $placeholder; |
151 | 144 | }, |
152 | 145 |
|
|
170 | 163 | } else { |
171 | 164 | $total.find('span').html(dashboardItem.total ? dashboardItem.total : 0); |
172 | 165 | } |
173 | | - |
| 166 | + |
174 | 167 | $dashboardItem.append($total, $name); |
175 | 168 | $dashboardItem.appendTo($dashboard); |
176 | 169 |
|
|
214 | 207 | var vpcChart = function(args) { |
215 | 208 | var context = args.context; |
216 | 209 | var vpcItem = context.vpc[0]; |
217 | | - |
| 210 | + |
218 | 211 | var chart = function(args) { |
219 | 212 | args = args ? args : {}; |
220 | 213 |
|
|
232 | 225 | response: { |
233 | 226 | success: function(data) { |
234 | 227 | var tiers = data.tiers; |
| 228 | + var $placeholder = elems.tierPlaceholder({ |
| 229 | + context: context |
| 230 | + }); |
235 | 231 |
|
236 | 232 | $(tiers).map(function(index, tier) { |
237 | 233 | var $tier = elems.tier({ |
238 | 234 | context: context, |
239 | 235 | tier: tier, |
240 | 236 | dashboardItems: tier._dashboardItems |
241 | 237 | }); |
242 | | - |
243 | 238 | $tier.appendTo($tiers); |
244 | 239 | }); |
245 | 240 |
|
246 | 241 | // Add placeholder tier |
247 | | - $tiers.append(elems.tierPlaceholder({ |
248 | | - context: context |
249 | | - })); |
250 | | - |
| 242 | + $tiers.append($placeholder); |
251 | 243 | $loading.remove(); |
252 | | - |
| 244 | + |
| 245 | + if (!tiers.length) { |
| 246 | + addTierDialog({ |
| 247 | + context: context, |
| 248 | + $placeholder: $placeholder |
| 249 | + }); |
| 250 | + } |
| 251 | + |
253 | 252 | if (args.complete) { |
254 | 253 | args.complete($chart); |
255 | 254 | } |
256 | | - |
| 255 | + |
257 | 256 | // Router |
258 | | - $router = elems.router({ |
| 257 | + elems.router({ |
259 | 258 | context: context, |
260 | 259 | dashboardItems: data.routerDashboard |
261 | 260 | }).appendTo($chart); |
262 | 261 | } |
263 | | - } |
| 262 | + } |
264 | 263 | }); |
265 | 264 |
|
266 | 265 | $chart.bind('reload', function() { |
267 | 266 | chart({ |
268 | 267 | complete: function($newChart) { |
269 | | - $chart.replaceWith($newChart); |
| 268 | + $chart.replaceWith($newChart); |
270 | 269 | } |
271 | 270 | }); |
272 | 271 | }); |
|
0 commit comments