Skip to content

Commit 0e66cb5

Browse files
committed
finished switch
fixed some jscs warnings
1 parent afb916e commit 0e66cb5

File tree

9 files changed

+174
-21
lines changed

9 files changed

+174
-21
lines changed

.gitignore

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,105 @@
1+
# Created by https://www.gitignore.io/api/osx,windows,phpstorm
2+
3+
### OSX ###
4+
.DS_Store
5+
.AppleDouble
6+
.LSOverride
7+
8+
# Icon must end with two \r
9+
Icon
10+
11+
12+
# Thumbnails
13+
._*
14+
15+
# Files that might appear in the root of a volume
16+
.DocumentRevisions-V100
17+
.fseventsd
18+
.Spotlight-V100
19+
.TemporaryItems
20+
.Trashes
21+
.VolumeIcon.icns
22+
23+
# Directories potentially created on remote AFP share
24+
.AppleDB
25+
.AppleDesktop
26+
Network Trash Folder
27+
Temporary Items
28+
.apdisk
29+
30+
31+
### Windows ###
32+
# Windows image file caches
33+
Thumbs.db
34+
ehthumbs.db
35+
36+
# Folder config file
37+
Desktop.ini
38+
39+
# Recycle Bin used on file shares
40+
$RECYCLE.BIN/
41+
42+
# Windows Installer files
43+
*.cab
44+
*.msi
45+
*.msm
46+
*.msp
47+
48+
# Windows shortcuts
49+
*.lnk
50+
51+
52+
### PhpStorm ###
53+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
54+
55+
*.iml
56+
57+
## Directory-based project format:
58+
.idea/
59+
# if you remove the above rule, at least ignore the following:
60+
61+
# User-specific stuff:
62+
# .idea/workspace.xml
63+
# .idea/tasks.xml
64+
# .idea/dictionaries
65+
66+
# Sensitive or high-churn files:
67+
# .idea/dataSources.ids
68+
# .idea/dataSources.xml
69+
# .idea/sqlDataSources.xml
70+
# .idea/dynamic.xml
71+
# .idea/uiDesigner.xml
72+
73+
# Gradle:
74+
# .idea/gradle.xml
75+
# .idea/libraries
76+
77+
# Mongo Explorer plugin:
78+
# .idea/mongoSettings.xml
79+
80+
## File-based project format:
81+
*.ipr
82+
*.iws
83+
84+
## Plugin-specific files:
85+
86+
# IntelliJ
87+
/out/
88+
89+
# mpeltonen/sbt-idea plugin
90+
.idea_modules/
91+
92+
# JIRA plugin
93+
atlassian-ide-plugin.xml
94+
95+
# Crashlytics plugin (for Android Studio and IntelliJ)
96+
com_crashlytics_export_strings.xml
97+
crashlytics.properties
98+
crashlytics-build.properties
99+
100+
1101
bower_components
2102
node_modules
3103

104+
material-decorator.js
105+
material-decorator.min.js

examples/data/switch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"schema": {
3+
"type": "object",
4+
"properties": {
5+
"live": {
6+
"title": "Mode",
7+
"type": "string",
8+
"titleMap": {
9+
"true": "'Yes I do'",
10+
"false": "'Hell no'"
11+
}
12+
}
13+
}
14+
},
15+
"form": [
16+
{
17+
"key":"live",
18+
"type":"switch"
19+
}
20+
]
21+
}

