Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines.html @ 71eade6b

History | View | Annotate | Download (29 kB)

1
{% load i18n %}
2

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

    
5
<!-- the create button -->
6
<div id="createcontainer">
7
    <span id="createbody">{% trans "Start by creating a new Virtual Machine:" %}</span><br />
8
    <a id="create" rel="#wizard" href="#">{% trans "Create New +" %}</a>
9
</div>
10

    
11
<!-- changing between standard/list view -->
12
<div id="view-select">
13
    <a id="standard" href="/machines/standard"></a>
14
    <a id="list" href="/machines/list"></a>
15
    <a id="single" href="#"></a>
16
</div>
17

    
18
<div id="emptymachineslist">
19
    <h1 id="welcomeheader">{% trans "Welcome to the ocean!" %}</h1>
20
    <br />
21
    <span class="welcomebody">{% trans "From this panel you will be able to manage your Virtual Machines (VMs). If you don't know what a VM is: take the " %}<a href="#">{% trans "tour" %}</a>.</span>
22
    <br />
23
    <br />
24
    <span class="welcomebody">{% trans "The panel is currently empty, because you don't have any VMs yet. You can start by creating your new VM by clicking the blue button on the right. The wizard will guide you through the hole process." %}</span>
25
    <br />
26
    <br />
27
    <span class="welcomefooter">{% trans "For more information or help, click " %}<a href="#">{% trans "here" %}</a>.</span>
28
</div>
29

    
30
<!-- the form -->
31
<form action="#">
32
        <!-- scrollable root element -->
33
        <div class="modal" id="wizard">
34
                <!-- status bar -->
35
                <ul id="status">
36
                        <li class="active">
37
                <span class="headernumber" class="first">1</span>
38
                <div class="headerbody first">{% trans "Image" %}</div>
39
            </li>
40
                        <li>
41
                <span class="headernumber">2</span>
42
                <div class="headerbody">{% trans "Flavor" %}</div>
43
            </li>
44
                        <li class="third">
45
                <span class="headernumber">3</span>
46
                <div class="headerbody">{% trans "Name" %}</div>
47
            </li>
48
                </ul>
49
                <!-- scrollable items -->
50
                <div class="items">
51
                        <!-- pages -->
52
                        <div class="page">
53
                <h2>{% trans "Select an OS" %}</h2>
54
                <hr class="topruler" />
55
                <ul class="tabs">
56
                    <li><a href="#">{% trans "system images" %}</a></li>
57
                    <li><a href="#">{% trans "custom images" %}</a></li>
58
                </ul>
59
                <div class="panes">
60
                            <li id="image-template" style="display:none">
61
                                    <label for="image.id"> 
62
                            <a>
63
                                <div class="image-container">
64
                                    <div class="image">
65
                                        <input class="radio" type="radio" name="image-id" id="image-id" />
66
                                        <img src="" class="image-logo"/>
67
                                        <strong class="image-title">image.title</strong>
68
                                        <br />
69
                                        <span class="description">image.description</span> 
70
                                        <span id="size" class="size">?? MB</span><span class="size"> MB</span>                         
71
                                    </div>
72
                                </div>  
73
                            </a>
74
                                    </label>
75
                            </li>
76
                    <ul class="pane" id="standard-images">
77
                                            <!-- standard images -->
78
                                    </ul>
79
                    <ul class="pane" id="custom-images">
80
                                            <!-- custom images -->
81
                    </ul>
82
                </div>
83
                <hr class="bottomruler" />
84
                                <button type="button" class="prev" id="cancel">{% trans "Cancel" %}</button>
85
                                <button type="button" class="next right">{% trans "Next" %}</button>
86
            </div>
87
                        <div class="page">
88
                                <h2>{% trans "Select CPUs, RAM and Disk Size" %}</h2>
89
                <hr class="topruler" />
90
                <ul>
91
                    <li id="machinetype">
92
                        <div class="machine-type">
93
                            <label for="small" id="small">
94
                                <input type="radio" id="small" name="machine-type" value="small" checked="true" />
95
                                <span class="typebody" id="small-body">{% trans "small" %}</span>
96
                            </label>
97
                        </div>
98
                        <div class="machine-type">      
99
                            <label for="medium" id="medium">
100
                                <input type="radio" id="medium" name="machine-type" value="medium" />                  
101
                                <span class="typebody" id="medium-body">{% trans "medium" %}</span>
