Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

xsdformjs alterado

  • Loading branch information...
commit 80dbf473861999c551e96abc486c48137a7edfd2 1 parent b3a8e19
Roneltton Lafitte authored

Showing 1 changed file with 83 additions and 2 deletions. Show diff stats Hide diff stats

  1. +83 2 Acao/root/static/js/xsdForm.js
85 Acao/root/static/js/xsdForm.js
@@ -223,7 +223,7 @@ function generateFormFromNode(tagRaiz, xmlNode, namePattern) {
223 223 return generateFormFromComplexTypeNode(tagRaiz, xmlNode.childNodes[i], namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, maxOccurs, engine, service );
224 224
225 225 } else if (xmlNode.childNodes[i].nodeType == 1 && xmlNode.childNodes[i].nodeName == 'xs:simpleType') {
226   - return generateFormFromSimpleTypeNode(tagRaiz, xmlNode.childNodes[i], namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, engine, service);
  226 + return generateFormFromSimpleTypeNode(tagRaiz, xmlNode.childNodes[i], namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, engine, service, maxOccurs);
227 227
228 228 }
229 229 }
@@ -411,7 +411,88 @@ function generateXmlFromComplexTypeNodeNoRepeat(odoc, namespace, tagRaiz, xmlNod
411 411
412 412 }
413 413
414   -function generateFormFromSimpleTypeNode(tagRaiz, xmlNode, namePattern, name, label, minOccurs, engine, service) {
  414 +function generateFormFromSimpleTypeNode(tagRaiz, xmlNode, namePattern, name, label, minOccurs, engine, service, maxOccurs) {
  415 + if (maxOccurs != null && maxOccurs != "1") {
  416 + // produzir a barra de repeticoes
  417 + var divRepeat = document.createElement('fieldset');
  418 + var divBarra = document.createElement('span');
  419 + var spanLabel = document.createElement('legend');
  420 + spanLabel.innerHTML = label;
  421 + var subnamePattern = namePattern +'__'+name;
  422 + var buttonAdd = document.createElement('input');
  423 + var buttonDel = document.createElement('input');
  424 + buttonAdd.setAttribute('type', 'button');
  425 + buttonAdd.setAttribute('value', '+');
  426 + buttonDel.setAttribute('type', 'button');
  427 + buttonDel.setAttribute('value', '-');
  428 + divRepeat.setAttribute('id', subnamePattern);
  429 + divBarra.setAttribute('id', subnamePattern+'__barra');
  430 + divBarra.setAttribute('class', 'xsdForm__repeatBarra');
  431 + divRepeat.setAttribute('class', 'xsdForm__repeat');
  432 + divRepeat.appendChild(spanLabel);
  433 + divBarra.appendChild(buttonDel);
  434 + divBarra.appendChild(buttonAdd);
  435 + spanLabel.appendChild(divBarra);
  436 +
  437 +
  438 + var currentCount = 0;
  439 +
  440 + var refreshEnableDisable = function() {
  441 + if (maxOccurs == "unbounded" || currentCount < maxOccurs) {
  442 + buttonAdd.removeAttribute('disabled');
  443 + } else {
  444 + buttonAdd.setAttribute('disabled',true);
  445 + }
  446 + if (currentCount > minOccurs) {
  447 + buttonDel.removeAttribute('disabled');
  448 + } else {
  449 + buttonDel.setAttribute('disabled',true);
  450 + }
  451 + }
  452 +
  453 + var getCurrentCount = function() {
  454 + return currentCount;
  455 + }
  456 + divRepeat.xsdFormCurrentCount = getCurrentCount;
  457 +
  458 + var onclickAdd = function() {
  459 + if (maxOccurs == "unbounded" || currentCount < maxOccurs) {
  460 + var html = generateFormFromSimpleTypeNodeNoRepeat(tagRaiz, xmlNode, namePattern+"__"+currentCount, name, "Item "+(currentCount+1), minOccurs, engine, service);
  461 + var divEngloba = document.createElement('div');
  462 + divEngloba.appendChild(html);
  463 + divRepeat.appendChild(divEngloba);
  464 + currentCount++;
  465 + }
  466 + refreshEnableDisable();
  467 + }
  468 + buttonAdd.onclick = onclickAdd;
  469 + divRepeat.addRepeat = onclickAdd;
  470 +
  471 + var onclickDel = function() {
  472 + alert(currentCount);
  473 + if (currentCount > minOccurs) {
  474 + divRepeat.removeChild(divRepeat.childNodes[currentCount]);
  475 + currentCount--;
  476 + //divRepeat.removeChild(divRepeat.childNodes[currentCount]);
  477 + //currentCount--;
  478 + }
  479 + refreshEnableDisable();
  480 + }
  481 + buttonDel.onclick = onclickDel;
  482 + divRepeat.delRepeat = onclickDel;
  483 +
  484 + for (var i = 0; i < minOccurs; i++) {
  485 + onclickAdd();
  486 + }
  487 + refreshEnableDisable();
  488 +
  489 + return divRepeat;
  490 + } else {
  491 + return generateFormFromSimpleTypeNodeNoRepeat(tagRaiz, xmlNode, namePattern, name, label, minOccurs, engine, service);
  492 + }
  493 +}
  494 +
  495 +function generateFormFromSimpleTypeNodeNoRepeat(tagRaiz, xmlNode, namePattern, name, label, minOccurs, engine, service) {
415 496
416 497 var restrictionNode = getNodeByTagName(xmlNode, 'xs:restriction');
417 498

0 comments on commit 80dbf47

Please sign in to comment.
Something went wrong with that request. Please try again.