examples/material-example.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ <h3>Schema</h3>
184184
app.controller('TestCtrl', function($scope, $http, $location, $timeout, $q) {
185185

186186
$scope.tests = [
187+
{ name: "Switch", data: 'data/switch.json'},
187188
{ name: "Material Flex Grid", data: 'data/grid.json' },
188189
{ name: "Autocomplete", data: 'data/autocomplete.json' },
189190
{ name: "Simple", data: 'data/simple.json' },

material-decorator.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $templateCache.put("decorators/material/checkbox.html","<div class=\"checkbox sc
66
$templateCache.put("decorators/material/checkboxes.html","<div sf-array=\"form\" sf-field-model=\"\" class=\"form-group schema-form-checkboxes {{form.htmlClass}}\" ng-class=\"{\'has-error\': hasError(), \'has-success\': hasSuccess()}\"><label class=\"control-label\" ng-show=\"showTitle()\">{{form.title}}</label><div class=\"checkbox\" ng-repeat=\"val in titleMapValues track by $index\"><md-checkbox ng-model=\"titleMapValues[$index]\" sf-changed=\"form\" ng-disabled=\"form.readonly\" name=\"{{form.key.slice(-1)[0]}}\" ng-true-value=\"true\" ng-false-value=\"false\" aria-label=\"{{form.title || form.key.slice(-1)[0]}}\"><span ng-bind-html=\"form.titleMap[$index].name\"></span></md-checkbox></div><div ng-messages=\"ngModel.$error\"><div sf-message=\"\" ng-message=\"\"></div></div></div>");
77
$templateCache.put("decorators/material/chips.html","<div class=\"form-group schema-form-chips {{form.htmlClass}}\" ng-class=\"{\'has-error\': hasError(), \'has-success\': hasSuccess(), \'has-feedback\': form.feedback !== false}\"><md-chips sf-field-model=\"\" readonly=\"form.readonly\" flex=\"\" placeholder=\"{{form.title || form.key.slice(-1)[0]}}\"><md-chip-template><strong ng-if=\"!form.template\">{{$chip}}</strong></md-chip-template></md-chips><div ng-messages=\"ngModel.$error\"><div sf-message=\"\" ng-message=\"\"></div></div></div>");
88
$templateCache.put("decorators/material/date.html","<div class=\"schema-form-date {{form.htmlClass}}\"><label ng-show=\"showTitle()\" for=\"{{form.key.slice(-1)[0]}}\">{{form.title}}</label><md-datepicker sf-field-model=\"\" sf-changed=\"form\" schema-validate=\"form\" sf-type-parser=\"form.schema\" id=\"{{form.key.slice(-1)[0]}}\" ng-show=\"form.key\" ng-class=\"form.fieldHtmlClass\" ng-disabled=\"form.readonly\" md-placeholder=\"Enter date\" sf-messages=\"\"></md-datepicker></div>");
9-
$templateCache.put("decorators/material/default.html","<md-input-container class=\"schema-form-{{form.type}} {{form.htmlClass}}\" sf-messages=\"\"><label ng-show=\"showTitle()\" for=\"{{form.key.slice(-1)[0]}}\">{{form.title}}</label><input sf-field-model=\"\" ng-show=\"form.key\" type=\"{{form.type}}\" step=\"any\" sf-changed=\"form\" id=\"{{form.key.slice(-1)[0]}}\" ng-class=\"form.fieldHtmlClass\" sf-type-parser=\"form.schema\" ng-disabled=\"form.readonly\" schema-validate=\"form\" name=\"{{form.key.slice(-1)[0]}}\" aria-describedby=\"{{form.key.slice(-1)[0] + \'Status\'}}\"></md-input-container>");
9+
$templateCache.put("decorators/material/default.html","<md-input-container class=\"schema-form-{{form.type}} {{form.htmlClass}}\" ng-class=\"{\'md-input-has-value\':model[\'{{form.key.slice(-1)[0]}}\']}\" sf-messages=\"\"><label ng-show=\"showTitle()\" for=\"{{form.key.slice(-1)[0]}}\">{{form.title}}</label><input sf-field-model=\"\" ng-show=\"form.key\" type=\"{{form.type}}\" step=\"any\" sf-changed=\"form\" id=\"{{form.key.slice(-1)[0]}}\" ng-class=\"form.fieldHtmlClass\" sf-type-parser=\"form.schema\" ng-disabled=\"form.readonly\" schema-validate=\"form\" name=\"{{form.key.slice(-1)[0]}}\" aria-describedby=\"{{form.key.slice(-1)[0] + \'Status\'}}\"></md-input-container>");
1010
$templateCache.put("decorators/material/fieldset-trcl.html","<fieldset ng-disabled=\"form.readonly\" class=\"standard {{form.htmlClass}}\" flex=\"\"><legend ng-show=\"form.title\">{{ form.title }}</legend><div ng-transclude=\"\"></div></fieldset>");
1111
$templateCache.put("decorators/material/fieldset.html","<fieldset ng-disabled=\"form.readonly\" class=\"standard {{form.htmlClass}}\" flex=\"\"><legend ng-show=\"form.title\">{{ form.title }}</legend></fieldset>");
1212
$templateCache.put("decorators/material/help.html","<div class=\"helpvalue schema-form-helpvalue {{form.htmlClass}}\" ng-bind-html=\"form.helpvalue\"></div>");
@@ -16,7 +16,7 @@ $templateCache.put("decorators/material/radios.html","<div class=\"form-group sc
1616
$templateCache.put("decorators/material/section.html","<div class=\"schema-form-section {{form.htmlClass}}\"></div>");
1717
$templateCache.put("decorators/material/select.html","<md-input-container class=\"form-group {{form.htmlClass}} schema-form-select\" ng-class=\"{\'has-error\': hasError(), \'has-success\': hasSuccess(), \'has-feedback\': form.feedback !== false}\"><label ng-show=\"showTitle()\">{{form.title}}</label><md-select sf-field-model=\"\"><md-optgroup ng-repeat-start=\"(key, opt) in form.titleMap | orderBy:\'group\' as optGroups\" ng-if=\"opt.group && opt.group != optGroups[key-1].group\" label=\"{{opt.group}}\"><md-option ng-repeat=\"(key, filtered) in form.titleMap | filter: {group: opt.group} | orderBy:\'name\' as opts\" ng-value=\"filtered.value\">{{filtered.name}}</md-option></md-optgroup><md-option ng-repeat-end=\"\" ng-if=\"!opt.group\" ng-value=\"opt.value\">{{opt.name}}</md-option></md-select><div ng-messages=\"ngModel.$error\"><div sf-message=\"\" ng-message=\"\"></div></div></md-input-container>");
1818
$templateCache.put("decorators/material/submit.html","<section class=\"schema-form-submit {{form.htmlClass}}\"><md-button class=\"md-raised {{ form.style || \'md-primary\' }} {{form.fieldHtmlClass}}\" ng-disabled=\"form.readonly\">{{form.title}}</md-button></section>");
19-
$templateCache.put("decorators/material/switch.html","<md-input-container class=\"schema-form-switch {{form.htmlClass}}\"><md-switch sf-field-model=\"\" sf-changed=\"form\" sf-type-parser=\"form.schema\" 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\"><label ng-show=\"showTitle()\" for=\"{{form.key.slice(-1)[0]}}\">{{form.title}}</label><div ng-messages=\"ngModel.$error\"><div sf-message=\"\" ng-message=\"\"></div></div></md-switch></md-input-container>");
19+
$templateCache.put("decorators/material/switch.html","<md-input-container class=\"schema-form-switch {{form.htmlClass}}\"><md-switch sf-field-model=\"\" sf-changed=\"form\" sf-type-parser=\"form.schema\" schema-validate=\"form\" id=\"{{form.key.slice(-1)[0]}}\" aria-label=\"{{form.title}}\" ng-show=\"form.key\" ng-class=\"form.fieldHtmlClass\" ng-disabled=\"form.readonly\"><span ng-show=\"showTitle()\" for=\"{{form.key.slice(-1)[0]}}\">{{form.title}}</span><div ng-messages=\"ngModel.$error\"><div sf-message=\"\" ng-message=\"\"></div></div></md-switch></md-input-container>");
2020
$templateCache.put("decorators/material/tabarray.html","<div sf-array=\"form\" ng-init=\"selected = { tab: 0 }\" class=\"clearfix schema-form-tabarray schema-form-tabarray-{{form.tabType || \'left\'}} {{form.htmlClass}}\"><div ng-if=\"!form.tabType || form.tabType !== \'right\'\" ng-class=\"{\'col-xs-3\': !form.tabType || form.tabType === \'left\'}\"><ul class=\"nav nav-tabs\" ng-class=\"{ \'tabs-left\': !form.tabType || form.tabType === \'left\'}\"><li ng-repeat=\"item in modelArray track by $index\" ng-click=\"$event.preventDefault() || (selected.tab = $index)\" ng-class=\"{active: selected.tab === $index}\"><a href=\"#\">{{interp(form.title,{\'$index\':$index, value: item}) || $index}}</a></li><li ng-hide=\"form.readonly\" ng-click=\"$event.preventDefault() || (selected.tab = appendToArray().length - 1)\"><a href=\"#\"><i class=\"glyphicon glyphicon-plus\"></i> {{ form.add || \'Add\'}}</a></li></ul></div><div ng-class=\"{\'col-xs-9\': !form.tabType || form.tabType === \'left\' || form.tabType === \'right\'}\"><div class=\"tab-content {{form.fieldHtmlClass}}\"><div class=\"tab-pane clearfix\" ng-repeat=\"item in modelArray track by $index\" ng-show=\"selected.tab === $index\" ng-class=\"{active: selected.tab === $index}\"><sf-decorator ng-init=\"arrayIndex = $index\" form=\"copyWithIndex($index)\"></sf-decorator><button ng-hide=\"form.readonly\" ng-click=\"selected.tab = deleteFromArray($index).length - 1\" type=\"button\" class=\"btn {{ form.style.remove || \'btn-default\' }} pull-right\"><i class=\"glyphicon glyphicon-trash\"></i> {{ form.remove || \'Remove\'}}</button></div></div></div><div ng-if=\"form.tabType === \'right\'\" class=\"col-xs-3\"><ul class=\"nav nav-tabs tabs-right\"><li ng-repeat=\"item in modelArray track by $index\" ng-click=\"$event.preventDefault() || (selected.tab = $index)\" ng-class=\"{active: selected.tab === $index}\"><a href=\"#\">{{interp(form.title,{\'$index\':$index, value: item}) || $index}}</a></li><li ng-hide=\"form.readonly\" ng-click=\"$event.preventDefault() || appendToArray()\"><a href=\"#\"><i class=\"glyphicon glyphicon-plus\"></i> {{ form.add || \'Add\'}}</a></li></ul></div></div>");
2121
$templateCache.put("decorators/material/tabs.html","<div sf-field-model=\"\" class=\"schema-form-tabs {{form.htmlClass}}\"><md-tabs md-dynamic-height=\"\" md-selected=\"selected\" md-autoselect=\"\" ng-init=\"selected = 0\"></md-tabs></div>");
2222
$templateCache.put("decorators/material/textarea.html","<md-input-container class=\"{{form.htmlClass}} schema-form-textarea\"><label ng-show=\"showTitle()\" for=\"{{form.key.slice(-1)[0]}}\">{{form.title}}</label> <textarea ng-class=\"form.fieldHtmlClass\" id=\"{{form.key.slice(-1)[0]}}\" sf-changed=\"form\" ng-disabled=\"form.readonly\" sf-field-model=\"\" schema-validate=\"form\" name=\"{{form.key.slice(-1)[0]}}\"></textarea><div ng-messages=\"ngModel.$error\"><div sf-message=\"\" ng-message=\"\"></div></div></md-input-container>");}]);
@@ -50,17 +50,28 @@ angular.module('schemaForm')
5050
if (mdAutocompleteFrag) {
5151
if (args.form.onChange) {
5252
mdAutocompleteFrag.setAttribute('md-selected-item-change', 'args.form.onChange(searchText)');
53-
};
53+
}
5454
if (args.form.onChange) {
5555
mdAutocompleteFrag.setAttribute('md-search-text-change', 'args.form.onChange(searchText)');
56-
};
56+
}
5757
// mdAutocompleteFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);');
5858
var minLength = args.form.minLength || 1;
5959
var maxLength = args.form.maxLength || false;
6060
mdAutocompleteFrag.setAttribute('md-min-length', minLength);
6161
if (maxLength) {
6262
mdAutocompleteFrag.setAttribute('md-max-length', maxLength);
63-
};
63+
}
64+
}
65+
};
66+
67+
var mdSwitch = function(args) {
68+
var mdSwitchFrag = args.fieldFrag.querySelector('md-switch');
69+
if (args.form.schema.titleMap) {
70+
mdSwitchFrag.setAttribute('ng-true-value',args.form.schema.titleMap.true);
71+
mdSwitchFrag.setAttribute('ng-false-value',args.form.schema.titleMap.false);
72+
}
73+
if (args.form.schema.ink) {
74+
mdSwitchFrag.setIdAttribute('md-no-ink',args.form.schema.ink);
6475
}
6576
};
6677

