1
- angular . module ( "umbraco" ) . controller ( "Our.Umbraco.PropertyList.Controllers.RepeatableDataTypeController" ,
2
- function ( $scope , contentTypeResource , umbPropEditorHelper ) {
1
+ angular . module ( "umbraco" ) . controller ( "Our.Umbraco.PropertyList.Controllers.PropertyListController" , [
2
+ "$scope" ,
3
+ "contentTypeResource" ,
4
+ "Our.Umbraco.PropertyList.Resources.PropertyListResources" ,
5
+ "umbPropEditorHelper" ,
6
+ function ( $scope , contentTypeResource , propertyListResource , umbPropEditorHelper ) {
3
7
4
8
//console.debug("pl", $scope.model.config.dataType, $scope.model.value);
5
9
6
- var dataTypeId = $scope . model . config . dataType ;
7
- var minItems = $scope . model . config . minItems || 0 ;
8
- var maxItems = $scope . model . config . maxItems || 0 ;
10
+ var dataTypeGuid = $scope . model . config . dataType ;
11
+ var minItems = $scope . model . config . minItems || 0 ;
12
+ var maxItems = $scope . model . config . maxItems || 0 ;
9
13
10
- $scope . isConfigured = dataTypeId != null ;
14
+ $scope . isConfigured = dataTypeGuid != null ;
11
15
12
16
if ( $scope . isConfigured ) {
13
17
14
18
if ( ! angular . isObject ( $scope . model . value ) )
15
19
$scope . model . value = undefined ;
16
20
17
21
$scope . model . value = $scope . model . value || {
18
- dtdId : dataTypeId ,
22
+ dtd : dataTypeGuid ,
19
23
values : [ ]
20
24
} ;
21
25
22
26
$scope . prompts = { } ;
23
27
24
- contentTypeResource . getPropertyTypeScaffold ( dataTypeId ) . then ( function ( propertyType ) {
28
+ propertyListResource . getPropertyTypeScaffoldByKey ( dataTypeGuid ) . then ( function ( propertyType ) {
25
29
26
30
$scope . propertyType = propertyType ;
27
31
76
80
} ;
77
81
78
82
$scope . model . controls . splice ( idx , 0 , control ) ;
83
+ $scope . setDirty ( ) ;
79
84
}
80
85
81
86
$scope . deleteContent = function ( evt , idx ) {
82
87
$scope . model . controls . splice ( idx , 1 ) ;
88
+ $scope . setDirty ( ) ;
83
89
}
84
90
85
91
$scope . sortableOptions = {
92
98
cursorAt : {
93
99
top : 0
94
100
} ,
95
- //update: function (e, ui) {
96
- // _.each($scope.model.controls, function (itm, idx) {
97
- // console.debug("sorted", itm, idx)
98
- // });
99
- //}
101
+ update : function ( e , ui ) {
102
+ $scope . setDirty ( ) ;
103
+ }
104
+ } ;
105
+
106
+ $scope . setDirty = function ( ) {
107
+ if ( $scope . propertyForm ) {
108
+ $scope . propertyForm . $setDirty ( ) ;
109
+ }
100
110
} ;
101
111
102
112
var unsubscribe = $scope . $on ( "formSubmitting" , function ( ev , args ) {
106
116
tmpValues [ idx ] = control . value ;
107
117
} ) ;
108
118
109
- $scope . model . value . values = ! _ . isEmpty ( tmpValues ) ? tmpValues : [ ] ;
110
- $scope . model . value . dtdId = dataTypeId ;
119
+ $scope . model . value = {
120
+ dtd : dataTypeGuid ,
121
+ values : ! _ . isEmpty ( tmpValues ) ? tmpValues : [ ]
122
+ } ;
111
123
} ) ;
112
124
113
125
$scope . $on ( '$destroy' , function ( ) {
114
126
unsubscribe ( ) ;
115
127
} ) ;
116
128
117
- } ) ;
129
+ } ] ) ;
118
130
119
- angular . module ( "umbraco" ) . controller ( "Our.Umbraco.PropertyList.Controllers.DataTypePickerController" ,
120
- function ( $scope , contentTypeResource , dataTypeResource , dataTypeHelper ) {
131
+ angular . module ( "umbraco" ) . controller ( "Our.Umbraco.PropertyList.Controllers.DataTypePickerController" , [
132
+ "$scope" ,
133
+ "contentTypeResource" ,
134
+ "dataTypeHelper" ,
135
+ "dataTypeResource" ,
136
+ "entityResource" ,
137
+ "Our.Umbraco.PropertyList.Resources.PropertyListResources" ,
138
+ function ( $scope , contentTypeResource , dataTypeHelper , dataTypeResource , entityResource , propertyListResource ) {
121
139
122
140
if ( ! $scope . model . property ) {
123
141
124
142
$scope . model . property = { } ;
125
143
126
144
if ( $scope . model . value ) {
127
- dataTypeResource . getById ( $scope . model . value ) . then ( function ( dataType ) {
128
-
145
+ propertyListResource . getDataTypeByKey ( $scope . model . value ) . then ( function ( dataType ) {
129
146
// update editor
130
147
$scope . model . property . editor = dataType . selectedEditor ;
131
148
$scope . model . property . dataTypeId = dataType . id ;
132
149
$scope . model . property . dataTypeIcon = dataType . icon ;
133
150
$scope . model . property . dataTypeName = dataType . name ;
134
-
135
151
} ) ;
136
152
}
137
153
}
@@ -141,8 +157,10 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
141
157
vm . openEditorPickerOverlay = openEditorPickerOverlay ;
142
158
vm . openEditorSettingsOverlay = openEditorSettingsOverlay ;
143
159
144
- function setDataTypeId ( dataTypeId ) {
145
- $scope . model . value = dataTypeId ;
160
+ function setModelValue ( dataTypeId ) {
161
+ entityResource . getById ( dataTypeId , "DataType" ) . then ( function ( entity ) {
162
+ $scope . model . value = entity . key ;
163
+ } ) ;
146
164
} ;
147
165
148
166
function openEditorPickerOverlay ( property ) {
@@ -154,7 +172,7 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
154
172
155
173
vm . editorPickerOverlay . submit = function ( model ) {
156
174
157
- setDataTypeId ( model . property . dataTypeId ) ;
175
+ setModelValue ( model . property . dataTypeId ) ;
158
176
159
177
vm . editorPickerOverlay . show = false ;
160
178
vm . editorPickerOverlay = null ;
@@ -186,7 +204,7 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
186
204
187
205
contentTypeResource . getPropertyTypeScaffold ( newDataType . id ) . then ( function ( propertyType ) {
188
206
189
- setDataTypeId ( newDataType . id ) ;
207
+ setModelValue ( newDataType . id ) ;
190
208
191
209
// update editor
192
210
property . config = propertyType . config ;
@@ -214,5 +232,4 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
214
232
215
233
}
216
234
217
- } ) ;
218
-
235
+ } ] ) ;
0 commit comments