Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines.html @ db4da4a8

History | View | Annotate | Download (14.6 kB)

1
{% load i18n %}
2

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

    
5
<a id="create" rel="#wizard" href="#">{% trans "Create New +" %}</a>
6
<a id="notify" rel="#misc" href="#"></a>
7
<div id="view-select">
8
    <a id="standard" class="current" href="/machines">#</a>
9
    <span class="view-seperator">|</span>
10
    <a id="list" href="/machines/list">=</a>
11
</div>
12

    
13
<div id="machinesview" class="standard">
14

    
15
    <div class="instance" id="instance-template" style="display:none">
16
        <div class="state">
17
            <div class="status">{% trans "Running" %}</div>
18
            <div class="indicator"></div>
19
            <div class="indicator"></div>
20
            <div class="indicator"></div>
21
            <div class="indicator"></div>
22
        </div>
23
        <img class="logo" src="path/to/logos" />
24
        <a href="#" class="name">
25
            <h5>Hostname: <span class="name">node.name</span><span class="rename"></span></h5>
26
        </a>
27
        <a href="#" class="ip">
28
            <h5>IP: <span class="public">node.public_ip</span></h5>
29
        </a>
30
        <h5 class="settings">
31
            {% trans "Show:" %} <a href="#">{% trans "disks" %}</a> | <a href="#">{% trans "networks" %}</a> | <a href="#">{% trans "group" %}</a>
32
        </h5>
33
        <div class="actions">
34
            <a href="#" class="action">{% trans "Reboot" %}</a>
35
            <a href="#" class="action">{% trans "Shutdown" %}</a>
36
            <a href="#" class="more">{% trans "more" %} &hellip;</a>
37
        </div>
38
    </div>
39

    
40
    <div class="running"></div>
41
    <div id="mini" class="seperator"></div>
42
    <div class="terminated"></div>
43
</div>
44

    
45
<div id="machines" class="seperator"></div>
46

    
47
<!-- the form -->
48
<form action="#">
49
        <!-- scrollable root element -->
50
        <div class="modal" id="wizard">
51
                <!-- status bar -->
52
                <ul id="status">
53
                        <li class="active"><strong>1.</strong> {% trans "Image" %}</li>
54
                        <li><strong>2.</strong> {% trans "Instance" %}</li>
55
                        <li><strong>3.</strong> {% trans "Review" %}</li>
56
                </ul>
57
                <!-- scrollable items -->
58
                <div class="items">
59
                        <!-- pages -->
60
                        <div class="page">
61
                <h2>{% trans "Select an OS" %}</h2>
62
                <ul class="tabs">
63
                    <li><a href="#">{% trans "standard" %}</a></li>
64
                    <li><a href="#">{% trans "custom" %}</a></li>
65
                </ul>
66
                <div class="panes">
67
                            <li id="image-template" style="display:none">
68
                                    <label for="image.id"> 
69
                            <a><div class="image">
70
                                <img src="static/os_logos/image.logo" class="image-logo"/>
71
                                <strong class="image-title">image.title</strong>
72
                                <input class="radio" type="radio" name="image-id" id="image-id" />
73
                                <br />
74
                                <span class="description">image.description</span> 
75
                                <span class="size">?? MB</span>
76
                                
77
                            </div></a>
78
                                    </label>
79
                            </li>
80
                    <ul class="pane" id="standard-images">
81
                                            <!-- standard images -->
82
                                    </ul>
83
                    <ul class="pane" id="custom-images">
84
                                            <!-- custom images -->
85

    
86
                    </ul>
87
                </div>
88
                                <button type="button" class="prev" id="cancel">{% trans "Cancel" %}</button>
89
                                <button type="button" class="next right">{% trans "Next" %} &raquo;</button>
90
            </div>
91
                        <div class="page">
92
                                <h2>{% trans "Select CPU, RAM and storage" %}</h2>
93
                <ul>
94
                    <li>
95
                        <div class="instance-type">
96
                            <label for="small">
97
                                <input type="radio" id="small" name="instance-type" value="small" checked="true" />
98
                                <strong>{% trans "small" %}</strong>
99
                            </label>
100
                        </div>
101
                        <div class="instance-type">      
102
                            <label for="medium">
103
                                <input type="radio" id="medium" name="instance-type" value="medium" />                  
104
                                <strong>{% trans "medium" %}</strong>
105
                            </label>
106
                        </div>
107
                        <div class="instance-type">
108
                            <label for="large">
109
                                <input type="radio" id="large" name="instance-type" value="large" />
110
                                <strong>{% trans "large" %}</strong>
111
                            </label>
112
                        </div>
113
                        <div class="instance-type">
114
                            <label for="custom">
115
                                <input type="radio" name="instance-type" id="custom" value="large" />
116
                                <strong>{% trans "custom" %}</strong>
117
                            </label>
118
                        </div>
119
                    </li>
120
                    <li>
121
                                    <label><strong class="sliders">CPU (cores)</strong></label>
122
                        <input type="range" id="cpu" value="1" max="8" min="1" />
