angular-schema-form
Advanced tools
Comparing version 0.7.12 to 0.7.13
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "0.7.12", | ||
"version": "0.7.13", | ||
"authors": [ | ||
@@ -10,0 +10,0 @@ "Textalk", |
@@ -293,5 +293,5 @@ // Deps is sort of a problem for us, maybe in the future we will ask the user to depend | ||
if (form.condition) { | ||
element.children().each(function() { | ||
var ngIf = this.getAttribute('ng-if'); | ||
this.setAttribute( | ||
angular.forEach(element.children(),function(child) { | ||
var ngIf = child.getAttribute('ng-if'); | ||
child.setAttribute( | ||
'ng-if', | ||
@@ -298,0 +298,0 @@ ngIf ? |
@@ -1,1 +0,1 @@ | ||
var deps=[];try{angular.module("ngSanitize"),deps.push("ngSanitize")}catch(e){}try{angular.module("ui.sortable"),deps.push("ui.sortable")}catch(e){}try{angular.module("angularSpectrumColorpicker"),deps.push("angularSpectrumColorpicker")}catch(e){}angular.module("schemaForm",deps),angular.module("schemaForm").provider("sfPath",[function(){var e={parse:ObjectPath.parse};e.stringify=1===angular.version.major&&angular.version.minor<3?function(e){return Array.isArray(e)?e.join("."):e.toString()}:ObjectPath.stringify,e.normalize=function(r,t){return e.stringify(Array.isArray(r)?r:e.parse(r),t)},this.parse=e.parse,this.stringify=e.stringify,this.normalize=e.normalize,this.$get=function(){return e}}]),angular.module("schemaForm").factory("sfSelect",["sfPath",function(e){var r=/^\d+$/;return function(t,a,n){a||(a=this);var i="string"==typeof t?e.parse(t):t;if("undefined"!=typeof n&&1===i.length)return a[i[0]]=n,a;"undefined"!=typeof n&&"undefined"==typeof a[i[0]]&&(a[i[0]]=i.length>2&&r.test(i[1])?[]:{});for(var o=a[i[0]],u=1;u<i.length;u++){if(""===i[u])return void 0;if("undefined"!=typeof n){if(u===i.length-1)return o[i[u]]=n,n;var l=o[i[u]];("undefined"==typeof l||null===l)&&(l=r.test(i[u+1])?[]:{},o[i[u]]=l),o=l}else o&&(o=o[i[u]])}return o}}]),angular.module("schemaForm").provider("schemaFormDecorators",["$compileProvider","sfPathProvider",function(e,r){var t="",a={},n=function(e,r){"sfDecorator"===e&&(e=t);for(var n=a[e],i=n.rules,o=0;o<i.length;o++){var u=i[o](r);if(u)return u}return n.mappings[r.type]?n.mappings[r.type]:n.mappings["default"]},i=function(t){e.directive(t,["$parse","$compile","$http","$templateCache",function(e,a,i,o){return{restrict:"AE",replace:!1,transclude:!1,scope:!0,require:"?^sfSchema",link:function(e,u,l,s){e.showTitle=function(){return e.form&&e.form.notitle!==!0&&e.form.title},e.listToCheckboxValues=function(e){var r={};return angular.forEach(e,function(e){r[e]=!0}),r},e.checkboxValuesToList=function(e){var r=[];return angular.forEach(e,function(e,t){e&&r.push(t)}),r},e.buttonClick=function(r,t){angular.isFunction(t.onClick)?t.onClick(r,t):angular.isString(t.onClick)&&(s?s.evalInParentScope(t.onClick,{$event:r,form:t}):e.$eval(t.onClick,{$event:r,form:t}))},e.evalExpr=function(r,t){return s?s.evalInParentScope(r,t):e.$eval(r,t)},e.evalInScope=function(r,t){return r?e.$eval(r,t):void 0},e.errorMessage=function(r){return e.form.validationMessage?r?angular.isString(e.form.validationMessage)?e.form.validationMessage:e.form.validationMessage[r.code]||e.form.validationMessage["default"]:e.form.validationMessage.number||e.form.validationMessage["default"]||e.form.validationMessage:r?r.message:"Not a number"};var c=e.$watch(l.form,function(l){if(l){l.ngModelOptions=l.ngModelOptions||{},e.form=l;var s=n(t,l);i.get(s,{cache:o}).then(function(t){var n=l.key?r.stringify(l.key).replace(/"/g,"""):"",i=t.data.replace(/\$\$value\$\$/g,"model"+("["!==n[0]?".":"")+n);u.html(i),l.condition&&u.children().each(function(){var e=this.getAttribute("ng-if");this.setAttribute("ng-if",e?"("+e+') || (evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex }))':'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex })')}),a(u.contents())(e)}),c()}})}}}])},o=function(r,t,a){a=angular.isDefined(a)?a:!1,e.directive("sf"+angular.uppercase(r[0])+r.substr(1),function(){return{restrict:"EAC",scope:!0,replace:!0,transclude:a,template:'<sf-decorator form="form"></sf-decorator>',link:function(e,t,a){var n={items:"c",titleMap:"c",schema:"c"},i={type:r},o=!0;angular.forEach(a,function(r,t){if("$"!==t[0]&&0!==t.indexOf("ng")&&"sfField"!==t){var u=function(r){angular.isDefined(r)&&r!==i[t]&&(i[t]=r,o&&i.type&&(i.key||angular.isUndefined(a.key))&&(e.form=i,o=!1))};"model"===t?e.$watch(r,function(r){r&&e.model!==r&&(e.model=r)}):"c"===n[t]?e.$watchCollection(r,u):a.$observe(t,u)}})}}})};this.createDecorator=function(e,r,n){a[e]={mappings:r||{},rules:n||[]},a[t]||(t=e),i(e)},this.createDirective=o,this.createDirectives=function(e){angular.forEach(e,function(e,r){o(r,e)})},this.directive=function(e){return e=e||t,a[e]},this.addMapping=function(e,r,t){a[e]&&(a[e].mappings[r]=t)},this.$get=function(){return{directive:function(e){return a[e]},defaultDecorator:t}},i("sfDecorator")}]),angular.module("schemaForm").provider("schemaForm",["sfPathProvider",function(e){var r=function(e){var r=[];return e.forEach(function(e){r.push({name:e,value:e})}),r},t=function(e,r){if(!angular.isArray(e)){var t=[];return r?angular.forEach(r,function(r){t.push({name:e[r],value:r})}):angular.forEach(e,function(e,r){t.push({name:e,value:r})}),t}return e},a=function(e,r,t){var a=d[r.type];if(a)for(var n,i=0;i<a.length;i++)if(n=a[i](e,r,t))return n.schema["x-schema-form"]&&angular.isObject(n.schema["x-schema-form"])&&(n=angular.extend(n,n.schema["x-schema-form"])),n},n=function(e,r,a){a=a||{};var n=a.global&&a.global.formDefaults?angular.copy(a.global.formDefaults):{};return n.title=a.global&&a.global.supressPropertyTitles===!0?r.title:r.title||e,r.description&&(n.description=r.description),(a.required===!0||r.required===!0)&&(n.required=!0),r.maxLength&&(n.maxlength=r.maxLength),r.minLength&&(n.minlength=r.maxLength),(r.readOnly||r.readonly)&&(n.readonly=!0),r.minimum&&(n.minimum=r.minimum+(r.exclusiveMinimum?1:0)),r.maximum&&(n.maximum=r.maximum-(r.exclusiveMaximum?1:0)),r.validationMessage&&(n.validationMessage=r.validationMessage),r.enumNames&&(n.titleMap=t(r.enumNames,r["enum"])),n.schema=r,n.ngModelOptions=n.ngModelOptions||{},n},i=function(r,t,a){if("string"===t.type&&!t["enum"]){var i=n(r,t,a);return i.key=a.path,i.type="text",a.lookup[e.stringify(a.path)]=i,i}},o=function(r,t,a){if("number"===t.type){var i=n(r,t,a);return i.key=a.path,i.type="number",a.lookup[e.stringify(a.path)]=i,i}},u=function(r,t,a){if("integer"===t.type){var i=n(r,t,a);return i.key=a.path,i.type="number",a.lookup[e.stringify(a.path)]=i,i}},l=function(r,t,a){if("boolean"===t.type){var i=n(r,t,a);return i.key=a.path,i.type="checkbox",a.lookup[e.stringify(a.path)]=i,i}},s=function(t,a,i){if("string"===a.type&&a["enum"]){var o=n(t,a,i);return o.key=i.path,o.type="select",o.titleMap||(o.titleMap=r(a["enum"])),i.lookup[e.stringify(i.path)]=o,o}},c=function(t,a,i){if("array"===a.type&&a.items&&a.items["enum"]){var o=n(t,a,i);return o.key=i.path,o.type="checkboxes",o.titleMap||(o.titleMap=r(a.items["enum"])),i.lookup[e.stringify(i.path)]=o,o}},f=function(r,t,i){if("object"===t.type){var o=n(r,t,i);return o.type="fieldset",o.items=[],i.lookup[e.stringify(i.path)]=o,angular.forEach(t.properties,function(r,n){var u=i.path.slice();if(u.push(n),i.ignore[e.stringify(u)]!==!0){var l=t.required&&-1!==t.required.indexOf(n),s=a(n,r,{path:u,required:l||!1,lookup:i.lookup,ignore:i.ignore});s&&o.items.push(s)}}),o}},m=function(r,t,i){if("array"===t.type){var o=n(r,t,i);o.type="array",o.key=i.path,i.lookup[e.stringify(i.path)]=o;var u=t.required&&-1!==t.required.indexOf(i.path[i.path.length-1]),l=i.path.slice();return l.push(""),o.items=[a(r,t.items,{path:l,required:u||!1,lookup:i.lookup,ignore:i.ignore,global:i.global})],o}},d={string:[s,i],object:[f],number:[o],integer:[u],"boolean":[l],array:[c,m]},p=function(e){return e};this.defaults=d,this.stdFormObj=n,this.defaultFormDefinition=a,this.postProcess=function(e){p=e},this.appendRule=function(e,r){d[e]||(d[e]=[]),d[e].push(r)},this.prependRule=function(e,r){d[e]||(d[e]=[]),d[e].unshift(r)},this.createStandardForm=n,this.$get=function(){var r={};return r.merge=function(a,n,i,o,u){n=n||["*"],o=o||{},u=u||a.readonly||a.readOnly;var l=r.defaults(a,i,o),s=n.indexOf("*");-1!==s&&(n=n.slice(0,s).concat(l.form).concat(n.slice(s+1)));var c=l.lookup;return p(n.map(function(n){if("string"==typeof n&&(n={key:n}),n.key&&"string"==typeof n.key&&(n.key=e.parse(n.key)),n.titleMap&&(n.titleMap=t(n.titleMap)),n.itemForm){n.items=[];var l=e.stringify(n.key),s=c[l];angular.forEach(s.items,function(e){var r=angular.copy(n.itemForm);r.key=e.key,n.items.push(r)})}if(n.key){var f=e.stringify(n.key);c[f]&&(n=angular.extend(c[f],n))}return u===!0&&(n.readonly=!0),n.items&&(n.items=r.merge(a,n.items,i,o,n.readonly)),n.tabs&&angular.forEach(n.tabs,function(e){e.items=r.merge(a,e.items,i,o,n.readonly)}),"checkbox"===n.type&&angular.isUndefined(n.schema["default"])&&(n.schema["default"]=!1),n}))},r.defaults=function(e,r,t){var n=[],i={};if(r=r||{},t=t||{},"object"!==e.type)throw new Error('Not implemented. Only type "object" allowed at root level of schema.');return angular.forEach(e.properties,function(o,u){if(r[u]!==!0){var l=e.required&&-1!==e.required.indexOf(u),s=a(u,o,{path:[u],lookup:i,ignore:r,required:l,global:t});s&&n.push(s)}}),{form:n,lookup:i}},r.traverseSchema=function(e,r,t,a){a=angular.isDefined(a)?a:!0,t=t||[];var n=function(e,r,t){if(r(e,t),angular.forEach(e.properties,function(e,a){var i=t.slice();i.push(a),n(e,r,i)}),!a&&e.items){var i=t.slice();i.push(""),n(e.items,r,i)}};n(e,r,t||[])},r.traverseForm=function(e,t){t(e),angular.forEach(e.items,function(e){r.traverseForm(e,t)}),e.tabs&&angular.forEach(e.tabs,function(e){angular.forEach(e.items,function(e){r.traverseForm(e,t)})})},r}}]),angular.module("schemaForm").factory("sfValidator",[function(){var e={};return e.validate=function(e,r){if(!e)return{valid:!0};var t=e.schema;if(!t)return{valid:!0};""===r&&(r=void 0),"number"===e.type&&null===r&&(r=void 0);var a={type:"object",properties:{}},n=e.key[e.key.length-1];a.properties[n]=t,e.required&&(a.required=[n]);var i={};return angular.isDefined(r)&&(i[n]=r),tv4.validateResult(i,a)},e}]),angular.module("schemaForm").directive("sfArray",["sfSelect","schemaForm","sfValidator","sfPath",function(e,r,t,a){var n=function(e){return function(r){r.key&&(r.key[r.key.indexOf("")]=e)}};return{restrict:"A",scope:!0,require:"?ngModel",link:function(i,o,u,l){var s={},c=i.$watch(u.sfArray,function(o){var u=e(o.key,i.model);if(i.$watch("model"+a.normalize(o.key),function(){u=e(o.key,i.model),i.modelArray=u}),angular.isUndefined(u)&&(u=[],e(o.key,i.model,u)),i.modelArray=u,o.items){var f=o.items[0];o.items.length>1&&(f={type:"section",items:o.items.map(function(e){return e.ngModelOptions=o.ngModelOptions,angular.isUndefined(e.readonly)&&(e.readonly=o.readonly),e})})}if(i.copyWithIndex=function(e){if(!s[e]&&f){var t=angular.copy(f);t.arrayIndex=e,r.traverseForm(t,n(e)),s[e]=t}return s[e]},i.appendToArray=function(){var t=u.length,a=i.copyWithIndex(t);if(r.traverseForm(a,function(r){if(r.key){var t;angular.isDefined(r["default"])&&(t=r["default"]),angular.isDefined(r.schema)&&angular.isDefined(r.schema["default"])&&(t=r.schema["default"]),angular.isDefined(t)&&e(r.key,i.model,t)}}),t===u.length){var n,l=e("schema.items.type",o);"object"===l?n={}:"array"===l&&(n=[]),u.push(n)}return i.validateArray&&i.validateArray(),u},i.deleteFromArray=function(e){return u.splice(e,1),i.validateArray&&i.validateArray(),l&&l.$setDirty&&l.$setDirty(),u},o.titleMap||o.startEmpty===!0||0!==u.length||i.appendToArray(),o.titleMap&&o.titleMap.length>0){i.titleMapValues=[];var m=function(e){i.titleMapValues=[],e=e||[],o.titleMap.forEach(function(r){i.titleMapValues.push(-1!==e.indexOf(r.value))})};m(i.modelArray),i.$watchCollection("modelArray",m),i.$watchCollection("titleMapValues",function(e){if(e){for(var r=i.modelArray;r.length>0;)r.pop();o.titleMap.forEach(function(t,a){e[a]&&r.push(t.value)})}})}if(l){var d;i.validateArray=function(){var e=t.validate(o,i.modelArray.length>0?i.modelArray:void 0);e.valid!==!1||!e.error||""!==e.error.dataPath&&e.error.dataPath!=="/"+o.key[o.key.length-1]?l.$setValidity("schema",!0):(l.$setViewValue(i.modelArray),d=e.error,l.$setValidity("schema",!1))},i.$on("schemaFormValidate",i.validateArray),i.hasSuccess=function(){return l.$valid&&!l.$pristine},i.hasError=function(){return l.$invalid},i.schemaError=function(){return d}}c()})}}}]),angular.module("schemaForm").directive("sfChanged",function(){return{require:"ngModel",restrict:"AC",scope:!1,link:function(e,r,t,a){var n=e.$eval(t.sfChanged);n&&n.onChange&&a.$viewChangeListeners.push(function(){angular.isFunction(n.onChange)?n.onChange(a.$modelValue,n):e.evalExpr(n.onChange,{modelValue:a.$modelValue,form:n})})}}}),angular.module("schemaForm").directive("sfSchema",["$compile","schemaForm","schemaFormDecorators","sfSelect","sfPath",function(e,r,t,a,n){var i=/[A-Z]/g,o=function(e,r){return r=r||"_",e.replace(i,function(e,t){return(t?r:"")+e.toLowerCase()})};return{scope:{schema:"=sfSchema",initialForm:"=sfForm",model:"=sfModel",options:"=sfOptions"},controller:["$scope",function(e){this.evalInParentScope=function(r,t){return e.$parent.$eval(r,t)}}],replace:!1,restrict:"A",transclude:!0,require:"?form",link:function(i,u,l,s,c){i.formCtrl=s;var f={};c(i,function(e){if(e.addClass("schema-form-ignore"),u.prepend(e),u[0].querySelectorAll){var r=u[0].querySelectorAll("[ng-model]");if(r)for(var t=0;t<r.length;t++){var a=r[t].getAttribute("ng-model");f[a.substring(a.indexOf(".")+1)]=!0}}});var m,d={},p=function(s,c){var d=r.merge(s,c,f,i.options),p=document.createDocumentFragment();m&&m.$destroy(),m=i.$new(),m.schemaForm={form:d,schema:s},u.children(":not(.schema-form-ignore)").remove();for(var h={},g=u[0].querySelectorAll("*[sf-insert-field]"),v=0;v<g.length;v++)h[g[v].getAttribute("sf-insert-field")]=g[v];angular.forEach(d,function(e,r){var a=document.createElement(l.sfDecorator||o(t.defaultDecorator,"-"));if(a.setAttribute("form","schemaForm.form["+r+"]"),e.key){var i=h[n.stringify(e.key)];if(i){for(;i.firstChild;)i.removeChild(i.firstChild);return void i.appendChild(a)}}p.appendChild(a)}),u[0].appendChild(p),e(u.children())(m),r.traverseSchema(s,function(e,r){if(angular.isDefined(e["default"])){var t=a(r,i.model);angular.isUndefined(t)&&a(r,i.model,e["default"])}}),i.$emit("sf-render-finished",u)};i.$watch(function(){var e=i.schema,r=i.initialForm||["*"];r&&e&&e.type&&(d.form!==r||d.schema!==e)&&Object.keys(e.properties).length>0&&(d.schema=e,d.form=r,p(e,r))}),i.$on("schemaFormRedraw",function(){var e=i.schema,r=i.initialForm||["*"];e&&p(e,r)})}}}]),angular.module("schemaForm").directive("schemaValidate",["sfValidator","sfSelect",function(e,r){return{restrict:"A",scope:!1,priority:1e3,require:"ngModel",link:function(t,a,n,i){t.ngModel=i;var o=null,u=function(){return l||(l=t.$eval(n.schemaValidate)),l},l=u();l.copyValueTo&&i.$viewChangeListeners.push(function(){var e=l.copyValueTo;angular.forEach(e,function(e){r(e,t.model,i.$modelValue)})}),i.$validators?i.$validators.schema=function(r){var t=e.validate(u(),r);return o=t.error,t.valid}:i.$parsers.push(function(r){if(l=u(),!l)return r;var t=e.validate(l,r);return t.valid?(i.$setValidity("schema",!0),r):(i.$setValidity("schema",!1),void(o=t.error))}),t.$on("schemaFormValidate",function(){i.$validate?(i.$validate(),i.$invalid&&(i.$dirty=!0,i.$pristine=!1)):i.$setViewValue(i.$viewValue)}),t.hasSuccess=function(){return i.$valid&&(!i.$pristine||!i.$isEmpty(i.$modelValue))},t.hasError=function(){return i.$invalid&&!i.$pristine},t.schemaError=function(){return o}}}}]); | ||
var deps=[];try{angular.module("ngSanitize"),deps.push("ngSanitize")}catch(e){}try{angular.module("ui.sortable"),deps.push("ui.sortable")}catch(e){}try{angular.module("angularSpectrumColorpicker"),deps.push("angularSpectrumColorpicker")}catch(e){}angular.module("schemaForm",deps),angular.module("schemaForm").provider("sfPath",[function(){var e={parse:ObjectPath.parse};e.stringify=1===angular.version.major&&angular.version.minor<3?function(e){return Array.isArray(e)?e.join("."):e.toString()}:ObjectPath.stringify,e.normalize=function(r,t){return e.stringify(Array.isArray(r)?r:e.parse(r),t)},this.parse=e.parse,this.stringify=e.stringify,this.normalize=e.normalize,this.$get=function(){return e}}]),angular.module("schemaForm").factory("sfSelect",["sfPath",function(e){var r=/^\d+$/;return function(t,a,n){a||(a=this);var i="string"==typeof t?e.parse(t):t;if("undefined"!=typeof n&&1===i.length)return a[i[0]]=n,a;"undefined"!=typeof n&&"undefined"==typeof a[i[0]]&&(a[i[0]]=i.length>2&&r.test(i[1])?[]:{});for(var o=a[i[0]],u=1;u<i.length;u++){if(""===i[u])return void 0;if("undefined"!=typeof n){if(u===i.length-1)return o[i[u]]=n,n;var l=o[i[u]];("undefined"==typeof l||null===l)&&(l=r.test(i[u+1])?[]:{},o[i[u]]=l),o=l}else o&&(o=o[i[u]])}return o}}]),angular.module("schemaForm").provider("schemaFormDecorators",["$compileProvider","sfPathProvider",function(e,r){var t="",a={},n=function(e,r){"sfDecorator"===e&&(e=t);for(var n=a[e],i=n.rules,o=0;o<i.length;o++){var u=i[o](r);if(u)return u}return n.mappings[r.type]?n.mappings[r.type]:n.mappings["default"]},i=function(t){e.directive(t,["$parse","$compile","$http","$templateCache",function(e,a,i,o){return{restrict:"AE",replace:!1,transclude:!1,scope:!0,require:"?^sfSchema",link:function(e,u,l,s){e.showTitle=function(){return e.form&&e.form.notitle!==!0&&e.form.title},e.listToCheckboxValues=function(e){var r={};return angular.forEach(e,function(e){r[e]=!0}),r},e.checkboxValuesToList=function(e){var r=[];return angular.forEach(e,function(e,t){e&&r.push(t)}),r},e.buttonClick=function(r,t){angular.isFunction(t.onClick)?t.onClick(r,t):angular.isString(t.onClick)&&(s?s.evalInParentScope(t.onClick,{$event:r,form:t}):e.$eval(t.onClick,{$event:r,form:t}))},e.evalExpr=function(r,t){return s?s.evalInParentScope(r,t):e.$eval(r,t)},e.evalInScope=function(r,t){return r?e.$eval(r,t):void 0},e.errorMessage=function(r){return e.form.validationMessage?r?angular.isString(e.form.validationMessage)?e.form.validationMessage:e.form.validationMessage[r.code]||e.form.validationMessage["default"]:e.form.validationMessage.number||e.form.validationMessage["default"]||e.form.validationMessage:r?r.message:"Not a number"};var c=e.$watch(l.form,function(l){if(l){l.ngModelOptions=l.ngModelOptions||{},e.form=l;var s=n(t,l);i.get(s,{cache:o}).then(function(t){var n=l.key?r.stringify(l.key).replace(/"/g,"""):"",i=t.data.replace(/\$\$value\$\$/g,"model"+("["!==n[0]?".":"")+n);u.html(i),l.condition&&angular.forEach(u.children(),function(e){var r=e.getAttribute("ng-if");e.setAttribute("ng-if",r?"("+r+') || (evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex }))':'evalExpr(form.condition,{ model: model, "arrayIndex": arrayIndex })')}),a(u.contents())(e)}),c()}})}}}])},o=function(r,t,a){a=angular.isDefined(a)?a:!1,e.directive("sf"+angular.uppercase(r[0])+r.substr(1),function(){return{restrict:"EAC",scope:!0,replace:!0,transclude:a,template:'<sf-decorator form="form"></sf-decorator>',link:function(e,t,a){var n={items:"c",titleMap:"c",schema:"c"},i={type:r},o=!0;angular.forEach(a,function(r,t){if("$"!==t[0]&&0!==t.indexOf("ng")&&"sfField"!==t){var u=function(r){angular.isDefined(r)&&r!==i[t]&&(i[t]=r,o&&i.type&&(i.key||angular.isUndefined(a.key))&&(e.form=i,o=!1))};"model"===t?e.$watch(r,function(r){r&&e.model!==r&&(e.model=r)}):"c"===n[t]?e.$watchCollection(r,u):a.$observe(t,u)}})}}})};this.createDecorator=function(e,r,n){a[e]={mappings:r||{},rules:n||[]},a[t]||(t=e),i(e)},this.createDirective=o,this.createDirectives=function(e){angular.forEach(e,function(e,r){o(r,e)})},this.directive=function(e){return e=e||t,a[e]},this.addMapping=function(e,r,t){a[e]&&(a[e].mappings[r]=t)},this.$get=function(){return{directive:function(e){return a[e]},defaultDecorator:t}},i("sfDecorator")}]),angular.module("schemaForm").provider("schemaForm",["sfPathProvider",function(e){var r=function(e){var r=[];return e.forEach(function(e){r.push({name:e,value:e})}),r},t=function(e,r){if(!angular.isArray(e)){var t=[];return r?angular.forEach(r,function(r){t.push({name:e[r],value:r})}):angular.forEach(e,function(e,r){t.push({name:e,value:r})}),t}return e},a=function(e,r,t){var a=d[r.type];if(a)for(var n,i=0;i<a.length;i++)if(n=a[i](e,r,t))return n.schema["x-schema-form"]&&angular.isObject(n.schema["x-schema-form"])&&(n=angular.extend(n,n.schema["x-schema-form"])),n},n=function(e,r,a){a=a||{};var n=a.global&&a.global.formDefaults?angular.copy(a.global.formDefaults):{};return n.title=a.global&&a.global.supressPropertyTitles===!0?r.title:r.title||e,r.description&&(n.description=r.description),(a.required===!0||r.required===!0)&&(n.required=!0),r.maxLength&&(n.maxlength=r.maxLength),r.minLength&&(n.minlength=r.maxLength),(r.readOnly||r.readonly)&&(n.readonly=!0),r.minimum&&(n.minimum=r.minimum+(r.exclusiveMinimum?1:0)),r.maximum&&(n.maximum=r.maximum-(r.exclusiveMaximum?1:0)),r.validationMessage&&(n.validationMessage=r.validationMessage),r.enumNames&&(n.titleMap=t(r.enumNames,r["enum"])),n.schema=r,n.ngModelOptions=n.ngModelOptions||{},n},i=function(r,t,a){if("string"===t.type&&!t["enum"]){var i=n(r,t,a);return i.key=a.path,i.type="text",a.lookup[e.stringify(a.path)]=i,i}},o=function(r,t,a){if("number"===t.type){var i=n(r,t,a);return i.key=a.path,i.type="number",a.lookup[e.stringify(a.path)]=i,i}},u=function(r,t,a){if("integer"===t.type){var i=n(r,t,a);return i.key=a.path,i.type="number",a.lookup[e.stringify(a.path)]=i,i}},l=function(r,t,a){if("boolean"===t.type){var i=n(r,t,a);return i.key=a.path,i.type="checkbox",a.lookup[e.stringify(a.path)]=i,i}},s=function(t,a,i){if("string"===a.type&&a["enum"]){var o=n(t,a,i);return o.key=i.path,o.type="select",o.titleMap||(o.titleMap=r(a["enum"])),i.lookup[e.stringify(i.path)]=o,o}},c=function(t,a,i){if("array"===a.type&&a.items&&a.items["enum"]){var o=n(t,a,i);return o.key=i.path,o.type="checkboxes",o.titleMap||(o.titleMap=r(a.items["enum"])),i.lookup[e.stringify(i.path)]=o,o}},f=function(r,t,i){if("object"===t.type){var o=n(r,t,i);return o.type="fieldset",o.items=[],i.lookup[e.stringify(i.path)]=o,angular.forEach(t.properties,function(r,n){var u=i.path.slice();if(u.push(n),i.ignore[e.stringify(u)]!==!0){var l=t.required&&-1!==t.required.indexOf(n),s=a(n,r,{path:u,required:l||!1,lookup:i.lookup,ignore:i.ignore});s&&o.items.push(s)}}),o}},m=function(r,t,i){if("array"===t.type){var o=n(r,t,i);o.type="array",o.key=i.path,i.lookup[e.stringify(i.path)]=o;var u=t.required&&-1!==t.required.indexOf(i.path[i.path.length-1]),l=i.path.slice();return l.push(""),o.items=[a(r,t.items,{path:l,required:u||!1,lookup:i.lookup,ignore:i.ignore,global:i.global})],o}},d={string:[s,i],object:[f],number:[o],integer:[u],"boolean":[l],array:[c,m]},p=function(e){return e};this.defaults=d,this.stdFormObj=n,this.defaultFormDefinition=a,this.postProcess=function(e){p=e},this.appendRule=function(e,r){d[e]||(d[e]=[]),d[e].push(r)},this.prependRule=function(e,r){d[e]||(d[e]=[]),d[e].unshift(r)},this.createStandardForm=n,this.$get=function(){var r={};return r.merge=function(a,n,i,o,u){n=n||["*"],o=o||{},u=u||a.readonly||a.readOnly;var l=r.defaults(a,i,o),s=n.indexOf("*");-1!==s&&(n=n.slice(0,s).concat(l.form).concat(n.slice(s+1)));var c=l.lookup;return p(n.map(function(n){if("string"==typeof n&&(n={key:n}),n.key&&"string"==typeof n.key&&(n.key=e.parse(n.key)),n.titleMap&&(n.titleMap=t(n.titleMap)),n.itemForm){n.items=[];var l=e.stringify(n.key),s=c[l];angular.forEach(s.items,function(e){var r=angular.copy(n.itemForm);r.key=e.key,n.items.push(r)})}if(n.key){var f=e.stringify(n.key);c[f]&&(n=angular.extend(c[f],n))}return u===!0&&(n.readonly=!0),n.items&&(n.items=r.merge(a,n.items,i,o,n.readonly)),n.tabs&&angular.forEach(n.tabs,function(e){e.items=r.merge(a,e.items,i,o,n.readonly)}),"checkbox"===n.type&&angular.isUndefined(n.schema["default"])&&(n.schema["default"]=!1),n}))},r.defaults=function(e,r,t){var n=[],i={};if(r=r||{},t=t||{},"object"!==e.type)throw new Error('Not implemented. Only type "object" allowed at root level of schema.');return angular.forEach(e.properties,function(o,u){if(r[u]!==!0){var l=e.required&&-1!==e.required.indexOf(u),s=a(u,o,{path:[u],lookup:i,ignore:r,required:l,global:t});s&&n.push(s)}}),{form:n,lookup:i}},r.traverseSchema=function(e,r,t,a){a=angular.isDefined(a)?a:!0,t=t||[];var n=function(e,r,t){if(r(e,t),angular.forEach(e.properties,function(e,a){var i=t.slice();i.push(a),n(e,r,i)}),!a&&e.items){var i=t.slice();i.push(""),n(e.items,r,i)}};n(e,r,t||[])},r.traverseForm=function(e,t){t(e),angular.forEach(e.items,function(e){r.traverseForm(e,t)}),e.tabs&&angular.forEach(e.tabs,function(e){angular.forEach(e.items,function(e){r.traverseForm(e,t)})})},r}}]),angular.module("schemaForm").factory("sfValidator",[function(){var e={};return e.validate=function(e,r){if(!e)return{valid:!0};var t=e.schema;if(!t)return{valid:!0};""===r&&(r=void 0),"number"===e.type&&null===r&&(r=void 0);var a={type:"object",properties:{}},n=e.key[e.key.length-1];a.properties[n]=t,e.required&&(a.required=[n]);var i={};return angular.isDefined(r)&&(i[n]=r),tv4.validateResult(i,a)},e}]),angular.module("schemaForm").directive("sfArray",["sfSelect","schemaForm","sfValidator","sfPath",function(e,r,t,a){var n=function(e){return function(r){r.key&&(r.key[r.key.indexOf("")]=e)}};return{restrict:"A",scope:!0,require:"?ngModel",link:function(i,o,u,l){var s={},c=i.$watch(u.sfArray,function(o){var u=e(o.key,i.model);if(i.$watch("model"+a.normalize(o.key),function(){u=e(o.key,i.model),i.modelArray=u}),angular.isUndefined(u)&&(u=[],e(o.key,i.model,u)),i.modelArray=u,o.items){var f=o.items[0];o.items.length>1&&(f={type:"section",items:o.items.map(function(e){return e.ngModelOptions=o.ngModelOptions,angular.isUndefined(e.readonly)&&(e.readonly=o.readonly),e})})}if(i.copyWithIndex=function(e){if(!s[e]&&f){var t=angular.copy(f);t.arrayIndex=e,r.traverseForm(t,n(e)),s[e]=t}return s[e]},i.appendToArray=function(){var t=u.length,a=i.copyWithIndex(t);if(r.traverseForm(a,function(r){if(r.key){var t;angular.isDefined(r["default"])&&(t=r["default"]),angular.isDefined(r.schema)&&angular.isDefined(r.schema["default"])&&(t=r.schema["default"]),angular.isDefined(t)&&e(r.key,i.model,t)}}),t===u.length){var n,l=e("schema.items.type",o);"object"===l?n={}:"array"===l&&(n=[]),u.push(n)}return i.validateArray&&i.validateArray(),u},i.deleteFromArray=function(e){return u.splice(e,1),i.validateArray&&i.validateArray(),l&&l.$setDirty&&l.$setDirty(),u},o.titleMap||o.startEmpty===!0||0!==u.length||i.appendToArray(),o.titleMap&&o.titleMap.length>0){i.titleMapValues=[];var m=function(e){i.titleMapValues=[],e=e||[],o.titleMap.forEach(function(r){i.titleMapValues.push(-1!==e.indexOf(r.value))})};m(i.modelArray),i.$watchCollection("modelArray",m),i.$watchCollection("titleMapValues",function(e){if(e){for(var r=i.modelArray;r.length>0;)r.pop();o.titleMap.forEach(function(t,a){e[a]&&r.push(t.value)})}})}if(l){var d;i.validateArray=function(){var e=t.validate(o,i.modelArray.length>0?i.modelArray:void 0);e.valid!==!1||!e.error||""!==e.error.dataPath&&e.error.dataPath!=="/"+o.key[o.key.length-1]?l.$setValidity("schema",!0):(l.$setViewValue(i.modelArray),d=e.error,l.$setValidity("schema",!1))},i.$on("schemaFormValidate",i.validateArray),i.hasSuccess=function(){return l.$valid&&!l.$pristine},i.hasError=function(){return l.$invalid},i.schemaError=function(){return d}}c()})}}}]),angular.module("schemaForm").directive("sfChanged",function(){return{require:"ngModel",restrict:"AC",scope:!1,link:function(e,r,t,a){var n=e.$eval(t.sfChanged);n&&n.onChange&&a.$viewChangeListeners.push(function(){angular.isFunction(n.onChange)?n.onChange(a.$modelValue,n):e.evalExpr(n.onChange,{modelValue:a.$modelValue,form:n})})}}}),angular.module("schemaForm").directive("sfSchema",["$compile","schemaForm","schemaFormDecorators","sfSelect","sfPath",function(e,r,t,a,n){var i=/[A-Z]/g,o=function(e,r){return r=r||"_",e.replace(i,function(e,t){return(t?r:"")+e.toLowerCase()})};return{scope:{schema:"=sfSchema",initialForm:"=sfForm",model:"=sfModel",options:"=sfOptions"},controller:["$scope",function(e){this.evalInParentScope=function(r,t){return e.$parent.$eval(r,t)}}],replace:!1,restrict:"A",transclude:!0,require:"?form",link:function(i,u,l,s,c){i.formCtrl=s;var f={};c(i,function(e){if(e.addClass("schema-form-ignore"),u.prepend(e),u[0].querySelectorAll){var r=u[0].querySelectorAll("[ng-model]");if(r)for(var t=0;t<r.length;t++){var a=r[t].getAttribute("ng-model");f[a.substring(a.indexOf(".")+1)]=!0}}});var m,d={},p=function(s,c){var d=r.merge(s,c,f,i.options),p=document.createDocumentFragment();m&&m.$destroy(),m=i.$new(),m.schemaForm={form:d,schema:s},u.children(":not(.schema-form-ignore)").remove();for(var h={},g=u[0].querySelectorAll("*[sf-insert-field]"),v=0;v<g.length;v++)h[g[v].getAttribute("sf-insert-field")]=g[v];angular.forEach(d,function(e,r){var a=document.createElement(l.sfDecorator||o(t.defaultDecorator,"-"));if(a.setAttribute("form","schemaForm.form["+r+"]"),e.key){var i=h[n.stringify(e.key)];if(i){for(;i.firstChild;)i.removeChild(i.firstChild);return void i.appendChild(a)}}p.appendChild(a)}),u[0].appendChild(p),e(u.children())(m),r.traverseSchema(s,function(e,r){if(angular.isDefined(e["default"])){var t=a(r,i.model);angular.isUndefined(t)&&a(r,i.model,e["default"])}}),i.$emit("sf-render-finished",u)};i.$watch(function(){var e=i.schema,r=i.initialForm||["*"];r&&e&&e.type&&(d.form!==r||d.schema!==e)&&Object.keys(e.properties).length>0&&(d.schema=e,d.form=r,p(e,r))}),i.$on("schemaFormRedraw",function(){var e=i.schema,r=i.initialForm||["*"];e&&p(e,r)})}}}]),angular.module("schemaForm").directive("schemaValidate",["sfValidator","sfSelect",function(e,r){return{restrict:"A",scope:!1,priority:1e3,require:"ngModel",link:function(t,a,n,i){t.ngModel=i;var o=null,u=function(){return l||(l=t.$eval(n.schemaValidate)),l},l=u();l.copyValueTo&&i.$viewChangeListeners.push(function(){var e=l.copyValueTo;angular.forEach(e,function(e){r(e,t.model,i.$modelValue)})}),i.$validators?i.$validators.schema=function(r){var t=e.validate(u(),r);return o=t.error,t.valid}:i.$parsers.push(function(r){if(l=u(),!l)return r;var t=e.validate(l,r);return t.valid?(i.$setValidity("schema",!0),r):(i.$setValidity("schema",!1),void(o=t.error))}),t.$on("schemaFormValidate",function(){i.$validate?(i.$validate(),i.$invalid&&(i.$dirty=!0,i.$pristine=!1)):i.$setViewValue(i.$viewValue)}),t.hasSuccess=function(){return i.$valid&&(!i.$pristine||!i.$isEmpty(i.$modelValue))},t.hasError=function(){return i.$invalid&&!i.$pristine},t.schemaError=function(){return o}}}}]); |
{ | ||
"name": "angular-schema-form", | ||
"version": "0.7.12", | ||
"version": "0.7.13", | ||
"description": "Create complex forms from a JSON schema with angular.", | ||
@@ -5,0 +5,0 @@ "repository": "Textalk/angular-schema-form", |
@@ -165,5 +165,5 @@ angular.module('schemaForm').provider('schemaFormDecorators', | ||
if (form.condition) { | ||
element.children().each(function() { | ||
var ngIf = this.getAttribute('ng-if'); | ||
this.setAttribute( | ||
angular.forEach(element.children(),function(child) { | ||
var ngIf = child.getAttribute('ng-if'); | ||
child.setAttribute( | ||
'ng-if', | ||
@@ -170,0 +170,0 @@ ngIf ? |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1986315