@@ -69,16 +80,16 @@ angular.module('schemaForm')
6980
if (mdDatepickerFrag) {
7081
if (args.form.onChange) {
7182
mdDatepickerFrag.setAttribute('ng-change', 'args.form.onChange(searchText)');
72-
};
83+
}
7384
// mdDatepickerFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);');
7485
var minDate = args.form.minimum || false;
7586
var maxDate = args.form.maximum || false;
7687
if (minDate) {
7788
mdDatepickerFrag.setAttribute('md-max-date', minDate);
78-
};
89+
}
7990
if (maxDate) {
8091
mdDatepickerFrag.setAttribute('md-max-date', maxDate);
81-
};
92+
}
8293
}
8394
};
8495

@@ -131,7 +142,11 @@ angular.module('schemaForm')
131142
submit: { template: base + 'submit.html', builder: defaults },
132143
tabs: { template: base + 'tabs.html', builder: [ sfField, mdTabs, condition ] },
133144
tabarray: { template: base + 'tabarray.html', builder: [ sfField, ngModelOptions, ngModel, array, condition ] },
134-
textarea: { template: base + 'textarea.html', builder: defaults }
145+
textarea: { template: base + 'textarea.html', builder: defaults },
146+
switch: {
147+
template: base + 'switch.html',
148+
builder: [ sfField, ngModel, ngModelOptions, sfMessages, condition, mdSwitch ]
149+
}
135150
});
136151

