From 59bec3217181f37320d066fe5a74cbc7fdc3e10b Mon Sep 17 00:00:00 2001 From: Doug Wikle Date: Wed, 15 Apr 2015 13:17:52 -0400 Subject: [PATCH 1/3] Added wrapper to properly support requirejs Fixes Textalk/angular-schema-form#190 --- gulp/tasks/minify.js | 12 ++++++++++++ package.json | 1 + src/module.js | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gulp/tasks/minify.js b/gulp/tasks/minify.js index afe2512cb..40b07e2ec 100644 --- a/gulp/tasks/minify.js +++ b/gulp/tasks/minify.js @@ -1,6 +1,7 @@ var gulp = require('gulp'), concat = require('gulp-concat'), rename = require('gulp-rename'), + umd = require('gulp-umd'), uglify = require('gulp-uglify'); gulp.task('minify', function() { @@ -11,6 +12,17 @@ gulp.task('minify', function() { './src/directives/*.js' ]) .pipe(concat('schema-form.js')) + .pipe(umd({ + dependencies: function() { + return [ + {name: 'angular'}, + {name: 'ObjectPath'}, + {name: 'tv4'}, + ] + }, + exports: function() {return 'schemaForm';}, + namespace: function() {return 'schemaForm';} + })) .pipe(gulp.dest('./dist/')) .pipe(uglify()) .pipe(rename('schema-form.min.js')) diff --git a/package.json b/package.json index d8c92e6d5..8ac819aa2 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "gulp-minify-html": "^0.1.1", "gulp-rename": "^1.2.0", "gulp-uglify": "^0.2.1", + "gulp-umd": "^0.1.3", "karma": "^0.12.0", "karma-chai-sinon": "^0.1.3", "karma-coverage": "^0.2.1", diff --git a/src/module.js b/src/module.js index 2e0136e55..3e107822a 100644 --- a/src/module.js +++ b/src/module.js @@ -20,4 +20,4 @@ try { deps.push('angularSpectrumColorpicker'); } catch (e) {} -angular.module('schemaForm', deps); +var schemaForm = angular.module('schemaForm', deps); From c2a9dfd5a3676be041583a270e6e407be8ce7cae Mon Sep 17 00:00:00 2001 From: Doug Wikle Date: Wed, 15 Apr 2015 13:21:31 -0400 Subject: [PATCH 2/3] gulped --- dist/bootstrap-decorator.js | 16 ++++++++-------- dist/bootstrap-decorator.min.js | 2 +- dist/schema-form.js | 27 +++++++++++++++++++++++---- dist/schema-form.min.js | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/dist/bootstrap-decorator.js b/dist/bootstrap-decorator.js index d20c85c33..da82ce655 100644 --- a/dist/bootstrap-decorator.js +++ b/dist/bootstrap-decorator.js @@ -1,21 +1,21 @@ angular.module("schemaForm").run(["$templateCache", function($templateCache) {$templateCache.put("directives/decorators/bootstrap/actions-trcl.html","
"); $templateCache.put("directives/decorators/bootstrap/actions.html","
"); $templateCache.put("directives/decorators/bootstrap/array.html","

{{ form.title }}

"); -$templateCache.put("directives/decorators/bootstrap/checkbox.html","
"); -$templateCache.put("directives/decorators/bootstrap/checkboxes.html","
"); -$templateCache.put("directives/decorators/bootstrap/default.html","
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
"); +$templateCache.put("directives/decorators/bootstrap/checkbox.html","
"); +$templateCache.put("directives/decorators/bootstrap/checkboxes.html","
"); +$templateCache.put("directives/decorators/bootstrap/default.html","
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
"); $templateCache.put("directives/decorators/bootstrap/fieldset-trcl.html","
{{ form.title }}
"); $templateCache.put("directives/decorators/bootstrap/fieldset.html","
{{ form.title }}
"); $templateCache.put("directives/decorators/bootstrap/help.html","
"); -$templateCache.put("directives/decorators/bootstrap/radio-buttons.html","
"); -$templateCache.put("directives/decorators/bootstrap/radios-inline.html","
"); -$templateCache.put("directives/decorators/bootstrap/radios.html","
"); +$templateCache.put("directives/decorators/bootstrap/radio-buttons.html","
"); +$templateCache.put("directives/decorators/bootstrap/radios-inline.html","
"); +$templateCache.put("directives/decorators/bootstrap/radios.html","
"); $templateCache.put("directives/decorators/bootstrap/section.html","
"); -$templateCache.put("directives/decorators/bootstrap/select.html","
"); +$templateCache.put("directives/decorators/bootstrap/select.html","
"); $templateCache.put("directives/decorators/bootstrap/submit.html","
"); $templateCache.put("directives/decorators/bootstrap/tabarray.html",""); $templateCache.put("directives/decorators/bootstrap/tabs.html",""); -$templateCache.put("directives/decorators/bootstrap/textarea.html","
");}]); +$templateCache.put("directives/decorators/bootstrap/textarea.html","
");}]); angular.module('schemaForm').config(['schemaFormDecoratorsProvider', function(decoratorsProvider) { var base = 'directives/decorators/bootstrap/'; diff --git a/dist/bootstrap-decorator.min.js b/dist/bootstrap-decorator.min.js index 65f836729..3c80468ea 100644 --- a/dist/bootstrap-decorator.min.js +++ b/dist/bootstrap-decorator.min.js @@ -1 +1 @@ -angular.module("schemaForm").run(["$templateCache",function(e){e.put("directives/decorators/bootstrap/actions-trcl.html",'
'),e.put("directives/decorators/bootstrap/actions.html",'
'),e.put("directives/decorators/bootstrap/array.html",'

{{ form.title }}

'),e.put("directives/decorators/bootstrap/checkbox.html",'
'),e.put("directives/decorators/bootstrap/checkboxes.html",'
'),e.put("directives/decorators/bootstrap/default.html",'
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
'),e.put("directives/decorators/bootstrap/fieldset-trcl.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/fieldset.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/help.html",'
'),e.put("directives/decorators/bootstrap/radio-buttons.html",'
'),e.put("directives/decorators/bootstrap/radios-inline.html",'
'),e.put("directives/decorators/bootstrap/radios.html",'
'),e.put("directives/decorators/bootstrap/section.html",'
'),e.put("directives/decorators/bootstrap/select.html",'
'),e.put("directives/decorators/bootstrap/submit.html",'
'),e.put("directives/decorators/bootstrap/tabarray.html",''),e.put("directives/decorators/bootstrap/tabs.html",''),e.put("directives/decorators/bootstrap/textarea.html",'
')}]),angular.module("schemaForm").config(["schemaFormDecoratorsProvider",function(e){var s="directives/decorators/bootstrap/";e.createDecorator("bootstrapDecorator",{textarea:s+"textarea.html",fieldset:s+"fieldset.html",array:s+"array.html",tabarray:s+"tabarray.html",tabs:s+"tabs.html",section:s+"section.html",conditional:s+"section.html",actions:s+"actions.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",password:s+"default.html",submit:s+"submit.html",button:s+"submit.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html",help:s+"help.html","default":s+"default.html"},[]),e.createDirectives({textarea:s+"textarea.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",submit:s+"submit.html",button:s+"submit.html",text:s+"default.html",date:s+"default.html",password:s+"default.html",datepicker:s+"datepicker.html",input:s+"default.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html"})}]).directive("sfFieldset",function(){return{transclude:!0,scope:!0,templateUrl:"directives/decorators/bootstrap/fieldset-trcl.html",link:function(e,s,t){e.title=e.$eval(t.title)}}}); \ No newline at end of file +angular.module("schemaForm").run(["$templateCache",function(e){e.put("directives/decorators/bootstrap/actions-trcl.html",'
'),e.put("directives/decorators/bootstrap/actions.html",'
'),e.put("directives/decorators/bootstrap/array.html",'

