4
4
"$rootScope" ,
5
5
"$timeout" ,
6
6
"$routeParams" ,
7
+ "editorState" ,
7
8
'assetsService' ,
8
9
"Our.Umbraco.DocTypeGridEditor.Services.DocTypeDialogService" ,
9
10
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources" ,
10
11
11
- function ( $scope , $rootScope , $timeout , $routeParams , assetsService , dtgeDialogService , dtgeResources ) {
12
+ function ( $scope , $rootScope , $timeout , $routeParams , editorState , assetsService , dtgeDialogService , dtgeResources ) {
12
13
13
14
$scope . title = "Click to insert item" ;
14
- $scope . icon = "icon-item-arrangement" ;
15
+ $scope . icon = "icon-item-arrangement" ;
15
16
16
- $scope . setValue = function ( data ) {
17
+ $scope . setValue = function ( data , callback ) {
17
18
$scope . control . value = data ;
18
19
if ( ! ( "id" in $scope . control . value ) || $scope . control . value . id == "" ) {
19
20
$scope . control . value . id = guid ( ) ;
20
21
}
21
22
if ( "name" in $scope . control . value . value && $scope . control . value . value . name ) {
22
23
$scope . title = $scope . control . value . value . name ;
23
24
}
24
- if ( "docType " in $scope . control . value && $scope . control . value . docType ) {
25
- dtgeResources . getContentTypeIcon ( $scope . control . value . docType ) . then ( function ( data2 ) {
25
+ if ( "dtgeContentTypeAlias " in $scope . control . value && $scope . control . value . dtgeContentTypeAlias ) {
26
+ dtgeResources . getContentTypeIcon ( $scope . control . value . dtgeContentTypeAlias ) . then ( function ( data2 ) {
26
27
if ( data2 . icon ) {
27
28
$scope . icon = data2 . icon ;
28
29
}
29
30
} ) ;
30
31
}
32
+ if ( callback )
33
+ callback ( ) ;
31
34
} ;
32
35
33
36
$scope . setDocType = function ( ) {
36
39
allowedDocTypes : $scope . control . editor . config . allowedDocTypes || [ ] ,
37
40
nameTemplate : $scope . control . editor . config . nameTemplate ,
38
41
dialogData : {
39
- docType : $scope . control . value . docType ,
42
+ docTypeAlias : $scope . control . value . dtgeContentTypeAlias ,
40
43
value : $scope . control . value . value
41
44
} ,
42
45
callback : function ( data ) {
43
46
$scope . setValue ( {
44
- docType : data . docType ,
47
+ dtgeContentTypeAlias : data . docTypeAlias ,
45
48
value : data . value
46
49
} ) ;
47
50
$scope . setPreview ( $scope . control . value ) ;
52
55
$scope . setPreview = function ( model ) {
53
56
if ( "enablePreview" in $scope . control . editor . config && $scope . control . editor . config . enablePreview ) {
54
57
var nodeId = $routeParams . id ;
55
- dtgeResources . getEditorMarkupForDocTypePartial ( nodeId , model . id , model . docType , model . value , $scope . control . editor . config . viewPath , $scope . control . editor . config . previewViewPath )
58
+ dtgeResources . getEditorMarkupForDocTypePartial ( nodeId , model . id , $scope . control . editor . alias , model . dtgeContentTypeAlias , model . value , $scope . control . editor . config . viewPath , $scope . control . editor . config . previewViewPath )
56
59
. success ( function ( htmlResult ) {
57
60
if ( htmlResult . trim ( ) . length > 0 ) {
58
61
$scope . preview = htmlResult ;
61
64
}
62
65
} ;
63
66
64
- $scope . setValue ( $scope . control . value || {
65
- id : guid ( ) ,
66
- docType : "" ,
67
- value : { }
68
- } ) ;
67
+ function init ( ) {
68
+ $timeout ( function ( ) {
69
+ if ( $scope . control . $initializing ) {
70
+ $scope . setDocType ( ) ;
71
+ } else if ( $scope . control . value ) {
72
+ $scope . setPreview ( $scope . control . value ) ;
73
+ }
74
+ } , 200 ) ;
75
+ }
76
+
77
+ if ( $scope . control . value ) {
78
+ if ( ! $scope . control . value . dtgeContentTypeAlias && $scope . control . value . docType ) {
79
+ $scope . control . value . dtgeContentTypeAlias = $scope . control . value . docType ;
80
+ }
81
+ if ( $scope . control . value . docType ) {
82
+ delete $scope . control . value . docType ;
83
+ }
84
+ if ( isGuid ( $scope . control . value . dtgeContentTypeAlias ) ) {
85
+ dtgeResources . getContentTypeAliasByGuid ( $scope . control . value . dtgeContentTypeAlias ) . then ( function ( data1 ) {
86
+ $scope . control . value . dtgeContentTypeAlias = data1 . alias ;
87
+ $scope . setValue ( $scope . control . value , init ) ;
88
+ } ) ;
89
+ } else {
90
+ $scope . setValue ( $scope . control . value , init ) ;
91
+ }
92
+ } else {
93
+ $scope . setValue ( {
94
+ id : guid ( ) ,
95
+ dtgeContentTypeAlias : "" ,
96
+ value : { }
97
+ } , init ) ;
98
+ }
69
99
70
100
// Load preview css / js files
71
101
if ( "enablePreview" in $scope . control . editor . config && $scope . control . editor . config . enablePreview )
79
109
}
80
110
}
81
111
82
- $timeout ( function ( ) {
83
- if ( $scope . control . $initializing ) {
84
- $scope . setDocType ( ) ;
85
- } else if ( $scope . control . value ) {
86
- $scope . setPreview ( $scope . control . value ) ;
87
- }
88
- } , 200 ) ;
89
-
90
112
function guid ( ) {
91
113
function s4 ( ) {
92
114
return Math . floor ( ( 1 + Math . random ( ) ) * 0x10000 )
97
119
s4 ( ) + '-' + s4 ( ) + s4 ( ) + s4 ( ) ;
98
120
}
99
121
122
+ function isGuid ( input ) {
123
+ return new RegExp ( "^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$" , "i" ) . test ( input . toString ( ) ) ;
124
+ }
125
+
100
126
}
101
127
] ) ;
102
128
@@ -122,7 +148,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
122
148
123
149
$scope . selectDocType = function ( ) {
124
150
$scope . dialogMode = "edit" ;
125
- $scope . dialogData . docType = $scope . selectedDocType . guid ;
151
+ $scope . dialogData . docTypeAlias = $scope . selectedDocType . alias ;
126
152
loadNode ( ) ;
127
153
} ;
128
154
@@ -164,33 +190,30 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
164
190
} ;
165
191
166
192
function loadNode ( ) {
167
- dtgeResources . getContentAliasByGuid ( $scope . dialogData . docType ) . then ( function ( data1 ) {
168
- contentResource . getScaffold ( - 20 , data1 . alias ) . then ( function ( data ) {
169
- // Remove the last tab
170
- data . tabs . pop ( ) ;
171
-
172
- // Merge current value
173
- if ( $scope . dialogData . value ) {
174
- for ( var t = 0 ; t < data . tabs . length ; t ++ ) {
175
- var tab = data . tabs [ t ] ;
176
- for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
177
- var prop = tab . properties [ p ] ;
178
- if ( $scope . dialogData . value [ prop . alias ] ) {
179
- prop . value = $scope . dialogData . value [ prop . alias ] ;
180
- }
193
+ contentResource . getScaffold ( - 20 , $scope . dialogData . docTypeAlias ) . then ( function ( data ) {
194
+ // Remove the last tab
195
+ data . tabs . pop ( ) ;
196
+
197
+ // Merge current value
198
+ if ( $scope . dialogData . value ) {
199
+ for ( var t = 0 ; t < data . tabs . length ; t ++ ) {
200
+ var tab = data . tabs [ t ] ;
201
+ for ( var p = 0 ; p < tab . properties . length ; p ++ ) {
202
+ var prop = tab . properties [ p ] ;
203
+ console . log ( prop . alias ) ;
204
+ if ( $scope . dialogData . value [ prop . alias ] ) {
205
+ prop . value = $scope . dialogData . value [ prop . alias ] ;
181
206
}
182
207
}
183
- } ;
184
-
185
- // Assign the model to scope
186
- $scope . nodeContext = $scope . node = data ;
208
+ }
209
+ } ;
187
210
188
- //editorState.set($ scope.node);
189
- } ) ;
211
+ // Assign the model to scope
212
+ $scope . nodeContext = $scope . node = data ;
190
213
} ) ;
191
- } ;
214
+ }
192
215
193
- if ( $scope . dialogData . docType ) {
216
+ if ( $scope . dialogData . docTypeAlias ) {
194
217
$scope . dialogMode = "edit" ;
195
218
loadNode ( ) ;
196
219
} else {
@@ -199,7 +222,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
199
222
dtgeResources . getContentTypes ( $scope . dialogOptions . allowedDocTypes ) . then ( function ( docTypes ) {
200
223
$scope . docTypes = docTypes ;
201
224
if ( $scope . docTypes . length == 1 ) {
202
- $scope . dialogData . docType = $scope . docTypes [ 0 ] . guid ;
225
+ $scope . dialogData . docTypeAlias = $scope . docTypes [ 0 ] . alias ;
203
226
$scope . dialogMode = "edit" ;
204
227
loadNode ( ) ;
205
228
}
0 commit comments