93
93
id : $scope . control . value . id
94
94
} ;
95
95
overlayOptions . close = function ( ) {
96
+ // ensure an empty doctype is not persisted
97
+ if ( $scope . control . $initializing ) {
98
+ $scope . removeControl ( $scope . area , $scope . control . $index - 1 ) ;
99
+ }
100
+
96
101
editorService . close ( ) ;
97
102
}
98
103
overlayOptions . submit = function ( newModel ) {
99
104
100
- // Copy property values to scope model value
101
- if ( newModel . node ) {
102
- var value = {
103
- name : newModel . editorName
104
- } ;
105
-
106
- for ( var v = 0 ; v < newModel . node . variants . length ; v ++ ) {
107
- var variant = newModel . node . variants [ v ] ;
108
- for ( var t = 0 ; t < variant . tabs . length ; t ++ ) {
109
- var tab = variant . tabs [ t ] ;
110
- for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
111
- var prop = tab . properties [ p ] ;
112
- if ( typeof prop . value !== "function" ) {
113
- value [ prop . alias ] = prop . value ;
105
+ // Copy property values to scope model value
106
+ if ( newModel . node ) {
107
+ var value = {
108
+ name : newModel . editorName
109
+ } ;
110
+
111
+ for ( var v = 0 ; v < newModel . node . variants . length ; v ++ ) {
112
+ var variant = newModel . node . variants [ v ] ;
113
+ for ( var t = 0 ; t < variant . tabs . length ; t ++ ) {
114
+ var tab = variant . tabs [ t ] ;
115
+ for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
116
+ var prop = tab . properties [ p ] ;
117
+ if ( typeof prop . value !== "function" ) {
118
+ value [ prop . alias ] = prop . value ;
119
+ }
120
+ }
114
121
}
115
122
}
116
- }
117
- }
118
123
119
- if ( newModel . nameExp ) {
120
- var newName = newModel . nameExp ( value ) ; // Run it against the stored dictionary value, NOT the node object
121
- if ( newName && ( newName = $ . trim ( newName ) ) ) {
122
- value . name = newName ;
123
- }
124
- }
124
+ if ( newModel . nameExp ) {
125
+ var newName = newModel . nameExp ( value ) ; // Run it against the stored dictionary value, NOT the node object
126
+ if ( newName && ( newName = $ . trim ( newName ) ) ) {
127
+ value . name = newName ;
128
+ }
129
+ }
125
130
126
- newModel . dialogData . value = value ;
127
- } else {
128
- newModel . dialogData . value = null ;
131
+ newModel . dialogData . value = value ;
132
+ } else {
133
+ newModel . dialogData . value = null ;
129
134
130
- }
135
+ }
131
136
132
- $scope . setValue ( {
133
- dtgeContentTypeAlias : newModel . dialogData . docTypeAlias ,
134
- value : newModel . dialogData . value ,
135
- id : newModel . dialogData . id
136
- } ) ;
137
- $scope . setPreview ( $scope . control . value ) ;
138
- editorService . close ( ) ;
137
+ $scope . setValue ( {
138
+ dtgeContentTypeAlias : newModel . dialogData . docTypeAlias ,
139
+ value : newModel . dialogData . value ,
140
+ id : newModel . dialogData . id
141
+ } ) ;
142
+ $scope . setPreview ( $scope . control . value ) ;
143
+ editorService . close ( ) ;
139
144
} ;
140
145
141
146
editorService . open ( overlayOptions ) ;
@@ -227,19 +232,52 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
227
232
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources" ,
228
233
"Our.Umbraco.DocTypeGridEditor.Services.DocTypeGridEditorUtilityService" ,
229
234
"blueprintConfig" ,
235
+ "contentEditingHelper" ,
236
+ "serverValidationManager" ,
230
237
231
- function ( $scope , $interpolate , formHelper , contentResource , dtgeResources , dtgeUtilityService , blueprintConfig ) {
238
+ function ( $scope , $interpolate , formHelper , contentResource , dtgeResources , dtgeUtilityService , blueprintConfig , contentEditingHelper , serverValidationManager ) {
232
239
233
240
var vm = this ;
234
241
vm . submit = submit ;
235
242
vm . close = close ;
236
243
vm . loading = true ;
237
244
vm . blueprintConfig = blueprintConfig ;
238
245
246
+ function cleanup ( ) {
247
+ if ( $scope . model . node . id > 0 ) {
248
+ // delete any temporary blueprints used for validation
249
+ contentResource . deleteBlueprint ( $scope . model . node . id ) ;
250
+ }
251
+
252
+ //clear server validation messages when this editor is destroyed
253
+ serverValidationManager . clear ( ) ;
254
+ }
255
+
256
+ $scope . $on ( '$destroy' , cleanup ) ;
257
+
239
258
function submit ( ) {
240
259
if ( $scope . model . submit ) {
241
- $scope . $broadcast ( 'formSubmitting' , { scope : $scope } ) ;
242
- $scope . model . submit ( $scope . model ) ;
260
+ $scope . model . node . name = "Dtge Temp: " + $scope . model . node . key ;
261
+ $scope . model . node . variants [ 0 ] . name = $scope . model . node . name
262
+ $scope . model . node . variants [ 0 ] . save = true ;
263
+
264
+ // save the content as a blueprint, to trigger validation
265
+ var args = {
266
+ saveMethod : contentResource . saveBlueprint ,
267
+ scope : $scope ,
268
+ content : $scope . model . node ,
269
+ create : true ,
270
+ action : "save" ,
271
+ showNotifications : true ,
272
+ softRedirect : true
273
+ }
274
+
275
+ contentEditingHelper . contentEditorPerformSave ( args ) . then ( function ( data ) {
276
+ $scope . model . submit ( $scope . model ) ;
277
+ } ,
278
+ function ( err ) {
279
+
280
+ } ) ;
243
281
}
244
282
}
245
283
function close ( ) {
@@ -282,7 +320,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
282
320
} ;
283
321
284
322
function createFromBlueprint ( blueprintId ) {
285
- contentResource . getBlueprintScaffold ( - 20 , blueprintId ) . then ( function ( data ) {
323
+ contentResource . getBlueprintScaffold ( - 1 , blueprintId ) . then ( function ( data ) {
286
324
// Assign the model to scope
287
325
$scope . nodeContext = $scope . model . node = data ;
288
326
$scope . dialogMode = "edit" ;
@@ -297,7 +335,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
297
335
298
336
function loadNode ( ) {
299
337
vm . loading = true ;
300
- contentResource . getScaffold ( - 20 , $scope . model . dialogData . docTypeAlias ) . then ( function ( data ) {
338
+ contentResource . getScaffold ( - 1 , $scope . model . dialogData . docTypeAlias ) . then ( function ( data ) {
301
339
302
340
// Merge current value
303
341
if ( $scope . model . dialogData . value ) {
0 commit comments