Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines.html @ 8550e831

History | View | Annotate | Download (14.7 kB)

1
{% load i18n %}
2

    
3
<div id="machines" class="separator"></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-separator">|</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>
38
                                <div class="image">
39
                                    <img src="" class="image-logo"/>
40
                                    <strong class="image-title">image.title</strong>
41
                                    <input class="radio" type="radio" name="image-id" id="image-id" />
42
                                    <br />
43
                                    <span class="description">image.description</span> 
44
                                    <span class="size">?? MB</span>                              
45
                                </div>
46
                            </a>
47
                                    </label>
48
                            </li>
49
                    <ul class="pane" id="standard-images">
50
                                            <!-- standard images -->
51
                                    </ul>
52
                    <ul class="pane" id="custom-images">
53
                                            <!-- custom images -->
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
<div class="confirm_multiple">
170
    <p>{% trans "Your actions will affect XX machines" %}</p>
171
    <button class="yes">{% trans "Confirm Αll" %}</button>
172
        <button class="no">{% trans "Cancel Αll" %}</button>
173
</div>
174

    
175
<div id="machines" class="separator"></div>
176

    
177
<script>
178
// hardcoded image types
179
// TODO: get this from the metadata
180
var image_tags = {
181
                1: 'archlinux',
182
                2: 'centos',
183
                3: 'debian',
184
                4: 'freebsd',
185
                5: 'gentoo',
186
                6: 'netbsd',
187
                7: 'openbsd',
188
                8: 'redhat',
189
                9: 'slackware',
190
                10: 'suse',
191
                11: 'ubuntu',
192
                12: 'windows',
193
                20: 'ubuntu',
194
               };
195

196
// switch to list view
197
$("a#list").click(function(){
198
    list_view(); 
199
    return false;
200
});
201

202
// switch to standard view
203
$("a#standard").click(function(){
204
    standard_view();
205
    return false;
206
});
207

208
// launch VM creation wizard
209
$("a#create").click(function(){
210
    // launch wizard only if images and flavors are found
211
    if (images.length > 0  && flavors.length > 0) {
212
        $("#wizard").scrollable().begin();
213
        $("#wizard").show();
214
        $('a#create').data('overlay').load()   
215
    } else if (images.length == 0 ) {
216
        ajax_error('NO_IMAGES');
217
        return false;   
218
    } else if (flavors.length == 0) {
219
        ajax_error('NO_FLAVORS');
220
        return false;
221
    }
222
});
223

224
// create wizard overlay
225
$(function() { 
226
    $("a#create").overlay({
227
        mask: '#000', 
228
        effect: 'default', 
229
        top: '5%', 
230
        oneInstance: false,
231
        closeOnClick: false
232
    });
233
});
234

235
// wizard
236
$(function() {
237
    var root = $("#wizard").scrollable();
238
    var api = root.scrollable();
239
    // rangeinput with default configuration
240
    // validation logic is done inside the onBeforeSeek callback
241
    api.onBeforeSeek(function(event, i) {
242
            // we are going 1 step backwards so no need for validation
243
            if (api.getIndex() < i) {
244
             // 1. get current page
245
                     var page = root.find(".page").eq(api.getIndex()),
246
                         // 2. .. and all required fields inside the page
247
                         inputs = page.find(".required :input").removeClass("error"),
248
                         // 3. .. which are empty
249
                         empty = inputs.filter(function() {
250
                                return $(this).val().replace(/\s*/g, '') == '';
251
                         });
252
                     // if there are empty fields, then
253
                    if (empty.length) {
254
                            // add a CSS class name "error" for empty & required fields
255
                            empty.addClass("error");
256
                            // cancel seeking of the scrollable by returning false
257
                            return false;
258
                    // everything is good
259
                    } 
260
            }
261
            // update status bar
262
            $("#status li").removeClass("active").eq(i).addClass("active");
263
        // update confirm step
264
        if (api.getIndex()==0) {
265
            var image = $("input[type=radio][name=image-id]:checked");
266
            var imageRef = image.length ? image[0].id : false
267
            if (imageRef) {
268
                var imageName = $("label[for=" + imageRef + "] .image-title").text();
269
                $("#machine_image-label")[0].textContent = imageName;
270
                $("input[type=text][name=machine_name]")[0].value = "My " + imageName + " server";
271
            }
272
        } else if (api.getIndex()==1) {
273
            $("#machine_cpu-label")[0].textContent = $("#cpu-indicator")[0].value;
274
            $("#machine_ram-label")[0].textContent = $("#ram-indicator")[0].value;
275
            $("#machine_storage-label")[0].textContent = $("#storage-indicator")[0].value;
276
        }    
277
    });
278
    // if tab is pressed on the next button seek to next page
279
    root.find("button.next").keydown(function(e) {
280
            if (e.keyCode == 9) {
281
                    // seeks to next tab by executing our validation routine
282
                    api.next();
283
                    e.preventDefault();
284
            }
285
    });
286
});
287

