Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines.html @ d36493ce

History | View | Annotate | Download (13.2 kB)

1
{% load i18n %}
2

    
3
<div id="machines" class="seperator"></div>
4

    
5
<!-- the create button -->
6
<a id="create" rel="#wizard" href="#">{% trans "Create New +" %}</a>
7

    
8
<!-- changing between standard/list view -->
9
<div id="view-select">
10
    <a id="standard" href="/machines/standard">#</a>
11
    <span class="view-seperator">|</span>
12
    <a id="list" href="/machines/list">=</a>
13
</div>
14

    
15
<!-- the form -->
16
<form action="#">
17
        <!-- scrollable root element -->
18
        <div class="modal" id="wizard">
19
                <!-- status bar -->
20
                <ul id="status">
21
                        <li class="active"><strong>1.</strong> {% trans "Image" %}</li>
22
                        <li><strong>2.</strong> {% trans "Machine" %}</li>
23
                        <li><strong>3.</strong> {% trans "Review" %}</li>
24
                </ul>
25
                <!-- scrollable items -->
26
                <div class="items">
27
                        <!-- pages -->
28
                        <div class="page">
29
                <h2>{% trans "Select an OS" %}</h2>
30
                <ul class="tabs">
31
                    <li><a href="#">{% trans "standard" %}</a></li>
32
                    <li><a href="#">{% trans "custom" %}</a></li>
33
                </ul>
34
                <div class="panes">
35
                            <li id="image-template" style="display:none">
36
                                    <label for="image.id"> 
37
                            <a><div class="image">
38
                                <img src="" class="image-logo"/>
39
                                <strong class="image-title">image.title</strong>
40
                                <input class="radio" type="radio" name="image-id" id="image-id" />
41
                                <br />
42
                                <span class="description">image.description</span> 
43
                                <span class="size">?? MB</span>
44
                                
45
                            </div></a>
46
                                    </label>
47
                            </li>
48
                    <ul class="pane" id="standard-images">
49
                                            <!-- standard images -->
50
                                    </ul>
51
                    <ul class="pane" id="custom-images">
52
                                            <!-- custom images -->
53

    
54
                    </ul>
55
                </div>
56
                                <button type="button" class="prev" id="cancel">{% trans "Cancel" %}</button>
57
                                <button type="button" class="next right">{% trans "Next" %} &raquo;</button>
58
            </div>
59
                        <div class="page">
60
                                <h2>{% trans "Select CPU, RAM and storage" %}</h2>
61
                <ul>
62
                    <li>
63
                        <div class="machine-type">
64
                            <label for="small">
65
                                <input type="radio" id="small" name="machine-type" value="small" checked="true" />
66
                                <strong>{% trans "small" %}</strong>
67
                            </label>
68
                        </div>
69
                        <div class="machine-type">      
70
                            <label for="medium">
71
                                <input type="radio" id="medium" name="machine-type" value="medium" />                  
72
                                <strong>{% trans "medium" %}</strong>
73
                            </label>
74
                        </div>
75
                        <div class="machine-type">
76
                            <label for="large">
77
                                <input type="radio" id="large" name="machine-type" value="large" />
78
                                <strong>{% trans "large" %}</strong>
79
                            </label>
80
                        </div>
81
                        <div class="machine-type">
82
                            <label for="custom">
83
                                <input type="radio" name="machine-type" id="custom" value="large" />
84
                                <strong>{% trans "custom" %}</strong>
85
                            </label>
86
                        </div>
87
                    </li>
88
                    <li>
89
                                    <label><strong class="sliders">CPU (cores)</strong></label>
90
                        <input type="range" id="cpu" style="display:none" />
91
                        <input type="text" class="range" id="cpu-indicator" />
92
                    </li>
93
                    <li>
94
                                    <label><strong class="sliders">RAM (MB)</strong></label>
95
                        <input type="range" id="ram" style="display:none" />
96
                        <input type="text" class="range" id="ram-indicator" />
97

    
98
                    </li>
99
                    <li>
100
                                <label><strong class="sliders">Storage (GB)</strong></label>
101
                        <input type="range" id="storage" style="display:none" />
102
                        <input type="text" class="range" id="storage-indicator" />
103

    
104
                    </li>
105
                    <li>
106
                        <div class="cost">
107
                            {% trans "Cost per hour:" %} 20 {% trans "credits" %} | {% trans "Credits currently in account:" %} 10.000
108
                        </div>
109
                    </li>
110
                </ul>
111
                                <button type="button" class="prev">&laquo; {% trans "Back" %}</button>
112
                                <button type="button" class="next right">{% trans "Next" %} &raquo;</button>
113
            </div>
114
                        <div class="page">
115
                                <h2>{% trans "Confirm your settings" %}</h2>