{{ form.title }}

'),e.put("directives/decorators/bootstrap/checkbox.html",'
'),e.put("directives/decorators/bootstrap/checkboxes.html",'
'),e.put("directives/decorators/bootstrap/default.html",'
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
'),e.put("directives/decorators/bootstrap/fieldset-trcl.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/fieldset.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/help.html",'
'),e.put("directives/decorators/bootstrap/radio-buttons.html",'
'),e.put("directives/decorators/bootstrap/radios-inline.html",'
'),e.put("directives/decorators/bootstrap/radios.html",'
'),e.put("directives/decorators/bootstrap/section.html",'
'),e.put("directives/decorators/bootstrap/select.html",'
'),e.put("directives/decorators/bootstrap/submit.html",'
'),e.put("directives/decorators/bootstrap/tabarray.html",''),e.put("directives/decorators/bootstrap/tabs.html",''),e.put("directives/decorators/bootstrap/textarea.html",'
')}]),angular.module("schemaForm").config(["schemaFormDecoratorsProvider",function(e){var s="directives/decorators/bootstrap/";e.createDecorator("bootstrapDecorator",{textarea:s+"textarea.html",fieldset:s+"fieldset.html",array:s+"array.html",tabarray:s+"tabarray.html",tabs:s+"tabs.html",section:s+"section.html",conditional:s+"section.html",actions:s+"actions.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",password:s+"default.html",submit:s+"submit.html",button:s+"submit.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html",help:s+"help.html","default":s+"default.html"},[]),e.createDirectives({textarea:s+"textarea.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",submit:s+"submit.html",button:s+"submit.html",text:s+"default.html",date:s+"default.html",password:s+"default.html",datepicker:s+"datepicker.html",input:s+"default.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html"})}]).directive("sfFieldset",function(){return{transclude:!0,scope:!0,templateUrl:"directives/decorators/bootstrap/fieldset-trcl.html",link:function(e,s,t){e.title=e.$eval(t.title)}}}); \ No newline at end of file diff --git a/dist/schema-form.js b/dist/schema-form.js index 539f248dc..88ca40f76 100644 --- a/dist/schema-form.js +++ b/dist/schema-form.js @@ -1,3 +1,12 @@ +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + define(['angular', 'ObjectPath', 'tv4'], factory); + } else if (typeof exports === 'object') { + module.exports = factory(require('angular'), require('ObjectPath'), require('tv4')); + } else { + root.schemaForm = factory(root.angular, root.ObjectPath, root.tv4); + } +}(this, function(angular, ObjectPath, tv4) { // Deps is sort of a problem for us, maybe in the future we will ask the user to depend // on modules for add-ons @@ -20,7 +29,7 @@ try { deps.push('angularSpectrumColorpicker'); } catch (e) {} -angular.module('schemaForm', deps); +var schemaForm = angular.module('schemaForm', deps); angular.module('schemaForm').provider('sfPath', [function() { @@ -378,9 +387,11 @@ angular.module('schemaForm').provider('schemaFormDecorators', scope.ngModel.$setValidity(error, validity === true); - // Setting or removing a validity can change the field to believe its valid - // but its not. So lets trigger its validation as well. - scope.$broadcast('schemaFormValidate'); + if (validity === true) { + // Setting or removing a validity can change the field to believe its valid + // but its not. So lets trigger its validation as well. + scope.$broadcast('schemaFormValidate'); + } } }) } @@ -1752,6 +1763,11 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele return viewValue; } + // Omit TV4 validation + if (scope.options && scope.options.tv4Validation === false) { + return viewValue; + } + var result = sfValidator.validate(form, viewValue); // Since we might have different tv4 errors we must clear all // errors that start with tv4- @@ -1814,3 +1830,6 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele } }; }]); + +return schemaForm; +})); diff --git a/dist/schema-form.min.js b/dist/schema-form.min.js index 1607d8c8c..8721f9743 100644 --- a/dist/schema-form.min.js +++ b/dist/schema-form.min.js @@ -1 +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,n,a){n||(n=this);var i="string"==typeof t?e.parse(t):t;if("undefined"!=typeof a&&1===i.length)return n[i[0]]=a,n;"undefined"!=typeof a&&"undefined"==typeof n[i[0]]&&(n[i[0]]=i.length>2&&r.test(i[1])?[]:{});for(var o=n[i[0]],l=1;l',link:function(e,t,n){var a={items:"c",titleMap:"c",schema:"c"},i={type:r},o=!0;angular.forEach(n,function(r,t){if("$"!==t[0]&&0!==t.indexOf("ng")&&"sfField"!==t){var l=function(r){angular.isDefined(r)&&r!==i[t]&&(i[t]=r,o&&i.type&&(i.key||angular.isUndefined(n.key))&&(e.form=i,o=!1))};"model"===t?e.$watch(r,function(r){r&&e.model!==r&&(e.model=r)}):"c"===a[t]?e.$watchCollection(r,l):n.$observe(t,l)}})}}})};this.createDecorator=function(e,r,a){n[e]={mappings:r||{},rules:a||[]},n[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,n[e]},this.addMapping=function(e,r,t){n[e]&&(n[e].mappings[r]=t)},this.$get=function(){return{directive:function(e){return n[e]},defaultDecorator:t}},i("sfDecorator")}]),angular.module("schemaForm").provider("sfErrorMessage",function(){var e={"default":"Field does not validate",0:"Invalid type, expected {{schema.type}})",1:"No enum match for: {{value}}",10:'Data does not match any schemas from "anyOf"',11:'Data does not match any schemas from "oneOf"',12:'Data is valid against more than one schema from "oneOf"',13:'Data matches schema from "not"',100:"Value {{value}} is not a multiple of {{schema.multipleOf}}",101:"Value {{value}} is less than minimum {{schema.minimum}}",102:"Value {{value}} is equal to exclusive minimum {{schema.minimum}}",103:"Value {{value}} is greater than maximum {{schema.maximum}}",104:"Value {{value}} is equal to exclusive maximum {{schema.maximum}}",105:"Value {{value}} is not a valid number",200:"String is too short ({{value.length}} chars), minimum {{schema.minimum}}",201:"String is too long ({{value.length}} chars), maximum {{schema.maximum}}",202:"String does not match pattern: {{schema.pattern}}",300:"Too few properties defined, minimum {{schema.minimum}}",301:"Too many properties defined, maximum {{schema.maximum}}",302:"Required",303:"Additional properties not allowed",304:"Dependency failed - key must exist",400:"Array is too short ({{value.length}}), minimum {{schema.minimum}}",401:"Array is too long ({{value.length}}), maximum {{schema.maximum}}",402:"Array items are not unique",403:"Additional items not allowed",500:"Format validation failed",501:'Keyword failed: "{{title}}"',600:"Circular $refs",1e3:"Unknown property (not in schema)"};this.setDefaultMessages=function(r){e=r},this.getDefaultMessages=function(){return e},this.setDefaultMessage=function(r,t){e[r]=t},this.$get=["$interpolate",function(r){var t={};return t.defaultMessages=e,t.interpolate=function(t,n,a,i){i=i||{};var o=a.validationMessage||{};0===t.indexOf("tv4-")&&(t=t.substring(4));var l=o["default"]||i["default"]||"";[o,i,e].some(function(e){return angular.isString(e)||angular.isFunction(e)?(l=e,!0):e&&e[t]?(l=e[t],!0):void 0});var u={error:t,value:n,form:a,schema:a.schema,title:a.title||a.schema&&a.schema.title};return angular.isFunction(l)?l(u):r(l)(u)},t}]}),angular.module("schemaForm").provider("schemaForm",["sfPathProvider",function(e){var r=function(e){if(Array.isArray(e)&&2==e.length){if("null"===e[0])return e[1];if("null"===e[1])return e[0]}return e},t=function(e){var r=[];return e.forEach(function(e){r.push({name:e,value:e})}),r},n=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,t,n){var a=h[r(t.type)];if(a)for(var i,o=0;o1&&(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,a(e)),s[e]=t}return s[e]},i.appendToArray=function(){var t=l.length,n=i.copyWithIndex(t);if(r.traverseForm(n,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===l.length){var a,u=e("schema.items.type",o);"object"===u?a={}:"array"===u&&(a=[]),l.push(a)}return i.validateArray&&i.validateArray(),l},i.deleteFromArray=function(e){return l.splice(e,1),i.validateArray&&i.validateArray(),u&&u.$setDirty&&u.$setDirty(),l},o.titleMap||o.startEmpty===!0||0!==l.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,n){e[n]&&r.push(t.value)})}})}if(u){var d;i.validateArray=function(){var e=t.validate(o,i.modelArray.length>0?i.modelArray:void 0);Object.keys(u.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){u.$setValidity(e,!0)}),e.valid!==!1||!e.error||""!==e.error.dataPath&&e.error.dataPath!=="/"+o.key[o.key.length-1]||(u.$setViewValue(i.modelArray),d=e.error,u.$setValidity("tv4-"+e.error.code,!1))},i.$on("schemaFormValidate",i.validateArray),i.hasSuccess=function(){return u.$valid&&!u.$pristine},i.hasError=function(){return u.$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,n){var a=e.$eval(t.sfChanged);a&&a.onChange&&n.$viewChangeListeners.push(function(){angular.isFunction(a.onChange)?a.onChange(n.$modelValue,a):e.evalExpr(a.onChange,{modelValue:n.$modelValue,form:a})})}}}),angular.module("schemaForm").directive("sfMessage",["$injector","sfErrorMessage",function(e,r){return{scope:!1,restrict:"EA",link:function(t,n,a){var i=e.has("$sanitize")?e.get("$sanitize"):function(e){return e},o="";a.sfMessage&&(o=t.$eval(a.sfMessage)||"",o=i(o));var l=function(e){if(e&&t.hasError())n.html(o);else{var a=Object.keys(t.ngModel&&t.ngModel.$error||{}),i=a[0];a.length>1&&(i=a.reduce(function(e,r){return e&&0===e.indexOf("tv4-")?e:r}),console.log("reduced",a,i)),n.html(i?r.interpolate(i,t.ngModel.$modelValue,t.form,t.options&&t.options.validationMessage):o)}};l(),t.$watchCollection("ngModel.$error",function(){t.ngModel&&l(t.ngModel.$valid)})}}}]),angular.module("schemaForm").directive("sfSchema",["$compile","schemaForm","schemaFormDecorators","sfSelect","sfPath",function(e,r,t,n,a){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,l,u,s,c){i.formCtrl=s;var f={};c(i,function(e){if(e.addClass("schema-form-ignore"),l.prepend(e),l[0].querySelectorAll){var r=l[0].querySelectorAll("[ng-model]");if(r)for(var t=0;t0&&(d.schema=e,d.form=r,h(e,r))}),i.$on("schemaFormRedraw",function(){var e=i.schema,r=i.initialForm||["*"];e&&h(e,r)})}}}]),angular.module("schemaForm").directive("schemaValidate",["sfValidator","sfSelect",function(e,r){return{restrict:"A",scope:!1,priority:500,require:"ngModel",link:function(t,n,a,i){t.$emit("schemaFormPropagateNgModelController",i);var o=null,l=function(){return u||(u=t.$eval(a.schemaValidate)),u},u=l();u.copyValueTo&&i.$viewChangeListeners.push(function(){var e=u.copyValueTo;angular.forEach(e,function(e){r(e,t.model,i.$modelValue)})});var s=function(r){if(u=l(),!u)return r;var t=e.validate(u,r);return Object.keys(i.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){i.$setValidity(e,!0)}),t.valid?r:(i.$setValidity("tv4-"+t.error.code,!1),void(o=t.error))};"function"==typeof u.ngModel&&u.ngModel(i),["$parsers","$viewChangeListeners","$formatters"].forEach(function(e){u[e]&&i[e]&&u[e].forEach(function(r){i[e].push(r)})}),["$validators","$asyncValidators"].forEach(function(e){u[e]&&i[e]&&angular.forEach(u[e],function(r,t){i[e][t]=r})}),i.$parsers.push(s),t.$on("schemaFormValidate",function(){i.$setDirty?(i.$setDirty(),s(i.$modelValue)):i.$setViewValue(i.$viewValue)}),t.schemaError=function(){return o}}}}]); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define(["angular","ObjectPath","tv4"],t):"object"==typeof exports?module.exports=t(require("angular"),require("ObjectPath"),require("tv4")):e.schemaForm=t(e.angular,e.ObjectPath,e.tv4)}(this,function(e,t,r){var n=[];try{e.module("ngSanitize"),n.push("ngSanitize")}catch(i){}try{e.module("ui.sortable"),n.push("ui.sortable")}catch(i){}try{e.module("angularSpectrumColorpicker"),n.push("angularSpectrumColorpicker")}catch(i){}var a=e.module("schemaForm",n);return e.module("schemaForm").provider("sfPath",[function(){var r={parse:t.parse};1===e.version.major&&e.version.minor<3?r.stringify=function(e){return Array.isArray(e)?e.join("."):e.toString()}:r.stringify=t.stringify,r.normalize=function(e,t){return r.stringify(Array.isArray(e)?e:r.parse(e),t)},this.parse=r.parse,this.stringify=r.stringify,this.normalize=r.normalize,this.$get=function(){return r}}]),e.module("schemaForm").factory("sfSelect",["sfPath",function(e){var t=/^\d+$/;return function(r,n,i){n||(n=this);var a="string"==typeof r?e.parse(r):r;if("undefined"!=typeof i&&1===a.length)return n[a[0]]=i,n;"undefined"!=typeof i&&"undefined"==typeof n[a[0]]&&(n[a[0]]=a.length>2&&t.test(a[1])?[]:{});for(var o=n[a[0]],s=1;s',link:function(t,n,i){var a={items:"c",titleMap:"c",schema:"c"},o={type:r},s=!0;e.forEach(i,function(r,n){if("$"!==n[0]&&0!==n.indexOf("ng")&&"sfField"!==n){var l=function(r){e.isDefined(r)&&r!==o[n]&&(o[n]=r,s&&o.type&&(o.key||e.isUndefined(i.key))&&(t.form=o,s=!1))};"model"===n?t.$watch(r,function(e){e&&t.model!==e&&(t.model=e)}):"c"===a[n]?t.$watchCollection(r,l):i.$observe(n,l)}})}}})};this.createDecorator=function(e,t,r){i[e]={mappings:t||{},rules:r||[]},i[n]||(n=e),o(e)},this.createDirective=s,this.createDirectives=function(t){e.forEach(t,function(e,t){s(t,e)})},this.directive=function(e){return e=e||n,i[e]},this.addMapping=function(e,t,r){i[e]&&(i[e].mappings[t]=r)},this.$get=function(){return{directive:function(e){return i[e]},defaultDecorator:n}},o("sfDecorator")}]),e.module("schemaForm").provider("sfErrorMessage",function(){var t={"default":"Field does not validate",0:"Invalid type, expected {{schema.type}})",1:"No enum match for: {{value}}",10:'Data does not match any schemas from "anyOf"',11:'Data does not match any schemas from "oneOf"',12:'Data is valid against more than one schema from "oneOf"',13:'Data matches schema from "not"',100:"Value {{value}} is not a multiple of {{schema.multipleOf}}",101:"Value {{value}} is less than minimum {{schema.minimum}}",102:"Value {{value}} is equal to exclusive minimum {{schema.minimum}}",103:"Value {{value}} is greater than maximum {{schema.maximum}}",104:"Value {{value}} is equal to exclusive maximum {{schema.maximum}}",105:"Value {{value}} is not a valid number",200:"String is too short ({{value.length}} chars), minimum {{schema.minimum}}",201:"String is too long ({{value.length}} chars), maximum {{schema.maximum}}",202:"String does not match pattern: {{schema.pattern}}",300:"Too few properties defined, minimum {{schema.minimum}}",301:"Too many properties defined, maximum {{schema.maximum}}",302:"Required",303:"Additional properties not allowed",304:"Dependency failed - key must exist",400:"Array is too short ({{value.length}}), minimum {{schema.minimum}}",401:"Array is too long ({{value.length}}), maximum {{schema.maximum}}",402:"Array items are not unique",403:"Additional items not allowed",500:"Format validation failed",501:'Keyword failed: "{{title}}"',600:"Circular $refs",1e3:"Unknown property (not in schema)"};this.setDefaultMessages=function(e){t=e},this.getDefaultMessages=function(){return t},this.setDefaultMessage=function(e,r){t[e]=r},this.$get=["$interpolate",function(r){var n={};return n.defaultMessages=t,n.interpolate=function(n,i,a,o){o=o||{};var s=a.validationMessage||{};0===n.indexOf("tv4-")&&(n=n.substring(4));var l=s["default"]||o["default"]||"";[s,o,t].some(function(t){return e.isString(t)||e.isFunction(t)?(l=t,!0):t&&t[n]?(l=t[n],!0):void 0});var u={error:n,value:i,form:a,schema:a.schema,title:a.title||a.schema&&a.schema.title};return e.isFunction(l)?l(u):r(l)(u)},n}]}),e.module("schemaForm").provider("schemaForm",["sfPathProvider",function(t){var r=function(e){if(Array.isArray(e)&&2==e.length){if("null"===e[0])return e[1];if("null"===e[1])return e[0]}return e},n=function(e){var t=[];return e.forEach(function(e){t.push({name:e,value:e})}),t},i=function(t,r){if(!e.isArray(t)){var n=[];return r?e.forEach(r,function(e,r){n.push({name:t[e],value:e})}):e.forEach(t,function(e,t){n.push({name:e,value:t})}),n}return t},a=function(t,n,i){var a=p[r(n.type)];if(a)for(var o,s=0;s1&&(m={type:"section",items:s.items.map(function(t){return t.ngModelOptions=s.ngModelOptions,e.isUndefined(t.readonly)&&(t.readonly=s.readonly),t})})}if(o.copyWithIndex=function(t){if(!c[t]&&m){var n=e.copy(m);n.arrayIndex=t,r.traverseForm(n,a(t)),c[t]=n}return c[t]},o.appendToArray=function(){var n=l.length,i=o.copyWithIndex(n);if(r.traverseForm(i,function(r){if(r.key){var n;e.isDefined(r["default"])&&(n=r["default"]),e.isDefined(r.schema)&&e.isDefined(r.schema["default"])&&(n=r.schema["default"]),e.isDefined(n)&&t(r.key,o.model,n)}}),n===l.length){var a,u=t("schema.items.type",s);"object"===u?a={}:"array"===u&&(a=[]),l.push(a)}return o.validateArray&&o.validateArray(),l},o.deleteFromArray=function(e){return l.splice(e,1),o.validateArray&&o.validateArray(),u&&u.$setDirty&&u.$setDirty(),l},s.titleMap||s.startEmpty===!0||0!==l.length||o.appendToArray(),s.titleMap&&s.titleMap.length>0){o.titleMapValues=[];var d=function(e){o.titleMapValues=[],e=e||[],s.titleMap.forEach(function(t){o.titleMapValues.push(-1!==e.indexOf(t.value))})};d(o.modelArray),o.$watchCollection("modelArray",d),o.$watchCollection("titleMapValues",function(e){if(e){for(var t=o.modelArray;t.length>0;)t.pop();s.titleMap.forEach(function(r,n){e[n]&&t.push(r.value)})}})}if(u){var h;o.validateArray=function(){var e=n.validate(s,o.modelArray.length>0?o.modelArray:void 0);Object.keys(u.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){u.$setValidity(e,!0)}),e.valid!==!1||!e.error||""!==e.error.dataPath&&e.error.dataPath!=="/"+s.key[s.key.length-1]||(u.$setViewValue(o.modelArray),h=e.error,u.$setValidity("tv4-"+e.error.code,!1))},o.$on("schemaFormValidate",o.validateArray),o.hasSuccess=function(){return u.$valid&&!u.$pristine},o.hasError=function(){return u.$invalid},o.schemaError=function(){return h}}f()})}}}]),e.module("schemaForm").directive("sfChanged",function(){return{require:"ngModel",restrict:"AC",scope:!1,link:function(t,r,n,i){var a=t.$eval(n.sfChanged);a&&a.onChange&&i.$viewChangeListeners.push(function(){e.isFunction(a.onChange)?a.onChange(i.$modelValue,a):t.evalExpr(a.onChange,{modelValue:i.$modelValue,form:a})})}}}),e.module("schemaForm").directive("sfMessage",["$injector","sfErrorMessage",function(e,t){return{scope:!1,restrict:"EA",link:function(r,n,i){var a=e.has("$sanitize")?e.get("$sanitize"):function(e){return e},o="";i.sfMessage&&(o=r.$eval(i.sfMessage)||"",o=a(o));var s=function(e){if(e&&r.hasError())n.html(o);else{var i=Object.keys(r.ngModel&&r.ngModel.$error||{}),a=i[0];i.length>1&&(a=i.reduce(function(e,t){return e&&0===e.indexOf("tv4-")?e:t}),console.log("reduced",i,a)),n.html(a?t.interpolate(a,r.ngModel.$modelValue,r.form,r.options&&r.options.validationMessage):o)}};s(),r.$watchCollection("ngModel.$error",function(){r.ngModel&&s(r.ngModel.$valid)})}}}]),e.module("schemaForm").directive("sfSchema",["$compile","schemaForm","schemaFormDecorators","sfSelect","sfPath",function(t,r,n,i,a){var o=/[A-Z]/g,s=function(e,t){return t=t||"_",e.replace(o,function(e,r){return(r?t:"")+e.toLowerCase()})};return{scope:{schema:"=sfSchema",initialForm:"=sfForm",model:"=sfModel",options:"=sfOptions"},controller:["$scope",function(e){this.evalInParentScope=function(t,r){return e.$parent.$eval(t,r)}}],replace:!1,restrict:"A",transclude:!0,require:"?form",link:function(o,l,u,c,f){o.formCtrl=c;var m={};f(o,function(e){if(e.addClass("schema-form-ignore"),l.prepend(e),l[0].querySelectorAll){var t=l[0].querySelectorAll("[ng-model]");if(t)for(var r=0;r0&&(h.schema=e,h.form=t,p(e,t))}),o.$on("schemaFormRedraw",function(){var e=o.schema,t=o.initialForm||["*"];e&&p(e,t)})}}}]),e.module("schemaForm").directive("schemaValidate",["sfValidator","sfSelect",function(t,r){return{restrict:"A",scope:!1,priority:500,require:"ngModel",link:function(n,i,a,o){n.$emit("schemaFormPropagateNgModelController",o);var s=null,l=function(){return u||(u=n.$eval(a.schemaValidate)),u},u=l();u.copyValueTo&&o.$viewChangeListeners.push(function(){var t=u.copyValueTo;e.forEach(t,function(e){r(e,n.model,o.$modelValue)})});var c=function(e){if(u=l(),!u)return e;if(n.options&&n.options.tv4Validation===!1)return e;var r=t.validate(u,e);return Object.keys(o.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){o.$setValidity(e,!0)}),r.valid?e:(o.$setValidity("tv4-"+r.error.code,!1),void(s=r.error))};"function"==typeof u.ngModel&&u.ngModel(o),["$parsers","$viewChangeListeners","$formatters"].forEach(function(e){u[e]&&o[e]&&u[e].forEach(function(t){o[e].push(t)})}),["$validators","$asyncValidators"].forEach(function(t){u[t]&&o[t]&&e.forEach(u[t],function(e,r){o[t][r]=e})}),o.$parsers.push(c),n.$on("schemaFormValidate",function(){o.$setDirty?(o.$setDirty(),c(o.$modelValue)):o.$setViewValue(o.$viewValue)}),n.schemaError=function(){return s}}}}]),a}); \ No newline at end of file From 2da7f9d19e8c07bed1773330c5e20f8ee9ee8608 Mon Sep 17 00:00:00 2001 From: Doug Wikle Date: Wed, 15 Apr 2015 14:05:50 -0400 Subject: [PATCH 3/3] Reverted gulped dist/ This reverts commit c2a9dfd5a3676be041583a270e6e407be8ce7cae. --- dist/bootstrap-decorator.js | 16 ++++++++-------- dist/bootstrap-decorator.min.js | 2 +- dist/schema-form.js | 27 ++++----------------------- dist/schema-form.min.js | 2 +- 4 files changed, 14 insertions(+), 33 deletions(-) diff --git a/dist/bootstrap-decorator.js b/dist/bootstrap-decorator.js index da82ce655..d20c85c33 100644 --- a/dist/bootstrap-decorator.js +++ b/dist/bootstrap-decorator.js @@ -1,21 +1,21 @@ angular.module("schemaForm").run(["$templateCache", function($templateCache) {$templateCache.put("directives/decorators/bootstrap/actions-trcl.html","
"); $templateCache.put("directives/decorators/bootstrap/actions.html","
"); $templateCache.put("directives/decorators/bootstrap/array.html","

{{ form.title }}

"); -$templateCache.put("directives/decorators/bootstrap/checkbox.html","
"); -$templateCache.put("directives/decorators/bootstrap/checkboxes.html","
"); -$templateCache.put("directives/decorators/bootstrap/default.html","
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
"); +$templateCache.put("directives/decorators/bootstrap/checkbox.html","
"); +$templateCache.put("directives/decorators/bootstrap/checkboxes.html","
"); +$templateCache.put("directives/decorators/bootstrap/default.html","
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
"); $templateCache.put("directives/decorators/bootstrap/fieldset-trcl.html","
{{ form.title }}
"); $templateCache.put("directives/decorators/bootstrap/fieldset.html","
{{ form.title }}
"); $templateCache.put("directives/decorators/bootstrap/help.html","
"); -$templateCache.put("directives/decorators/bootstrap/radio-buttons.html","
"); -$templateCache.put("directives/decorators/bootstrap/radios-inline.html","
"); -$templateCache.put("directives/decorators/bootstrap/radios.html","
"); +$templateCache.put("directives/decorators/bootstrap/radio-buttons.html","
"); +$templateCache.put("directives/decorators/bootstrap/radios-inline.html","
"); +$templateCache.put("directives/decorators/bootstrap/radios.html","
"); $templateCache.put("directives/decorators/bootstrap/section.html","
"); -$templateCache.put("directives/decorators/bootstrap/select.html","
"); +$templateCache.put("directives/decorators/bootstrap/select.html","
"); $templateCache.put("directives/decorators/bootstrap/submit.html","
"); $templateCache.put("directives/decorators/bootstrap/tabarray.html",""); $templateCache.put("directives/decorators/bootstrap/tabs.html",""); -$templateCache.put("directives/decorators/bootstrap/textarea.html","
");}]); +$templateCache.put("directives/decorators/bootstrap/textarea.html","
");}]); angular.module('schemaForm').config(['schemaFormDecoratorsProvider', function(decoratorsProvider) { var base = 'directives/decorators/bootstrap/'; diff --git a/dist/bootstrap-decorator.min.js b/dist/bootstrap-decorator.min.js index 3c80468ea..65f836729 100644 --- a/dist/bootstrap-decorator.min.js +++ b/dist/bootstrap-decorator.min.js @@ -1 +1 @@ -angular.module("schemaForm").run(["$templateCache",function(e){e.put("directives/decorators/bootstrap/actions-trcl.html",'
'),e.put("directives/decorators/bootstrap/actions.html",'
'),e.put("directives/decorators/bootstrap/array.html",'

{{ form.title }}

'),e.put("directives/decorators/bootstrap/checkbox.html",'
'),e.put("directives/decorators/bootstrap/checkboxes.html",'
'),e.put("directives/decorators/bootstrap/default.html",'
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
'),e.put("directives/decorators/bootstrap/fieldset-trcl.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/fieldset.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/help.html",'
'),e.put("directives/decorators/bootstrap/radio-buttons.html",'
'),e.put("directives/decorators/bootstrap/radios-inline.html",'
'),e.put("directives/decorators/bootstrap/radios.html",'
'),e.put("directives/decorators/bootstrap/section.html",'
'),e.put("directives/decorators/bootstrap/select.html",'
'),e.put("directives/decorators/bootstrap/submit.html",'
'),e.put("directives/decorators/bootstrap/tabarray.html",''),e.put("directives/decorators/bootstrap/tabs.html",''),e.put("directives/decorators/bootstrap/textarea.html",'
')}]),angular.module("schemaForm").config(["schemaFormDecoratorsProvider",function(e){var s="directives/decorators/bootstrap/";e.createDecorator("bootstrapDecorator",{textarea:s+"textarea.html",fieldset:s+"fieldset.html",array:s+"array.html",tabarray:s+"tabarray.html",tabs:s+"tabs.html",section:s+"section.html",conditional:s+"section.html",actions:s+"actions.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",password:s+"default.html",submit:s+"submit.html",button:s+"submit.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html",help:s+"help.html","default":s+"default.html"},[]),e.createDirectives({textarea:s+"textarea.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",submit:s+"submit.html",button:s+"submit.html",text:s+"default.html",date:s+"default.html",password:s+"default.html",datepicker:s+"datepicker.html",input:s+"default.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html"})}]).directive("sfFieldset",function(){return{transclude:!0,scope:!0,templateUrl:"directives/decorators/bootstrap/fieldset-trcl.html",link:function(e,s,t){e.title=e.$eval(t.title)}}}); \ No newline at end of file +angular.module("schemaForm").run(["$templateCache",function(e){e.put("directives/decorators/bootstrap/actions-trcl.html",'
'),e.put("directives/decorators/bootstrap/actions.html",'
'),e.put("directives/decorators/bootstrap/array.html",'

{{ form.title }}

'),e.put("directives/decorators/bootstrap/checkbox.html",'
'),e.put("directives/decorators/bootstrap/checkboxes.html",'
'),e.put("directives/decorators/bootstrap/default.html",'
{{ hasSuccess() ? \'(success)\' : \'(error)\' }}
'),e.put("directives/decorators/bootstrap/fieldset-trcl.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/fieldset.html",'
{{ form.title }}
'),e.put("directives/decorators/bootstrap/help.html",'
'),e.put("directives/decorators/bootstrap/radio-buttons.html",'
'),e.put("directives/decorators/bootstrap/radios-inline.html",'
'),e.put("directives/decorators/bootstrap/radios.html",'
'),e.put("directives/decorators/bootstrap/section.html",'
'),e.put("directives/decorators/bootstrap/select.html",'
'),e.put("directives/decorators/bootstrap/submit.html",'
'),e.put("directives/decorators/bootstrap/tabarray.html",''),e.put("directives/decorators/bootstrap/tabs.html",''),e.put("directives/decorators/bootstrap/textarea.html",'
')}]),angular.module("schemaForm").config(["schemaFormDecoratorsProvider",function(e){var s="directives/decorators/bootstrap/";e.createDecorator("bootstrapDecorator",{textarea:s+"textarea.html",fieldset:s+"fieldset.html",array:s+"array.html",tabarray:s+"tabarray.html",tabs:s+"tabs.html",section:s+"section.html",conditional:s+"section.html",actions:s+"actions.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",password:s+"default.html",submit:s+"submit.html",button:s+"submit.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html",help:s+"help.html","default":s+"default.html"},[]),e.createDirectives({textarea:s+"textarea.html",select:s+"select.html",checkbox:s+"checkbox.html",checkboxes:s+"checkboxes.html",number:s+"default.html",submit:s+"submit.html",button:s+"submit.html",text:s+"default.html",date:s+"default.html",password:s+"default.html",datepicker:s+"datepicker.html",input:s+"default.html",radios:s+"radios.html","radios-inline":s+"radios-inline.html",radiobuttons:s+"radio-buttons.html"})}]).directive("sfFieldset",function(){return{transclude:!0,scope:!0,templateUrl:"directives/decorators/bootstrap/fieldset-trcl.html",link:function(e,s,t){e.title=e.$eval(t.title)}}}); \ No newline at end of file diff --git a/dist/schema-form.js b/dist/schema-form.js index 88ca40f76..539f248dc 100644 --- a/dist/schema-form.js +++ b/dist/schema-form.js @@ -1,12 +1,3 @@ -(function(root, factory) { - if (typeof define === 'function' && define.amd) { - define(['angular', 'ObjectPath', 'tv4'], factory); - } else if (typeof exports === 'object') { - module.exports = factory(require('angular'), require('ObjectPath'), require('tv4')); - } else { - root.schemaForm = factory(root.angular, root.ObjectPath, root.tv4); - } -}(this, function(angular, ObjectPath, tv4) { // Deps is sort of a problem for us, maybe in the future we will ask the user to depend // on modules for add-ons @@ -29,7 +20,7 @@ try { deps.push('angularSpectrumColorpicker'); } catch (e) {} -var schemaForm = angular.module('schemaForm', deps); +angular.module('schemaForm', deps); angular.module('schemaForm').provider('sfPath', [function() { @@ -387,11 +378,9 @@ angular.module('schemaForm').provider('schemaFormDecorators', scope.ngModel.$setValidity(error, validity === true); - if (validity === true) { - // Setting or removing a validity can change the field to believe its valid - // but its not. So lets trigger its validation as well. - scope.$broadcast('schemaFormValidate'); - } + // Setting or removing a validity can change the field to believe its valid + // but its not. So lets trigger its validation as well. + scope.$broadcast('schemaFormValidate'); } }) } @@ -1763,11 +1752,6 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele return viewValue; } - // Omit TV4 validation - if (scope.options && scope.options.tv4Validation === false) { - return viewValue; - } - var result = sfValidator.validate(form, viewValue); // Since we might have different tv4 errors we must clear all // errors that start with tv4- @@ -1830,6 +1814,3 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele } }; }]); - -return schemaForm; -})); diff --git a/dist/schema-form.min.js b/dist/schema-form.min.js index 8721f9743..1607d8c8c 100644 --- a/dist/schema-form.min.js +++ b/dist/schema-form.min.js @@ -1 +1 @@ -!function(e,t){"function"==typeof define&&define.amd?define(["angular","ObjectPath","tv4"],t):"object"==typeof exports?module.exports=t(require("angular"),require("ObjectPath"),require("tv4")):e.schemaForm=t(e.angular,e.ObjectPath,e.tv4)}(this,function(e,t,r){var n=[];try{e.module("ngSanitize"),n.push("ngSanitize")}catch(i){}try{e.module("ui.sortable"),n.push("ui.sortable")}catch(i){}try{e.module("angularSpectrumColorpicker"),n.push("angularSpectrumColorpicker")}catch(i){}var a=e.module("schemaForm",n);return e.module("schemaForm").provider("sfPath",[function(){var r={parse:t.parse};1===e.version.major&&e.version.minor<3?r.stringify=function(e){return Array.isArray(e)?e.join("."):e.toString()}:r.stringify=t.stringify,r.normalize=function(e,t){return r.stringify(Array.isArray(e)?e:r.parse(e),t)},this.parse=r.parse,this.stringify=r.stringify,this.normalize=r.normalize,this.$get=function(){return r}}]),e.module("schemaForm").factory("sfSelect",["sfPath",function(e){var t=/^\d+$/;return function(r,n,i){n||(n=this);var a="string"==typeof r?e.parse(r):r;if("undefined"!=typeof i&&1===a.length)return n[a[0]]=i,n;"undefined"!=typeof i&&"undefined"==typeof n[a[0]]&&(n[a[0]]=a.length>2&&t.test(a[1])?[]:{});for(var o=n[a[0]],s=1;s',link:function(t,n,i){var a={items:"c",titleMap:"c",schema:"c"},o={type:r},s=!0;e.forEach(i,function(r,n){if("$"!==n[0]&&0!==n.indexOf("ng")&&"sfField"!==n){var l=function(r){e.isDefined(r)&&r!==o[n]&&(o[n]=r,s&&o.type&&(o.key||e.isUndefined(i.key))&&(t.form=o,s=!1))};"model"===n?t.$watch(r,function(e){e&&t.model!==e&&(t.model=e)}):"c"===a[n]?t.$watchCollection(r,l):i.$observe(n,l)}})}}})};this.createDecorator=function(e,t,r){i[e]={mappings:t||{},rules:r||[]},i[n]||(n=e),o(e)},this.createDirective=s,this.createDirectives=function(t){e.forEach(t,function(e,t){s(t,e)})},this.directive=function(e){return e=e||n,i[e]},this.addMapping=function(e,t,r){i[e]&&(i[e].mappings[t]=r)},this.$get=function(){return{directive:function(e){return i[e]},defaultDecorator:n}},o("sfDecorator")}]),e.module("schemaForm").provider("sfErrorMessage",function(){var t={"default":"Field does not validate",0:"Invalid type, expected {{schema.type}})",1:"No enum match for: {{value}}",10:'Data does not match any schemas from "anyOf"',11:'Data does not match any schemas from "oneOf"',12:'Data is valid against more than one schema from "oneOf"',13:'Data matches schema from "not"',100:"Value {{value}} is not a multiple of {{schema.multipleOf}}",101:"Value {{value}} is less than minimum {{schema.minimum}}",102:"Value {{value}} is equal to exclusive minimum {{schema.minimum}}",103:"Value {{value}} is greater than maximum {{schema.maximum}}",104:"Value {{value}} is equal to exclusive maximum {{schema.maximum}}",105:"Value {{value}} is not a valid number",200:"String is too short ({{value.length}} chars), minimum {{schema.minimum}}",201:"String is too long ({{value.length}} chars), maximum {{schema.maximum}}",202:"String does not match pattern: {{schema.pattern}}",300:"Too few properties defined, minimum {{schema.minimum}}",301:"Too many properties defined, maximum {{schema.maximum}}",302:"Required",303:"Additional properties not allowed",304:"Dependency failed - key must exist",400:"Array is too short ({{value.length}}), minimum {{schema.minimum}}",401:"Array is too long ({{value.length}}), maximum {{schema.maximum}}",402:"Array items are not unique",403:"Additional items not allowed",500:"Format validation failed",501:'Keyword failed: "{{title}}"',600:"Circular $refs",1e3:"Unknown property (not in schema)"};this.setDefaultMessages=function(e){t=e},this.getDefaultMessages=function(){return t},this.setDefaultMessage=function(e,r){t[e]=r},this.$get=["$interpolate",function(r){var n={};return n.defaultMessages=t,n.interpolate=function(n,i,a,o){o=o||{};var s=a.validationMessage||{};0===n.indexOf("tv4-")&&(n=n.substring(4));var l=s["default"]||o["default"]||"";[s,o,t].some(function(t){return e.isString(t)||e.isFunction(t)?(l=t,!0):t&&t[n]?(l=t[n],!0):void 0});var u={error:n,value:i,form:a,schema:a.schema,title:a.title||a.schema&&a.schema.title};return e.isFunction(l)?l(u):r(l)(u)},n}]}),e.module("schemaForm").provider("schemaForm",["sfPathProvider",function(t){var r=function(e){if(Array.isArray(e)&&2==e.length){if("null"===e[0])return e[1];if("null"===e[1])return e[0]}return e},n=function(e){var t=[];return e.forEach(function(e){t.push({name:e,value:e})}),t},i=function(t,r){if(!e.isArray(t)){var n=[];return r?e.forEach(r,function(e,r){n.push({name:t[e],value:e})}):e.forEach(t,function(e,t){n.push({name:e,value:t})}),n}return t},a=function(t,n,i){var a=p[r(n.type)];if(a)for(var o,s=0;s1&&(m={type:"section",items:s.items.map(function(t){return t.ngModelOptions=s.ngModelOptions,e.isUndefined(t.readonly)&&(t.readonly=s.readonly),t})})}if(o.copyWithIndex=function(t){if(!c[t]&&m){var n=e.copy(m);n.arrayIndex=t,r.traverseForm(n,a(t)),c[t]=n}return c[t]},o.appendToArray=function(){var n=l.length,i=o.copyWithIndex(n);if(r.traverseForm(i,function(r){if(r.key){var n;e.isDefined(r["default"])&&(n=r["default"]),e.isDefined(r.schema)&&e.isDefined(r.schema["default"])&&(n=r.schema["default"]),e.isDefined(n)&&t(r.key,o.model,n)}}),n===l.length){var a,u=t("schema.items.type",s);"object"===u?a={}:"array"===u&&(a=[]),l.push(a)}return o.validateArray&&o.validateArray(),l},o.deleteFromArray=function(e){return l.splice(e,1),o.validateArray&&o.validateArray(),u&&u.$setDirty&&u.$setDirty(),l},s.titleMap||s.startEmpty===!0||0!==l.length||o.appendToArray(),s.titleMap&&s.titleMap.length>0){o.titleMapValues=[];var d=function(e){o.titleMapValues=[],e=e||[],s.titleMap.forEach(function(t){o.titleMapValues.push(-1!==e.indexOf(t.value))})};d(o.modelArray),o.$watchCollection("modelArray",d),o.$watchCollection("titleMapValues",function(e){if(e){for(var t=o.modelArray;t.length>0;)t.pop();s.titleMap.forEach(function(r,n){e[n]&&t.push(r.value)})}})}if(u){var h;o.validateArray=function(){var e=n.validate(s,o.modelArray.length>0?o.modelArray:void 0);Object.keys(u.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){u.$setValidity(e,!0)}),e.valid!==!1||!e.error||""!==e.error.dataPath&&e.error.dataPath!=="/"+s.key[s.key.length-1]||(u.$setViewValue(o.modelArray),h=e.error,u.$setValidity("tv4-"+e.error.code,!1))},o.$on("schemaFormValidate",o.validateArray),o.hasSuccess=function(){return u.$valid&&!u.$pristine},o.hasError=function(){return u.$invalid},o.schemaError=function(){return h}}f()})}}}]),e.module("schemaForm").directive("sfChanged",function(){return{require:"ngModel",restrict:"AC",scope:!1,link:function(t,r,n,i){var a=t.$eval(n.sfChanged);a&&a.onChange&&i.$viewChangeListeners.push(function(){e.isFunction(a.onChange)?a.onChange(i.$modelValue,a):t.evalExpr(a.onChange,{modelValue:i.$modelValue,form:a})})}}}),e.module("schemaForm").directive("sfMessage",["$injector","sfErrorMessage",function(e,t){return{scope:!1,restrict:"EA",link:function(r,n,i){var a=e.has("$sanitize")?e.get("$sanitize"):function(e){return e},o="";i.sfMessage&&(o=r.$eval(i.sfMessage)||"",o=a(o));var s=function(e){if(e&&r.hasError())n.html(o);else{var i=Object.keys(r.ngModel&&r.ngModel.$error||{}),a=i[0];i.length>1&&(a=i.reduce(function(e,t){return e&&0===e.indexOf("tv4-")?e:t}),console.log("reduced",i,a)),n.html(a?t.interpolate(a,r.ngModel.$modelValue,r.form,r.options&&r.options.validationMessage):o)}};s(),r.$watchCollection("ngModel.$error",function(){r.ngModel&&s(r.ngModel.$valid)})}}}]),e.module("schemaForm").directive("sfSchema",["$compile","schemaForm","schemaFormDecorators","sfSelect","sfPath",function(t,r,n,i,a){var o=/[A-Z]/g,s=function(e,t){return t=t||"_",e.replace(o,function(e,r){return(r?t:"")+e.toLowerCase()})};return{scope:{schema:"=sfSchema",initialForm:"=sfForm",model:"=sfModel",options:"=sfOptions"},controller:["$scope",function(e){this.evalInParentScope=function(t,r){return e.$parent.$eval(t,r)}}],replace:!1,restrict:"A",transclude:!0,require:"?form",link:function(o,l,u,c,f){o.formCtrl=c;var m={};f(o,function(e){if(e.addClass("schema-form-ignore"),l.prepend(e),l[0].querySelectorAll){var t=l[0].querySelectorAll("[ng-model]");if(t)for(var r=0;r0&&(h.schema=e,h.form=t,p(e,t))}),o.$on("schemaFormRedraw",function(){var e=o.schema,t=o.initialForm||["*"];e&&p(e,t)})}}}]),e.module("schemaForm").directive("schemaValidate",["sfValidator","sfSelect",function(t,r){return{restrict:"A",scope:!1,priority:500,require:"ngModel",link:function(n,i,a,o){n.$emit("schemaFormPropagateNgModelController",o);var s=null,l=function(){return u||(u=n.$eval(a.schemaValidate)),u},u=l();u.copyValueTo&&o.$viewChangeListeners.push(function(){var t=u.copyValueTo;e.forEach(t,function(e){r(e,n.model,o.$modelValue)})});var c=function(e){if(u=l(),!u)return e;if(n.options&&n.options.tv4Validation===!1)return e;var r=t.validate(u,e);return Object.keys(o.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){o.$setValidity(e,!0)}),r.valid?e:(o.$setValidity("tv4-"+r.error.code,!1),void(s=r.error))};"function"==typeof u.ngModel&&u.ngModel(o),["$parsers","$viewChangeListeners","$formatters"].forEach(function(e){u[e]&&o[e]&&u[e].forEach(function(t){o[e].push(t)})}),["$validators","$asyncValidators"].forEach(function(t){u[t]&&o[t]&&e.forEach(u[t],function(e,r){o[t][r]=e})}),o.$parsers.push(c),n.$on("schemaFormValidate",function(){o.$setDirty?(o.$setDirty(),c(o.$modelValue)):o.$setViewValue(o.$viewValue)}),n.schemaError=function(){return s}}}}]),a}); \ No newline at end of file +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,n,a){n||(n=this);var i="string"==typeof t?e.parse(t):t;if("undefined"!=typeof a&&1===i.length)return n[i[0]]=a,n;"undefined"!=typeof a&&"undefined"==typeof n[i[0]]&&(n[i[0]]=i.length>2&&r.test(i[1])?[]:{});for(var o=n[i[0]],l=1;l',link:function(e,t,n){var a={items:"c",titleMap:"c",schema:"c"},i={type:r},o=!0;angular.forEach(n,function(r,t){if("$"!==t[0]&&0!==t.indexOf("ng")&&"sfField"!==t){var l=function(r){angular.isDefined(r)&&r!==i[t]&&(i[t]=r,o&&i.type&&(i.key||angular.isUndefined(n.key))&&(e.form=i,o=!1))};"model"===t?e.$watch(r,function(r){r&&e.model!==r&&(e.model=r)}):"c"===a[t]?e.$watchCollection(r,l):n.$observe(t,l)}})}}})};this.createDecorator=function(e,r,a){n[e]={mappings:r||{},rules:a||[]},n[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,n[e]},this.addMapping=function(e,r,t){n[e]&&(n[e].mappings[r]=t)},this.$get=function(){return{directive:function(e){return n[e]},defaultDecorator:t}},i("sfDecorator")}]),angular.module("schemaForm").provider("sfErrorMessage",function(){var e={"default":"Field does not validate",0:"Invalid type, expected {{schema.type}})",1:"No enum match for: {{value}}",10:'Data does not match any schemas from "anyOf"',11:'Data does not match any schemas from "oneOf"',12:'Data is valid against more than one schema from "oneOf"',13:'Data matches schema from "not"',100:"Value {{value}} is not a multiple of {{schema.multipleOf}}",101:"Value {{value}} is less than minimum {{schema.minimum}}",102:"Value {{value}} is equal to exclusive minimum {{schema.minimum}}",103:"Value {{value}} is greater than maximum {{schema.maximum}}",104:"Value {{value}} is equal to exclusive maximum {{schema.maximum}}",105:"Value {{value}} is not a valid number",200:"String is too short ({{value.length}} chars), minimum {{schema.minimum}}",201:"String is too long ({{value.length}} chars), maximum {{schema.maximum}}",202:"String does not match pattern: {{schema.pattern}}",300:"Too few properties defined, minimum {{schema.minimum}}",301:"Too many properties defined, maximum {{schema.maximum}}",302:"Required",303:"Additional properties not allowed",304:"Dependency failed - key must exist",400:"Array is too short ({{value.length}}), minimum {{schema.minimum}}",401:"Array is too long ({{value.length}}), maximum {{schema.maximum}}",402:"Array items are not unique",403:"Additional items not allowed",500:"Format validation failed",501:'Keyword failed: "{{title}}"',600:"Circular $refs",1e3:"Unknown property (not in schema)"};this.setDefaultMessages=function(r){e=r},this.getDefaultMessages=function(){return e},this.setDefaultMessage=function(r,t){e[r]=t},this.$get=["$interpolate",function(r){var t={};return t.defaultMessages=e,t.interpolate=function(t,n,a,i){i=i||{};var o=a.validationMessage||{};0===t.indexOf("tv4-")&&(t=t.substring(4));var l=o["default"]||i["default"]||"";[o,i,e].some(function(e){return angular.isString(e)||angular.isFunction(e)?(l=e,!0):e&&e[t]?(l=e[t],!0):void 0});var u={error:t,value:n,form:a,schema:a.schema,title:a.title||a.schema&&a.schema.title};return angular.isFunction(l)?l(u):r(l)(u)},t}]}),angular.module("schemaForm").provider("schemaForm",["sfPathProvider",function(e){var r=function(e){if(Array.isArray(e)&&2==e.length){if("null"===e[0])return e[1];if("null"===e[1])return e[0]}return e},t=function(e){var r=[];return e.forEach(function(e){r.push({name:e,value:e})}),r},n=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,t,n){var a=h[r(t.type)];if(a)for(var i,o=0;o1&&(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,a(e)),s[e]=t}return s[e]},i.appendToArray=function(){var t=l.length,n=i.copyWithIndex(t);if(r.traverseForm(n,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===l.length){var a,u=e("schema.items.type",o);"object"===u?a={}:"array"===u&&(a=[]),l.push(a)}return i.validateArray&&i.validateArray(),l},i.deleteFromArray=function(e){return l.splice(e,1),i.validateArray&&i.validateArray(),u&&u.$setDirty&&u.$setDirty(),l},o.titleMap||o.startEmpty===!0||0!==l.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,n){e[n]&&r.push(t.value)})}})}if(u){var d;i.validateArray=function(){var e=t.validate(o,i.modelArray.length>0?i.modelArray:void 0);Object.keys(u.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){u.$setValidity(e,!0)}),e.valid!==!1||!e.error||""!==e.error.dataPath&&e.error.dataPath!=="/"+o.key[o.key.length-1]||(u.$setViewValue(i.modelArray),d=e.error,u.$setValidity("tv4-"+e.error.code,!1))},i.$on("schemaFormValidate",i.validateArray),i.hasSuccess=function(){return u.$valid&&!u.$pristine},i.hasError=function(){return u.$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,n){var a=e.$eval(t.sfChanged);a&&a.onChange&&n.$viewChangeListeners.push(function(){angular.isFunction(a.onChange)?a.onChange(n.$modelValue,a):e.evalExpr(a.onChange,{modelValue:n.$modelValue,form:a})})}}}),angular.module("schemaForm").directive("sfMessage",["$injector","sfErrorMessage",function(e,r){return{scope:!1,restrict:"EA",link:function(t,n,a){var i=e.has("$sanitize")?e.get("$sanitize"):function(e){return e},o="";a.sfMessage&&(o=t.$eval(a.sfMessage)||"",o=i(o));var l=function(e){if(e&&t.hasError())n.html(o);else{var a=Object.keys(t.ngModel&&t.ngModel.$error||{}),i=a[0];a.length>1&&(i=a.reduce(function(e,r){return e&&0===e.indexOf("tv4-")?e:r}),console.log("reduced",a,i)),n.html(i?r.interpolate(i,t.ngModel.$modelValue,t.form,t.options&&t.options.validationMessage):o)}};l(),t.$watchCollection("ngModel.$error",function(){t.ngModel&&l(t.ngModel.$valid)})}}}]),angular.module("schemaForm").directive("sfSchema",["$compile","schemaForm","schemaFormDecorators","sfSelect","sfPath",function(e,r,t,n,a){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,l,u,s,c){i.formCtrl=s;var f={};c(i,function(e){if(e.addClass("schema-form-ignore"),l.prepend(e),l[0].querySelectorAll){var r=l[0].querySelectorAll("[ng-model]");if(r)for(var t=0;t0&&(d.schema=e,d.form=r,h(e,r))}),i.$on("schemaFormRedraw",function(){var e=i.schema,r=i.initialForm||["*"];e&&h(e,r)})}}}]),angular.module("schemaForm").directive("schemaValidate",["sfValidator","sfSelect",function(e,r){return{restrict:"A",scope:!1,priority:500,require:"ngModel",link:function(t,n,a,i){t.$emit("schemaFormPropagateNgModelController",i);var o=null,l=function(){return u||(u=t.$eval(a.schemaValidate)),u},u=l();u.copyValueTo&&i.$viewChangeListeners.push(function(){var e=u.copyValueTo;angular.forEach(e,function(e){r(e,t.model,i.$modelValue)})});var s=function(r){if(u=l(),!u)return r;var t=e.validate(u,r);return Object.keys(i.$error).filter(function(e){return 0===e.indexOf("tv4-")}).forEach(function(e){i.$setValidity(e,!0)}),t.valid?r:(i.$setValidity("tv4-"+t.error.code,!1),void(o=t.error))};"function"==typeof u.ngModel&&u.ngModel(i),["$parsers","$viewChangeListeners","$formatters"].forEach(function(e){u[e]&&i[e]&&u[e].forEach(function(r){i[e].push(r)})}),["$validators","$asyncValidators"].forEach(function(e){u[e]&&i[e]&&angular.forEach(u[e],function(r,t){i[e][t]=r})}),i.$parsers.push(s),t.$on("schemaFormValidate",function(){i.$setDirty?(i.$setDirty(),s(i.$modelValue)):i.$setViewValue(i.$viewValue)}),t.schemaError=function(){return o}}}}]); \ No newline at end of file