Permalink
Browse files

novo modelo de implementar o autocomplete sem quebrar o xsd

  • Loading branch information...
1 parent 2b7ad68 commit d3338f326f8d97e58adc515f4ecc717a948ca791 @sikora sikora committed Mar 11, 2011
Showing with 51 additions and 18 deletions.
  1. +16 −0 extensions.xsd
  2. +6 −1 sample_autocomplete.xsd
  3. +1 −0 xsdForm-ui.js
  4. +28 −17 xsdForm.js
View
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://schemas.fortaleza.ce.gov.br/xsdform/extensions.xsd"
+ targetNamespace="http://schemas.fortaleza.ce.gov.br/xsdform/extensions.xsd"
+ elementFormDefault="qualified">
+
+ <xs:complexType name="extensions">
+ <xs:sequence>
+ <xs:element name="engine" minOccurs="0" maxOccurs="1" type="xs:string" />
+ <xs:element name="service" minOccurs="0" maxOccurs="1" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="extension" type="extensions" />
+
+</xs:schema>
View
@@ -15,6 +15,7 @@
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xhtml="http://www.w3.org/1999/xhtml" targetNamespace="test:ns"
+ xmlns:xsdext="http://schemas.fortaleza.ce.gov.br/xsdform/extensions.xsd"
elementFormDefault="qualified">
@@ -199,8 +200,12 @@
<xs:appinfo>
<xhtml:label>Município</xhtml:label>
</xs:appinfo>
+ <xsdext:extensions>
+ <xsdext:engine>autoComplete</xsdext:engine>
+ <xsdext:service>/cgi-bin/loadMunicipios.cgi?UF=CE</xsdext:service>
+ </xsdext:extensions>
</xs:annotation>
- <xs:simpleType engine="autoComplete" service="/cgi-bin/loadMunicipios.cgi?UF=CE" >
+ <xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="100" />
</xs:restriction>
View
@@ -236,6 +236,7 @@ function generateXsdFormUI() {
$('input.autoComplete').each(
function(i,elemento) {
+ alert('teste');
$(this).autocomplete({
source: $(elemento).attr('rel'),
minLength: 2
View
@@ -128,16 +128,17 @@ function getTextByIndex(xmlNode,index) {
}
function getTextByTagName(xmlNode,tagName) {
- var node;
- for (var i = 0; i < xmlNode.childNodes.length; i++) {
- if ( xmlNode.childNodes[i].nodeType == 1 ) {
- if ( xmlNode.childNodes[i].nodeName == tagName ) {
- node = xmlNode.childNodes[i];
- break;
- }
- }
- }
- return getText(node);
+ var node;
+ if (!xmlNode) return "";
+ for (var i = 0; i < xmlNode.childNodes.length; i++) {
+ if ( xmlNode.childNodes[i].nodeType == 1 ) {
+ if ( xmlNode.childNodes[i].nodeName == tagName ) {
+ node = xmlNode.childNodes[i];
+ break;
+ }
+ }
+ }
+ return getText(node);
}
// Retorna o atributo 'attributeName' do no xmlNode
function getValueAttributeByName(xmlNode,attributeName) {
@@ -186,6 +187,8 @@ function static_type(type) {
function generateFormFromNode(tagRaiz, xmlNode, namePattern) {
var label;
+ var engine;
+ var service;
var type = getValueAttributeByName(xmlNode, "type");
var minOccurs = getValueAttributeByName(xmlNode, "minOccurs");
var maxOccurs = getValueAttributeByName(xmlNode, "maxOccurs");
@@ -197,27 +200,30 @@ function generateFormFromNode(tagRaiz, xmlNode, namePattern) {
for (var i = 0; i < xmlNode.childNodes.length; i++) {
if (xmlNode.childNodes[i].nodeType == 1 && xmlNode.childNodes[i].nodeName == 'xs:annotation' ) {
label = getTextTagInAnnotationAppinfo(xmlNode.childNodes[i], 'xhtml:label', true);
+ engine = getTextTagInAnnotationExtensions(xmlNode.childNodes[i], 'xsdext:engine');
+ service = getTextTagInAnnotationExtensions(xmlNode.childNodes[i], 'xsdext:service');
break;
}
}
for (var i = 0; i < tagRaiz.childNodes.length; i++) {
var inner = tagRaiz.childNodes[i];
if (inner.nodeType == 1 && inner.nodeName == 'xs:complexType' &&
getValueAttributeByName(inner, "name") == type) {
- return generateFormFromComplexTypeNode(tagRaiz, inner, namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, maxOccurs );
+ return generateFormFromComplexTypeNode(tagRaiz, inner, namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, maxOccurs, engine, service );
}
}
} else {
// inline type definition
for (var i = 0; i < xmlNode.childNodes.length; i++) {
if (xmlNode.childNodes[i].nodeType == 1 && xmlNode.childNodes[i].nodeName == 'xs:annotation' ) {
label = getTextTagInAnnotationAppinfo(xmlNode.childNodes[i], 'xhtml:label', true);
-
+ engine = getTextTagInAnnotationExtensions(xmlNode.childNodes[i], 'xsdext:engine');
+ service = getTextTagInAnnotationExtensions(xmlNode.childNodes[i], 'xsdext:service');
} else if (xmlNode.childNodes[i].nodeType == 1 && xmlNode.childNodes[i].nodeName == 'xs:complexType') {
- return generateFormFromComplexTypeNode(tagRaiz, xmlNode.childNodes[i], namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, maxOccurs );
+ return generateFormFromComplexTypeNode(tagRaiz, xmlNode.childNodes[i], namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, maxOccurs, engine, service );
} else if (xmlNode.childNodes[i].nodeType == 1 && xmlNode.childNodes[i].nodeName == 'xs:simpleType') {
- return generateFormFromSimpleTypeNode(tagRaiz, xmlNode.childNodes[i], namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs);
+ return generateFormFromSimpleTypeNode(tagRaiz, xmlNode.childNodes[i], namePattern, getValueAttributeByName(xmlNode, "name"), label, minOccurs, engine, service);
}
}
@@ -405,11 +411,9 @@ function generateXmlFromComplexTypeNodeNoRepeat(odoc, namespace, tagRaiz, xmlNod
}
-function generateFormFromSimpleTypeNode(tagRaiz, xmlNode, namePattern, name, label, minOccurs) {
+function generateFormFromSimpleTypeNode(tagRaiz, xmlNode, namePattern, name, label, minOccurs, engine, service) {
var restrictionNode = getNodeByTagName(xmlNode, 'xs:restriction');
- var engine = getValueAttributeByName(xmlNode, "engine");
- var service = getValueAttributeByName(xmlNode, "service");
for (var i = 0; i < restrictionNode.childNodes.length; i++) {
if (restrictionNode.childNodes[i].nodeType == 1 && restrictionNode.childNodes[i].nodeName == 'xs:pattern' ) {
@@ -589,6 +593,13 @@ function generateXmlFromSimpleTypeNode(odoc, namespace, tagRaiz, xmlNode, namePa
}
+function getTextTagInAnnotationExtensions(xmlNode, strTag) {
+
+ var xmlNodeAux = getNodeByTagName(xmlNode, "xsdext:extensions");
+ return getTextByTagName(xmlNodeAux, strTag);
+}
+
+
function getTextTagInAnnotationAppinfo(xmlNode, strTag, annotation) {
var xmlNodeAux;

0 comments on commit d3338f3

Please sign in to comment.