102
                            </label>
103
                        </div>
104
                        <div class="machine-type">
105
                            <label for="large" id="large">
106
                                <input type="radio" id="large" name="machine-type" value="large" />
107
                                <span class="typebody" id="large-body">{% trans "large" %}</span>
108
                            </label>
109
                        </div>
110
                        <div class="machine-type">
111
                            <label for="custom" id="custom">
112
                                <input type="radio" name="machine-type" id="custom" value="large" />
113
                                <span class="typebody" id="custom-body">{% trans "custom" %}</span>
114
                            </label>
115
                        </div>
116
                    </li>
117
                    <div id="page2-container">
118
                        <li class="slider-container">
119
                                        <label><strong class="sliders">CPUs</strong></label>
120
                            <input type="range" id="cpu" style="display:none" />
121
                            <input type="text" class="range" id="cpu-indicator" />
122
                                        <span class="units">cores</span>
123
                        </li>
124
                        <li class="slider-container">
125
                                        <label><strong class="sliders">RAM</strong></label>
126
                            <input type="range" id="ram" style="display:none" />
127
                            <input type="text" class="range" id="ram-indicator" />
128
                                        <span class="units">MB</span>
129
                        </li>
130
                        <li class="slider-container">
131
                                    <label><strong class="sliders">Size</strong></label>
132
                            <input type="range" id="storage" style="display:none" />
133
                            <input type="text" class="range" id="storage-indicator" />
134
                                        <span class="units">GB</span>
135
                        </li>
136
                        <li>
137
                            <div class="cost">
138
                                <span> {% trans "Your wallet:" %} 10,000 Credits </span> | <span>{% trans "This setup will cost you:" %}<input type="text" id="credits-indicator" value="20" class="range" disabled="disabled" /> {% trans "C/hour" %}</span>
139
                            </div>
140
                        </li>
141
                    </div>
142
                </ul>
143
                <hr class="bottomruler" />
144
                                <button type="button" class="prev">{% trans "Back" %}</button>
145
                                <button type="button" class="next right">{% trans "Next" %}</button>
146
            </div>
147
                        <div class="page">
148
                                <h2>{% trans "Confirm your settings" %}</h2>
149
                <hr class="topruler" />
150
                <ul id="page3-container">
151
                    <li class="required" id="label-name">
152
                        <label>
153
                            <strong>Name:</strong>
154
                            <input type="text" class="text" name="machine_name" id="name" value="My Ubuntu 10.04 x86_64 server"/>
155
                        </label>
156
                    </li>
157
                    <li>
158
                        <span>{% trans "Image:" %}</span> <span id="machine_image-label">Ubuntu 10.04 x86_64 server</span>
159
                    </li>
160
                    <li>
161
                        <span>{% trans "CPUs:" %}</span> <span id="machine_cpu-label">2</span> <span>{% trans "cores" %}</span>
162
                    </li>
163
                    <li>
164
                        <span>{% trans "RAM:" %}</span> <span id="machine_ram-label">1024</span><span>MB</span>
165
                    </li>
166
                    <li>
167
                        <span>{% trans "System Disk:" %}</span> <span id="machine_storage-label">10</span><span>GB</span>
168
                    </li>
169
                    <li>
170
                        <span>{% trans "Cost per Hour:" %}</span> <span>40 {% trans "credits" %}</span>
171
                    </li>
172
                    <li>
173
                        <span>{% trans "Credits in Wallet:" %}</span> <span>10.000</span>
174
                    </li>
175
                </ul>
176
                <hr class="bottomruler" />
177
                                <button type="button" class="prev">{% trans "Back" %}</button>
178
                                <button type="button" class="next right" id="start">{% trans "Create VM" %}</button>        
179
            </div>
180
                </div>
181
        </div>
182
</form>
183

    
184
<!-- base notification for error/success reporting -->
185
<a id="notification" rel="#error-success" href="#"></a>
186

    
187
<div class="modal" id="error-success">
188
    <h3>{% trans "Error!/Success!" %}</h3>
189
    <div><p>{% trans "More details about the result"%}</p></div>
190
</div>
191

    
192
<!-- metadata scrollable -->
193
<div>
194
    <!-- root element for scrollable -->
195
    <div id="metadata-wizard">
196

    
197
        <!-- root element for the items -->
198
        <div class="items">
