1
1
angular . module ( "umbraco" ) . controller ( "Our.Umbraco.DocTypeGridEditor.GridEditors.DocTypeGridEditor" , [
2
2
3
3
"$scope" ,
4
- "$rootScope" ,
5
4
"$timeout" ,
6
- "$routeParams" ,
7
5
"editorState" ,
8
6
'assetsService' ,
9
7
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources" ,
10
8
"umbRequestHelper" ,
11
9
"localizationService" ,
10
+ "editorService" ,
12
11
13
- function ( $scope , $rootScope , $ timeout, $routeParams , editorState , assetsService , dtgeResources , umbRequestHelper , localizationService ) {
12
+ function ( $scope , $timeout , editorState , assetsService , dtgeResources , umbRequestHelper , localizationService , editorService ) {
14
13
15
14
const defaultTitle = "Click to insert item" ,
16
15
defaultSelectContentTypeLabel = "Choose a Content Type" ,
17
- defaultOverlayTitle = "Edit tem " ;
16
+ defaultOverlayTitle = "Edit item " ;
18
17
19
18
$scope . title = defaultTitle ;
20
19
$scope . selectContentTypeLabel = defaultSelectContentTypeLabel ;
21
20
22
21
var overlayTitle = defaultOverlayTitle ;
22
+
23
+ var overlayOptions = {
24
+ view : umbRequestHelper . convertVirtualToAbsolutePath (
25
+ "~/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.dialog.html" ) ,
26
+ model : { }
27
+ } ;
28
+
23
29
$scope . icon = "icon-item-arrangement" ;
24
- $scope . overlay = { } ;
25
- $scope . overlay . show = false ;
26
- $scope . overlay . view =
27
- umbRequestHelper . convertVirtualToAbsolutePath (
28
- "~/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.dialog.html" ) ;
29
30
30
31
// localize strings
31
32
localizationService . localizeMany ( [ "docTypeGridEditor_insertItem" , "docTypeGridEditor_editItem" , "docTypeGridEditor_selectContentType" ] ) . then ( function ( data ) {
55
56
56
57
$scope . setDocType = function ( ) {
57
58
58
- $scope . overlay = { } ;
59
- $scope . overlay . show = true ;
60
- $scope . overlay . title = overlayTitle ;
61
- $scope . overlay . submitButtonLabelKey = "bulk_done" ;
62
- $scope . overlay . view =
63
- umbRequestHelper . convertVirtualToAbsolutePath (
64
- "~/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.dialog.html" ) ;
65
- $scope . overlay . editorName = $scope . control . editor . name ;
66
- $scope . overlay . allowedDocTypes = $scope . control . editor . config . allowedDocTypes || [ ] ;
67
- $scope . overlay . nameTemplate = $scope . control . editor . config . nameTemplate ;
68
- $scope . overlay . dialogData = {
59
+ overlayOptions . title = overlayTitle ;
60
+ overlayOptions . submitButtonLabelKey = "bulk_done" ;
61
+ overlayOptions . editorName = $scope . control . editor . name ;
62
+ overlayOptions . allowedDocTypes = $scope . control . editor . config . allowedDocTypes || [ ] ;
63
+ overlayOptions . nameTemplate = $scope . control . editor . config . nameTemplate ;
64
+
65
+ overlayOptions . dialogData = {
69
66
docTypeAlias : $scope . control . value . dtgeContentTypeAlias ,
70
67
value : $scope . control . value . value ,
71
68
id : $scope . control . value . id
72
69
} ;
73
- $scope . overlay . close = function ( oldModel ) {
74
- $scope . overlay . show = false ;
75
- $scope . overlay = null ;
70
+ overlayOptions . close = function ( ) {
71
+ editorService . close ( ) ;
76
72
}
77
- $scope . overlay . submit = function ( newModel ) {
73
+ overlayOptions . submit = function ( newModel ) {
78
74
79
75
// Copy property values to scope model value
80
76
if ( newModel . node ) {
81
77
var value = {
82
78
name : newModel . editorName
83
79
} ;
84
80
85
- for ( var v = 0 ; v < newModel . node . variants . length ; v ++ ) {
86
- var variant = newModel . node . variants [ v ] ;
87
- for ( var t = 0 ; t < variant . tabs . length ; t ++ ) {
88
- var tab = variant . tabs [ t ] ;
89
- for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
90
- var prop = tab . properties [ p ] ;
91
- if ( typeof prop . value !== "function" ) {
92
- value [ prop . alias ] = prop . value ;
93
- }
94
- }
95
- }
96
- }
81
+ for ( var v = 0 ; v < newModel . node . variants . length ; v ++ ) {
82
+ var variant = newModel . node . variants [ v ] ;
83
+ for ( var t = 0 ; t < variant . tabs . length ; t ++ ) {
84
+ var tab = variant . tabs [ t ] ;
85
+ for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
86
+ var prop = tab . properties [ p ] ;
87
+ if ( typeof prop . value !== "function" ) {
88
+ value [ prop . alias ] = prop . value ;
89
+ }
90
+ }
91
+ }
92
+ }
97
93
98
94
if ( newModel . nameExp ) {
99
95
var newName = newModel . nameExp ( value ) ; // Run it against the stored dictionary value, NOT the node object
114
110
id : newModel . dialogData . id
115
111
} ) ;
116
112
$scope . setPreview ( $scope . control . value ) ;
117
- $scope . overlay . show = false ;
118
- $scope . overlay = null ;
113
+ editorService . close ( ) ;
119
114
} ;
115
+
116
+ editorService . open ( overlayOptions ) ;
120
117
} ;
121
118
122
119
$scope . setPreview = function ( model ) {
@@ -207,6 +204,21 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
207
204
208
205
function ( $scope , $interpolate , formHelper , contentResource , dtgeResources , dtgeUtilityService ) {
209
206
207
+ var vm = this ;
208
+ vm . submit = submit ;
209
+ vm . close = close ;
210
+ vm . loading = true ;
211
+ function submit ( ) {
212
+ if ( $scope . model . submit ) {
213
+ $scope . model . submit ( $scope . model ) ;
214
+ }
215
+ }
216
+ function close ( ) {
217
+ if ( $scope . model . close ) {
218
+ $scope . model . close ( ) ;
219
+ }
220
+ }
221
+
210
222
$scope . docTypes = [ ] ;
211
223
$scope . dialogMode = "selectDocType" ;
212
224
$scope . selectedDocType = null ;
@@ -225,26 +237,29 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
225
237
} ;
226
238
227
239
function loadNode ( ) {
240
+ vm . loading = true ;
228
241
contentResource . getScaffold ( - 20 , $scope . model . dialogData . docTypeAlias ) . then ( function ( data ) {
229
-
242
+
230
243
// Merge current value
231
244
if ( $scope . model . dialogData . value ) {
232
- for ( var v = 0 ; v < data . variants . length ; v ++ ) {
233
- var variant = data . variants [ v ] ;
234
- for ( var t = 0 ; t < variant . tabs . length ; t ++ ) {
235
- var tab = variant . tabs [ t ] ;
236
- for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
237
- var prop = tab . properties [ p ] ;
238
- if ( $scope . model . dialogData . value [ prop . alias ] ) {
239
- prop . value = $scope . model . dialogData . value [ prop . alias ] ;
240
- }
241
- }
242
- }
243
- }
245
+ for ( var v = 0 ; v < data . variants . length ; v ++ ) {
246
+ var variant = data . variants [ v ] ;
247
+ for ( var t = 0 ; t < variant . tabs . length ; t ++ ) {
248
+ var tab = variant . tabs [ t ] ;
249
+ for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
250
+ var prop = tab . properties [ p ] ;
251
+ if ( $scope . model . dialogData . value [ prop . alias ] ) {
252
+ prop . value = $scope . model . dialogData . value [ prop . alias ] ;
253
+ }
254
+ }
255
+ }
256
+ }
244
257
} ;
245
258
246
259
// Assign the model to scope
247
260
$scope . nodeContext = $scope . model . node = data ;
261
+ vm . content = $scope . nodeContext . variants [ 0 ] ;
262
+ vm . loading = false ;
248
263
} ) ;
249
264
}
250
265
@@ -261,6 +276,9 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
261
276
$scope . dialogMode = "edit" ;
262
277
loadNode ( ) ;
263
278
}
279
+ else {
280
+ vm . loading = false ;
281
+ }
264
282
} ) ;
265
283
}
266
284
0 commit comments