Statistics
| Branch: | Tag: | Revision:

root / ui / templates / instances.html @ cf0eb36b

History | View | Annotate | Download (14.6 kB)

1
{% load i18n %}
2

    
3
<div id="instances" 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="/instances">#</a>
9
    <span class="view-seperator">|</span>
10
    <a id="list" href="/instances/list">=</a>
11
</div>
12

    
13
<div id="instancesview" 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 class="seperator"></div>
39
    </div>
40

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

    
46
<div id="instances" class="seperator"></div>
47

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

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

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

    
183
<script>
184
// <![CDATA[ 
185
var image_tags = {
186
                1: 'archlinux',
187
                2: 'centos',
188
                3: 'debian',
189
                4: 'freebsd',
190
                5: 'gentoo',
191
                6: 'netbsd',
192
                7: 'openbsd',
193
                8: 'redhat',
194
                9: 'slackware',
195
                10: 'suse',
196
                11: 'ubuntu',
197
                12: 'windows',
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
                } else {
231
                    instance.find("div.status").text('Unknown');
232
                    instance.find("img.logo").attr("src","static/machines/"+image_tags[server.imageId]+'-off.png');
233
                    instance.appendTo("div.terminated");
234
                }
235

236

237
            });
238
        }
239
    });
240

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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