diff --git a/.gitignore b/.gitignore index a450d65..ee43924 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,105 @@ +# Created by https://www.gitignore.io/api/osx,windows,phpstorm + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +### Windows ### +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +### PhpStorm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + + bower_components node_modules +material-decorator.js +material-decorator.min.js \ No newline at end of file diff --git a/examples/data/switch.json b/examples/data/switch.json new file mode 100644 index 0000000..6cc03a7 --- /dev/null +++ b/examples/data/switch.json @@ -0,0 +1,21 @@ +{ + "schema": { + "type": "object", + "properties": { + "live": { + "title": "Mode", + "type": "string", + "titleMap": { + "true": "'Yes I do'", + "false": "'Hell no'" + } + } + } + }, + "form": [ + { + "key":"live", + "type":"switch" + } + ] +} \ No newline at end of file diff --git a/examples/material-example.html b/examples/material-example.html index a18fed5..dd396f4 100644 --- a/examples/material-example.html +++ b/examples/material-example.html @@ -184,6 +184,7 @@

Schema

app.controller('TestCtrl', function($scope, $http, $location, $timeout, $q) { $scope.tests = [ + { name: "Switch", data: 'data/switch.json'}, { name: "Material Flex Grid", data: 'data/grid.json' }, { name: "Autocomplete", data: 'data/autocomplete.json' }, { name: "Simple", data: 'data/simple.json' }, diff --git a/material-decorator.js b/material-decorator.js index 571f15c..319191f 100644 --- a/material-decorator.js +++ b/material-decorator.js @@ -6,7 +6,7 @@ $templateCache.put("decorators/material/checkbox.html","
"); $templateCache.put("decorators/material/chips.html","
{{$chip}}
"); $templateCache.put("decorators/material/date.html","
"); -$templateCache.put("decorators/material/default.html",""); +$templateCache.put("decorators/material/default.html",""); $templateCache.put("decorators/material/fieldset-trcl.html","
{{ form.title }}
"); $templateCache.put("decorators/material/fieldset.html","
{{ form.title }}
"); $templateCache.put("decorators/material/help.html","
"); @@ -16,7 +16,7 @@ $templateCache.put("decorators/material/radios.html","
"); $templateCache.put("decorators/material/select.html","{{filtered.name}}{{opt.name}}
"); $templateCache.put("decorators/material/submit.html","
{{form.title}}
"); -$templateCache.put("decorators/material/switch.html","
"); +$templateCache.put("decorators/material/switch.html","{{form.title}}
"); $templateCache.put("decorators/material/tabarray.html","
"); $templateCache.put("decorators/material/tabs.html","
"); $templateCache.put("decorators/material/textarea.html","
");}]); @@ -50,17 +50,28 @@ angular.module('schemaForm') if (mdAutocompleteFrag) { if (args.form.onChange) { mdAutocompleteFrag.setAttribute('md-selected-item-change', 'args.form.onChange(searchText)'); - }; + } if (args.form.onChange) { mdAutocompleteFrag.setAttribute('md-search-text-change', 'args.form.onChange(searchText)'); - }; + } // mdAutocompleteFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);'); var minLength = args.form.minLength || 1; var maxLength = args.form.maxLength || false; mdAutocompleteFrag.setAttribute('md-min-length', minLength); if (maxLength) { mdAutocompleteFrag.setAttribute('md-max-length', maxLength); - }; + } + } + }; + + var mdSwitch = function(args) { + var mdSwitchFrag = args.fieldFrag.querySelector('md-switch'); + if (args.form.schema.titleMap) { + mdSwitchFrag.setAttribute('ng-true-value',args.form.schema.titleMap.true); + mdSwitchFrag.setAttribute('ng-false-value',args.form.schema.titleMap.false); + } + if (args.form.schema.ink) { + mdSwitchFrag.setIdAttribute('md-no-ink',args.form.schema.ink); } }; @@ -69,16 +80,16 @@ angular.module('schemaForm') if (mdDatepickerFrag) { if (args.form.onChange) { mdDatepickerFrag.setAttribute('ng-change', 'args.form.onChange(searchText)'); - }; + } // mdDatepickerFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);'); var minDate = args.form.minimum || false; var maxDate = args.form.maximum || false; if (minDate) { mdDatepickerFrag.setAttribute('md-max-date', minDate); - }; + } if (maxDate) { mdDatepickerFrag.setAttribute('md-max-date', maxDate); - }; + } } }; @@ -131,7 +142,11 @@ angular.module('schemaForm') submit: { template: base + 'submit.html', builder: defaults }, tabs: { template: base + 'tabs.html', builder: [ sfField, mdTabs, condition ] }, tabarray: { template: base + 'tabarray.html', builder: [ sfField, ngModelOptions, ngModel, array, condition ] }, - textarea: { template: base + 'textarea.html', builder: defaults } + textarea: { template: base + 'textarea.html', builder: defaults }, + switch: { + template: base + 'switch.html', + builder: [ sfField, ngModel, ngModelOptions, sfMessages, condition, mdSwitch ] + } }); /** diff --git a/material-decorator.min.js b/material-decorator.min.js index 2fab929..eb93316 100644 --- a/material-decorator.min.js +++ b/material-decorator.min.js @@ -1 +1 @@ -angular.module("schemaForm").run(["$templateCache",function(e){e.put("decorators/material/actions-trcl.html",'
'),e.put("decorators/material/actions.html",'
'),e.put("decorators/material/array.html",'
{{ form.add || \'Add\'}}
'),e.put("decorators/material/autocomplete.html",'
{{item.title}}No matches found
'),e.put("decorators/material/checkbox.html",'
'),e.put("decorators/material/checkboxes.html",'
'),e.put("decorators/material/chips.html",'
{{$chip}}
'),e.put("decorators/material/date.html",'
'),e.put("decorators/material/default.html",''),e.put("decorators/material/fieldset-trcl.html",'
{{ form.title }}
'),e.put("decorators/material/fieldset.html",'
{{ form.title }}
'),e.put("decorators/material/help.html",'
'),e.put("decorators/material/radio-buttons.html",'
'),e.put("decorators/material/radios-inline.html",'
'),e.put("decorators/material/radios.html",'
'),e.put("decorators/material/section.html",'
'),e.put("decorators/material/select.html",'{{filtered.name}}{{opt.name}}
'),e.put("decorators/material/submit.html",'
{{form.title}}
'),e.put("decorators/material/switch.html",'
'),e.put("decorators/material/tabarray.html",'
'),e.put("decorators/material/tabs.html",'
'),e.put("decorators/material/textarea.html",'
')}]),angular.module("schemaForm").config(["schemaFormProvider","schemaFormDecoratorsProvider","sfBuilderProvider","sfPathProvider","$injector",function(e,a,t,s,r){var l="decorators/material/",o=t.builders.simpleTransclusion,m=t.builders.ngModelOptions,i=t.builders.ngModel,d=t.builders.sfField,n=t.builders.condition,c=t.builders.array,f=function(){var e='
',a=document.createElement("div");return a.innerHTML=e,a.firstChild}(),h=function(e){var a=e.fieldFrag.querySelector("[sf-messages]");a&&f&&a.appendChild(f)},g=function(e){var a=e.fieldFrag.querySelector("md-autocomplete");if(a){e.form.onChange&&a.setAttribute("md-selected-item-change","args.form.onChange(searchText)"),e.form.onChange&&a.setAttribute("md-search-text-change","args.form.onChange(searchText)");var t=e.form.minLength||1,s=e.form.maxLength||!1;a.setAttribute("md-min-length",t),s&&a.setAttribute("md-max-length",s)}},u=function(e){var a=e.fieldFrag.querySelector("md-datepicker");if(a){e.form.onChange&&a.setAttribute("ng-change","args.form.onChange(searchText)");var t=e.form.minimum||!1,s=e.form.maximum||!1;t&&a.setAttribute("md-max-date",t),s&&a.setAttribute("md-max-date",s)}},p=function(e){if(e.form.tabs&&e.form.tabs.length>0){var a=e.fieldFrag.querySelector("md-tabs");e.form.tabs.forEach(function(t,s){var r=document.createElement("md-tab");r.setAttribute("label","{{"+e.path+".tabs["+s+"].title}}");var l=document.createElement("md-tab-body"),o=e.build(t.items,e.path+".tabs["+s+"].items",e.state);l.appendChild(o),r.appendChild(l),a.appendChild(r)})}},b=[d,i,m,h,n];a.defineDecorator("materialDecorator",{actions:{template:l+"actions.html",builder:[d,o,n]},array:{template:l+"array.html",builder:[d,m,i,c,n]},autocomplete:{template:l+"autocomplete.html",builder:[d,i,m,h,n,g]},"boolean":{template:l+"checkbox.html",builder:b},button:{template:l+"submit.html",builder:b},checkbox:{template:l+"checkbox.html",builder:b},checkboxes:{template:l+"checkboxes.html",builder:[d,m,i,c,n]},date:{template:l+"date.html",builder:[d,i,m,h,u,n]},"default":{template:l+"default.html",builder:b},fieldset:{template:l+"fieldset.html",builder:[d,o,n]},help:{template:l+"help.html",builder:b},number:{template:l+"default.html",builder:b},password:{template:l+"default.html",builder:b},radios:{template:l+"radios.html",builder:b},"radios-inline":{template:l+"radios-inline.html",builder:b},radiobuttons:{template:l+"radio-buttons.html",builder:b},section:{template:l+"section.html",builder:[d,o,n]},select:{template:l+"select.html",builder:b},submit:{template:l+"submit.html",builder:b},tabs:{template:l+"tabs.html",builder:[d,p,n]},tabarray:{template:l+"tabarray.html",builder:[d,m,i,c,n]},textarea:{template:l+"textarea.html",builder:b}});var v=function(a,t,r){if("string"===t.type&&("date"===t.format||"date-time"===t.format)){var l=e.stdFormObj(a,t,r);return l.key=r.path,l.type="date",r.lookup[s.stringify(r.path)]=l,l}};e.defaults.string.unshift(v)}]),angular.module("schemaForm").directive("sfTypeParser",function(){return{restrict:"A",scope:!1,require:"ngModel",link:function(e,a,t,s){var r=e.$watch(t.sfTypeParser,function(e){if(e){var a=-1!==e.type.indexOf("number"),t=-1!==e.type.indexOf("integer"),l=/^[0-9]*$/;(a||t)&&s.$parsers.push(function(e){var t;return a?t=parseFloat(e):l.test(e)&&(t=parseInt(e,10)),console.log("parser",l.test(e),e,t),void 0===t||isNaN(t)?e:t}),r()}})}}}); \ No newline at end of file +angular.module("schemaForm").run(["$templateCache",function(e){e.put("decorators/material/actions-trcl.html",'
'),e.put("decorators/material/actions.html",'
'),e.put("decorators/material/array.html",'
{{ form.add || \'Add\'}}
'),e.put("decorators/material/autocomplete.html",'
{{item.title}}No matches found
'),e.put("decorators/material/checkbox.html",'
'),e.put("decorators/material/checkboxes.html",'
'),e.put("decorators/material/chips.html",'
{{$chip}}
'),e.put("decorators/material/date.html",'
'),e.put("decorators/material/default.html",''),e.put("decorators/material/fieldset-trcl.html",'
{{ form.title }}
'),e.put("decorators/material/fieldset.html",'
{{ form.title }}
'),e.put("decorators/material/help.html",'
'),e.put("decorators/material/radio-buttons.html",'
'),e.put("decorators/material/radios-inline.html",'
'),e.put("decorators/material/radios.html",'
'),e.put("decorators/material/section.html",'
'),e.put("decorators/material/select.html",'{{filtered.name}}{{opt.name}}
'),e.put("decorators/material/submit.html",'
{{form.title}}
'),e.put("decorators/material/switch.html",'{{form.title}}
'),e.put("decorators/material/tabarray.html",'
'),e.put("decorators/material/tabs.html",'
'),e.put("decorators/material/textarea.html",'
')}]),angular.module("schemaForm").config(["schemaFormProvider","schemaFormDecoratorsProvider","sfBuilderProvider","sfPathProvider","$injector",function(e,a,t,s,r){var l="decorators/material/",o=t.builders.simpleTransclusion,m=t.builders.ngModelOptions,i=t.builders.ngModel,d=t.builders.sfField,n=t.builders.condition,c=t.builders.array,f=function(){var e='
',a=document.createElement("div");return a.innerHTML=e,a.firstChild}(),h=function(e){var a=e.fieldFrag.querySelector("[sf-messages]");a&&f&&a.appendChild(f)},g=function(e){var a=e.fieldFrag.querySelector("md-autocomplete");if(a){e.form.onChange&&a.setAttribute("md-selected-item-change","args.form.onChange(searchText)"),e.form.onChange&&a.setAttribute("md-search-text-change","args.form.onChange(searchText)");var t=e.form.minLength||1,s=e.form.maxLength||!1;a.setAttribute("md-min-length",t),s&&a.setAttribute("md-max-length",s)}},u=function(e){var a=e.fieldFrag.querySelector("md-switch");e.form.schema.titleMap&&(a.setAttribute("ng-true-value",e.form.schema.titleMap["true"]),a.setAttribute("ng-false-value",e.form.schema.titleMap["false"])),e.form.schema.ink&&a.setIdAttribute("md-no-ink",e.form.schema.ink)},p=function(e){var a=e.fieldFrag.querySelector("md-datepicker");if(a){e.form.onChange&&a.setAttribute("ng-change","args.form.onChange(searchText)");var t=e.form.minimum||!1,s=e.form.maximum||!1;t&&a.setAttribute("md-max-date",t),s&&a.setAttribute("md-max-date",s)}},b=function(e){if(e.form.tabs&&e.form.tabs.length>0){var a=e.fieldFrag.querySelector("md-tabs");e.form.tabs.forEach(function(t,s){var r=document.createElement("md-tab");r.setAttribute("label","{{"+e.path+".tabs["+s+"].title}}");var l=document.createElement("md-tab-body"),o=e.build(t.items,e.path+".tabs["+s+"].items",e.state);l.appendChild(o),r.appendChild(l),a.appendChild(r)})}},v=[d,i,m,h,n];a.defineDecorator("materialDecorator",{actions:{template:l+"actions.html",builder:[d,o,n]},array:{template:l+"array.html",builder:[d,m,i,c,n]},autocomplete:{template:l+"autocomplete.html",builder:[d,i,m,h,n,g]},"boolean":{template:l+"checkbox.html",builder:v},button:{template:l+"submit.html",builder:v},checkbox:{template:l+"checkbox.html",builder:v},checkboxes:{template:l+"checkboxes.html",builder:[d,m,i,c,n]},date:{template:l+"date.html",builder:[d,i,m,h,p,n]},"default":{template:l+"default.html",builder:v},fieldset:{template:l+"fieldset.html",builder:[d,o,n]},help:{template:l+"help.html",builder:v},number:{template:l+"default.html",builder:v},password:{template:l+"default.html",builder:v},radios:{template:l+"radios.html",builder:v},"radios-inline":{template:l+"radios-inline.html",builder:v},radiobuttons:{template:l+"radio-buttons.html",builder:v},section:{template:l+"section.html",builder:[d,o,n]},select:{template:l+"select.html",builder:v},submit:{template:l+"submit.html",builder:v},tabs:{template:l+"tabs.html",builder:[d,b,n]},tabarray:{template:l+"tabarray.html",builder:[d,m,i,c,n]},textarea:{template:l+"textarea.html",builder:v},"switch":{template:l+"switch.html",builder:[d,i,m,h,n,u]}});var y=function(a,t,r){if("string"===t.type&&("date"===t.format||"date-time"===t.format)){var l=e.stdFormObj(a,t,r);return l.key=r.path,l.type="date",r.lookup[s.stringify(r.path)]=l,l}};e.defaults.string.unshift(y)}]),angular.module("schemaForm").directive("sfTypeParser",function(){return{restrict:"A",scope:!1,require:"ngModel",link:function(e,a,t,s){var r=e.$watch(t.sfTypeParser,function(e){if(e){var a=-1!==e.type.indexOf("number"),t=-1!==e.type.indexOf("integer"),l=/^[0-9]*$/;(a||t)&&s.$parsers.push(function(e){var t;return a?t=parseFloat(e):l.test(e)&&(t=parseInt(e,10)),console.log("parser",l.test(e),e,t),void 0===t||isNaN(t)?e:t}),r()}})}}}); \ No newline at end of file diff --git a/src/material-decorator.js b/src/material-decorator.js index 3b52959..c3d8a1e 100644 --- a/src/material-decorator.js +++ b/src/material-decorator.js @@ -28,17 +28,28 @@ angular.module('schemaForm') if (mdAutocompleteFrag) { if (args.form.onChange) { mdAutocompleteFrag.setAttribute('md-selected-item-change', 'args.form.onChange(searchText)'); - }; + } if (args.form.onChange) { mdAutocompleteFrag.setAttribute('md-search-text-change', 'args.form.onChange(searchText)'); - }; + } // mdAutocompleteFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);'); var minLength = args.form.minLength || 1; var maxLength = args.form.maxLength || false; mdAutocompleteFrag.setAttribute('md-min-length', minLength); if (maxLength) { mdAutocompleteFrag.setAttribute('md-max-length', maxLength); - }; + } + } + }; + + var mdSwitch = function(args) { + var mdSwitchFrag = args.fieldFrag.querySelector('md-switch'); + if (args.form.schema.titleMap) { + mdSwitchFrag.setAttribute('ng-true-value',args.form.schema.titleMap.true); + mdSwitchFrag.setAttribute('ng-false-value',args.form.schema.titleMap.false); + } + if (args.form.schema.ink) { + mdSwitchFrag.setIdAttribute('md-no-ink',args.form.schema.ink); } }; @@ -47,16 +58,16 @@ angular.module('schemaForm') if (mdDatepickerFrag) { if (args.form.onChange) { mdDatepickerFrag.setAttribute('ng-change', 'args.form.onChange(searchText)'); - }; + } // mdDatepickerFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);'); var minDate = args.form.minimum || false; var maxDate = args.form.maximum || false; if (minDate) { mdDatepickerFrag.setAttribute('md-max-date', minDate); - }; + } if (maxDate) { mdDatepickerFrag.setAttribute('md-max-date', maxDate); - }; + } } }; @@ -109,7 +120,11 @@ angular.module('schemaForm') submit: { template: base + 'submit.html', builder: defaults }, tabs: { template: base + 'tabs.html', builder: [ sfField, mdTabs, condition ] }, tabarray: { template: base + 'tabarray.html', builder: [ sfField, ngModelOptions, ngModel, array, condition ] }, - textarea: { template: base + 'textarea.html', builder: defaults } + textarea: { template: base + 'textarea.html', builder: defaults }, + switch: { + template: base + 'switch.html', + builder: [ sfField, ngModel, ngModelOptions, sfMessages, condition, mdSwitch ] + } }); /** diff --git a/src/switch.html b/src/switch.html index 0f0d5d2..725f09d 100644 --- a/src/switch.html +++ b/src/switch.html @@ -5,12 +5,10 @@ schema-validate="form" id="{{form.key.slice(-1)[0]}}" aria-label="{{form.title}}" - ng-true-value="'yup'" - ng-false-value="'nope'" ng-show="form.key" ng-class="form.fieldHtmlClass" ng-disabled="form.readonly"> - + {{form.title}}