199
            <div class="page" id="edit-dialog">
200
                <div class='container'>
201
                    <h3>
202
                        <label>{% trans "Tags for machine:" %}</label>
203
                        <span>Server name</span>
204
                        <p style='display:none;'>hidden server id</p>
205
                    </h3>
206
                    <hr class="topruler" />
207
                    <hr class="fatruler" />
208
                    <div class="content">
209
                        <ul class="meta-template" style="display:none">
210
                            <li>
211
                                <label>{% trans "Key" %}</label>
212
                                <button type="button" class="remove">{% trans "remove x" %}</button>
213
                                <hr class="meta-separator">
214
                                <p>{% trans "Value" %}</p>
215
                                <button type="button" class="edit">{% trans "edit" %}</button>
216
                            </li>
217
                        </ul>
218
                        <ul class="meta-list">
219
                        </ul>
220
                    </div>
221
                </div>
222
                <button type="button" class="create next browse right">{% trans "Create New+" %}</button>
223
                <div class="bottomruler"></div>
224
            </div>
225
            <div class="page" id="add-dialog">
226
                <div class='container'>
227
                    <h3>
228
                        <label>{% trans "Tags for machine:" %}</label>
229
                        <span>Server name</span>
230
                        <p style='display:none;'>hidden server id</p>
231
                    </h3>
232
                    <hr class="topruler" />
233
                    <hr class="fatruler" />
234
                    <div class="content">
235
                        <label class="meta-key">{% trans "Key:" %}</label>
236
                        <input type="text" maxlength="15" class="key" value="{% trans 'max 15 characters' %}"/>
237
                        <hr class="meta-separator">
238
                        <label class="meta-value">{% trans "Value:" %}</label>
239
                        <textarea class="value">{% trans "max 150 characters" %}</textarea>
240
                    </div>
241
                </div>
242
                <button type="button" class="cancel prev browse left">{% trans "Cancel" %}</button>
243
                <button type="button" class="save">{% trans "Save" %}</button>
244
                <div class="bottomruler"></div>
245
            </div>
246
        </div>
247
    </div>
248
</div>
249

    
250
<a id="metadata-scrollable" href="#" rel="#metadata-wizard"></a>
251

    
252
<div id="machinesview"></div>
253

    
254
<div class="confirm_multiple">
255
    <p>{% trans "Your actions will affect" %} <span class="actionLen">XX</span> {% trans "machines" %}</p>
256
    <button class="yes">{% trans "Confirm All" %}</button>
257
        <button class="no">{% trans "Cancel All" %}</button>
258
</div>
259

    
260
<div id="machines" class="separator"></div>
261

    
262
<script>
263

264
//add hover to labels
265
$('span.typebody').mouseover(function() {
266
    $(this).addClass('typehover');
267
});
268
$('span.typebody').mouseout(function() {
269
    $(this).removeClass('typehover');
270
});
271

272
// return value from metadata key "OS", if it exists
273
function os_icon(metadata) {
274
    if (!metadata) {
275
        return 'unknown';
276
    }
277

278
    if (metadata.values.OS == undefined || metadata.values.OS == '') {
279
        return 'unknown';
280
    } else {
281
        if (UrlExists("static/machines/" + metadata.values.OS + '-on.png')) {
282
            return metadata.values.OS;
283
        } else {
284
            return 'unknown';
285
        }
286
    }
287
} 
288

289
//helper function to check file existance
290
function UrlExists(url)
291
{
292
    var http = new XMLHttpRequest();
293
    http.open('HEAD', url, false);
294
    http.send();
295
    return http.status!=404;
296
}
297

298
// switch to list view
299
$("a#list").click(function(){
300
    list_view(); 
301
    return false;
302
});
303

304
// switch to standard view
305
$("a#standard").click(function(){
306
    standard_view();
307
    return false;
308
});
309

310
// launch VM creation wizard
311
$("a#create").click(function(){
312
    // launch wizard only if images and flavors are found
313
    if (images.length > 0  && flavors.length > 0) {
314
        $("#wizard").scrollable().begin();
315
        $("#wizard").show();
316
        $('a#create').data('overlay').load()   
317
    } else if (images.length == 0 ) {
318
        ajax_error('NO_IMAGES');
319
        return false;   
320
    } else if (flavors.length == 0) {
321
        ajax_error('NO_FLAVORS');
322
        return false;
323
    }
324
});
325