116
                <ul>
117
                    <li class="required">
118
                        <label>
119
                            <strong>Machine name</strong>
120
                            <input type="text" class="text" name="machine_name" value="My Ubuntu 10.04 x86_64 server"/>
121
                        </label>
122
                    </li>
123
                    <li>
124
                        <strong>{% trans "Image:" %}</strong> <span id="machine_image-label">Ubuntu 10.04 x86_64 server</span>
125
                    </li>
126
                    <li>
127
                        <strong>{% trans "CPU:" %}</strong> <span id="machine_cpu-label">2</span> <span>{% trans "cores" %}</span>
128
                    </li>
129
                    <li>
130
                        <strong>{% trans "RAM:" %}</strong> <span id="machine_ram-label">1024</span><span>MB</span>
131
                    </li>
132
                    <li>
133
                        <strong>{% trans "Storage:" %}</strong> <span id="machine_storage-label">10</span><span>GB</span>
134
                    </li>
135
                    <li>
136
                        <strong>{% trans "Cost per hour:" %}</strong> <span>20 {% trans "credits" %}</span>
137
                    </li>
138
                    <li>
139
                        <strong>{% trans "Remaining credits:" %}</strong> <span>10.000</span>
140
                    </li>
141
                </ul>
142
                                <button type="button" class="prev">&laquo; {% trans "Back" %}</button>
143
                                <button type="button" class="next right" id="start">{% trans "Create VM" %}</button>        
144
            </div>
145
                </div>
146
        </div>
147
</form>
148

    
149
<!-- notification after wizard completion -->
150
<a id="notification" rel="#error-success" href="#"></a>
151

    
152
<div class="modal" id="error-success">
153
    <h3>{% trans "Error!/Success!" %}</h3>
154
    <p>{% trans "More details about the result"%}</p>
155
</div>
156

    
157
<!-- confirmation before executing an action -->
158
<a id="confirmation" rel="#yes-no" href="#"></a>
159

    
160
<div class="modal" id="yes-no">
161
    <h3>{% trans "You are about to xxx machine yyy" %}</h3>
162
    <p>{% trans "Are you sure you want to proceed?" %}</p>
163
    <button>{% trans "Yes" %}</button>
164
        <button>{% trans "No" %}</button>
165
</div>
166

    
167
<div id="machinesview"></div>
168

    
169
<script>
170

171

172
    
173
// hardcoded image types
174
var image_tags = {
175
                1: 'archlinux',
176
                2: 'centos',
177
                3: 'debian',
178
                4: 'freebsd',
179
                5: 'gentoo',
180
                6: 'netbsd',
181
                7: 'openbsd',
182
                8: 'redhat',
183
                9: 'slackware',
184
                10: 'suse',
185
                11: 'ubuntu',
186
                12: 'windows',
187
                20: 'ubuntu',
188
               };
189

190
// switch to list view
191
$("a#list").click(function(){list_view(); return false;});
192
// switch to standard view
193
$("a#standard").click(function(){standard_view(); return false;});
194

195

196
// launch VM creation wizard
197
$("a#create").click(function(){
198
    // populate image list
199
    update_images();
200
    // configure flavors
201
    update_flavors(); 
202
    // launch the wizard
203
    $("#wizard").scrollable().begin();
204
    $("#wizard").show();
205
    $('a#create').data('overlay').load()    
206
});
207

208
// create wizard overlay
209
$(function() { 
210
    $("a#create").overlay({
211
        mask: '#000', 
212
        effect: 'default', 
213
        top: '5%', 
214
        oneInstance: false,
215
        closeOnClick: false
216
    });
217
});
218

