Revision 993cc81d

View differences:

src/sunstone/public/js/plugins/vms-tab.js
244 244
                        {data:obj, 
245 245
                         success: function (req) {
246 246
                                Sunstone.runAction("VM.show",
247
                                                    req.request.data[0]);
247
                                                    req.request.data[0][0]);
248 248
                        },
249 249
                         error: onError });
250 250
        }
251 251
    },
252
            
252

  
253
    "VM.saveas_disks" : {
254
        type: "single",
255
        call: OpenNebula.VM.show,
256
        callback: saveasDisksCallback,
257
        error: onError,
258
        notify: false
259
    },
260

  
253 261
    "VM.shutdown" : {
254 262
        type: "multiple",
255 263
        call: OpenNebula.VM.shutdown,
......
689 697
        <form action="javascript:alert(\'js error!\');">\
690 698
            <div id="saveas_tabs">\
691 699
            </div>\
692
			<div class="form_buttons">\
693
			  <button id="vm_saveas_proceed" value="">OK</button>\
694
			  <button id="vm_saveas_cancel" value="">Cancel</button>\
695
			</div>\
700
            <div class="form_buttons">\
701
                <button id="vm_saveas_proceed" value="">OK</button>\
702
                <button id="vm_saveas_cancel" value="">Cancel</button>\
703
            </div>\
696 704
            </fieldset>\
697 705
       </form>');
698 706
       
......
711 719
            var id = $('#vm_id',this).text();
712 720
            var disk_id = $('#vm_disk_id',this).val();
713 721
            var image_name = $('#image_name',this).val();
714
            var type = $('#image_type',this).val();
722
            //var type = $('#image_type',this).val();
715 723
            
716 724
            if (!id.length || !disk_id.length || !image_name.length) {
717 725
                notifyError("Skipping VM "+id+
......
721 729
                var obj = {
722 730
                    vm_id: id,
723 731
                    disk_id : disk_id,
724
                    image_name : image_name,
725
                    type: type
732
                    image_name : image_name
733
                    //type: type
726 734
                };
727 735
                args.push(id);
728 736
                Sunstone.runAction("VM.saveas",obj);
......
755 763
        <div id="vm_id_text">Saveas for VM with ID <span id="vm_id">'+this+'</span></div>\
756 764
            <fieldset>\
757 765
            <div>\
758
                <label for="vm_disk_id">Disk id:</label>\
759
                <input type="text" id="vm_disk_id" name="vm_disk_id" value="" size="2"/>\
766
                <label for="vm_disk_id">Select disk:</label>\
767
                <select id="vm_disk_id" name="vm_disk_id">\
768
                    <option value="">Retrieving...</option>\
769
                </select>\
760 770
            </div>\
761 771
            <div>\
762 772
                <label for="image_name">Image name:</label>\
763 773
                <input type="text" id="image_name" name="image_name" value="" />\
764 774
            </div>\
775
            <!-- not used anymore\
765 776
            <div>\
766 777
                <label for="img_attr_value">Type:</label>\
767 778
                <select id="image_type" name="image_type">\
768 779
                    <option value="">Default</option>\
769
					<option value="disk">Disk</option>\
770
					<option value="floppy">Floppy</option>\
771
					<option value="cdrom">CD-ROM</option>\
772
					<option value="swap">Swap</option>\
773
					<option value="fs">FS</option>\
774
					<option value="block">Block</option>\
775
				  </select>\
780
                    <option value="disk">Disk</option>\
781
                    <option value="floppy">Floppy</option>\
782
                    <option value="cdrom">CD-ROM</option>\
783
                    <option value="swap">Swap</option>\
784
                    <option value="fs">FS</option>\
785
                    <option value="block">Block</option>\
786
                </select>\
776 787
            </div>\
788
            -->\
777 789
            </fieldset>\
778 790
        </div>';
779 791
        $('#saveas_vm_dialog #saveas_tabs').append(tab);
792
        Sunstone.runAction("VM.saveas_disks",this);
780 793
    });
781 794
    $('#saveas_vm_dialog #saveas_tabs').tabs();
782 795
    $('#saveas_vm_dialog button').button();
783
       
784 796
    $('#saveas_vm_dialog').dialog('open');
785 797
}
786 798

  
799
function saveasDisksCallback(req,response){
800
    var vm_info = response.VM;
801
    var id=vm_info.ID;
802
    var select="";
803

  
804
    var gen_option = function(id, name, source){
805
        if (name){
806
            return '<option value="'+id+'">'+name+' (disk id: '+id+')</option>';
807
        }
808
        else {
809
            return '<option value="'+id+'">'+source+' (disk id: '+id+')</option>';
810
        }
811
    }
812

  
813
    var disks = vm_info.TEMPLATE.DISK;
814
    if (!disks) { select = '<option value="">No disks defined</option>';}
815
    else if (disks.constructor == Array) //several disks
816
    {
817
        for (var i=0;i<disks.length;i++){
818
            select += gen_option(disks[i].DISK_ID,disks[i].IMAGE,disks[i].SOURCE);
819
        }
820
    } else {
821
        select+= gen_option(disks.DISK_ID,disks.IMAGE,disks.SOURCE);
822
    }
823
    //introduce options in the right tab
824
    $('#saveas_tabs #saveas_tab_'+id+' #vm_disk_id').html(select);
825

  
826
}
827

  
787 828
//Prepares autorefresh
788 829
function setVMAutorefresh(){
789 830
     setInterval(function(){

Also available in: Unified diff