diff --git a/dist/css/brutusin-json-forms.css b/dist/css/brutusin-json-forms.css index 5b27251..86a5a2a 100644 --- a/dist/css/brutusin-json-forms.css +++ b/dist/css/brutusin-json-forms.css @@ -1,112 +1,112 @@ -/* - * Copyright 2015 brutusin.org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @author Ignacio del Valle Alles idelvall@brutusin.org - */ -.add-pattern-div{ - margin-top: 6px; -} -.loading-layer{ - position: absolute; - top:0px; - left:0px; - z-index : 10; - width: 100%; - height: 100%; - opacity: 0.7; - background-color: white; -} -.loading-icon{ - position: absolute; - top:14px; - left:50%; - z-index : 11; -} -.loading-icon-select{ - position: absolute; - top:14px; - left:50%; - z-index : 11; -} -.loading-icon-checkbox{ - position: absolute; - top:7px; - left:3px; - z-index : 11; -} -.glyphicon-refresh-animate { - animation: spin .7s infinite linear; - -webkit-animation: spin2 .7s infinite linear; -} - -@-webkit-keyframes spin2 { - from { -webkit-transform: rotate(0deg);} - to { -webkit-transform: rotate(360deg);} -} - -@keyframes spin { - from { transform: scale(1) rotate(0deg);} - to { transform: scale(1) rotate(360deg);} -} -form.brutusin-form table, form.brutusin-form input, form.brutusin-form select, form.brutusin-form textarea{ - width: 100% !important; - min-width: 80px; -} -form.brutusin-form input[type=checkbox]{ - width: auto !important; - min-width: auto !important; -} -form.brutusin-form textarea{ - height: 8em; -} -form.brutusin-form table table{ - border-left: solid 1px; - border-color: lightgray; - margin: 4px; -} -form.brutusin-form td { - vertical-align: top; - padding: 4px; - white-space: nowrap; -} -form.brutusin-form td.prop-name { - text-align: right; -} -form.brutusin-form td.add-prop-name table { - text-align: right; - border: none; -} -form.brutusin-form td.add-prop-name table td { - vertical-align: middle; -} -form.brutusin-form td.prop-value { - width: 100%; - text-align: left; -} -form.brutusin-form td.item-index{ - font-size: 0.8em; - color: lightgray; - width: 25px; - text-align: right; -} -form.brutusin-form td.item-action{ - width: 30px; -} -form.brutusin-form .error { - border-color: red; -} -form.brutusin-form .error-message { - color: red; -} +/* + * Copyright 2015 brutusin.org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @author Ignacio del Valle Alles idelvall@brutusin.org + */ +.add-pattern-div{ + margin-top: 6px; +} +.loading-layer{ + position: absolute; + top:0px; + left:0px; + z-index : 10; + width: 100%; + height: 100%; + opacity: 0.7; + background-color: white; +} +.loading-icon{ + position: absolute; + top:14px; + left:50%; + z-index : 11; +} +.loading-icon-select{ + position: absolute; + top:14px; + left:50%; + z-index : 11; +} +.loading-icon-checkbox{ + position: absolute; + top:7px; + left:3px; + z-index : 11; +} +.glyphicon-refresh-animate { + animation: spin .7s infinite linear; + -webkit-animation: spin2 .7s infinite linear; +} + +@-webkit-keyframes spin2 { + from { -webkit-transform: rotate(0deg);} + to { -webkit-transform: rotate(360deg);} +} + +@keyframes spin { + from { transform: scale(1) rotate(0deg);} + to { transform: scale(1) rotate(360deg);} +} +form.brutusin-form table, form.brutusin-form input, form.brutusin-form select, form.brutusin-form textarea{ + width: 100% !important; + min-width: 80px; +} +form.brutusin-form input[type=checkbox]{ + width: auto !important; + min-width: auto !important; +} +form.brutusin-form textarea{ + height: 8em; +} +form.brutusin-form table table{ + border-left: solid 1px; + border-color: lightgray; + margin: 4px; +} +form.brutusin-form td { + vertical-align: top; + padding: 4px; + white-space: nowrap; +} +form.brutusin-form td.prop-name { + text-align: right; +} +form.brutusin-form td.add-prop-name table { + text-align: right; + border: none; +} +form.brutusin-form td.add-prop-name table td { + vertical-align: middle; +} +form.brutusin-form td.prop-value { + width: 100%; + text-align: left; +} +form.brutusin-form td.item-index{ + font-size: 0.8em; + color: lightgray; + width: 25px; + text-align: right; +} +form.brutusin-form td.item-action{ + width: 30px; +} +form.brutusin-form .error { + border-color: red; +} +form.brutusin-form .error-message { + color: red; +} diff --git a/dist/js/brutusin-json-forms.js b/dist/js/brutusin-json-forms.js index cbecd7d..463921d 100644 --- a/dist/js/brutusin-json-forms.js +++ b/dist/js/brutusin-json-forms.js @@ -177,7 +177,6 @@ if (typeof brutusin === "undefined") { } else if (s.media) { input = document.createElement("input"); input.type = "file"; - appendChild(input, option, s); // XXX TODO, encode the SOB properly. } else if (s.enum) { input = document.createElement("select"); @@ -205,7 +204,7 @@ if (typeof brutusin === "undefined") { } } if (s.enum.length === 1) - input.selectedIndex = 1; + input.selectedIndex = 0; else input.selectedIndex = selectedIndex; } else { @@ -223,6 +222,10 @@ if (typeof brutusin === "undefined") { // #46, problem in IE11. TODO polyfill? input.type = "text"; } + } else if (s.format === "date") { + input.type = "date"; + } else if (s.format === "time") { + input.type = "time"; } else if (s.format === "email") { input.type = "email"; } else if (s.format === "text") { @@ -345,8 +348,8 @@ if (typeof brutusin === "undefined") { if (s.required) { input = document.createElement("input"); input.type = "checkbox"; - if (value === true) { - input.checked = true; + if (value === true || value !== false && s.default) { + input.checked = true; } } else { input = document.createElement("select"); @@ -747,6 +750,7 @@ if (typeof brutusin === "undefined") { if (s.readOnly) addButton.disabled = true; addButton.setAttribute('type', 'button'); + addButton.className = "addItem"; addButton.getValidationError = function () { if (s.minItems && s.minItems > table.rows.length) { return BrutusinForms.messages["minItems"].format(s.minItems); @@ -827,8 +831,8 @@ if (typeof brutusin === "undefined") { obj.getData = function () { function removeEmptiesAndNulls(object, s) { - if (ss === null) { - ss = SCHEMA_ANY; + if (s === null) { + s = SCHEMA_ANY; } if (s.$ref) { s = getDefinition(s.$ref); @@ -844,7 +848,7 @@ if (typeof brutusin === "undefined") { return clone; } else if (object === "") { return null; - } else if (object instanceof Object) { + } else if (object instanceof Object && !(object instanceof File)) { var clone = new Object(); var nonEmpty = false; for (var prop in object) { @@ -1193,7 +1197,7 @@ if (typeof brutusin === "undefined") { } else if (propertyProvider) { renderTitle(titleContainer, propertyProvider.getValue(), s); } - if (!value) { + if (typeof value === "undefined" || value === null) { if (typeof initialValue !== "undefined" && initialValue !== null) { value = getInitialValue(id); } else { @@ -1247,6 +1251,16 @@ if (typeof brutusin === "undefined") { } function getValue(schema, input) { + if(schema.$id === "$.Document") { + input.type = 'file'; + input.getValue = function(){ + if(input.value && input.files.length ){ + return input.files[0]; + } else { + return null; + } + }; + } if (typeof input.getValue === "function") { return input.getValue(); } @@ -1307,7 +1321,7 @@ if (typeof brutusin === "undefined") { function cleanSchemaMap(schemaId) { for (var prop in schemaMap) { - if (schemaId.startsWith(prop)) { + if (prop.startsWith(schemaId)) { delete schemaMap[prop]; } } diff --git a/dist/js/brutusin-json-forms.min.js b/dist/js/brutusin-json-forms.min.js index 22cd6af..4dd449c 100644 --- a/dist/js/brutusin-json-forms.min.js +++ b/dist/js/brutusin-json-forms.min.js @@ -1 +1 @@ -if("undefined"==typeof brutusin)window.brutusin=new Object;else if("object"!=typeof brutusin)throw"brutusin global variable already exists";!function(){String.prototype.startsWith||(String.prototype.startsWith=function(e,t){return t=t||0,this.indexOf(e,t)===t}),String.prototype.endsWith||(String.prototype.endsWith=function(e,t){var r=this.toString();(void 0===t||t>r.length)&&(t=r.length),t-=e.length;var n=r.indexOf(e,t);return-1!==n&&n===t}),String.prototype.includes||(String.prototype.includes=function(){"use strict";return-1!==String.prototype.indexOf.apply(this,arguments)}),String.prototype.format||(String.prototype.format=function(){for(var e=this,t=0;t0)throw"Error parsing expression '"+e+"': Multiple tokens found inside a bracket";o+=u,i++}else r[r.length]=u;if(s===n.length-1&&a)throw"Error parsing expression '"+e+"': Unbalanced [ found"}this.exp=e,this.queue=r,this.visit=function(e,t){function r(e,n,a,i,o){if(null!=a){var s=n.shift();if("$"===s){e="$";var s=n.shift()}if(s)if(Array.isArray(a)){if(!s.startsWith("["))throw"Node '"+e+"' is of type array";var u=s.substring(1,s.length-1);if(u.equals("#"))for(var l=0;lp)throw"Element '"+u+"' of node '"+e+"' is lower than zero";var d=a[p];r(e+s,n.slice(0),d,a,p)}}else{if("object"!=typeof a)throw"boolean"==typeof a||"number"==typeof a||"string"==typeof a?"Node is leaf but still are tokens remaining: "+s:"Node type '"+typeof a+"' not supported for index field '"+e+"'";if("[*]"===s)for(var c in a){var d=a[c];r(e+s,n.slice(0),d,a,c),r(e+'["'+c+'"]',n.slice(0),d,a,c)}else{var d;if(s.startsWith("[")){var u=s.substring(1,s.length-1);if(!u.startsWith('"')&&!u.startsWith("'"))throw"Element '"+u+"' of node '"+e+"' must be a string expression or wilcard '*'";u=u.substring(1,u.length()-1),e+=s,d=a[u]}else e=e.length>0?e+"."+s:s,d=a[s];r(e,n,d,a,s)}}else t(a,i,o)}}r(this.exp,this.queue,e)}}var SCHEMA_ANY={type:"any"},obj=new Object,schemaMap=new Object,dependencyMap=new Object,renderInfoMap=new Object,container,data,error,initialValue,inputCounter=0,root=schema,formId="BrutusinForms#"+BrutusinForms.instances.length;renameRequiredPropeties(schema),populateSchemaMap("$",schema),validateDepencyMapIsAcyclic();var renderers=new Object;return renderers.integer=function(e,t,r,n,a){renderers.string(e,t,r,n,a)},renderers.number=function(e,t,r,n,a){renderers.string(e,t,r,n,a)},renderers.any=function(e,t,r,n,a){renderers.string(e,t,r,n,a)},renderers.string=function(e,t,r,n,a){var i,o=getSchemaId(t),s=getParentSchemaId(o),u=getSchema(o),l=getSchema(s);if("any"===u.type)i=document.createElement("textarea"),a&&(i.value=JSON.stringify(a,null,4),u.readOnly&&(i.disabled=!0));else if(u.media)i=document.createElement("input"),i.type="file",appendChild(i,d,u);else if(u["enum"]){if(i=document.createElement("select"),!u.required){var d=document.createElement("option"),p=document.createTextNode("");d.value="",appendChild(d,p,u),appendChild(i,d,u)}for(var c=0,m=0;me.length))return BrutusinForms.messages.minLength.format(u.minLength);if(u.maxLength&&e&&u.maxLength=u.maximum)return BrutusinForms.messages.exclusiveMaximum.format(u.maximum);if(!u.exclusiveMaximum&&e>u.maximum)return BrutusinForms.messages.maximum.format(u.maximum)}if(u.hasOwnProperty("minimum")){if(u.exclusiveMinimum&&e<=u.minimum)return BrutusinForms.messages.exclusiveMinimum.format(u.minimum);if(!u.exclusiveMinimum&&eu.maxProperties?BrutusinForms.messages.maxProperties.format(u.maxProperties):void 0}),C.description&&(S.title=C.description),appendChild(S,document.createTextNode("Add "+x),u),appendChild(E,S,u),a)for(var I in a)if(!u.properties||!u.properties.hasOwnProperty(I)){var N=RegExp(x);-1!==I.search(N)&&-1===O.indexOf(I)&&(o(l,d,t+"["+x+"]",I,a[I],x),O.push(I))}appendChild(w,E,u)}if(u.additionalProperties){var F=getSchema(u.additionalProperties),S=document.createElement("button");if(S.setAttribute("type","button"),S.onclick=function(){o(l,d,t+"[*]",void 0)},(u.maxProperties||u.minProperties)&&(S.getValidationError=function(){return u.minProperties&&c+d.rows.lengthu.maxProperties?BrutusinForms.messages.maxProperties.format(u.maxProperties):void 0}),F.description&&(S.title=F.description),appendChild(S,document.createTextNode("Add"),u),appendChild(w,S,u),a)for(var I in a)u.properties&&u.properties.hasOwnProperty(I)||-1===O.indexOf(I)&&o(l,d,t+'["'+m+'"]',I,a[I])}appendChild(e,w,u)}else appendChild(e,d,u)},renderers.array=function(e,t,r,n,a){function i(e,t,r,n,a){var i=getSchemaId(r),o=getSchema(i),s=document.createElement("tbody"),u=document.createElement("tr");u.className="item";var l=document.createElement("td");l.className="item-index";var d=document.createElement("td");d.className="item-action";var p=document.createElement("td");p.className="item-value";var c=document.createElement("button");c.setAttribute("type","button"),c.className="remove",a===!0&&(c.disabled=!0),appendChild(c,document.createTextNode("x"),o);var m=function(){for(var e=0;ep.rows.length)return BrutusinForms.messages.minItems.format(s.minItems);if(s.maxItems&&s.maxItemsr.length)&&(t=r.length),t-=e.length;var n=r.indexOf(e,t);return-1!==n&&n===t}),String.prototype.includes||(String.prototype.includes=function(){"use strict";return-1!==String.prototype.indexOf.apply(this,arguments)}),String.prototype.format||(String.prototype.format=function(){for(var e=this,t=0;t0)throw"Error parsing expression '"+e+"': Multiple tokens found inside a bracket";o+=u,i++}else r[r.length]=u;if(s===n.length-1&&a)throw"Error parsing expression '"+e+"': Unbalanced [ found"}this.exp=e,this.queue=r,this.visit=function(e,t){function r(e,n,a,i,o){if(null!=a){var s=n.shift();if("$"===s){e="$";var s=n.shift()}if(s)if(Array.isArray(a)){if(!s.startsWith("["))throw"Node '"+e+"' is of type array";var u=s.substring(1,s.length-1);if(u.equals("#"))for(var l=0;lp)throw"Element '"+u+"' of node '"+e+"' is lower than zero";var d=a[p];r(e+s,n.slice(0),d,a,p)}}else{if("object"!=typeof a)throw"boolean"==typeof a||"number"==typeof a||"string"==typeof a?"Node is leaf but still are tokens remaining: "+s:"Node type '"+typeof a+"' not supported for index field '"+e+"'";if("[*]"===s)for(var m in a){var d=a[m];r(e+s,n.slice(0),d,a,m),r(e+'["'+m+'"]',n.slice(0),d,a,m)}else{var d;if(s.startsWith("[")){var u=s.substring(1,s.length-1);if(!u.startsWith('"')&&!u.startsWith("'"))throw"Element '"+u+"' of node '"+e+"' must be a string expression or wilcard '*'";u=u.substring(1,u.length()-1),e+=s,d=a[u]}else e=e.length>0?e+"."+s:s,d=a[s];r(e,n,d,a,s)}}else t(a,i,o)}}r(this.exp,this.queue,e)}}var SCHEMA_ANY={type:"any"},obj=new Object,schemaMap=new Object,dependencyMap=new Object,renderInfoMap=new Object,container,data,error,initialValue,inputCounter=0,root=schema,formId="BrutusinForms#"+BrutusinForms.instances.length;renameRequiredPropeties(schema),populateSchemaMap("$",schema),validateDepencyMapIsAcyclic();var renderers=new Object;return renderers.integer=function(e,t,r,n,a){renderers.string(e,t,r,n,a)},renderers.number=function(e,t,r,n,a){renderers.string(e,t,r,n,a)},renderers.any=function(e,t,r,n,a){renderers.string(e,t,r,n,a)},renderers.string=function(e,t,r,n,a){var i,o=getSchemaId(t),s=getParentSchemaId(o),u=getSchema(o),l=getSchema(s);if("any"===u.type)i=document.createElement("textarea"),a&&(i.value=JSON.stringify(a,null,4),u.readOnly&&(i.disabled=!0));else if(u.media)i=document.createElement("input"),i.type="file";else if(u["enum"]){if(i=document.createElement("select"),!u.required){var d=document.createElement("option"),p=document.createTextNode("");d.value="",appendChild(d,p,u),appendChild(i,d,u)}for(var m=0,c=0;ce.length))return BrutusinForms.messages.minLength.format(u.minLength);if(u.maxLength&&e&&u.maxLength=u.maximum)return BrutusinForms.messages.exclusiveMaximum.format(u.maximum);if(!u.exclusiveMaximum&&e>u.maximum)return BrutusinForms.messages.maximum.format(u.maximum)}if(u.hasOwnProperty("minimum")){if(u.exclusiveMinimum&&e<=u.minimum)return BrutusinForms.messages.exclusiveMinimum.format(u.minimum);if(!u.exclusiveMinimum&&eu.maxProperties?BrutusinForms.messages.maxProperties.format(u.maxProperties):void 0}),C.description&&(S.title=C.description),appendChild(S,document.createTextNode("Add "+x),u),appendChild(E,S,u),a)for(var I in a)if(!u.properties||!u.properties.hasOwnProperty(I)){var N=RegExp(x);-1!==I.search(N)&&-1===O.indexOf(I)&&(o(l,d,t+"["+x+"]",I,a[I],x),O.push(I))}appendChild(w,E,u)}if(u.additionalProperties){var F=getSchema(u.additionalProperties),S=document.createElement("button");if(S.setAttribute("type","button"),S.onclick=function(){o(l,d,t+"[*]",void 0)},(u.maxProperties||u.minProperties)&&(S.getValidationError=function(){return u.minProperties&&m+d.rows.lengthu.maxProperties?BrutusinForms.messages.maxProperties.format(u.maxProperties):void 0}),F.description&&(S.title=F.description),appendChild(S,document.createTextNode("Add"),u),appendChild(w,S,u),a)for(var I in a)u.properties&&u.properties.hasOwnProperty(I)||-1===O.indexOf(I)&&o(l,d,t+'["'+c+'"]',I,a[I])}appendChild(e,w,u)}else appendChild(e,d,u)},renderers.array=function(e,t,r,n,a){function i(e,t,r,n,a){var i=getSchemaId(r),o=getSchema(i),s=document.createElement("tbody"),u=document.createElement("tr");u.className="item";var l=document.createElement("td");l.className="item-index";var d=document.createElement("td");d.className="item-action";var p=document.createElement("td");p.className="item-value";var m=document.createElement("button");m.setAttribute("type","button"),m.className="remove",a===!0&&(m.disabled=!0),appendChild(m,document.createTextNode("x"),o);var c=function(){for(var e=0;ep.rows.length)return BrutusinForms.messages.minItems.format(s.minItems);if(s.maxItems&&s.maxItems