3
Class Piso
and class Consola
/**
* Classe Piso
* contem um numero piso
*/
function Piso(id) {
this.id = id;
}
/**
* Classe Consola
* contem uma lista de pisos
*/
function Consola(nome) {
this.nome = nome;
this.indice= -1;
this.pisos = [];
}
function to insert a piso
in consola
/**
* Função para inserir um piso
* entrada: numero
* saida: -
*/
Consola.prototype.inserirPiso = function () {
//cria o piso apartir de zero
var novo = new Piso(this.indice++);
//adiciona na lista de compartimentos
this.pisos.push(novo);
};
/**
* Função para remover um piso
* entrada: numero
* saida: -
*/
Consola.prototype.remover = function (base) {
while (base.firstChild != undefined) {
base.removeChild(base.firstChild);
}
}
/**
* Função para inserir um piso
* entrada: numero
* saida: -
*/
Consola.prototype.criarPiso = function criarPiso() {
var div = document.createElement("div");
var btnCriar = document.createElement("button");
var btnCriarText = document.createTextNode("Criar");
btnCriar.appendChild(btnCriarText);
//cria o evento
btnCriar.onclick = function () {
//inserir Piso
inserirPiso();
}
div.appendChild(btnCriar);
this.visualizacao.appendChild(div);
};
/**
* Função para remover um piso
* entrada: numero
* saida: -
*/
Consola.prototype.removerPiso = function (indice) {
var div = document.createElement("div");
var btnApagar = document.createElement("button");
var btnApagarText = document.createTextNode("Apagar");
btnApagar.appendChild(btnApagarText);
//cria o evento
btnApagar.onclick = function () {
//remover Piso
remover(indice);
}
div.appendChild(btnApagar);
this.visualizacao.appendChild(div);
};
/**
* Função para criar novo Checkbox
* entrada: nome e id
* saida: novo Checkbox
*/
function criarCheckbox(nome, id) {
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.nome = nome;
checkbox.id = id;
return checkbox;
}
/**
* Função para ver todos piso com checkbox
* entrada:
* saida: todos os pisos criados
*/
Consola.prototype.verTodosPisos = function () {
for (var i = 0; i < this.pisos.length; i++) {
if (this.pisos[i] !== undefined) {
this.visualizacao.appendChild(criarCheckbox("Piso" + this.pisos[i].id, this.pisos[i].id));
}
}
};
/**
* Função para ver um piso
* entrada: indice do piso
* saida: piso
*/
Consola.prototype.verPiso = function (indice) {
for (var i = 0; i < this.pisos.length; i++) {
if (this.pisos[i].id === indice)
return this.pisos[i];
}
return false;
};
my doubt is when I try to create the Piso
through DOM
does not even show the button
created and also by calling the window.unload
shows nothing on the screen
I think now just missing the function to show the console on the screen
function that will be executed when the page is fully loaded.
window.onload = function () {
//chama criar piso e nao mostra nenhum dados da consola
criarPiso();
}
my goal is to implement that when testing, it would have to be more or less, as shown in the figure,
thank you and I forgot to mention the
checkbox
should be dynamic usingDOM
– Renata P Souza
@Renatapsouza, do you have only one Console? Or several too?
– Tobias Mesquita
@TobyMosque
are various consoles and the goal, it is intended that the program can handle numerous consoles and can create independent consoles to control groups of compartments (eg: have floors and attachments).– Renata P Souza
@TobyMosque
, I think I misexplained the doubt and from what I’ve been examining, I’m wrong about the doubt, the image above is a console with two floors created and to delete would have to select one of them through the checkbox and then confirm type when delete a comment on the forum, that is, the first page will be as shown on the link [http://imgur.com/jh2WIQn ] and as I was going to create the floor, I was going to create an element checkbox to serve as a floor id and sorry it was bad my doubt.– Renata P Souza
@Renatapsouza, updated response.
– Tobias Mesquita
@TobyMosque
, I’ve already solved it and thank you very much, thank you very much,– Renata P Souza
@TobyMosque
, only one question remains whether it is possible to view the contents of the floor within itcontainer
where theconsolas
created, because thepiso
visualized containscompartimentos
kitchen and living room types that have not been introduced in doubt– Renata P Souza
@Renatapsouza, it is possible, either by changing the label of the checkbox, creating a menu or even a dialog. To give you a more complete answer, you would have to see the layout you are trying to assemble
– Tobias Mesquita