137152
/**

material-decorator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"gulp": "^3.9.0",
1616
"gulp-angular-templatecache": "^1.6.0",
1717
"gulp-concat": "^2.5.2",
18+
"gulp-jscs": "^3.0.2",
1819
"gulp-minify-html": "^1.0.2",
1920
"gulp-rename": "^1.2.2",
2021
"gulp-uglify": "^1.2.0",

src/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<md-input-container class="schema-form-{{form.type}} {{form.htmlClass}}" sf-messages>
1+
<md-input-container class="schema-form-{{form.type}} {{form.htmlClass}}" ng-class="{'md-input-has-value':model['{{form.key.slice(-1)[0]}}']}" sf-messages>
22
<label ng-show="showTitle()" for="{{form.key.slice(-1)[0]}}">{{form.title}}</label>
33
<!--
44
<input ng-if="!form.fieldAddonLeft && !form.fieldAddonRight"

src/material-decorator.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,28 @@ angular.module('schemaForm')
2828
if (mdAutocompleteFrag) {
2929
if (args.form.onChange) {
3030
mdAutocompleteFrag.setAttribute('md-selected-item-change', 'args.form.onChange(searchText)');
31-
};
31+
}
3232
if (args.form.onChange) {
3333
mdAutocompleteFrag.setAttribute('md-search-text-change', 'args.form.onChange(searchText)');
34-
};
34+
}
3535
// mdAutocompleteFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);');
3636
var minLength = args.form.minLength || 1;
3737
var maxLength = args.form.maxLength || false;
3838
mdAutocompleteFrag.setAttribute('md-min-length', minLength);
3939
if (maxLength) {
4040
mdAutocompleteFrag.setAttribute('md-max-length', maxLength);
41-
};
41+
}
42+
}
43+
};
44+
45+
var mdSwitch = function(args) {
46+
var mdSwitchFrag = args.fieldFrag.querySelector('md-switch');
47+
if (args.form.schema.titleMap) {
48+
mdSwitchFrag.setAttribute('ng-true-value',args.form.schema.titleMap.true);
49+
mdSwitchFrag.setAttribute('ng-false-value',args.form.schema.titleMap.false);
50+
}
51+
if (args.form.schema.ink) {
52+
mdSwitchFrag.setIdAttribute('md-no-ink',args.form.schema.ink);
4253
}
4354
};
4455

@@ -47,16 +58,16 @@ angular.module('schemaForm')
4758
if (mdDatepickerFrag) {
4859
if (args.form.onChange) {
4960
mdDatepickerFrag.setAttribute('ng-change', 'args.form.onChange(searchText)');
50-
};
61+
}
5162
// mdDatepickerFrag.setAttribute('md-items', 'item in $filter(''autocomplete'')(searchText);');
5263
var minDate = args.form.minimum || false;
5364
var maxDate = args.form.maximum || false;
5465
if (minDate) {
5566
mdDatepickerFrag.setAttribute('md-max-date', minDate);
56-
};
67+
}
5768
if (maxDate) {
5869
mdDatepickerFrag.setAttribute('md-max-date', maxDate);
59-
};
70+
}
6071
}
6172
};
6273

@@ -109,7 +120,11 @@ angular.module('schemaForm')
109120
submit: { template: base + 'submit.html', builder: defaults },
110121
tabs: { template: base + 'tabs.html', builder: [ sfField, mdTabs, condition ] },
111122
tabarray: { template: base + 'tabarray.html', builder: [ sfField, ngModelOptions, ngModel, array, condition ] },
112-
textarea: { template: base + 'textarea.html', builder: defaults }
123+
textarea: { template: base + 'textarea.html', builder: defaults },
124+
switch: {
125+
template: base + 'switch.html',
126+
builder: [ sfField, ngModel, ngModelOptions, sfMessages, condition, mdSwitch ]
127+
}
113128
});
114129

115130
/**

src/switch.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
schema-validate="form"
66
id="{{form.key.slice(-1)[0]}}"
77
aria-label="{{form.title}}"
8-
ng-true-value="'yup'"
9-
ng-false-value="'nope'"
108
ng-show="form.key"
119
ng-class="form.fieldHtmlClass"
1210
ng-disabled="form.readonly">
13-
<label ng-show="showTitle()" for="{{form.key.slice(-1)[0]}}">{{form.title}}</label>
11+
<span ng-show="showTitle()" for="{{form.key.slice(-1)[0]}}">{{form.title}}</span>
1412
<div ng-messages="ngModel.$error">
1513
<!--
1614
This is a bit of a hack. sf-message does the work, but ng-messages and ng-message

0 commit comments

Comments
 (0)