288
// disable sliders in flavor selection
289
function disableSliders() {
290
    $("#cpu").attr('disabled',true);
291
    $("#ram").attr('disabled',true);
292
    $("#storage").attr('disabled',true);
293
}
294

295
// confirm all actions
296
$("div.confirm_multiple .yes").live('click', function(){
297
    while(pending_actions.length > 0){ // if there is a pending action for this server execute it
298
        action = pending_actions.pop(); // extract action
299
        var serverID = action[1];
300
        action[0]([serverID]); // execute action
301
        $('#'+serverID+' .spinner').show();
302
        $('#'+serverID+' .selected').removeClass('selected');
303
        $('#'+serverID+' .display').removeClass('display');
304
    }
305
    update_confirmations();    
306
});
307

308
// cancel all actions
309
$("div.confirm_multiple .no").live('click', function(){
310
    pending_actions = [];
311
    $('.machine .selected').removeClass('selected');
312
    $('.machine .display').removeClass('display');
313
    update_confirmations();
314
});
315

316
// selecting the small size
317
$("#small").click(function(){
318
    $("#cpu").data('rangeinput').setValue(0);
319
    $("#ram").data('rangeinput').setValue(0);
320
    $("#storage").data('rangeinput').setValue(0);
321
    $("#cpu-indicator")[0].value = cpus[0];
322
    $("#ram-indicator")[0].value = ram[0];
323
    $("#storage-indicator")[0].value = disks[0];
324
});
325

326
// selecting the medium size
327
$("#medium").click(function(){
328
    $("#cpu").data('rangeinput').setValue(1);
329
    $("#ram").data('rangeinput').setValue(1);
330
    $("#storage").data('rangeinput').setValue(1);
331
    $("#cpu-indicator")[0].value = cpus[1];
332
    $("#ram-indicator")[0].value = ram[1];
333
    $("#storage-indicator")[0].value = disks[1];    
334
});
335

336
// selecting the large size
337
$("#large").click(function(){
338
    $("#cpu").data('rangeinput').setValue(2);
339
    $("#ram").data('rangeinput').setValue(2);
340
    $("#storage").data('rangeinput').setValue(2);
341
    $("#cpu-indicator")[0].value = cpus[2];
342
    $("#ram-indicator")[0].value = ram[2];
343
    $("#storage-indicator")[0].value = disks[2];    
344
});
345

346
// selecting the custom flavor enables the sliders
347
$("#custom").click(function(){
348
    $("#cpu").attr('disabled',false);
349
    $("#ram").attr('disabled',false);
350
    $("#storage").attr('disabled',false);
351
    $("strong.sliders").style = 'color: #778899;';
352
});
353

354
// exit the wizard
355
$("#cancel").click(function(){
356
    $("a#create").overlay().close();
357
});
358

359
// starting a new VM through the wizard
360
$("#start").click(function(){
361
    var imageRef = $('input[type=radio][name=image-id]:checked')[0].id.replace('img-radio-','');   
362
    var flavorRef = identify_flavor($("#cpu-indicator")[0].value, $("#storage-indicator")[0].value, $("#ram-indicator")[0].value);
363
    var machineName = $('input[name=machine_name]')[0].value;
364
    var payload = {
365
        "server": {
366
            "name": machineName,
367
            "imageRef": imageRef,
368
            "flavorRef" : flavorRef,
369
            "metadata" : {
370
                "My Server Name" : machineName
371
            },
372
        }
373
    };
374

375
    $('a#create').data('overlay').close();
376
    $.ajax({
377
    url: "/api/v1.0/servers",
378
    type: "POST",
379
    dataType: "json",    
380
    data: JSON.stringify(payload),
381
    timeout: TIMEOUT,
382
    error: function(jqXHR, textStatus, errorThrown) { 
383
                ajax_error(jqXHR.status);
384
           },
385
    success: function(data, textStatus, jqXHR) {
386
                if ( jqXHR.status == '202') {
387
                    ajax_success("CREATE_VM_SUCCESS", data.server.adminPass);                   
388
                } else {
389
                    ajax_error(jqXHR.status);
390
                }
391
            }
392
    });
393
    $("#emptymachineslist").hide();
394

395
    try{console.warn('creating ' + $("input[name=machine_name]")[0].value)} catch(err){}
396

397
    $("#wizard").hide();
398
});
399

400
// basic functions executed on page load
401

402
// create tabs for main menu
403
$("ul.tabs").tabs("div.panes ul");
404

    
405
</script>