// Metawidget 3.7 minified
//
// This library is dual licensed under both LGPL and a commercial
// license. See http://metawidget.org for details 
//
// Author: Richard Kennard (http://kennardconsulting.com)

var metawidget=metawidget||{};(function(){metawidget.inspectionresultprocessor=metawidget.inspectionresultprocessor||{}})();
var metawidget=metawidget||{};(function(){metawidget.inspector=metawidget.inspector||{};metawidget.inspector.CompositeInspector=function(a){if(!(this instanceof metawidget.inspector.CompositeInspector)){throw new Error("Constructor called as a function")}var b;if(a.inspectors!==undefined){b=a.inspectors.slice(0)}else{b=a.slice(0)}this.inspect=function(j,d,h){var e={};for(var c=0,g=b.length;c<g;c++){var f;var i=b[c];if(i.inspect!==undefined){f=i.inspect(j,d,h)}else{f=i(j,d,h)}metawidget.util.combineInspectionResults(e,f)}return e}};metawidget.inspector.PropertyTypeInspector=function(){if(!(this instanceof metawidget.inspector.PropertyTypeInspector)){throw new Error("Constructor called as a function")}};metawidget.inspector.PropertyTypeInspector.prototype.inspect=function(f,b,e){f=metawidget.util.traversePath(f,e);var d={};if(e!==undefined&&e.length>0){d.name=e[e.length-1]}else{if(f===undefined){return}}if(f!==undefined){d.type=a(f);if(d.type===undefined){d.properties={};for(var c in f){d.properties[c]={type:a(f[c])}}}}return d;function a(g){if(g instanceof Array){return"array"}else{if(g instanceof Date){return"date"}else{var h=typeof(g);if(h!=="object"){return h}}}}};metawidget.inspector.JsonSchemaInspector=function(a){if(!(this instanceof metawidget.inspector.JsonSchemaInspector)){throw new Error("Constructor called as a function")}var b;if(a.schema!==undefined){b=a.schema}else{b=a}this.inspect=function(h,d,g){if(b.type!==undefined&&b.type!==d){if(b.type!=="array"&&b.type!=="boolean"&&b.type!=="number"&&b.type!=="string"){return undefined}}var f=c(b,g);if(f===undefined){return undefined}var e={};if(g!==undefined){e.name=g[g.length-1]}metawidget.util.combineInspectionResults(e,f);return e;function c(m,l){if(m===undefined){return undefined}if(l!==undefined){if(!(l instanceof Array)){throw new Error("Expected array of names")}for(var i=0,k=l.length;i<k;i++){var j=l[i];if(!isNaN(j)){m=m.items;if(m===undefined){return undefined}continue}m=m.properties;if(m===undefined){return undefined
}m=m[j];if(m===undefined){return undefined}}}return m}}}})();
var metawidget=metawidget||{};(function(){metawidget.layout=metawidget.layout||{};metawidget.layout.SimpleLayout=function(){if(!(this instanceof metawidget.layout.SimpleLayout)){throw new Error("Constructor called as a function")}};metawidget.layout.SimpleLayout.prototype.layoutWidget=function(d,a,c,b,e){if(d.tagName==="STUB"&&!metawidget.util.hasChildElements(d)){return}b.appendChild(d)};metawidget.layout.DefinitionListLayout=function(b){if(!(this instanceof metawidget.layout.DefinitionListLayout)){throw new Error("Constructor called as a function")}var c=b!==undefined?b.labelStyleClass:undefined;var a=b!==undefined&&b.labelSuffix!==undefined?b.labelSuffix:":";this.startContainerLayout=function(d,g){var e=metawidget.util.createElement(g,"dl");if(g.path!==undefined){var f=metawidget.util.getId("property",{},g);if(f!==undefined){e.setAttribute("id","dl-"+f)}}d.appendChild(e)};this.layoutWidget=function(i,e,g,f,j){if(i.tagName==="STUB"&&!metawidget.util.hasChildElements(i)){return}var h=f.childNodes[f.childNodes.length-1];this.layoutLabel(h,i,e,g,j);var d=metawidget.util.createElement(j,"dd");d.appendChild(i);h.appendChild(d)};this.layoutLabel=function(h,j,d,e,k){if(d==="entity"||d==="action"){return}if(e.name===undefined&&e.title===undefined){return}var g=metawidget.util.getLabelString(e,k);if(g===""){return}var i=metawidget.util.createElement(k,"dt");var f=metawidget.util.createElement(k,"label");if(j.getAttribute("id")!==null){f.setAttribute("for",j.getAttribute("id"))}if(c!==undefined){f.setAttribute("class",c)}f.innerHTML=g+a;i.appendChild(f);h.appendChild(i)}};metawidget.layout.DivLayout=function(c){if(!(this instanceof metawidget.layout.DivLayout)){throw new Error("Constructor called as a function")}var b=c!==undefined?c.divStyleClasses:undefined;var g=c!==undefined?c.labelStyleClass:undefined;var a=c!==undefined&&c.labelSuffix!==undefined?c.labelSuffix:":";var d=c!==undefined&&c.suppressLabelSuffixOnCheckboxes!==undefined?c.suppressLabelSuffixOnCheckboxes:false;
var e=c!==undefined&&c.appendRequiredClassOnLabelDiv!==undefined?c.appendRequiredClassOnLabelDiv:undefined;var f=c!==undefined&&c.appendRequiredClassOnWidgetDiv!==undefined?c.appendRequiredClassOnWidgetDiv:undefined;this.layoutWidget=function(m,q,k,h,p){if(m.tagName==="STUB"&&!metawidget.util.hasChildElements(m)){return}if(m.tagName==="INPUT"&&(m.getAttribute("type")==="button"||m.getAttribute("type")==="submit")){if(h.childNodes.length>0){var j=h.childNodes[h.childNodes.length-1];if(j.childNodes.length===1){var n=j.childNodes[0];if(n.childNodes.length>0){var i=n.childNodes[n.childNodes.length-1];if(i.tagName==="INPUT"&&(i.getAttribute("type")==="button"||i.getAttribute("type")==="submit")){n.appendChild(m);return}}}}}var o=metawidget.util.createElement(p,"div");if(b!==undefined&&b[0]!==undefined){o.setAttribute("class",b[0])}this.layoutLabel(o,m,q,k,p);var l=metawidget.util.createElement(p,"div");if(b!==undefined&&b[2]!==undefined){l.setAttribute("class",b[2])}if(metawidget.util.isTrueOrTrueString(k.required)&&f!==undefined){metawidget.util.appendToAttribute(l,"class",f)}l.appendChild(m);o.appendChild(l);h.appendChild(o)};this.layoutLabel=function(l,m,h,i,o){if(h==="entity"||h==="action"){return}if(i.name===undefined&&i.title===undefined){return}var k=this.getLabelString(m,i,o);if(k===""){return}var n=metawidget.util.createElement(o,"div");if(b!==undefined&&b[1]!==undefined){n.setAttribute("class",b[1])}if(metawidget.util.isTrueOrTrueString(i.required)&&e!==undefined){metawidget.util.appendToAttribute(n,"class",e)}var j=metawidget.util.createElement(o,"label");if(m.getAttribute("id")!==null){j.setAttribute("for",m.getAttribute("id"));j.setAttribute("id",m.getAttribute("id")+"-label")}if(g!==undefined){j.setAttribute("class",g)}j.innerHTML=k;n.appendChild(j);l.appendChild(n)};this.getLabelString=function(j,h,k){var i=metawidget.util.getLabelString(h,k);if(i===""){return i}if(d===true&&j.tagName==="INPUT"&&j.getAttribute("type")==="checkbox"){return i}return i+a}};metawidget.layout.TableLayout=function(d){if(!(this instanceof metawidget.layout.TableLayout)){throw new Error("Constructor called as a function")
}var f=d!==undefined?d.tableStyleClass:undefined;var g=d!==undefined?d.columnStyleClasses:undefined;var a=d!==undefined?d.headerStyleClass:undefined;var c=d!==undefined?d.footerStyleClass:undefined;var e=d!==undefined&&d.numberOfColumns?d.numberOfColumns:1;var b=0;this.startContainerLayout=function(h,p){var q=metawidget.util.createElement(p,"table");if(p.path!==undefined){var i=metawidget.util.getId("property",{},p);if(i!==undefined){q.setAttribute("id","table-"+i)}}if(f!==undefined){q.setAttribute("class",f)}h.appendChild(q);if(p.overriddenNodes!==undefined){for(var n=0,j=p.overriddenNodes.length;n<j;n++){var k=p.overriddenNodes[n];if(k.tagName!=="FACET"){continue}var o;if(k.getAttribute("name")==="header"){o=metawidget.util.createElement(p,"thead")}else{if(k.getAttribute("name")==="footer"){o=metawidget.util.createElement(p,"tfoot")}else{continue}}q.appendChild(o);var m=metawidget.util.createElement(p,"tr");o.appendChild(m);var l=metawidget.util.createElement(p,"td");l.setAttribute("colspan",e*2);if(k.getAttribute("name")==="header"){if(a!==undefined){l.setAttribute("class",a)}}else{if(c!==undefined){l.setAttribute("class",c)}}m.appendChild(l);while(k.childNodes.length>0){l.appendChild(k.removeChild(k.childNodes[0]))}}}q.appendChild(metawidget.util.createElement(p,"tbody"))};this.layoutWidget=function(m,r,k,i,p){if(m.tagName==="STUB"&&!metawidget.util.hasChildElements(m)){return}var n=metawidget.util.isSpanAllColumns(k);if(n===true&&b>0){b=0}var q=i.childNodes[i.childNodes.length-1];var h=undefined;if(k.name!==undefined){if(q.hasAttribute("id")){h=q.getAttribute("id")}if(h!==undefined){if(r!=="entity"){if(h.charAt(h.length-1)!=="-"){h+=metawidget.util.capitalize(k.name)}else{h+=k.name}}}else{h="table-"+k.name}}var l=q.childNodes[q.childNodes.length-1];var o;if(b===0){o=metawidget.util.createElement(p,"tr");if(h!==undefined){o.setAttribute("id",h+"-row")}l.appendChild(o)}else{o=l.childNodes[l.childNodes.length-1]}this.layoutLabel(o,h,m,r,k,p);var j=metawidget.util.createElement(p,"td");
if(h!==undefined){j.setAttribute("id",h+"-cell")}if(g!==undefined&&g[1]!==undefined){j.setAttribute("class",g[1])}if(n===true){j.setAttribute("colspan",((e*3)-1)-o.childNodes.length)}else{if(o.childNodes.length<1){j.setAttribute("colspan",2-o.childNodes.length)}}j.appendChild(m);o.appendChild(j);this.layoutRequired(o,k,p);if(n===true){b=e-1}b=(b+1)%e};this.layoutLabel=function(n,l,m,h,i,o){if(h==="entity"){return}if(i.name===undefined&&i.title===undefined){return}var k=metawidget.util.createElement(o,"th");if(l!==undefined){k.setAttribute("id",l+"-label-cell")}if(g!==undefined&&g[0]!==undefined){k.setAttribute("class",g[0])}if(h!=="action"){var j=metawidget.util.createElement(o,"label");if(m.hasAttribute("id")){j.setAttribute("for",m.getAttribute("id"))}if(l!==undefined){j.setAttribute("id",l+"-label")}j.innerHTML=metawidget.util.getLabelString(i,o)+":";k.appendChild(j)}n.appendChild(k)};this.layoutRequired=function(i,h,k){var j=metawidget.util.createElement(k,"td");if(g!==undefined&&g[2]!==undefined){j.setAttribute("class",g[2])}if(!metawidget.util.isTrueOrTrueString(h.readOnly)&&metawidget.util.isTrueOrTrueString(h.required)){j.innerHTML="*"}i.appendChild(j)}};metawidget.layout._createSectionLayoutDecorator=function(b,a,d){var c;if(b.delegate!==undefined){c=b.delegate}else{c=b}a.getDelegate=function(){return c};a.onStartBuild=function(e){if(a.getDelegate().onStartBuild!==undefined){a.getDelegate().onStartBuild(e)}};a.startContainerLayout=function(e,f){e[d]={};if(a.getDelegate().startContainerLayout!==undefined){a.getDelegate().startContainerLayout(e,f)}};a.endContainerLayout=function(e,f){if(a.getDelegate().endContainerLayout!==undefined){a.getDelegate().endContainerLayout(e,f)}e[d]={}};a.onEndBuild=function(e){if(a.getDelegate().onEndBuild!==undefined){a.getDelegate().onEndBuild(e)}}};metawidget.layout.createFlatSectionLayoutDecorator=function(b,a,c){if(this instanceof metawidget.layout.createFlatSectionLayoutDecorator){throw new Error("Function called as a Constructor")
}metawidget.layout._createSectionLayoutDecorator(b,a,c);a.layoutWidget=function(g,l,f,e,j){if(a.getDelegate().nestedSectionLayoutDecorator===true){var i=metawidget.util.stripSection(f);if(i===undefined||i===e[c].currentSection){return a.getDelegate().layoutWidget(g,l,f,e,j)}if(e[c].currentSection!==undefined){a.getDelegate().endContainerLayout(e,j)}e[c].currentSection=i;if(i!==""){a.addSectionWidget(i,0,f,e,j)}}else{if(f.section===undefined||f.section===e[c].currentSection){return a.getDelegate().layoutWidget(g,l,f,e,j)}var k=f.section;if(!(k instanceof Array)){k=[k]}var h;if(e[c].currentSection!==undefined){h=e[c].currentSection}else{h=[]}for(var d=0;d<k.length;d++){var i=k[d];if(i===""){continue}if(d<h.length&&i===h[d]){continue}a.addSectionWidget(i,d,f,e,j)}e[c].currentSection=k}a.getDelegate().layoutWidget(g,l,f,e,j)}};metawidget.layout.createNestedSectionLayoutDecorator=function(b,a,d){if(this instanceof metawidget.layout.createNestedSectionLayoutDecorator){throw new Error("Function called as a Constructor")}metawidget.layout._createSectionLayoutDecorator(b,a,d);a.nestedSectionLayoutDecorator=true;a.layoutWidget=function(i,e,g,f,k){var j=metawidget.util.stripSection(g);if(j===undefined||j===f[d].currentSection){if(f[d].currentSectionWidget){return a.getDelegate().layoutWidget(i,e,g,f[d].currentSectionWidget,k)}return a.getDelegate().layoutWidget(i,e,g,f,k)}if(f[d].currentSectionWidget!==undefined){a.endContainerLayout(f[d].currentSectionWidget,k)}f[d].currentSection=j;var h=f[d].currentSectionWidget;delete f[d].currentSectionWidget;if(j===""){a.getDelegate().layoutWidget(i,e,g,f,k);return}f[d].currentSectionWidget=a.createSectionWidget(h,j,g,f,k);a.startContainerLayout(f[d].currentSectionWidget,k);a.getDelegate().layoutWidget(i,e,g,f[d].currentSectionWidget,k)};var c=a.endContainerLayout;a.endContainerLayout=function(e,f){if(e[d].currentSectionWidget!==undefined){a.endContainerLayout(e[d].currentSectionWidget,f)}c.call(this,e,f)}};metawidget.layout.HeadingTagLayoutDecorator=function(a){if(!(this instanceof metawidget.layout.HeadingTagLayoutDecorator)){throw new Error("Constructor called as a function")
}metawidget.layout.createFlatSectionLayoutDecorator(a,this,"headingTagLayoutDecorator")};metawidget.layout.HeadingTagLayoutDecorator.prototype.addSectionWidget=function(d,f,b,a,e){var c=metawidget.util.createElement(e,"h"+(f+1));c.innerHTML=d;this.getDelegate().layoutWidget(c,"property",{wide:"true"},a,e)};metawidget.layout.DivLayoutDecorator=function(a){if(!(this instanceof metawidget.layout.DivLayoutDecorator)){throw new Error("Constructor called as a function")}metawidget.layout.createNestedSectionLayoutDecorator(a,this,"divLayoutDecorator")};metawidget.layout.DivLayoutDecorator.prototype.createSectionWidget=function(c,d,b,a,f){var e=metawidget.util.createElement(f,"div");e.setAttribute("title",d);this.getDelegate().layoutWidget(e,"property",{wide:"true"},a,f);return e}})();
var metawidget=metawidget||{};(function(){metawidget.util=metawidget.util||{};metawidget.util.getLabelString=function(d,k){if(d.title!==undefined){return metawidget.util.getLocalizedString(d.title,k)}var b=d.name;if(k.l10n!==undefined&&k.l10n[b]!==undefined){return k.l10n[b]}var h="";var e=true;var l=" ";for(var f=0;f<b.length;f++){var g=b[f];if(e===true){h+=g.toUpperCase();e=false}else{if(a(g)&&(!a(l)||(f<b.length-1&&b[f+1]!=" "&&!a(b[f+1])))){if(l!==" "){h+=" "}h+=g}else{if(i(g)&&j(l)&&l!=" "){h+=" "+g}else{h+=g}}}l=g}return h;function i(n){var m=n.charCodeAt(0);return(m>=48&&m<=57)}function j(n){var m=n.charCodeAt(0);return(m>=65&&m<=90)||(m>=97&&m<=122)}};metawidget.util.getLocalizedString=function(c,d){var b=metawidget.util.camelCase(c);if(d.l10n!==undefined&&d.l10n[b]!==undefined){return d.l10n[b]}return c};metawidget.util.decapitalize=function(b){if(b.length===0){return b}var c=b.charAt(0);if(!a(c)){return b}if(b.length>1){if(a(b.charAt(1))){return b}}return b.charAt(0).toLowerCase()+b.slice(1)};metawidget.util.capitalize=function(b){if(b.length===0){return b}if(b.length>1){if(a(b.charAt(1))){return b}}return b.charAt(0).toUpperCase()+b.slice(1)};metawidget.util.isTrueOrTrueString=function(b){return(b==="true"||b===true)};metawidget.util.camelCase=function(e){if(!(e instanceof Array)){e=e.split(" ")}var d="";var c=e.length;if(c>0){d+=metawidget.util.decapitalize(e[0])}for(var b=1;b<c;b++){d+=metawidget.util.capitalize(e[b])}return d};metawidget.util.fillString=function(b,d){var c="";for(;;){if(d&1){c+=b}d>>=1;if(d){b+=b}else{break}}return c};metawidget.util.lookupEnumTitle=function(d,e,b){var c=e.indexOf(d);if(c===-1||c>=b.length){return d}return b[c]};metawidget.util.getId=function(b,d,f){if(f.path!==undefined){var c=f.path.split(".");if(c[0]==="object"){c=c.slice(1)}if(d.name&&b!=="entity"){c.push(d.name)}else{if(c.length==0){return undefined}}var e=metawidget.util.camelCase(c);e=e.replace(/[\[\]]/g,"");return e}if(d!==undefined){return d.name}};metawidget.util.hasChildElements=function(d){var e=d.childNodes;
for(var b=0,c=e.length;b<c;b++){if(e[b].nodeType===1){return true}}return false};metawidget.util.isSpanAllColumns=function(b){if(b===undefined){return false}if(metawidget.util.isTrueOrTrueString(b.large)){return true}return metawidget.util.isTrueOrTrueString(b.wide)};metawidget.util.splitPath=function(g){var c={};if(g!==undefined){var f=g.match(/([^\.\[\]]*)/g);c.type=f[0];for(var b=1,e=f.length;b<e;b++){if(f[b]===""){continue}if(c.names===undefined){c.names=[]}var d=f[b].match(/^(?:\s*(?:\'|\"))([^\']*)(?:(?:\'|\")\s*)$/);if(d!==null&&d[1]!==undefined){f[b]=d[1]}c.names.push(f[b])}}return c};metawidget.util.appendPath=function(b,c){if(c.path!==undefined){return c.path+"."+b.name}if(c.toInspect!==undefined){return typeof(c.toInspect)+"."+b.name}return"object."+b.name};metawidget.util.traversePath=function(e,d){if(e===undefined){return undefined}if(d!==undefined){if(!(d instanceof Array)){throw new Error("Expected array of names")}for(var b=0,c=d.length;b<c;b++){e=e[d[b]];if(e===undefined){return undefined}}}return e};metawidget.util.getSortedInspectionResultProperties=function(e){var d=[];for(var b in e.properties){var c=e.properties[b];d.push(c);c.name=b;c._syntheticOrder=d.length}d.sort(function(g,f){if(g.propertyOrder===undefined){if(f.propertyOrder===undefined){return(g._syntheticOrder-f._syntheticOrder)}return 1}if(f.propertyOrder===undefined){return -1}var h=(g.propertyOrder-f.propertyOrder);if(h===0){return(g._syntheticOrder-f._syntheticOrder)}return h});return d};metawidget.util.combineInspectionResults=function(d,c){if(c===undefined){return}e(c,d);if(c.properties===undefined){return}d.properties=d.properties||{};for(var b in c.properties){d.properties[b]=d.properties[b]||{};e(c.properties[b],d.properties[b])}function e(i,h){for(var g in i){var f=i[g];if(f instanceof Array){h[g]=f.slice(0);continue}if(f instanceof Object){continue}h[g]=i[g]}}};metawidget.util.stripSection=function(b){var c=b.section;if(c===undefined){return undefined}if(!(c instanceof Array)){delete b.section;
return c}switch(c.length){case 0:delete b.section;return"";case 1:delete b.section;return c[0];case 2:b.section=c.slice(1);return c[0]}};metawidget.util.appendToAttribute=function(e,d,c){var b=e.getAttribute(d);if(b===null){e.setAttribute(d,c)}else{e.setAttribute(d,b+" "+c)}};metawidget.util.createElement=function(c,b){return c.getElement().ownerDocument.createElement(b.toUpperCase())};metawidget.util.createTextNode=function(c,b){return c.getElement().ownerDocument.createTextNode(b)};metawidget.util.createEvent=function(d,b){var c=d.getElement().ownerDocument.createEvent("Event");c.initEvent(b,true,true);return c};function a(d){var b=d.charCodeAt(0);return(b>=65&&b<=90)}})();
var metawidget=metawidget||{};(function(){metawidget.widgetbuilder=metawidget.widgetbuilder||{};metawidget.widgetbuilder.CompositeWidgetBuilder=function(a){if(!(this instanceof metawidget.widgetbuilder.CompositeWidgetBuilder)){throw new Error("Constructor called as a function")}var b;if(a.widgetBuilders!==undefined){b=a.widgetBuilders.slice(0)}else{b=a.slice(0)}this.onStartBuild=function(){for(var c=0,e=b.length;c<e;c++){var d=b[c];if(d.onStartBuild!==undefined){d.onStartBuild()}}};this.buildWidget=function(c,e,i){for(var d=0,g=b.length;d<g;d++){var h;var f=b[d];if(f.buildWidget!==undefined){h=f.buildWidget(c,e,i)}else{h=f(c,e,i)}if(h!==undefined){return h}}};this.onEndBuild=function(){for(var c=0,e=b.length;c<e;c++){var d=b[c];if(d.onEndBuild!==undefined){d.onEndBuild()}}}};metawidget.widgetbuilder.OverriddenWidgetBuilder=function(){if(!(this instanceof metawidget.widgetbuilder.OverriddenWidgetBuilder)){throw new Error("Constructor called as a function")}};metawidget.widgetbuilder.OverriddenWidgetBuilder.prototype.buildWidget=function(b,d,g){if(g.overriddenNodes===undefined){return}var a=metawidget.util.getId(b,d,g);for(var c=0,e=g.overriddenNodes.length;c<e;c++){var f=g.overriddenNodes[c];if(f.nodeType===1&&f.getAttribute("id")===a){g.overriddenNodes.splice(c,1);return f}}};metawidget.widgetbuilder.ReadOnlyWidgetBuilder=function(){if(!(this instanceof metawidget.widgetbuilder.ReadOnlyWidgetBuilder)){throw new Error("Constructor called as a function")}};metawidget.widgetbuilder.ReadOnlyWidgetBuilder.prototype.buildWidget=function(a,b,c){if(!metawidget.util.isTrueOrTrueString(b.readOnly)){return}if(metawidget.util.isTrueOrTrueString(b.hidden)||b.type==="function"){return metawidget.util.createElement(c,"stub")}if(b["enum"]!==undefined||b.type==="string"||b.type==="boolean"||b.type==="number"||b.type==="date"){return metawidget.util.createElement(c,"output")}if(metawidget.util.isTrueOrTrueString(b.dontExpand)){return metawidget.util.createElement(c,"output")}};metawidget.widgetbuilder.HtmlWidgetBuilder=function(a){if(!(this instanceof metawidget.widgetbuilder.HtmlWidgetBuilder)){throw new Error("Constructor called as a function")
}var b=false;if(a!==undefined){b=a.alwaysUseNestedMetawidgetInTables}this.buildWidget=function(s,g,r){if(metawidget.util.isTrueOrTrueString(g.hidden)){return metawidget.util.createElement(r,"stub")}if(g["enum"]!==undefined){if(g.type==="array"||g.componentType!==undefined){var c=metawidget.util.createElement(r,"div");for(var k=0,d=g["enum"].length;k<d;k++){var o=metawidget.util.createElement(r,"label");var j=metawidget.util.createElement(r,"input");if(g.componentType!==undefined){j.setAttribute("type",g.componentType)}else{j.setAttribute("type","checkbox")}j.value=g["enum"][k];o.appendChild(j);if(g.enumTitles!==undefined&&g.enumTitles[k]!==undefined){o.appendChild(metawidget.util.createTextNode(r,g.enumTitles[k]))}else{o.appendChild(metawidget.util.createTextNode(r,g["enum"][k]))}c.appendChild(o)}return c}var n=metawidget.util.createElement(r,"select");if(!metawidget.util.isTrueOrTrueString(g.required)){n.appendChild(metawidget.util.createElement(r,"option"))}for(var k=0,d=g["enum"].length;k<d;k++){var j=metawidget.util.createElement(r,"option");j.value=g["enum"][k];if(g.enumTitles!==undefined&&g.enumTitles[k]!==undefined){j.innerHTML=g.enumTitles[k]}else{j.innerHTML=g["enum"][k]}n.appendChild(j)}return n}if(g.type==="function"){var i=metawidget.util.createElement(r,"input");if(metawidget.util.isTrueOrTrueString(g.submit)){i.setAttribute("type","submit")}else{i.setAttribute("type","button")}i.setAttribute("value",metawidget.util.getLabelString(g,r));return i}if(g.type==="number"){if(g.minimum!==undefined&&g.maximum!==undefined){var h=metawidget.util.createElement(r,"input");h.setAttribute("type","range");h.setAttribute("min",g.minimum);h.setAttribute("max",g.maximum);return h}var f=metawidget.util.createElement(r,"input");f.setAttribute("type","number");if(g.minimum!==undefined){f.setAttribute("min",g.minimum)}else{if(g.maximum!==undefined){f.setAttribute("max",g.maximum)}}return f}if(g.type==="boolean"){var l=metawidget.util.createElement(r,"input");l.setAttribute("type","checkbox");
return l}if(g.type==="date"){var e=metawidget.util.createElement(r,"input");e.setAttribute("type","date");return e}if(g.type==="string"){if(metawidget.util.isTrueOrTrueString(g.masked)){var p=metawidget.util.createElement(r,"input");p.setAttribute("type","password");if(g.maxLength!==undefined){p.setAttribute("maxlength",g.maxLength)}return p}if(metawidget.util.isTrueOrTrueString(g.large)){return metawidget.util.createElement(r,"textarea")}var m=metawidget.util.createElement(r,"input");if(g.componentType!==undefined){m.setAttribute("type",g.componentType)}else{m.setAttribute("type","text")}if(g.maxLength!==undefined){m.setAttribute("maxlength",g.maxLength)}return m}if(g.type==="array"){return this.createTable(s,g,r)}if(metawidget.util.isTrueOrTrueString(g.dontExpand)){var q=metawidget.util.createElement(r,"input");q.setAttribute("type","text");return q}};this.createTable=function(p,e,j){var l=metawidget.util.createElement(j,"table");var o=metawidget.util.splitPath(j.path);var k=metawidget.util.traversePath(j.toInspect,o.names);if(o.names===undefined){o.names=[]}var h=undefined;if(p!=="entity"&&k!==undefined){h=k[e.name];o.names.push(e.name)}else{h=k}o.names.push("0");var d=j.inspect(j.toInspect,o.type,o.names);if(d!==undefined){var f=metawidget.util.createElement(j,"tbody");if(d.properties===undefined){l.appendChild(f);if(h!==undefined){for(var n=0,m=h.length;n<m;n++){this.addRow(f,h,n,[{type:d.type}],p,e,j)}}}else{var c=metawidget.util.getSortedInspectionResultProperties(d);var g=metawidget.util.createElement(j,"thead");l.appendChild(g);var i=this.addHeaderRow(g,c,j);l.appendChild(f);if(h!==undefined){for(var n=0,m=h.length;n<m;n++){this.addRow(f,h,n,i,p,e,j)}}}}return l};metawidget.widgetbuilder.HtmlWidgetBuilder.prototype.addHeaderRow=function(i,f,j){var h=metawidget.util.createElement(j,"tr");i.appendChild(h);var d=[];for(var c=0,g=f.length;c<g;c++){var e=f[c];if(this.addHeader(h,e,j)){d.push(e)}}return d};this.addHeader=function(e,c,f){if(c.hidden===true){return false
}var d=metawidget.util.createElement(f,"th");if(c.type!=="function"){d.innerHTML=metawidget.util.getLabelString(c,f)}e.appendChild(d);return true};this.addRow=function(f,i,k,c,l,d,j){var h=metawidget.util.createElement(j,"tr");f.appendChild(h);for(var g=0,e=c.length;g<e;g++){this.addColumn(h,i,k,c[g],l,d,j)}return h};this.addColumn=function(g,h,l,j,m,c,i){var d=metawidget.util.createElement(i,"td");var k;if(j.name===undefined){k=h[l]}else{k=h[l][j.name]}if(j.type===undefined||j.type==="array"||j.type==="function"||b===true){var e={};for(var f in j){e[f]=j[f]}if(e.name===undefined){e.name="["+l+"]"}else{e.name="["+l+"]."+e.name}if(m!=="entity"){e.name=c.name+e.name}if(e.readOnly===undefined){e.readOnly=c.readOnly}if(e.type===undefined||e.type==="array"){d.appendChild(i.buildNestedMetawidget(e))}else{d.appendChild(i.buildNestedMetawidget(e,{layout:new metawidget.layout.SimpleLayout()}))}}else{if(k!==undefined){d.innerHTML=""+k}}g.appendChild(d);return d}}})();
var metawidget=metawidget||{};(function(){metawidget.widgetprocessor=metawidget.widgetprocessor||{};metawidget.widgetprocessor.IdProcessor=function(){if(!(this instanceof metawidget.widgetprocessor.IdProcessor)){throw new Error("Constructor called as a function")}};metawidget.widgetprocessor.IdProcessor.prototype.processWidget=function(c,a,b,e){if(!c.hasAttribute("id")){var d=metawidget.util.getId(a,b,e);if(d!==undefined){c.setAttribute("id",d)}}return c};metawidget.widgetprocessor.RequiredAttributeProcessor=function(){if(!(this instanceof metawidget.widgetprocessor.RequiredAttributeProcessor)){throw new Error("Constructor called as a function")}};metawidget.widgetprocessor.RequiredAttributeProcessor.prototype.processWidget=function(c,a,b,d){if(metawidget.util.isTrueOrTrueString(b.required)){c.setAttribute("required","required")}return c};metawidget.widgetprocessor.PlaceholderAttributeProcessor=function(){if(!(this instanceof metawidget.widgetprocessor.PlaceholderAttributeProcessor)){throw new Error("Constructor called as a function")}};metawidget.widgetprocessor.PlaceholderAttributeProcessor.prototype.processWidget=function(c,a,b,d){if(b.placeholder!==undefined){c.setAttribute("placeholder",b.placeholder)}return c};metawidget.widgetprocessor.DisabledAttributeProcessor=function(){if(!(this instanceof metawidget.widgetprocessor.DisabledAttributeProcessor)){throw new Error("Constructor called as a function")}};metawidget.widgetprocessor.DisabledAttributeProcessor.prototype.processWidget=function(c,a,b,d){if(metawidget.util.isTrueOrTrueString(b.disabled)){c.setAttribute("disabled","disabled")}return c};metawidget.widgetprocessor.SimpleBindingProcessor=function(){if(!(this instanceof metawidget.widgetprocessor.SimpleBindingProcessor)){throw new Error("Constructor called as a function")}};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.onStartBuild=function(a){a._simpleBindingProcessor={}};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.processWidget=function(f,a,b,h){if(f.tagName==="INPUT"&&(f.getAttribute("type")==="button"||f.getAttribute("type")==="submit")){f.onclick=function(){try{return h.toInspect[b.name]()
}catch(i){if(alert){alert(i)}else{throw i}}};return f}var e;var c=metawidget.util.splitPath(h.path);if(a==="entity"){e=metawidget.util.traversePath(h.toInspect,c.names);if(c.names!==undefined){a="property";h._simpleBindingProcessor.topLevel=true}}else{var g=metawidget.util.traversePath(h.toInspect,c.names);if(g!==undefined){e=g[b.name]}else{e=undefined}}var d=this.bindToWidget(f,e,a,b,h);if(a!=="entity"&&(d===true||f.getMetawidget!==undefined)){h._simpleBindingProcessor.bindings=h._simpleBindingProcessor.bindings||[];h._simpleBindingProcessor.bindings[b.name]={widget:f,elementName:a,attributes:b}}return f};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.bindToWidget=function(e,h,j,d,i){var c=(e.tagName==="INPUT"||e.tagName==="SELECT"||e.tagName==="TEXTAREA");if(c===true&&e.hasAttribute("id")){e.setAttribute("name",e.getAttribute("id"))}if(d["enum"]!==undefined&&e.tagName==="DIV"){if(d.type==="array"||d.componentType!==undefined){c=true;for(var f=0,b=e.childNodes.length;f<b;f++){var a=e.childNodes[f];if(a.tagName==="LABEL"){var g=a.childNodes[0];if(g.tagName==="INPUT"){g.setAttribute("name",e.getAttribute("id"));if(d.type==="array"){g.checked=(h!==undefined&&h.indexOf(g.value)!==-1)}else{if(d.type==="boolean"){g.checked=(h===g.value||g.value===""+h)}else{g.checked=(h===g.value)}}}}}}}if(h!==undefined){if(e.tagName==="OUTPUT"||e.tagName==="TEXTAREA"){if(d.masked===true){e.innerHTML=metawidget.util.fillString("*",h.length)}else{if(d.enumTitles!==undefined){if(d.type==="array"){for(var f=0,b=h.length;f<b;f++){if(f==0){e.innerHTML=""}else{e.innerHTML+=", "}e.innerHTML+=metawidget.util.lookupEnumTitle(h[f],d["enum"],d.enumTitles)}}else{e.innerHTML=metawidget.util.lookupEnumTitle(h,d["enum"],d.enumTitles)}}else{if(d.type==="boolean"){if(h===true){e.innerHTML=metawidget.util.getLocalizedString("Yes",i)}else{if(h===false){e.innerHTML=metawidget.util.getLocalizedString("No",i)}else{e.innerHTML=h}}}else{e.innerHTML=h}}}}else{if(e.tagName==="INPUT"&&e.getAttribute("type")==="checkbox"){e.checked=h
}else{if(c===true){e.value=h}}}}return c};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.save=function(i){var j;var a=false;var k=metawidget.util.splitPath(i.path);if(k.names===undefined){j=i.toInspect}else{var d=k.names.slice(0,k.names.length-1);var g=metawidget.util.traversePath(i.toInspect,d);if(i._simpleBindingProcessor.topLevel===true){j=g}else{var h=k.names[k.names.length-1];j=g[h];if(j===undefined){j={};g[h]=j}}}for(var b in i._simpleBindingProcessor.bindings){var e=i._simpleBindingProcessor.bindings[b];var c=this.getWidgetFromBinding(e,i);if(c.getMetawidget!==undefined){this.save(c.getMetawidget());continue}var f=this.saveFromWidget(e,i);if(a===false&&j[b]!==f){a=true}j[b]=f}return a};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.saveFromWidget=function(f,i){var c=this.getWidgetFromBinding(f,i);if(c.getAttribute("type")==="checkbox"){return c.checked}if(f.attributes.type==="number"){var g=parseFloat(c.value);if(isNaN(g)){return undefined}return g}if(f.attributes["enum"]!==undefined&&c.tagName==="DIV"){if(f.attributes.type==="array"||f.attributes.componentType!==undefined){var e=[];for(var d=0,b=c.childNodes.length;d<b;d++){var a=c.childNodes[d];if(a.tagName==="LABEL"){var h=a.childNodes[0];if(h.checked){if(f.attributes.type==="boolean"){return(h.value===true||h.value==="true")}if(f.attributes.type!=="array"){return h.value}e.push(h.value)}}}return e}}if(f.attributes.type==="boolean"){return(c.value===true||c.value==="true")}if(c.value===""||c.value===null){return}return c.value};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.getWidgetFromBinding=function(a,b){return a.widget};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.reload=function(b,e){for(var a in e._simpleBindingProcessor.bindings){var d=e._simpleBindingProcessor.bindings[a];var c=this.getWidgetFromBinding(d,e);if(c.getMetawidget!==undefined){this.reload(b,c.getMetawidget());continue}this.bindToWidget(c,b[c.getAttribute("id")],d.elementName,d.attributes,e)
}}})();
var metawidget=metawidget||{};(function(){metawidget.Metawidget=function(d,a){if(!(this instanceof metawidget.Metawidget)){throw new Error("Constructor called as a function")}var f=this;d.getMetawidget=function(){return f};var c=new metawidget.Pipeline(d);c.inspector=new metawidget.inspector.PropertyTypeInspector();c.widgetBuilder=new metawidget.widgetbuilder.CompositeWidgetBuilder([new metawidget.widgetbuilder.OverriddenWidgetBuilder(),new metawidget.widgetbuilder.ReadOnlyWidgetBuilder(),new metawidget.widgetbuilder.HtmlWidgetBuilder()]);c.widgetProcessors=[new metawidget.widgetprocessor.IdProcessor(),new metawidget.widgetprocessor.RequiredAttributeProcessor(),new metawidget.widgetprocessor.PlaceholderAttributeProcessor(),new metawidget.widgetprocessor.DisabledAttributeProcessor(),new metawidget.widgetprocessor.SimpleBindingProcessor()];c.layout=new metawidget.layout.HeadingTagLayoutDecorator(new metawidget.layout.TableLayout());c.configure(a);var e=[];while(d.childNodes.length>0){var b=d.childNodes[0];d.removeChild(b);if(b.nodeType===1){e.push(b)}}this.getWidgetProcessor=function(g){return c.getWidgetProcessor(g)};this.setLayout=function(g){c.layout=g};this.inspect=function(i,g,h){return c.inspect(i,g,h,this)};this.buildWidgets=function(j){this.overriddenNodes=[];for(var g=0,i=e.length;g<i;g++){this.overriddenNodes.push(e[g].cloneNode(true))}if(j===undefined){if(arguments.length>0){throw new Error("Calling buildWidgets( undefined ) may cause infinite loop. Check your argument, or pass no arguments instead")}var h=metawidget.util.splitPath(this.path);j=c.inspect(this.toInspect,h.type,h.names,this)}c.buildWidgets(j,this)};this.getElement=function(){return c.element};this.buildNestedMetawidget=function(g,h){var j=metawidget.util.createElement(this,"div");var i=new metawidget.Metawidget(j,[c,h]);i.toInspect=this.toInspect;i.path=metawidget.util.appendPath(g,this);i.readOnly=this.readOnly||metawidget.util.isTrueOrTrueString(g.readOnly);i.buildWidgets();return j}};metawidget.Pipeline=function(a){if(!(this instanceof metawidget.Pipeline)){throw new Error("Constructor called as a function")
}this.inspectionResultProcessors=[];this.widgetProcessors=[];this.element=a;this.maximumInspectionDepth=10};metawidget.Pipeline.prototype.configure=function(b){if(b===undefined){return}var a;if(b instanceof Array){for(a=0;a<b.length;a++){this.configure(b[a])}return}if(b.inspector!==undefined){this.inspector=b.inspector}if(b.inspectionResultProcessors!==undefined){this.inspectionResultProcessors=b.inspectionResultProcessors.slice(0)}if(b.addInspectionResultProcessors!==undefined){for(a=0;a<b.addInspectionResultProcessors.length;a++){this.inspectionResultProcessors.push(b.addInspectionResultProcessors[a])}}if(b.widgetBuilder!==undefined){this.widgetBuilder=b.widgetBuilder}if(b.widgetProcessors!==undefined){this.widgetProcessors=b.widgetProcessors.slice(0)}if(b.prependWidgetProcessors!==undefined){for(a=0;a<b.prependWidgetProcessors.length;a++){this.widgetProcessors.splice(a,0,b.prependWidgetProcessors[a])}}if(b.addWidgetProcessors!==undefined){for(a=0;a<b.addWidgetProcessors.length;a++){this.widgetProcessors.push(b.addWidgetProcessors[a])}}if(b.layout!==undefined){this.layout=b.layout}if(b.maximumInspectionDepth!==undefined){this.maximumInspectionDepth=b.maximumInspectionDepth-1}};metawidget.Pipeline.prototype.getWidgetProcessor=function(b){for(var a=0,c=this.widgetProcessors.length;a<c;a++){var d=this.widgetProcessors[a];if(b(d)){return d}}};metawidget.Pipeline.prototype.inspect=function(g,c,f,h){var e;if(this.inspector.inspect!==undefined){e=this.inspector.inspect(g,c,f)}else{e=this.inspector(g,c,f)}if(e===undefined){return}for(var a=0,d=this.inspectionResultProcessors.length;a<d;a++){var b=this.inspectionResultProcessors[a];if(b.processInspectionResult!==undefined){e=b.processInspectionResult(e,h,g,c,f)}else{e=b(e,h,g,c,f)}if(e===undefined){return}}return e};metawidget.Pipeline.prototype.buildWidgets=function(g,l){while(this.element.childNodes.length>0){this.element.removeChild(this.element.childNodes[0])}c(this,l);if(g!==undefined){var b=a(g,l,"properties");var m="entity";
var h=f(this,m,b,l);if(h!==undefined){h=j(this,h,m,b,l);if(h!==undefined){this.layoutWidget(h,m,b,this.element,l)}}else{var e=metawidget.util.getSortedInspectionResultProperties(g);for(var i=0,d=e.length;i<d;i++){b=a(e[i],l);var m;if(b.type==="function"){m="action"}else{m="property"}var h=f(this,m,b,l);if(h===undefined){if(this.maximumInspectionDepth<=0){continue}h=l.buildNestedMetawidget(b);if(h===undefined){continue}}h=j(this,h,m,b,l);if(h!==undefined){this.layoutWidget(h,m,b,this.element,l)}}}}k(this,l);this.element.dispatchEvent(metawidget.util.createEvent(l,"buildEnd"));function a(n,r,q){var p={};for(var o in n){if(q!==undefined&&q.indexOf(o)!==-1){continue}p[o]=n[o]}if(r.readOnly===true){p.readOnly="true"}return p}function c(o,r){for(var n=0,p=r.overriddenNodes.length;n<p;n++){r.overriddenNodes[n].overridden=true}if(o.widgetBuilder.onStartBuild!==undefined){o.widgetBuilder.onStartBuild(r)}for(var n=0,p=o.widgetProcessors.length;n<p;n++){var q=o.widgetProcessors[n];if(q.onStartBuild!==undefined){q.onStartBuild(r)}}if(o.layout.onStartBuild!==undefined){o.layout.onStartBuild(r)}if(o.layout.startContainerLayout!==undefined){o.layout.startContainerLayout(o.element,r)}}function f(p,n,o,q){if(p.widgetBuilder.buildWidget!==undefined){return p.widgetBuilder.buildWidget(n,o,q)}return p.widgetBuilder(n,o,q)}function j(q,s,n,p,u){for(var o=0,r=q.widgetProcessors.length;o<r;o++){var t=q.widgetProcessors[o];if(t.processWidget!==undefined){s=t.processWidget(s,n,p,u)}else{s=t(s,n,p,u)}if(s===undefined){return}}return s}function k(o,u){if(u.onEndBuild!==undefined){u.onEndBuild()}else{while(u.overriddenNodes.length>0){var t=u.overriddenNodes[0];u.overriddenNodes.splice(0,1);if(t.tagName==="FACET"){continue}var q={section:""};if(t.tagName==="STUB"){for(var n=0,p=t.attributes.length;n<p;n++){var s=t.attributes[n];q[s.nodeName]=s.nodeValue}}o.layoutWidget(t,"property",q,o.element,u)}}if(o.layout.endContainerLayout!==undefined){o.layout.endContainerLayout(o.element,u)}if(o.layout.onEndBuild!==undefined){o.layout.onEndBuild(u)
}for(var n=0,p=o.widgetProcessors.length;n<p;n++){var r=o.widgetProcessors[n];if(r.onEndBuild!==undefined){r.onEndBuild(u)}}if(o.widgetBuilder.onEndBuild!==undefined){o.widgetBuilder.onEndBuild(u)}}};metawidget.Pipeline.prototype.layoutWidget=function(d,a,c,b,e){if(this.layout.layoutWidget!==undefined){this.layout.layoutWidget(d,a,c,b,e);return}this.layout(d,a,c,b,e)}})();
module.exports = metawidget;