// Metawidget 3.5 minified (licensed under LGPL)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

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){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.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 d=c!==undefined?c.labelStyleClass:undefined;var a=c!==undefined&&c.labelSuffix!==undefined?c.labelSuffix:":";this.layoutWidget=function(j,e,g,f,k){if(j.tagName==="STUB"&&!metawidget.util.hasChildElements(j)){return}var i=metawidget.util.createElement(k,"div");if(b!==undefined&&b[0]!==undefined){i.setAttribute("class",b[0])}this.layoutLabel(i,j,e,g,k);var h=metawidget.util.createElement(k,"div");if(b!==undefined&&b[2]!==undefined){h.setAttribute("class",b[2])}h.appendChild(j);i.appendChild(h);f.appendChild(i)};this.layoutLabel=function(h,i,e,f,k){if(e==="action"){return}if(f.name===undefined&&f.title===undefined){return}var j=metawidget.util.createElement(k,"div");if(b!==undefined&&b[1]!==undefined){j.setAttribute("class",b[1])}var g=metawidget.util.createElement(k,"label");if(i.getAttribute("id")!==null){g.setAttribute("for",i.getAttribute("id"))}if(d!==undefined){g.setAttribute("class",d)}g.innerHTML=metawidget.util.getLabelString(f,k)+a;j.appendChild(g);h.appendChild(j)}};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(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,l){if(d.title!==undefined){var b=metawidget.util.camelCase(d.title);if(l.l10n!==undefined&&l.l10n[b]!==undefined){return l.l10n[b]}return d.title}var a=d.name;if(l.l10n!==undefined&&l.l10n[a]!==undefined){return l.l10n[a]}var i="";var e=true;var m=" ";for(var f=0;f<a.length;f++){var h=a[f];if(e===true){i+=h.toUpperCase();e=false}else{if(g(h)&&(!g(m)||(f<a.length-1&&a[f+1]!=" "&&!g(a[f+1])))){if(m!==" "){i+=" "}i+=h}else{if(j(h)&&k(m)&&m!=" "){i+=" "+h}else{i+=h}}}m=h}return i;function j(o){var n=o.charCodeAt(0);return(n>=48&&n<=57)}function g(o){var n=o.charCodeAt(0);return(n>=65&&n<=90)}function k(o){var n=o.charCodeAt(0);return(n>=65&&n<=90)||(n>=97&&n<=122)}};metawidget.util.capitalize=function(a){return a.charAt(0).toUpperCase()+a.slice(1)};metawidget.util.isTrueOrTrueString=function(a){return(a==="true"||a===true)};metawidget.util.camelCase=function(d){if(!(d instanceof Array)){d=d.split(" ")}var c="";var b=d.length;if(b>0){c+=d[0]}for(var a=1;a<b;a++){c+=metawidget.util.capitalize(d[a])}return c};metawidget.util.getId=function(a,c,e){if(e.path!==undefined){var b=e.path.split(".");if(b[0]==="object"){b=b.slice(1)}if(c.name&&a!=="entity"){b.push(c.name)}else{if(b.length==0){return undefined}}var d=metawidget.util.camelCase(b);d=d.replace(/[\[\]]/g,"");return d}if(c!==undefined){return c.name}};metawidget.util.hasChildElements=function(c){var d=c.childNodes;for(var a=0,b=d.length;a<b;a++){if(d[a].nodeType===1){return true}}return false};metawidget.util.isSpanAllColumns=function(a){if(a===undefined){return false}if(metawidget.util.isTrueOrTrueString(a.large)){return true}return metawidget.util.isTrueOrTrueString(a.wide)};metawidget.util.splitPath=function(f){var b={};if(f!==undefined){var e=f.match(/([^\.\[\]]*)/g);b.type=e[0];for(var a=1,d=e.length;a<d;a++){if(e[a]===""){continue}if(b.names===undefined){b.names=[]}var c=e[a].match(/^(?:\s*(?:\'|\"))([^\']*)(?:(?:\'|\")\s*)$/);
if(c!==null&&c[1]!==undefined){e[a]=c[1]}b.names.push(e[a])}}return b};metawidget.util.appendPath=function(a,b){if(b.path!==undefined){return b.path+"."+a.name}if(b.toInspect!==undefined){return typeof(b.toInspect)+"."+a.name}return"object."+a.name};metawidget.util.traversePath=function(d,c){if(d===undefined){return undefined}if(c!==undefined){if(!(c instanceof Array)){throw new Error("Expected array of names")}for(var a=0,b=c.length;a<b;a++){d=d[c[a]];if(d===undefined){return undefined}}}return d};metawidget.util.getSortedInspectionResultProperties=function(d){var c=[];for(var a in d.properties){var b=d.properties[a];c.push(b);b.name=a;b._syntheticOrder=c.length}c.sort(function(f,e){if(f.propertyOrder===undefined){if(e.propertyOrder===undefined){return(f._syntheticOrder-e._syntheticOrder)}return 1}if(e.propertyOrder===undefined){return -1}var g=(f.propertyOrder-e.propertyOrder);if(g===0){return(f._syntheticOrder-e._syntheticOrder)}return g});return c};metawidget.util.combineInspectionResults=function(c,b){if(b===undefined){return}d(b,c);if(b.properties===undefined){return}c.properties=c.properties||{};for(var a in b.properties){c.properties[a]=c.properties[a]||{};d(b.properties[a],c.properties[a])}function d(h,g){for(var f in h){var e=h[f];if(e instanceof Array){g[f]=e.slice(0);continue}if(e instanceof Object){continue}g[f]=h[f]}}};metawidget.util.stripSection=function(a){var b=a.section;if(b===undefined){return undefined}if(!(b instanceof Array)){delete a.section;return b}switch(b.length){case 0:delete a.section;return"";case 1:delete a.section;return b[0];case 2:a.section=b.slice(1);return b[0]}};metawidget.util.appendToAttribute=function(d,c,b){var a=d.getAttribute(c);if(a===null){d.setAttribute(c,b)}else{d.setAttribute(c,a+" "+b)}};metawidget.util.createElement=function(b,a){return b.getElement().ownerDocument.createElement(a)};metawidget.util.createTextNode=function(b,a){return b.getElement().ownerDocument.createTextNode(a)}})();
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){f.overridden=true;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,d){if(!metawidget.util.isTrueOrTrueString(b.readOnly)){return}if(metawidget.util.isTrueOrTrueString(b.hidden)||b.type==="function"){return metawidget.util.createElement(d,"stub")}if(b["enum"]!==undefined||b.type==="string"||b.type==="boolean"||b.type==="number"||b.type==="date"){if(metawidget.util.isTrueOrTrueString(b.masked)){var c=metawidget.util.createElement(d,"stub");c.appendChild(metawidget.util.createElement(d,"stub"));
return c}return metawidget.util.createElement(d,"output")}if(metawidget.util.isTrueOrTrueString(b.dontExpand)){return metawidget.util.createElement(d,"output")}};metawidget.widgetbuilder.HtmlWidgetBuilder=function(){if(!(this instanceof metawidget.widgetbuilder.HtmlWidgetBuilder)){throw new Error("Constructor called as a function")}};metawidget.widgetbuilder.HtmlWidgetBuilder.prototype.buildWidget=function(p,e,o){if(metawidget.util.isTrueOrTrueString(e.hidden)){return metawidget.util.createElement(o,"stub")}if(e["enum"]!==undefined){if(e.type==="array"||e.componentType!==undefined){var a=metawidget.util.createElement(o,"div");for(var i=0,b=e["enum"].length;i<b;i++){var l=metawidget.util.createElement(o,"label");var h=metawidget.util.createElement(o,"input");if(e.componentType!==undefined){h.setAttribute("type",e.componentType)}else{h.setAttribute("type","checkbox")}h.setAttribute("value",e["enum"][i]);l.appendChild(h);if(e.enumTitles!==undefined&&e.enumTitles[i]!==undefined){l.appendChild(metawidget.util.createTextNode(o,e.enumTitles[i]))}else{l.appendChild(metawidget.util.createTextNode(o,e["enum"][i]))}a.appendChild(l)}return a}var k=metawidget.util.createElement(o,"select");if(!metawidget.util.isTrueOrTrueString(e.required)){k.appendChild(metawidget.util.createElement(o,"option"))}for(var i=0,b=e["enum"].length;i<b;i++){var h=metawidget.util.createElement(o,"option");h.setAttribute("value",e["enum"][i]);if(e.enumTitles!==undefined&&e.enumTitles[i]!==undefined){h.innerHTML=e.enumTitles[i]}else{h.innerHTML=e["enum"][i]}k.appendChild(h)}return k}if(e.type==="function"){var g=metawidget.util.createElement(o,"button");g.innerHTML=metawidget.util.getLabelString(e,o);return g}if(e.type==="number"){if(e.minimum!==undefined&&e.maximum!==undefined){var f=metawidget.util.createElement(o,"input");f.setAttribute("type","range");f.setAttribute("min",e.minimum);f.setAttribute("max",e.maximum);return f}var d=metawidget.util.createElement(o,"input");d.setAttribute("type","number");
if(e.minimum!==undefined){d.setAttribute("min",e.minimum)}else{if(e.maximum!==undefined){d.setAttribute("max",e.maximum)}}return d}if(e.type==="boolean"){var j=metawidget.util.createElement(o,"input");j.setAttribute("type","checkbox");return j}if(e.type==="date"){var c=metawidget.util.createElement(o,"input");c.setAttribute("type","date");return c}if(e.type==="string"){if(metawidget.util.isTrueOrTrueString(e.masked)){var m=metawidget.util.createElement(o,"input");m.setAttribute("type","password");if(e.maxLength!==undefined){m.setAttribute("maxlength",e.maxLength)}return m}if(metawidget.util.isTrueOrTrueString(e.large)){return metawidget.util.createElement(o,"textarea")}var n=metawidget.util.createElement(o,"input");n.setAttribute("type","text");if(e.maxLength!==undefined){n.setAttribute("maxlength",e.maxLength)}return n}if(e.type==="array"){return this.createTable(p,e,o)}if(metawidget.util.isTrueOrTrueString(e.dontExpand)){var n=metawidget.util.createElement(o,"input");n.setAttribute("type","text");return n}};metawidget.widgetbuilder.HtmlWidgetBuilder.prototype.createTable=function(n,c,h){var j=metawidget.util.createElement(h,"table");var m=metawidget.util.splitPath(h.path);var i=metawidget.util.traversePath(h.toInspect,m.names);if(m.names===undefined){m.names=[]}var f;if(n!=="entity"){f=i[c.name];m.names.push(c.name)}else{f=i}m.names.push("0");var b=h.inspect(h.toInspect,m.type,m.names);var d=metawidget.util.createElement(h,"tbody");if(b.properties===undefined){j.appendChild(d);for(var l=0,k=f.length;l<k;l++){this.addRow(d,f[l],[{}],h)}}else{var a=metawidget.util.getSortedInspectionResultProperties(b);var e=metawidget.util.createElement(h,"thead");j.appendChild(e);var g=this.addHeaderRow(e,a,h);j.appendChild(d);for(var l=0,k=f.length;l<k;l++){this.addRow(d,f[l],g,h)}}return j};metawidget.widgetbuilder.HtmlWidgetBuilder.prototype.addHeaderRow=function(g,d,h){var f=metawidget.util.createElement(h,"tr");g.appendChild(f);var b=[];for(var a=0,e=d.length;a<e;a++){var c=d[a];
if(this.addHeader(f,c,h)){b.push(c)}}return b};metawidget.widgetbuilder.HtmlWidgetBuilder.prototype.addHeader=function(c,a,d){if(a.hidden===true){return false}var b=metawidget.util.createElement(d,"th");b.innerHTML=metawidget.util.getLabelString(a,d);c.appendChild(b);return true};metawidget.widgetbuilder.HtmlWidgetBuilder.prototype.addRow=function(c,f,b,g){var e=metawidget.util.createElement(g,"tr");c.appendChild(e);for(var a=0,d=b.length;a<d;a++){this.addColumn(e,f,b[a],g)}return e};metawidget.widgetbuilder.HtmlWidgetBuilder.prototype.addColumn=function(c,b,a,e){var d=metawidget.util.createElement(e,"td");if(a.name===undefined){if(b!==undefined){d.innerHTML=""+b}}else{if(b[a.name]!==undefined){d.innerHTML=""+b[a.name]}}c.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.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(c,i,b,f){if(c.tagName==="BUTTON"){c.onclick=function(){try{return f.toInspect[b.name]()}catch(j){if(alert){alert(j)}else{throw j}}};return c}var e;var h=metawidget.util.splitPath(f.path);if(i==="entity"){e=metawidget.util.traversePath(f.toInspect,h.names);if(h.names!==undefined){i="property";f._simpleBindingProcessor.topLevel=true}}else{var g=metawidget.util.traversePath(f.toInspect,h.names);if(g!==undefined){e=g[b.name]}else{e=undefined}}var a=(c.tagName==="INPUT"||c.tagName==="SELECT"||c.tagName==="TEXTAREA");if(a===true&&c.hasAttribute("id")){c.setAttribute("name",c.getAttribute("id"))}if(e!==undefined){if(c.tagName==="OUTPUT"||c.tagName==="TEXTAREA"){c.innerHTML=e;if(b.enumTitles!==undefined){var d=b["enum"].indexOf(e);if(d!==-1&&d<b.enumTitles.length){c.innerHTML=b.enumTitles[d]
}}}else{if(c.tagName==="INPUT"&&c.getAttribute("type")==="checkbox"){c.checked=e}else{if(a===true){c.value=e}}}}if(i!=="entity"){if(a===true||c.metawidget!==undefined){f._simpleBindingProcessor.bindings=f._simpleBindingProcessor.bindings||[];f._simpleBindingProcessor.bindings[b.name]=c}}return c};metawidget.widgetprocessor.SimpleBindingProcessor.prototype.save=function(h){var g;var d=metawidget.util.splitPath(h.path);if(d.names===undefined){g=metawidget.util.traversePath(h.toInspect)}else{var f=d.names.slice(0,d.names.length-1);var c=metawidget.util.traversePath(h.toInspect,f);if(h._simpleBindingProcessor.topLevel===true){g=c}else{var a=d.names[d.names.length-1];g=c[a];if(g===undefined){g={};c[a]=g}}}for(var b in h._simpleBindingProcessor.bindings){var e=h._simpleBindingProcessor.bindings[b];if(e.metawidget!==undefined){this.save(e.metawidget);continue}if(e.getAttribute("type")==="checkbox"){g[b]=e.checked;continue}g[b]=e.value}}})();
var metawidget=metawidget||{};(function(){metawidget.Metawidget=function(d,a){if(!(this instanceof metawidget.Metawidget)){throw new Error("Constructor called as a function")}var c=new metawidget.Pipeline(d);c.buildNestedMetawidget=function(f,i){var h=d.ownerDocument.createElement("div");var g=new metawidget.Metawidget(h,c);g.toInspect=i.toInspect;g.path=metawidget.util.appendPath(f,i);g.readOnly=i.readOnly||metawidget.util.isTrueOrTrueString(f.readOnly);h.metawidget=g;g.buildWidgets();return h};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.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(f){return c.getWidgetProcessor(f)};this.setLayout=function(f){c.layout=f};this.inspect=function(h,f,g){return c.inspect(h,f,g,this)};this.buildWidgets=function(i){this.overriddenNodes=[];for(var f=0,h=e.length;f<h;f++){this.overriddenNodes.push(e[f].cloneNode(true))}if(i===undefined){if(arguments.length>0){throw new Error("Calling buildWidgets( undefined ) may cause infinite loop. Check your argument, or pass no arguments instead")}var g=metawidget.util.splitPath(this.path);i=c.inspect(this.toInspect,g.type,g.names,this)}c.buildWidgets(i,this)};this.getElement=function(){return c.element}};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=this.buildNestedMetawidget(b,l);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);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){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)};metawidget.Pipeline.prototype.buildNestedMetawidget=function(a,b){return undefined}})();
module.exports = metawidget;