Boa tarde,
Criei um formulário para registro de Ordens de Serviços e um dataset interno com ele (TesteForm).
Formulário:
<html>
<head>
<title>Form</title>
<link type="text/css" rel="stylesheet" href="/style-guide/css/fluig-style-guide.min.css"/>
<script type="text/javascript" src="/portal/resources/js/jquery/jquery.js"></script>
<script type="text/javascript" src="/portal/resources/js/jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="/portal/resources/js/mustache/mustache-min.js"></script>
<script type="text/javascript" src="/style-guide/js/fluig-style-guide.min.js" charset="utf-8"></script>
<link href='/webdesk/customresources?cid=1&resourceName=temaFormulario/0.css' type='text/css' rel='stylesheet' />
</head>
<body>
<div class="fluig-style-guide">
<form name="form" role="form">
<div id="formPrincipal">
<div class="panel panel-primary">
<!----------------------------------INFORMAÇÕES OS------------------------------------------------->
<div class="panel-heading" name="infoIni">
<h3 class="panel-title"><i class="fluigicon fluigicon-verified icon-md"></i> Informe os dados do consultor e cliente </h3>
</div>
<div class="panel-body" name="infoIni">
<div class="col-sm-12 col-sm-offset-0">
<div class="row">
<div class="form-group col-xs-8 col-sm-3 col-md-3">
<label for="consultor">Consultor</label>
<input
type="zoom"
id = "consultor"
name="consultor"
data-zoom="{
'displayKey':'colleagueName',
'datasetId':'colleague',
'maximumSelectionLength':'1',
'placeholder':'Escolha o usuário',
'fields':[
{
'field':'colleagueName',
'label':'Nome',
'standard':'true'
},{
'field':'login',
'label':'Login'
}
]
}"
/>
</div>
<div class="form-group col-xs-6 col-sm-2 col-md-2">
<label for="empresa">Empresa</label>
<input type="text" name="empresa" id="empresa" class="form-control">
</div>
<div class="form-group col-xs-6 col-sm-2 col-md-2">
<label for="coordenadorEmpresa">Coordenador Empresa</label>
<input type="text" name="coordenadorEmpresa" id="coordenadorEmpresa" class="form-control">
</div>
<div class="form-group col-xs-8 col-sm-3 col-md-3">
<label for="gerenteInntec">Gerente Inntecnet</label>
<input
type="zoom"
id = "gerenteInntec"
name="gerenteInntec"
data-zoom="{
'displayKey':'colleagueName',
'datasetId':'colleague',
'maximumSelectionLength':'1',
'placeholder':'Escolha o usuário',
'fields':[
{
'field':'colleagueName',
'label':'Nome',
'standard':'true'
},{
'field':'login',
'label':'Login'
}
]
}"
/>
</div>
<div class="form-group col-xs-6 col-sm-3 col-md-3">
<label for="coordenadorInntec">Coordenador Inntecnet</label>
<input
type="zoom"
id = "coordenadorInntec"
name="coordenadorInntec"
data-zoom="{
'displayKey':'colleagueName',
'datasetId':'colleague',
'maximumSelectionLength':'1',
'placeholder':'Escolha o usuário',
'fields':[
{
'field':'colleagueName',
'label':'Nome',
'standard':'true'
},{
'field':'login',
'label':'Login'
}
]
}"
/>
</div>
<div class="form-group col-xs-6 col-sm-3 col-md-3">
<label for="projeto">Projeto</label>
<input type="text" name="projeto" id="projeto" class="form-control">
</div>
<div class="form-group col-xs-6 col-sm-2 col-md-2">
<label for="dataIni">Data do Início</label>
<input type="text" name="dataIni" id="dataIni" class="form-control" mask="00/00/0000">
</div>
<div class="form-group col-xs-6 col-sm-2 col-md-2">
<label for="dataResol">Data da Resolução</label>
<input type="text" name="dataResol" id="dataResol" class="form-control" mask="00/00/0000">
</div>
<div class="form-group col-xs-4 col-sm-1 col-md-1">
<label for="translado">Traslado</label>
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-12">
<input type="text" name="translado" id="translado" class="form-control" placeholder="00:00" mask="00:00">
</div>
</div>
</div>
<div class="form-group col-xs-12 col-sm-12 col-md-12">
<label for="translado">Descrição</label>
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-12">
<textarea rows="3" name="descricao" id="descricao" class="form-control"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<!----------------------------------------TABELA------------------------------------------------->
<div class="panel-heading" name="Servicos">
<h3 class="panel-title"><i class="fluigicon fluigicon-home icon-md"></i> Serviços Executados</h3>
</div>
<div class="panel-body" name="Servicos">
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-12">
<label for="name">Serviços Executados na OS </label>
<div class="panel-body table-responsive">
<table tablename="servicosTabela" class="table table-striped" addbuttonlabel="Adicionar Serviço" addbuttonclass="btn btn-primary">
<thead>
<tr>
<td><b></b></td>
<td><b>Item</b></td>
<td><b>Tipo de Serviço</b></td>
<td><b>Hora Inicio</b></td>
<td><b>Hora Fim</b></td>
<td><b>Hora Extra</b></td>
<td><b>Hora FSF</b></td>
<td><b>Total de Hora</b></td>
<td><b>Total de Horas Traslado</b></td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td class="form-group col-xs-1 col-sm-1 col-md-1"><input class="form-control" type="text" name="item" id="item"></td>
<td class="form-group col-xs-2 col-sm-2 col-md-2">
<select name="tipoServico" id="tipoServico" class="form-control">
<option value=""></option>
<option value="Consultoria"> Consultoria </option>
<option value="Coordenação"> Coordenação </option>
<option value="Desenvolvimento"> Desenvolvimento </option>
<option value="Fora do Escopo"> Fora do Escopo </option>
<option value="Nao Faturado"> Não Faturado </option>
<option value="Outros Servicos"> Outros Serviços </option>
<option value="Projeto"> Projeto </option>
<option value="Suporte Tecnico"> Suporte Técnico </option>
<option value="Treinamento"> Treinamento </option>
</select>
</td>
<td class="form-group col-xs-1 col-sm-1 col-md-1"><input class="form-control" type="text" name="horaIni" id="horaIni" mask="00:00" onKeypress="maskEv();"></td>
<td class="form-group col-xs-1 col-sm-1 col-md-1"><input class="form-control" type="text" name="horaFim" id="horaFim" mask="00:00" onKeypress="maskEv();"></td>
<td class="form-group col-xs-1 col-sm-1 col-md-1"><input class="form-control" type="text" name="horaExtra" id="horaExtra" mask="00:00" onKeypress="maskEv();"></td>
<td class="form-group col-xs-1 col-sm-1 col-md-1"><input class="form-control" type="text" name="horaFSF" id="horaFSF" mask="00:00" onKeypress="maskEv();"></td>
<td class="form-group col-xs-1 col-sm-1 col-md-1"><input class="form-control" type="text" name="TOThora" id="TOThora" mask="00:00" onKeypress="maskEv();"></td>
<td class="form-group col-xs-1 col-sm-1 col-md-1"><input class="form-control" type="text" name="totalHorasTranslado" id="totalHorasTranslado" mask="00:00" onKeypress="maskEv();"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="custom.js"></script>
<script type="text/javascript">
var calendarioDataEntr = FLUIGC.calendar('#dataIni');
var calendarioDataSair = FLUIGC.calendar('#dataResol');
var onlyTime = FLUIGC.calendar('#translado', {
pickDate: false,
pickTime: true
});
</script>
<script type="text/javascript">
var keyDown = false, ctrl = 17, vKey = 86, Vkey = 118;
$(document).keydown(function (e) {
if (e.keyCode == ctrl) keyDown = true;
}).keyup(function (e) {
if (e.keyCode == ctrl) keyDown = false;
});
$('[data-only-numbers]').on('keypress', function (e) {
if (!e) {
var e = window.event;
}
if (e.keyCode > 0 && e.which == 0) {
return true;
}
if (e.keyCode) {
code = e.keyCode;
} else if (e.which) {
code = e.which;
}
if(code == 46) {
return true;
}
var character = String.fromCharCode(code);
if (character == '\b' || character == ' ' || character == '\t') {
return true;
}
if (keyDown && (code == vKey || code == Vkey)) {
return (character);
} else {
return (/[0-9]$/.test(character));
}
}).on('focusout', function (e) {
var $this = $(this);
if($this.val() == "") {
return true;
}
$this.val($this.val().replace(/[^0-9\.]/g, ''));
}).on('paste', function (e) {
var $this = $(this);
setTimeout(function () {
$this.val($this.val().replace(/[^0-9\.]/g, ''));
}, 5);
});
$('.create-form-components').on('keyup', 'input[required="required"][type="text"], input[required="required"][type="number"], input[required="required"][type="date"], textarea[required="required"]', function(){
validationFieldsForm($(this), $(this).parents('.form-field').data('type'));
});
$('.create-form-components').on('change', 'input[required="required"][type="checkbox"], input[required="required"][type="radio"], select[required="required"]', function(){
validationFieldsForm($(this), $(this).parents('.form-field').data('type'));
});
function validationFieldsForm(field, type){
if(type === "checkbox" || type === "radio"){
if(!field.is(':checked')){
field.parents('.form-field').addClass('required');
}else{
field.parents('.form-field').removeClass('required');
}
}else{
if(!field.val().trim()){
field.parents('.form-field').addClass('required');
}else{
field.parents('.form-field').removeClass('required');
}
}
}
var $zoomPreview = $(".zoom-preview");
if ($zoomPreview.length) {
$zoomPreview.parent().removeClass("input-group");
$zoomPreview.remove();
}
var ratings = $(".rating");
if (ratings.length > 0) ratingStars(ratings);
function ratingStars(stars) {
$.each(stars, function(i, obj) {
var field = $(this).closest(".form-group").find(".rating-value");
var tgt = $(obj);
tgt.html("");
var rating = FLUIGC.stars(tgt, { value: field.val() });
rating.on("click", function(o) {
field.val($(this).index() + 1);
});
});
}
$.each($("[data-date]"), function(i, o) {
var id = $(o).attr("id");
FLUIGC.calendar("#" + id);
});
$(document).ready(function() {
$.each($("[data-date]"), function(i, o) {
var id = $(o).attr("id");
if($("#" + id).attr("readonly")) {
$("#" + id).data('DateTimePicker').disable();
}
});
});
</script>
</body>
</html>
Feito isso criei dois datasets, que consultam o dataset TesteForm, um para os principais campos do formulário (datasetCabecalho), outro para os itens da minha tabela (datasetItens).
O datasetCabecalho consegui fazer normalmente pegando os dados do TesteForm.
Minha duvida é como pegar os itens da minha tabela do formulário, uma vez que esses dados nao ficam explicitos no dataset TesteForm.
Dei uma olhada nesse link: https://forum.fluig.com/1349-inserir-valor-de-um-campo-do-dataset-interno-em-um-dataset-customozado Mas sem sucesso!
Seguindo o exemplo citado, pelo que entendi ele faz uma constranit para pegar os itens da tabela:
var constraintsFilhos = new Array();
constraintsFilhos.push(DatasetFactory.createConstraint("tablename", "ingre" ,"ingre", ConstraintType.MUST));
E pega as "colunas" do dataset:
constraintsFilhos.push(DatasetFactory.createConstraint("metadata#id", documentId, documentId, ConstraintType.MUST));
constraintsFilhos.push(DatasetFactory.createConstraint("metadata#version", documentVersion, documentVersion, ConstraintType.MUST));
Meu dataset (datasetItens):
function createDataset(fields, constraints, sortFields) {
var formItem = DatasetBuilder.newDataset();
formItem.addColumn("OSnum");
formItem.addColumn("Item");
formItem.addColumn("TipoServico");
formItem.addColumn("HoraInicio");
formItem.addColumn("HoraFim");
formItem.addColumn("HoraExtra");
formItem.addColumn("HoraFSF");
formItem.addColumn("TotalHoras");
formItem.addColumn("TotalHorasTraslado");
var datasetPrincipal = DatasetFactory.getDataset("TesteForm", null, null, null);
for(var i = 0; i < datasetPrincipal.rowsCount; i++){
var documentId = datasetPrincipal.getValue(i, "metadata#id");
//escreve os ids na coluna OSnum
//formItem.addRow(new Array(documentId));
var constraintsFilhos = new Array();
constraintsFilhos.push(DatasetFactory.createConstraint("servicosTabela", null, null, ConstraintType.MUST));
constraintsFilhos.push(DatasetFactory.createConstraint("metadata#id", documentId, documentId, ConstraintType.MUST));
var datasetFilhos = DatasetFactory.getDataset("TesteFormRaul", null, constraintFilhos, null);
for(j = 0; j < datasetFilhos.rowsCount; i++){
formItem.addRow(
new Array(
documentId,
datasetFilhos.getValue(j, "item")
)
);
}
}
return formItem;
}
Acredito que o erro possa estar nessa na minha constraint.
Lembrando que quero escrever todos os dados das minhas tabelas nesse datasetItens.
Obrigado desde já!