create works
This commit is contained in:
		@@ -140,33 +140,99 @@ function upload(evt) {
 | 
			
		||||
            if (evt.target.error) return error("error reading file", true);
 | 
			
		||||
            if (evt.target.readyState==0) return notice("waiting for data …");
 | 
			
		||||
            if (evt.target.readyState==1) return notice("loading data …");
 | 
			
		||||
            emit("create", evt.target.result);
 | 
			
		||||
            tobecreated = JSON.parse(evt.target.result);
 | 
			
		||||
            showCreate();
 | 
			
		||||
        }
 | 
			
		||||
        reader.readAsText(file);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var tobecreated = {};
 | 
			
		||||
function previewCreate() {
 | 
			
		||||
    var name = $('#name').val();
 | 
			
		||||
    var nodes = {};
 | 
			
		||||
    nodes[name] =  {
 | 
			
		||||
        status: docker.containers.Status.Preview,
 | 
			
		||||
        id: null,
 | 
			
		||||
        name: name,
 | 
			
		||||
        image: {
 | 
			
		||||
            name: $('#image').val(),
 | 
			
		||||
            id: null
 | 
			
		||||
        },
 | 
			
		||||
        ports: $('#createports option').map(function() {return $(this).data();}).get(),
 | 
			
		||||
        env: $('#createvars option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
        volumes: $('#createvolumes option').map(function() {return $(this).data();}).get(),
 | 
			
		||||
        volumesfrom: $('#createvolumefroms option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
        links: $('#createlinks option').map(function() {return $(this).data();}).get(),
 | 
			
		||||
        entrypoint: $('#createentrypoints option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
        cmd: $('#createcommands option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
    };
 | 
			
		||||
    console.log("PREVIEW", nodes[name]);
 | 
			
		||||
    $('#preview').html(Viz("digraph {\n"+"  rankdir="+rankdir+";\n"+docker.containers.subgraph(name, nodes)+"\n}"));
 | 
			
		||||
    var nodes = Object.create(tobecreated);
 | 
			
		||||
    if (name != '') {
 | 
			
		||||
        nodes[name] =  {
 | 
			
		||||
            status: docker.containers.Status.Preview,
 | 
			
		||||
            id: null,
 | 
			
		||||
            name: name,
 | 
			
		||||
            image: {
 | 
			
		||||
                name: $('#image').val(),
 | 
			
		||||
                id: null
 | 
			
		||||
            },
 | 
			
		||||
            ports: $('#createports option').map(function() {return $(this).data();}).get(),
 | 
			
		||||
            env: $('#createvars option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
            volumes: $('#createvolumes option').map(function() {return $(this).data();}).get(),
 | 
			
		||||
            volumesfrom: $('#createvolumefroms option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
            links: $('#createlinks option').map(function() {return $(this).data();}).get(),
 | 
			
		||||
            entrypoint: $('#createentrypoints option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
            cmd: $('#createcommands option').map(function() {return $(this).val();}).get(),
 | 
			
		||||
        };
 | 
			
		||||
        $('#doappend').unbind().click(function() {
 | 
			
		||||
            tobecreated[name] = Object.create(nodes[name]);
 | 
			
		||||
            tobecreated[name].status = docker.containers.Status.Prepared;
 | 
			
		||||
            $('#createpreview').append('<option>'+name+'</option>');
 | 
			
		||||
            $('#create form input[type=text]').val('');
 | 
			
		||||
            $('#create form select.collect option').remove();
 | 
			
		||||
            previewCreate();
 | 
			
		||||
        });
 | 
			
		||||
        $('#doremove').unbind().click(function() {
 | 
			
		||||
            $(this).siblings('#createpreview').children('option:selected').each(function(a,b,c) {
 | 
			
		||||
                delete tobecreated[b.innerHTML];
 | 
			
		||||
            }).remove();
 | 
			
		||||
            previewCreate();
 | 
			
		||||
        });
 | 
			
		||||
        $('#dosend').unbind().click(function() {
 | 
			
		||||
            if (Object.keys(tobecreated).length>0) {
 | 
			
		||||
                emit("create", docker.containers.configuration(tobecreated));
 | 
			
		||||
                tobecreated = {};
 | 
			
		||||
                showImage();
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    if ($('#image').val()!='') {
 | 
			
		||||
        var img = docker.images.get($('#image').val());
 | 
			
		||||
        if (img) {
 | 
			
		||||
            $('#portintdata').empty().append(img.ports.map(function(i) {
 | 
			
		||||
                var option =  document.createElement('option');
 | 
			
		||||
                option.value = i.replace(/\/.*/g, '');
 | 
			
		||||
                return option;
 | 
			
		||||
            }));
 | 
			
		||||
            $('#varnamedata').empty().append(img.env.map(function(i) {
 | 
			
		||||
                var option =  document.createElement('option');
 | 
			
		||||
                option.value = i.replace(/=.*/g, '');
 | 
			
		||||
                return option;
 | 
			
		||||
            }));
 | 
			
		||||
            $('#varvaluedata').empty().append(img.env.map(function(i) {
 | 
			
		||||
                var option =  document.createElement('option');
 | 
			
		||||
                option.value = i.replace(/^[^=]*=/g, '');
 | 
			
		||||
                return option;
 | 
			
		||||
            }));
 | 
			
		||||
            $('#volumeextdata').empty();
 | 
			
		||||
            $('#volumeintdata').empty();
 | 
			
		||||
            for (i in img.volumes) {
 | 
			
		||||
                var option =  document.createElement('option');
 | 
			
		||||
                option.value = i;
 | 
			
		||||
                $('#volumeextdata').append(option);
 | 
			
		||||
                $('#volumeintdata').append(option);
 | 
			
		||||
            }
 | 
			
		||||
            $('#volumesfromdata').empty().append(docker.containers.names(tobecreated).map(function(i) {
 | 
			
		||||
                var option =  document.createElement('option');
 | 
			
		||||
                option.value = i;
 | 
			
		||||
                return option;
 | 
			
		||||
            }));
 | 
			
		||||
            $('#linkcontainerdata').empty().append(docker.containers.names(tobecreated).map(function(i) {
 | 
			
		||||
                var option =  document.createElement('option');
 | 
			
		||||
                option.value = i;
 | 
			
		||||
                return option;
 | 
			
		||||
            }));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (name=='' && nodes) for (name in nodes) break;
 | 
			
		||||
    if (name && name!='') $('#preview').html(Viz("digraph {\n"+"  rankdir="+rankdir+";\n"
 | 
			
		||||
                                                 +docker.containers.subgraph(name, nodes)
 | 
			
		||||
                                                 +"\n}"));
 | 
			
		||||
    else $('#preview').html('');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function create() {
 | 
			
		||||
@@ -289,6 +355,11 @@ function stats(data) {
 | 
			
		||||
function images(i) {
 | 
			
		||||
    console.log("->rcv images");
 | 
			
		||||
    docker.images.set(i);
 | 
			
		||||
    $('#imagedata').empty().append(docker.images.tags().map(function(i) {
 | 
			
		||||
        var option =  document.createElement('option');
 | 
			
		||||
        option.value = i;
 | 
			
		||||
        return option;
 | 
			
		||||
    }));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function containers(c) {
 | 
			
		||||
@@ -490,7 +561,7 @@ function start() {
 | 
			
		||||
 | 
			
		||||
function initForms() {
 | 
			
		||||
    $('#create form *').change(previewCreate);
 | 
			
		||||
    $("#create form fieldset .add").click(function() {
 | 
			
		||||
    $("#create form fieldset .add").unbind().click(function() {
 | 
			
		||||
        $(this).siblings("select.collect")
 | 
			
		||||
            .append('<option '+$(this).siblings("input")
 | 
			
		||||
                    .map(function() {
 | 
			
		||||
@@ -516,10 +587,13 @@ function initForms() {
 | 
			
		||||
                        }
 | 
			
		||||
                        return sep+val;
 | 
			
		||||
                    }).get().join('')+'</option>');
 | 
			
		||||
        $(this).siblings("input").val();
 | 
			
		||||
        $(this).siblings("input[type=text]").val('');
 | 
			
		||||
        previewCreate();
 | 
			
		||||
    });    
 | 
			
		||||
    $("#create form fieldset .remove").unbind().click(function() {
 | 
			
		||||
        $(this).siblings('select.collect').children('option:selected').remove();
 | 
			
		||||
        previewCreate();
 | 
			
		||||
    });
 | 
			
		||||
    //$("#preview").html(Viz("digraph {\nrankdir="+rankdir+";\n"+docker.containers.graph()+"\n}"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function init() {
 | 
			
		||||
 
 | 
			
		||||
@@ -67,9 +67,15 @@ select {
 | 
			
		||||
  width: 100%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
input:invalid {
 | 
			
		||||
input:invalid, select:invalid {
 | 
			
		||||
  background-color: #FDD;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
form #name:valid ~ button#dosend, form !button#dosend ~ #createpreview:invalid, form:invalid button#doappend, input:invalid ~ button.add {
 | 
			
		||||
  opacity: .5;
 | 
			
		||||
  pointer-events: none;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
form:invalid input[type=submit] {
 | 
			
		||||
  opacity: .5;
 | 
			
		||||
  pointer-events: none;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user