Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines.html @ 146b6003

History | View | Annotate | Download (13.6 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
<script>
170
// hardcoded image types
171
// TODO: get this from the metadata
172
var image_tags = {
173
                1: 'archlinux',
174
                2: 'centos',
175
                3: 'debian',
176
                4: 'freebsd',
177
                5: 'gentoo',
178
                6: 'netbsd',
179
                7: 'openbsd',
180
                8: 'redhat',
181
                9: 'slackware',
182
                10: 'suse',
183
                11: 'ubuntu',
184
                12: 'windows',
185
                20: 'ubuntu',
186
               };
187

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

194
// switch to standard view
195
$("a#standard").click(function(){
196
    standard_view();
197
    return false;
198
});
199

200
// launch VM creation wizard
201
$("a#create").click(function(){
202
    // launch wizard only if images and flavors are found
203
    if (images.length > 0  && flavors.length > 0) {
204
        $("#wizard").scrollable().begin();
205
        $("#wizard").show();
206
        $('a#create').data('overlay').load()   
207
    } else if (images.length == 0 ) {
208
        ajax_error('NO_IMAGES');
209
        return false;   
210
    } else if (flavors.length == 0) {
211
        ajax_error('NO_FLAVORS');
212
        return false;
213
    }
214
});
215

216
// create wizard overlay
217
$(function() { 
218
    $("a#create").overlay({
219
        mask: '#000', 
220
        effect: 'default', 
221
        top: '5%', 
222
        oneInstance: false,
223
        closeOnClick: false
224
    });
225
});
226

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

280
// disable sliders in flavor selection
281
function disableSliders() {
282
    $("#cpu").attr('disabled',true);
283
    $("#ram").attr('disabled',true);
284
    $("#storage").attr('disabled',true);
285
}
286

287
// selecting the small size
288
$("#small").click(function(){
289
    $("#cpu").data('rangeinput').setValue(0);
290
    $("#ram").data('rangeinput').setValue(0);
291
    $("#storage").data('rangeinput').setValue(0);
292
    $("#cpu-indicator")[0].value = cpus[0];
293
    $("#ram-indicator")[0].value = ram[0];
294
    $("#storage-indicator")[0].value = disks[0];
295
});
296

297
// selecting the medium size
298
$("#medium").click(function(){
299
    $("#cpu").data('rangeinput').setValue(1);
300
    $("#ram").data('rangeinput').setValue(1);
301
    $("#storage").data('rangeinput').setValue(1);
302
    $("#cpu-indicator")[0].value = cpus[1];
303
    $("#ram-indicator")[0].value = ram[1];
304
    $("#storage-indicator")[0].value = disks[1];    
305
});
306

307
// selecting the large size
308
$("#large").click(function(){
309
    $("#cpu").data('rangeinput').setValue(2);
310
    $("#ram").data('rangeinput').setValue(2);
311
    $("#storage").data('rangeinput').setValue(2);
312
    $("#cpu-indicator")[0].value = cpus[2];
313
    $("#ram-indicator")[0].value = ram[2];
314
    $("#storage-indicator")[0].value = disks[2];    
315
});
316

317
// selecting the custom flavor enables the sliders
318
$("#custom").click(function(){
319
    $("#cpu").attr('disabled',false);
320
    $("#ram").attr('disabled',false);
321
    $("#storage").attr('disabled',false);
322
    $("strong.sliders").style = 'color: #778899;';
323
});
324

325
// exit the wizard
326
$("#cancel").click(function(){
327
    $("a#create").overlay().close();
328
});
329

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

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

366
    $("#wizard").hide();
367
});
368

369
// basic functions executed on page load
370

371
// create tabs for main menu
372
$("ul.tabs").tabs("div.panes ul");
373

    
374
</script>