326
// create wizard overlay
327
$(function() { 
328
    $("a#create").overlay({
329
        mask: '#000', 
330
        effect: 'default', 
331
        top: '5%', 
332
        oneInstance: false,
333
        closeOnClick: false
334
    });
335
});
336

337
// wizard
338
$(function() {    
339
    var root = $("#wizard").scrollable();
340
    var api = root.scrollable();
341
    // rangeinput with default configuration
342
    // validation logic is done inside the onBeforeSeek callback
343
    api.onBeforeSeek(function(event, i) {
344
            // we are going 1 step backwards so no need for validation
345
            if (api.getIndex() < i) {
346
             // 1. get current page
347
                     var page = root.find(".page").eq(api.getIndex()),
348
                         // 2. .. and all required fields inside the page
349
                         inputs = page.find(".required :input").removeClass("error"),
350
                         // 3. .. which are empty
351
                         empty = inputs.filter(function() {
352
                                return $(this).val().replace(/\s*/g, '') == '';
353
                         });
354
                     // if there are empty fields, then
355
                    if (empty.length) {
356
                            // add a CSS class name "error" for empty & required fields
357
                            empty.addClass("error");
358
                            // cancel seeking of the scrollable by returning false
359
                            return false;
360
                    // everything is good
361
                    } 
362
            } 
363
        // update confirm step
364
        if (api.getIndex()==0) {
365
            var image = $("input[type=radio][name=image-id]:checked");
366
            var imageRef = image.length ? image[0].id : false
367
            if (imageRef) {
368
                var imageName = $("label[for=" + imageRef + "] .image-title").text();
369
                $("#machine_image-label")[0].textContent = imageName;
370
                $("input[type=text][name=machine_name]")[0].value = "My " + imageName + " server";
371
            }
372
        } else if (api.getIndex()==1) {
373
            $("#machine_cpu-label")[0].textContent = $("#cpu-indicator")[0].value;
374
            $("#machine_ram-label")[0].textContent = $("#ram-indicator")[0].value;
375
            $("#machine_storage-label")[0].textContent = $("#storage-indicator")[0].value;
376
        }   
377
    });
378
    api.onSeek(function(event, i) {
379
            // update status bar
380
            $("#status li").removeClass("active").eq(i).addClass("active");
381
    });
382
    // if tab is pressed on the next button seek to next page
383
    $(root).live('keydown', function (e) {
384
       if ( e.keyCode == 9 ){
385
           if(e.preventDefault) {
386
               e.preventDefault();
387
           }
388
           api.next();
389
        }
390
    });
391
    //submit wizard by pressing enter on the name textbox
392
    $("#name").keypress(function (e) {
393
                if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
394
                        $('#start').click();
395
                        return false;
396
                } else {
397
                        return true;
398
                }
399
    });
400
});
401

402
// disable sliders in flavor selection
403
function disableSliders() {
404
    $("#cpu").attr('disabled',true);
405
    $("#ram").attr('disabled',true);
406
    $("#storage").attr('disabled',true);
407
}
408

409
//update radio button when clicking on text
410
$("#small-body").live('click' ,function() { 
411
    $(this).parent().find("#small").click();
412
});
413
$("#medium-body").live('click' ,function() { 
414
    $(this).parent().find("#medium").click();
415
});
416
$("#large-body").live('click' ,function() { 
417
    $(this).parent().find("#large").click();
418
});
419
$("#custom-body").live('click' ,function() { 
420
    $(this).parent().find("#custom").click();
421
});
422

423
//select image div on radio button select
424
$('.radio').live('click' ,function() {           
425
    $(this).parents("div").find(".image").removeClass('selecteddiv');
426
    if($(this).is(':checked'))  {
427
        $(this).parent().addClass('selecteddiv');
428
    }
429
    
430
});
431

432
// validate cpu input box
433
$("#cpu-indicator").live('change',function(){
434
    var v = Number(this.value);
435
    var i = cpus.indexOf(v);
436
    if (isNaN(v)) {
437
        $(this).value = cpus[0];
438
        $("#cpu").data('rangeinput').setValue(0);
439
    } else if (i == -1) {
440
        for (var j=0; j < cpus.length; j++)
441
            if (v<cpus[j])
442
                break;
443
        $("#cpu").data('rangeinput').setValue(j);
444
    } else {
445
        $("#cpu").data('rangeinput').setValue(i);
446
    }   
447
    return false;
448
});
449