219
// wizard
220
$(function() {
221
    var root = $("#wizard").scrollable();
222
    var api = root.scrollable();
223
    // rangeinput with default configuration
224
    // validation logic is done inside the onBeforeSeek callback
225
    api.onBeforeSeek(function(event, i) {
226
            // we are going 1 step backwards so no need for validation
227
            if (api.getIndex() < i) {
228
             // 1. get current page
229
                     var page = root.find(".page").eq(api.getIndex()),
230
                         // 2. .. and all required fields inside the page
231
                         inputs = page.find(".required :input").removeClass("error"),
232
                         // 3. .. which are empty
233
                         empty = inputs.filter(function() {
234
                                return $(this).val().replace(/\s*/g, '') == '';
235
                         });
236
                     // if there are empty fields, then
237
                    if (empty.length) {
238
                            // add a CSS class name "error" for empty & required fields
239
                            empty.addClass("error");
240
                            // cancel seeking of the scrollable by returning false
241
                            return false;
242
                    // everything is good
243
                    } 
244
            }
245
            // update status bar
246
            $("#status li").removeClass("active").eq(i).addClass("active");
247
        // update confirm step
248
        if (api.getIndex()==0) {
249
            var image = $("input[type=radio][name=image-id]:checked");
250
            var imageId = image.length ? image[0].id : false
251
            if (imageId) {
252
                var imageName = $("label[for=" + imageId + "] .image-title").text();
253
                $("#machine_image-label")[0].textContent = imageName;
254
                $("input[type=text][name=machine_name]")[0].value = "My " + imageName + " server";
255
            }
256
        } else if (api.getIndex()==1) {
257
            $("#machine_cpu-label")[0].textContent = $("#cpu-indicator")[0].value;
258
            $("#machine_ram-label")[0].textContent = $("#ram-indicator")[0].value;
259
            $("#machine_storage-label")[0].textContent = $("#storage-indicator")[0].value;
260
        }
261
        
262
    });
263

264
    // if tab is pressed on the next button seek to next page
265
    root.find("button.next").keydown(function(e) {
266
            if (e.keyCode == 9) {
267
                    // seeks to next tab by executing our validation routine
268
                    api.next();
269
                    e.preventDefault();
270
            }
271
    });
272

273
});
274

275
// disable sliders in flavor selection
276
function disableSliders() {
277
    $("#cpu").attr('disabled',true);
278
    $("#ram").attr('disabled',true);
279
    $("#storage").attr('disabled',true);
280
}
281

282
// selecting the small size
283
$("#small").click(function(){
284
    $("#cpu").data('rangeinput').setValue(0);
285
    $("#ram").data('rangeinput').setValue(0);
286
    $("#storage").data('rangeinput').setValue(0);
287
    $("#cpu-indicator")[0].value = cpus[0];
288
    $("#ram-indicator")[0].value = ram[0];
289
    $("#storage-indicator")[0].value = disks[0];
290
});
291

292
// selecting the medium size
293
$("#medium").click(function(){
294
    $("#cpu").data('rangeinput').setValue(1);
295
    $("#ram").data('rangeinput').setValue(1);
296
    $("#storage").data('rangeinput').setValue(1);
297
    $("#cpu-indicator")[0].value = cpus[1];
298
    $("#ram-indicator")[0].value = ram[1];
299
    $("#storage-indicator")[0].value = disks[1];    
300
});
301

302
// selecting the large size
303
$("#large").click(function(){
304
    $("#cpu").data('rangeinput').setValue(2);
305
    $("#ram").data('rangeinput').setValue(2);
306
    $("#storage").data('rangeinput').setValue(2);
307
    $("#cpu-indicator")[0].value = cpus[2];
308
    $("#ram-indicator")[0].value = ram[2];
309
    $("#storage-indicator")[0].value = disks[2];    
310
});
311

312
// selecting the custom flavor enables the sliders
313
$("#custom").click(function(){
314
    $("#cpu").attr('disabled',false);
315
    $("#ram").attr('disabled',false);
316
    $("#storage").attr('disabled',false);
317
    $("strong.sliders").style = 'color: #778899;';
318
});
319

320
// exit the wizard
321
$("#cancel").click(function(){
322
    $("a#create").overlay().close();
323
});
324

325
// starting a new VM through the wizard
326
$("#start").click(function(){
327
    var imageId = $('input[type=radio][name=image-id]:checked')[0].id.replace('img-radio-','');   
328
    var flavorId = identify_flavor($("#cpu-indicator")[0].value, $("#storage-indicator")[0].value, $("#ram-indicator")[0].value);
329
    var machineName = $('input[name=machine_name]')[0].value;
330
    var payload = {
331
        "server": {
332
            "name": machineName,
333
            "imageId": imageId,
334
            "flavorId" : flavorId,
335
            "metadata" : {
336
                "My Server Name" : machineName
337
            },
338
        }
339
    };
340

341
    $('a#create').data('overlay').close();
342
    $.ajax({
343
    url: "/api/v1.0/servers",
344
    type: "POST",
345
    dataType: "json",    
346
    data: JSON.stringify(payload),
347
    timeout: TIMEOUT,
348
    error: function(jqXHR, textStatus, errorThrown) { 
349
                ajax_error(jqXHR);
350
           },
351
    success: function(data, textStatus, jqXHR) {
352
                if ( jqXHR.status == '202') {
353
                    ajax_success(jqXHR);                   
354
                } else {
355
                    ajax_error(jqXHR);
356
                }
357
            }
358
    });
359
    console.warn('creating ' + $("input[name=machine_name]")[0].value)
360

361
    $("#wizard").hide();
362
});
363

364

365

366
// basic functions executed on page load
367

368
// create tabs for main menu
369
$("ul.tabs").tabs("div.panes ul");
370

    
371

    
372

    
373
</script>