Skip to content

Commit e702834

Browse files
committed
Merge branch 'mike-marcacci-readonly' into development
2 parents e1a663a + 2d24b23 commit e702834

21 files changed

+210
-44
lines changed

dist/bootstrap-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.

dist/schema-form.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ angular.module('schemaForm').provider('schemaForm',
586586
};
587587

588588
var fieldset = function(name, schema, options) {
589-
590589
if (schema.type === 'object') {
591590
var f = stdFormObj(name, schema, options);
592591
f.type = 'fieldset';
@@ -640,7 +639,8 @@ angular.module('schemaForm').provider('schemaForm',
640639
path: arrPath,
641640
required: required || false,
642641
lookup: options.lookup,
643-
ignore: options.ignore
642+
ignore: options.ignore,
643+
global: options.global
644644
})];
645645

646646
return f;
@@ -720,23 +720,27 @@ angular.module('schemaForm').provider('schemaForm',
720720

721721
var service = {};
722722

723-
service.merge = function(schema, form, ignore, options) {
723+
service.merge = function(schema, form, ignore, options, readonly) {
724724
form = form || ['*'];
725725
options = options || {};
726726

727+
// Get readonly from root object
728+
readonly = readonly || schema.readonly || schema.readOnly;
729+
727730
var stdForm = service.defaults(schema, ignore, options);
731+
728732
//simple case, we have a "*", just put the stdForm there
729733
var idx = form.indexOf('*');
730734
if (idx !== -1) {
731735
form = form.slice(0, idx)
732736
.concat(stdForm.form)
733737
.concat(form.slice(idx + 1));
734-
return form;
735738
}
736739

737740
//ok let's merge!
738741
//We look at the supplied form and extend it with schema standards
739742
var lookup = stdForm.lookup;
743+
740744
return postProcessFn(form.map(function(obj) {
741745

742746
//handle the shortcut with just a name
@@ -767,26 +771,32 @@ angular.module('schemaForm').provider('schemaForm',
767771
});
768772
}
769773

774+
//extend with std form from schema.
775+
776+
if (obj.key) {
777+
var strid = sfPathProvider.stringify(obj.key);
778+
if (lookup[strid]) {
779+
obj = angular.extend(lookup[strid], obj);
780+
}
781+
}
782+
783+
// Are we inheriting readonly?
784+
if (readonly === true) { // Inheriting false is not cool.
785+
obj.readonly = true;
786+
}
787+
770788
//if it's a type with items, merge 'em!
771789
if (obj.items) {
772-
obj.items = service.merge(schema, obj.items, ignore);
790+
obj.items = service.merge(schema, obj.items, ignore, options, obj.readonly);
773791
}
774792

775793
//if its has tabs, merge them also!
776794
if (obj.tabs) {
777795
angular.forEach(obj.tabs, function(tab) {
778-
tab.items = service.merge(schema, tab.items, ignore);
796+
tab.items = service.merge(schema, tab.items, ignore, options, obj.readonly);
779797
});
780798
}
781799

782-
//extend with std form from schema.
783-
if (obj.key) {
784-
var str = sfPathProvider.stringify(obj.key);
785-
if (lookup[str]) {
786-
obj = angular.extend(lookup[str], obj);
787-
}
788-
}
789-
790800
// Special case: checkbox
791801
// Since have to ternary state we need a default
792802
if (obj.type === 'checkbox' && angular.isUndefined(obj.schema['default'])) {
@@ -984,8 +994,16 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
984994
// section. Unless there is just one.
985995
var subForm = form.items[0];
986996
if (form.items.length > 1) {
987-
subForm = {type: 'section', items: form.items};
997+
subForm = {
998+
type: 'section',
999+
items: form.items.map(function(item){
1000+
item.ngModelOptions = form.ngModelOptions;
1001+
item.readonly = form.readonly;
1002+
return item;
1003+
})
1004+
};
9881005
}
1006+
9891007
}
9901008

9911009
// We ceate copies of the form on demand, caching them for

dist/schema-form.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.

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ General options most field types can handle:
309309
onChange: "valueChanged(form.key,modelValue)", // onChange event handler, expression or function
310310
feedback: false, // Inline feedback icons
311311
placeholder: "Input...", // placeholder on inputs and textarea
312-
ngModelOptions: { ... } // Passed along to ng-model-options
312+
ngModelOptions: { ... }, // Passed along to ng-model-options
313+
readonly: true // Same effect as readOnly in schema. Put on a fieldset or array
314+
// and their items will inherit it.
313315
}
314316
```
315317

src/directives/array.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
4646
// section. Unless there is just one.
4747
var subForm = form.items[0];
4848
if (form.items.length > 1) {
49-
subForm = {type: 'section', items: form.items};
49+
subForm = {
50+
type: 'section',
51+
items: form.items.map(function(item){
52+
item.ngModelOptions = form.ngModelOptions;
53+
item.readonly = form.readonly;
54+
return item;
55+
})
56+
};
5057
}
58+
5159
}
5260

5361
// We ceate copies of the form on demand, caching them for

src/directives/decorators/bootstrap/actions.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
ng-if="item.type === 'submit'">
77
<button ng-repeat-end class="btn {{ item.style || 'btn-default' }}"
88
type="button"
9+
ng-disabled="form.readonly"
910
ng-if="item.type !== 'submit'"
1011
ng-click="buttonClick($event,item)">{{item.title}}</button>
1112
</div>

src/directives/decorators/bootstrap/array.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<h3 ng-show="form.title && form.notitle !== true">{{ form.title }}</h3>
33
<ol class="list-group" ng-model="modelArray" ui-sortable>
44
<li class="list-group-item" ng-repeat="item in modelArray track by $index">
5-
<button ng-click="deleteFromArray($index)"
5+
<button ng-hide="form.readonly"
6+
ng-click="deleteFromArray($index)"
67
style="position: relative; z-index: 20;"
78
type="button" class="close pull-right">
89
<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
@@ -11,7 +12,8 @@ <h3 ng-show="form.title && form.notitle !== true">{{ form.title }}</h3>
1112
</li>
1213
</ol>
1314
<div class="clearfix" style="padding: 15px;">
14-
<button ng-click="appendToArray()"
15+
<button ng-hide="form.readonly"
16+
ng-click="appendToArray()"
1517
type="button"
1618
class="btn {{ form.style.add || 'btn-default' }} pull-right">
1719
<i class="glyphicon glyphicon-plus"></i>

src/directives/decorators/bootstrap/bootstrap-decorator.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ angular.module('schemaForm').config(['schemaFormDecoratorsProvider', function(de
2323
help: base + 'help.html',
2424
'default': base + 'default.html'
2525
}, [
26-
function(form) {
27-
if (form.readonly && form.key && form.type !== 'fieldset') {
28-
return base + 'readonly.html';
29-
}
30-
}
26+
// function(form) {
27+
// if (form.readonly && form.key && form.type !== 'fieldset') {
28+
// return base + 'readonly.html';
29+
// }
30+
// }
3131
]);
3232

3333
//manual use directives

src/directives/decorators/bootstrap/checkbox.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<label>
33
<input type="checkbox"
44
sf-changed="form"
5+
ng-disabled="form.readonly"
56
ng-model="$$value$$"
67
ng-model-options="form.ngModelOptions"
78
schema-validate="form">

src/directives/decorators/bootstrap/checkboxes.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<div class="checkbox" ng-repeat="val in titleMapValues track by $index" >
44
<label>
55
<input type="checkbox"
6+
ng-disabled="form.readonly"
67
sf-changed="form"
78
ng-model="titleMapValues[$index]">
89
<span ng-bind-html="form.titleMap[$index].name"></span>

0 commit comments

Comments
 (0)