450
// validate ram input box
451
$("#ram-indicator").live('change',function(){
452
    var v = Number(this.value);
453
    var i = ram.indexOf(v);
454
    if (isNaN(v)) {
455
        $(this).value = cpus[0];
456
        $("#ram").data('rangeinput').setValue(0);
457
    } else if (i == -1) {
458
        for (var j=0; j < ram.length; j++)
459
            if (v<ram[j])
460
                break;
461
        $("#ram").data('rangeinput').setValue(j);
462
    } else {
463
        $("#ram").data('rangeinput').setValue(i);
464
    }   
465
    return false;
466
});
467

468
// validate storage input box
469
$("#storage-indicator").live('change',function(){
470
    var v = Number(this.value);
471
    var i = disks.indexOf(v);
472
    if (isNaN(v)) {
473
        $(this).value = disks[0];
474
        $("#storage").data('rangeinput').setValue(0);
475
    } else if (i == -1) {
476
        for (var j=0; j < disks.length; j++)
477
            if (v<disks[j])
478
                break;
479
        $("#storage").data('rangeinput').setValue(j);
480
    } else {
481
        $("#storage").data('rangeinput').setValue(i);
482
    }   
483
    return false;
484
});
485

486
// selecting the small size
487
$("#small").click(function(){
488
    $("#cpu").data('rangeinput').setValue(0);
489
    $("#ram").data('rangeinput').setValue(0);
490
    $("#storage").data('rangeinput').setValue(0);
491
    $("#cpu-indicator")[0].value = cpus[0];
492
    $("#ram-indicator")[0].value = ram[0];
493
    $("#storage-indicator")[0].value = disks[0];
494
    $("#small").addClass("active");
495
    $("#medium").removeClass("active");    
496
    $("#large").removeClass("active");    
497
    $("#custom").removeClass("active");    
498
});
499

500
// selecting the medium size
501
$("#medium").click(function(){
502
    $("#cpu").data('rangeinput').setValue(1);
503
    $("#ram").data('rangeinput').setValue(1);
504
    $("#storage").data('rangeinput').setValue(1);
505
    $("#cpu-indicator")[0].value = cpus[1];
506
    $("#ram-indicator")[0].value = ram[1];
507
    $("#storage-indicator")[0].value = disks[1];  
508
    $("#medium").addClass("active");  
509
    $("#small").removeClass("active");    
510
    $("#large").removeClass("active");    
511
    $("#custom").removeClass("active");  
512
});
513

514
// selecting the large size
515
$("#large").click(function(){
516
    $("#cpu").data('rangeinput').setValue(2);
517
    $("#ram").data('rangeinput').setValue(2);
518
    $("#storage").data('rangeinput').setValue(2);
519
    $("#cpu-indicator")[0].value = cpus[2];
520
    $("#ram-indicator")[0].value = ram[2];
521
    $("#storage-indicator")[0].value = disks[2];   
522
    $("#large").addClass("active"); 
523
    $("#medium").removeClass("active");    
524
    $("#small").removeClass("active");    
525
    $("#custom").removeClass("active");  
526
});
527

528
// selecting the custom flavor enables the sliders
529
$("#custom").click(function(){
530
    $("#cpu").attr('disabled',false);
531
    $("#ram").attr('disabled',false);
532
    $("#storage").attr('disabled',false);
533
    $("strong.sliders").style = 'color: #778899;';
534
    $("#custom input").attr('checked', 'checked');                
535
    $("#custom").addClass("active"); 
536
    $("#medium").removeClass("active");    
537
    $("#large").removeClass("active");    
538
    $("#small").removeClass("active");  
539
});
540

541
//when textbox gains focus, add selection in css
542
$('#cpu-indicator').focus(function() {
543
    $(this).addClass('selectedrange');
544
});
545
$('#ram-indicator').focus(function() {
546
    $(this).addClass('selectedrange');
547
});
548
$('#storage-indicator').focus(function() {
549
    $(this).addClass('selectedrange');
550
});
551

552
//when textbox loses focus, clear selection in css
553
$('#cpu-indicator').blur(function() {
554
    $(this).removeClass('selectedrange');
555
});
556
$('#ram-indicator').blur(function() {
557
    $(this).removeClass('selectedrange');
558
});
559
$('#storage-indicator').blur(function() {
560
    $(this).removeClass('selectedrange');
561
});
562