123
                    </li>
124
                    <li>
125
                                    <label><strong class="sliders">RAM (MB)</strong></label>
126
                        <input type="range" id="ram" value="256" max="2048" min="256" step="256" />
127
                    </li>
128
                    <li>
129
                                <label><strong class="sliders">Storage (GB)</strong></label>
130
                        <input type="range" id="storage" value="5" step="1" max="100" min="2" />
131
                    </li>
132
                    <li>
133
                        <div class="cost">
134
                            {% trans "Cost per hour:" %} 20 {% trans "credits" %} | {% trans "Credits currently in account:" %} 10.000
135
                        </div>
136
                    </li>
137
                </ul>
138
                                <button type="button" class="prev">&laquo; {% trans "Back" %}</button>
139
                                <button type="button" class="next right">{% trans "Next" %} &raquo;</button>
140
            </div>
141
                        <div class="page">
142
                                <h2>{% trans "Confirm your settings" %}</h2>
143
                <ul>
144
                    <li class="required">
145
                        <label>
146
                            <strong>Instance name</strong>
147
                            <input type="text" class="text" name="instance_name" value="My Ubuntu 10.04 x86_64 server"/>
148
                        </label>
149
                    </li>
150
                    <li>
151
                        <strong>{% trans "Image:" %}</strong> <span>Ubuntu 10.04 x86_64 server</span>
152
                    </li>
153
                    <li>
154
                        <strong>{% trans "CPU:" %}</strong> <span>2 cores</span>
155
                    </li>
156
                    <li>
157
                        <strong>{% trans "RAM:" %}</strong> <span>1024MB</span>
158
                    </li>
159
                    <li>
160
                        <strong>{% trans "Storage:" %}</strong> <span>10GB</span>
161
                    </li>
162
                    <li>
163
                        <strong>{% trans "Cost per hour:" %}</strong> <span>20 {% trans "credits" %}</span>
164
                    </li>
165
                    <li>
166
                        <strong>{% trans "Remaining credits:" %}</strong> <span>10.000</span>
167
                    </li>
168
                </ul>
169
                                <button type="button" class="prev">&laquo; {% trans "Back" %}</button>
170
                                <button type="button" class="next right" id="start">{% trans "Create VM" %}</button>        
171
            </div>
172
                </div>
173
        </div>
174
</form>
175

    
176
<div class="modal" id="misc">
177
    <h3>Your VM is being created!</h3>
178
    <p>{% trans "Your password is:" %}<strong> sdeEFre</strong></p>
179
    <p>{% trans "Please copy this! Without it you can not connect to your VM." %}</p>
180
</div>
181

    
182
<script>
183
// <![CDATA[ 
184
var image_tags = {
185
                1: 'archlinux',
186
                2: 'centos',
187
                3: 'debian',
188
                4: 'freebsd',
189
                5: 'gentoo',
190
                6: 'netbsd',
191
                7: 'openbsd',
192
                8: 'redhat',
193
                9: 'slackware',
194
                10: 'suse',
195
                11: 'ubuntu',
196
                12: 'windows',
197
                20: 'ubuntu',
198
               };
199

200
function update() {
201

202
    $("div.running").text('');
203
    $("div.terminated").text('');
204
    $("ul#standard-images").text('');
205
    $("ul#custom-images").text('');
206

207
    $.ajax({
208
        url: '/api/v1.0/servers/detail',
209
        type: "GET",
210
    //    async: false,
211
        dataType: "json",
212
        success: function(data) {
213
            $.each(data.servers, function(i,server){
214
                var instance = $('#instance-template').clone().attr("id",server.id).fadeIn("slow");
215
                instance.find("a.name span.name").text(server.name);
216
                instance.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'.png');
217
                instance.find("img.list-logo").attr("src","static/os_logos/"+image_tags[server.imageId]+'.png');
218
                instance.find("a.ip span.public").text(String(server.addresses.public));            
219

220
                if (server.status == 'BUILD'){
221
                    instance.find("div.status").text('Building');
222
                    instance.appendTo("div.running");
223
                } else if (server.status == 'ACTIVE') {
224
                    instance.find("div.status").text('Running');
225
                    instance.appendTo("div.running");
226
                } else if (server.status == 'SUSPENDED') {
227
                    instance.find("div.status").text('Terminated');
228
                    instance.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'-off.png');
229
                    instance.appendTo("div.terminated");
230
                    $("#mini.seperator").fadeIn("slow");
231
                } else {
232
                    instance.find("div.status").text('Unknown');
233
                    instance.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'-off.png');
234
                    instance.appendTo("div.terminated");
235
                }
236

237

238
            });
239
        }
240
    });
241

