@@ -65,81 +65,6 @@ angular.module('schemaForm').provider('sfPath',
65
65
} ;
66
66
} ] ) ;
67
67
68
- /**
69
- * @ngdoc service
70
- * @name sfSelect
71
- * @kind function
72
- *
73
- */
74
- angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ 'sfPath' , function ( sfPath ) {
75
- var numRe = / ^ \d + $ / ;
76
-
77
- /**
78
- * @description
79
- * Utility method to access deep properties without
80
- * throwing errors when things are not defined.
81
- * Can also set a value in a deep structure, creating objects when missing
82
- * ex.
83
- * var foo = Select('address.contact.name',obj)
84
- * Select('address.contact.name',obj,'Leeroy')
85
- *
86
- * @param {string } projection A dot path to the property you want to get/set
87
- * @param {object } obj (optional) The object to project on, defaults to 'this'
88
- * @param {Any } valueToSet (opional) The value to set, if parts of the path of
89
- * the projection is missing empty objects will be created.
90
- * @returns {Any|undefined } returns the value at the end of the projection path
91
- * or undefined if there is none.
92
- */
93
- return function ( projection , obj , valueToSet ) {
94
- if ( ! obj ) {
95
- obj = this ;
96
- }
97
- //Support [] array syntax
98
- var parts = typeof projection === 'string' ? sfPath . parse ( projection ) : projection ;
99
-
100
- if ( typeof valueToSet !== 'undefined' && parts . length === 1 ) {
101
- //special case, just setting one variable
102
- obj [ parts [ 0 ] ] = valueToSet ;
103
- return obj ;
104
- }
105
-
106
- if ( typeof valueToSet !== 'undefined' &&
107
- typeof obj [ parts [ 0 ] ] === 'undefined' ) {
108
- // We need to look ahead to check if array is appropriate
109
- obj [ parts [ 0 ] ] = parts . length > 2 && numRe . test ( parts [ 1 ] ) ? [ ] : { } ;
110
- }
111
-
112
- var value = obj [ parts [ 0 ] ] ;
113
- for ( var i = 1 ; i < parts . length ; i ++ ) {
114
- // Special case: We allow JSON Form syntax for arrays using empty brackets
115
- // These will of course not work here so we exit if they are found.
116
- if ( parts [ i ] === '' ) {
117
- return undefined ;
118
- }
119
- if ( typeof valueToSet !== 'undefined' ) {
120
- if ( i === parts . length - 1 ) {
121
- //last step. Let's set the value
122
- value [ parts [ i ] ] = valueToSet ;
123
- return valueToSet ;
124
- } else {
125
- // Make sure to create new objects on the way if they are not there.
126
- // We need to look ahead to check if array is appropriate
127
- var tmp = value [ parts [ i ] ] ;
128
- if ( typeof tmp === 'undefined' || tmp === null ) {
129
- tmp = numRe . test ( parts [ i + 1 ] ) ? [ ] : { } ;
130
- value [ parts [ i ] ] = tmp ;
131
- }
132
- value = tmp ;
133
- }
134
- } else if ( value ) {
135
- //Just get nex value.
136
- value = value [ parts [ i ] ] ;
137
- }
138
- }
139
- return value ;
140
- } ;
141
- } ] ) ;
142
-
143
68
144
69
// FIXME: type template (using custom builder)
145
70
angular . module ( 'schemaForm' ) . provider ( 'sfBuilder' , [ 'sfPathProvider' , function ( sfPathProvider ) {
@@ -771,7 +696,7 @@ angular.module('schemaForm').provider('schemaFormDecorators',
771
696
772
697
var createManualDirective = function ( type , templateUrl , transclude ) {
773
698
transclude = angular . isDefined ( transclude ) ? transclude : false ;
774
- $compileProvider . directive ( 'sf' + angular . uppercase ( type [ 0 ] ) + type . substr ( 1 ) , function ( ) {
699
+ $compileProvider . directive ( 'sf' + type [ 0 ] . toUpperCase ( ) + type . substr ( 1 ) , function ( ) {
775
700
return {
776
701
restrict : 'EAC' ,
777
702
scope : true ,
@@ -1584,6 +1509,81 @@ angular.module('schemaForm').provider('schemaForm',
1584
1509
1585
1510
} ] ) ;
1586
1511
1512
+ /**
1513
+ * @ngdoc service
1514
+ * @name sfSelect
1515
+ * @kind function
1516
+ *
1517
+ */
1518
+ angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ 'sfPath' , function ( sfPath ) {
1519
+ var numRe = / ^ \d + $ / ;
1520
+
1521
+ /**
1522
+ * @description
1523
+ * Utility method to access deep properties without
1524
+ * throwing errors when things are not defined.
1525
+ * Can also set a value in a deep structure, creating objects when missing
1526
+ * ex.
1527
+ * var foo = Select('address.contact.name',obj)
1528
+ * Select('address.contact.name',obj,'Leeroy')
1529
+ *
1530
+ * @param {string } projection A dot path to the property you want to get/set
1531
+ * @param {object } obj (optional) The object to project on, defaults to 'this'
1532
+ * @param {Any } valueToSet (opional) The value to set, if parts of the path of
1533
+ * the projection is missing empty objects will be created.
1534
+ * @returns {Any|undefined } returns the value at the end of the projection path
1535
+ * or undefined if there is none.
1536
+ */
1537
+ return function ( projection , obj , valueToSet ) {
1538
+ if ( ! obj ) {
1539
+ obj = this ;
1540
+ }
1541
+ //Support [] array syntax
1542
+ var parts = typeof projection === 'string' ? sfPath . parse ( projection ) : projection ;
1543
+
1544
+ if ( typeof valueToSet !== 'undefined' && parts . length === 1 ) {
1545
+ //special case, just setting one variable
1546
+ obj [ parts [ 0 ] ] = valueToSet ;
1547
+ return obj ;
1548
+ }
1549
+
1550
+ if ( typeof valueToSet !== 'undefined' &&
1551
+ typeof obj [ parts [ 0 ] ] === 'undefined' ) {
1552
+ // We need to look ahead to check if array is appropriate
1553
+ obj [ parts [ 0 ] ] = parts . length > 2 && numRe . test ( parts [ 1 ] ) ? [ ] : { } ;
1554
+ }
1555
+
1556
+ var value = obj [ parts [ 0 ] ] ;
1557
+ for ( var i = 1 ; i < parts . length ; i ++ ) {
1558
+ // Special case: We allow JSON Form syntax for arrays using empty brackets
1559
+ // These will of course not work here so we exit if they are found.
1560
+ if ( parts [ i ] === '' ) {
1561
+ return undefined ;
1562
+ }
1563
+ if ( typeof valueToSet !== 'undefined' ) {
1564
+ if ( i === parts . length - 1 ) {
1565
+ //last step. Let's set the value
1566
+ value [ parts [ i ] ] = valueToSet ;
1567
+ return valueToSet ;
1568
+ } else {
1569
+ // Make sure to create new objects on the way if they are not there.
1570
+ // We need to look ahead to check if array is appropriate
1571
+ var tmp = value [ parts [ i ] ] ;
1572
+ if ( typeof tmp === 'undefined' || tmp === null ) {
1573
+ tmp = numRe . test ( parts [ i + 1 ] ) ? [ ] : { } ;
1574
+ value [ parts [ i ] ] = tmp ;
1575
+ }
1576
+ value = tmp ;
1577
+ }
1578
+ } else if ( value ) {
1579
+ //Just get nex value.
1580
+ value = value [ parts [ i ] ] ;
1581
+ }
1582
+ }
1583
+ return value ;
1584
+ } ;
1585
+ } ] ) ;
1586
+
1587
1587
/* Common code for validating a value against its form and schema definition */
1588
1588
/* global tv4 */
1589
1589
angular . module ( 'schemaForm' ) . factory ( 'sfValidator' , [ function ( ) {
0 commit comments