563
// exit the wizard
564
$("#cancel").click(function(){
565
    $("a#create").overlay().close();
566
});
567

568
// starting a new VM through the wizard
569
$("#start").click(function(){
570
    var imageRef = $('input[type=radio][name=image-id]:checked')[0].id.replace('img-radio-','');   
571
    var flavorRef = identify_flavor($("#cpu-indicator")[0].value, $("#storage-indicator")[0].value, $("#ram-indicator")[0].value);
572
    var machineName = $('input[name=machine_name]')[0].value;
573
    if (jQuery.trim(machineName) == ''){
574
        return false;
575
    }
576
    create_vm(machineName, imageRef, flavorRef);
577

578
    $('a#create').data('overlay').close();
579

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

582
    $("#wizard").hide();
583
});
584

585
// metadata wizard
586
$(function() {
587
        // initialize scrollable
588
    $("#metadata-wizard").scrollable();
589
    // create wizard overlay
590
    $("a#metadata-scrollable").overlay({
591
        mask: '#000',
592
        effect: 'default',
593
        top: '10%',
594
        closeOnClick: false,
595
        oneInstance: false,
596
        load: false,
597
        onClose: function(){
598
            // reset input areas
599
            $("#metadata-wizard input.key").removeClass("input-enabled");
600
            $("#metadata-wizard input.key")[0].value = 'max 15 characters';
601
            $("#metadata-wizard textarea.value").removeClass("input-enabled");
602
            $("#metadata-wizard textarea.value")[0].value = 'max 150 characters';
603
        }
604
    });
605
});
606

607
// bring up metadata scrollable
608
function show_metadata_wizard() {
609
    // get metadata for current server and fill the dialog
610
    serverID = $("#edit-dialog h3 p").text();
611
    get_metadata(serverID);
612
    $("#metadata-wizard").scrollable().begin();
613
    $("#metadata-wizard").show();
614
    $("a#metadata-scrollable").data('overlay').load();
615
    return false; 
616
}
617

618
// update metadata list
619
function list_metadata(data) {    
620
    // empty the list if it already exists
621
    $("#edit-dialog div.content ul.meta-list").empty();
622
    // get the values to show
623
    meta = data.metadata.values;
624
    // show values
625
    for (key in meta) {
626
        pair = $("ul.meta-template li").clone();
627
        //truncate metadata
628
        pair.find("label").text(key.substring(0,15));
629
        if (meta[key].length > 25) {
630
            pair.find("p").text(meta[key].substring(0,25) + "...");
631
        } else {
632
            pair.find("p").text(meta[key]);            
633
        }
634
        pair.appendTo("#edit-dialog div.content ul.meta-list").fadeIn();
635
    }
636
}
637

638
// trapping keydown event
639
jQuery.expr[':'].focus = function( elem ) {
640
  return elem === document.activeElement && ( elem.type || elem.href );
641
};
642

643
$('*').keydown(function (){
644
    if ($('#add-dialog').is(":visible") && !($('input.key').is(':focus') || $('textarea.value').is(':focus'))){
645
        $('input.key').focus();
646
        $('input.key').focusin();         
647
    }
648
    return true;
649
});
650

651
// intercept click on remove button in metadata edit dialog
652
$('#edit-dialog button.remove').live('click', function() { 
653
    // get the server id and meta key needed for the ajax call   
654
    var serverID = $(this).closest('div.container').find('h3 p').text();
655
    var meta_key = $(this).parent().find('label').text();
656
    // make the ajax call and list the new GET results
657
    delete_metadata(serverID, meta_key);
658
    return false;
659
});
660

661
// intercept click on edit button in metadata edit dialog
662
$('#edit-dialog.meta-modal button.edit').click( function(){
663
    // inline editing of selected key-value pair
664
    // on submission ajax call from updating
665
    // on success update the overlay
666
    // TODO
667
});
668

669
// intercept create metadata key focus
670
$("#metadata-wizard input.key").live('focusin', function() {
671
    if ($(this).hasClass("input-enabled")) {
672
    } else {
673
        $("#metadata-wizard input.key").addClass("input-enabled"); 
674
        $(this).addClass("input-enabled"); 
675
        this.value = '';
676
    }
677
    return false;
678
});
679