242
    $.ajax({
243
        url: '/api/v1.0/images/detail',
244
        type: "GET",
245
    //    async: false,
246
        dataType: "json",
247
        success: function(data) {
248
            $.each(data.images, function(i,image){
249
                var img = $('#image-template').clone().attr("id","img-"+image.id).fadeIn("slow");
250
                img.find("label").attr('for',"img-radio-" + image.id);
251
                img.find(".image-title").text(image.name);
252
                img.find("input.radio").attr('id',"img-radio-" + image.id);
253
                if (i==0) img.find("input.radio").attr("checked","checked"); 
254
                img.find("img.image-logo").attr('src','static/os_logos/'+image_tags[image.id]+'.png');
255
                if (image.serverId) {
256
                    img.appendTo("ul#custom-images");
257
                } else {
258
                    img.appendTo("ul#standard-images");
259
                }
260
            });
261
        }
262
    });
263
}
264
update();
265
$("#list").click(function(event){
266
    $("div.standard#machinesview").load($("#list").attr("href"));
267
    $("a#standard")[0].className += ' activelink'
268
    this.style.color = '#5f8dd3';
269
    update(); 
270
    return false;
271
});
272

273
$("a#standard").click(function(event){
274
    href=$("a#standard").attr("href");
275
    $("div.pane#machines-pane").load(href);
276
    //$("a#standard")[0].className += ' activelink'
277
    //this.style.color = '#5f8dd3';
278
    return false;
279
});
280

281
$("ul.tabs").tabs("div.panes ul");
282

283
$(":range").rangeinput({progress:true});
284

285
function disableSliders() {
286
    $("#cpu").attr('disabled',true);
287
    $("#ram").attr('disabled',true);
288
    $("#storage").attr('disabled',true);
289
}
290

291
$("#custom").click(function(event){
292
    $("#cpu").attr('disabled',false);
293
    $("#ram").attr('disabled',false);
294
    $("#storage").attr('disabled',false);
295
    $("strong.sliders").style = 'color: #778899;';
296
});
297

298
$("#small").click(function(event){
299
    $("#cpu").data('rangeinput').setValue(1);
300
    $("#ram").data('rangeinput').setValue(256);
301
    $("#storage").data('rangeinput').setValue(5);
302
});
303

304
$("#medium").click(function(event){
305
    $("#cpu").data('rangeinput').setValue(4);
306
    $("#ram").data('rangeinput').setValue(1024);
307
    $("#storage").data('rangeinput').setValue(30);
308
});
309

310
$("#large").click(function(event){
311
    $("#cpu").data('rangeinput').setValue(8);
312
    $("#ram").data('rangeinput').setValue(4096);
313
    $("#storage").data('rangeinput').setValue(80);
314
});
315

316
$("#cancel").click(function(event){
317
    $("a#create[rel]").overlay().close();
318
});
319

320
$("#start").click(function(event){
321
    var triggers = $("a#notify").overlay({
322
            // some mask tweaks suitable for modal dialogs
323
            mask: {
324
                    color: '#ebecff',
325
                    opacity: '0.9'
326
            },
327
        top: 'center',
328
            closeOnClick: false,
329
        oneInstance: false,
330
        load: true,
331
        onClose: function(event){
332
            $("div.pane#machines-pane").load($("a#standard").attr("href"));
333
        }
334
    });
335
    $("#wizard").hide();
336
    update();
337
});
338

339
$("a#create").click(function(event){
340
    $("#wizard").scrollable().begin();
341
});
342

343
$("#cpu").change(function(event){
344
    $("#custom").click();
345
});
346

347
$("#ram").change(function(event){
348
    $("#custom").click();
349
});
350

351
$("#storage").change(function(event){
352
    $("#custom").click();
353
});
354

355
$(function() { 
356
    $("a#create[rel]").overlay({mask: '#000', effect: 'default', top: '5%', oneInstance: false, closeOnClick: false});
357
});
358

359
$(function() {
360
    var root = $("#wizard").scrollable();
361

362
    // some variables that we need
363
    var api = root.scrollable();
364

365
    // rangeinput with default configuration
366
    // validation logic is done inside the onBeforeSeek callback
367
    api.onBeforeSeek(function(event, i) {
368
            // we are going 1 step backwards so no need for validation
369
            if (api.getIndex() < i) {
370
             // 1. get current page
371
                     var page = root.find(".page").eq(api.getIndex()),
372
                         // 2. .. and all required fields inside the page
373
                         inputs = page.find(".required :input").removeClass("error"),
374
                         // 3. .. which are empty
375
                         empty = inputs.filter(function() {
376
                                return $(this).val().replace(/\s*/g, '') == '';
377
                         });
378
                     // if there are empty fields, then
379
                    if (empty.length) {
380
                            // add a CSS class name "error" for empty & required fields
381
                            empty.addClass("error");
382
                            // cancel seeking of the scrollable by returning false
383
                            return false;
384
                    // everything is good
385
                    } 
386
            }
387
            // update status bar
388
            $("#status li").removeClass("active").eq(i).addClass("active");
389
    });
390

391
    // if tab is pressed on the next button seek to next page
392
    root.find("button.next").keydown(function(e) {
393
            if (e.keyCode == 9) {
394
                    // seeks to next tab by executing our validation routine
395
                    api.next();
396
                    e.preventDefault();
397
            }
398
    });
399
// ]]>
400
});
401
</script>
402