680
// intercept create metadata key focus out
681
$("#metadata-wizard input.key").live('focusout', function() {
682
    if (this.value == "") {
683
        $(this).removeClass("input-enabled"); 
684
        this.value = 'max 15 characters';
685
    }
686
    return false;
687
});
688

689
// intercept create metadata key focus
690
$("#metadata-wizard textarea.value").live('focusin', function() {
691
    if ($(this).hasClass("input-enabled")) {
692
    } else {
693
        $("#metadata-wizard textarea.value").addClass("input-enabled"); 
694
        $(this).addClass("input-enabled"); 
695
        this.value = '';
696
    }
697
    return false;
698
});
699

700
// intercept create metadata key focus out
701
$("#metadata-wizard textarea.value").live('focusout', function() {
702
    if (this.value == "") {
703
        $(this).removeClass("input-enabled"); 
704
        this.value = 'max 150 characters';
705
    }
706
    return false;
707
});
708

709
// intercept click on save button in metadata add dialog
710
$('#add-dialog button.save').live('click', function() {
711
    // if both fields are filled in     
712
    if ($('input.key').hasClass("input-enabled") && $('textarea.value').hasClass("input-enabled")) {
713
        // get the server id, meta key and meta value needed for the ajax call     
714
        var serverID = $(this).parent().find('h3 p').text();
715
        var meta_key = $(this).parent().find('input.key').attr('value');
716
        var meta_value = $(this).parent().find('textarea.value')[0].value;
717
        // make the ajax call and list the new GET results
718
        add_metadata(serverID, meta_key, meta_value);
719
        // go to previous step
720
        $('#add-dialog button.prev').click();
721
    } else {
722
        // find which field is not filled in and focus there
723
        if (!$('input.key').hasClass("input-enabled")) {
724
            $('input.key').focus();
725
            $('input.key').focusin();
726
        } else {
727
            $('textarea.value').focus();
728
            $('textarea.value').focusin();
729
        }
730
    }
731
    return false;
732
});
733

734
// confirm all actions
735
$("div.confirm_multiple .yes").live('click', function(){
736
    while(pending_actions.length > 0){ // if there is a pending action for this server execute it
737
        action = pending_actions.pop(); // extract action
738
        var serverID = action[1];
739
        if ($.cookie("list") != '1') { // standard view
740
            $('#' + serverID + ' .selected').removeClass('selected');
741
            $('#' + serverID + ' .display').removeClass('display');
742
            if (action[0] == shutdown) {
743
                $('#' + serverID + ' .status').text('Shutting down');
744
            } else if (action[0] == start) {
745
                $('#' + serverID + ' .status').text('Starting');
746
            } else if (action[0] == reboot) {
747
                $('#' + serverID + ' .status').text('Rebooting');
748
            } else if (action[0] == destroy) {
749
                $('#' + serverID + ' .status').text('Destroying');
750
            }
751
            $('#' + serverID + ' .spinner').show();
752
        } else { // list view
753
            osIcon = $('#'+serverID).parent().parent().find('.list-logo');
754
            osIcon.attr('os',osIcon.attr('src'));
755
            osIcon.attr('src','static/progress.gif');
756
            if (action[0] == shutdown) {
757
                $('#' + serverID).parent().parent().find('span.status').text('Shutting down');
758
            } else if (action[0] == start) {
759
                $('#' + serverID).parent().parent().find('span.status').text('Starting');
760
            } else if (action[0] == reboot) {
761
                $('#' + serverID).parent().parent().find('span.status').text('Rebooting');
762
            } else if (action[0] == destroy) {
763
                $('#' + serverID).parent().parent().find('span.status').text('Destroying');
764
            }
765
        }
766
        action[0]([serverID]); // execute action
767
    }
768
    update_confirmations();    
769
});
770

771
// cancel all actions
772
$("div.confirm_multiple .no").live('click', function(){
773
    pending_actions = [];
774
    $('.machine .selected').removeClass('selected');
775
    $('.machine .display').removeClass('display');
776
    update_confirmations();
777
});
778

779
// basic functions executed on page load
780
if (images.length > 0) {
781
    // populate image list
782
    update_wizard_images();
783
}
784
if (flavors.length > 0) {
785
    // configure flavors
786
    update_wizard_flavors(); 
787
}
788
// create tabs for main menu
789
$("ul.tabs").tabs("div.panes ul");
790

    
791
</script>