1
+ angular . module ( "umbraco" ) . controller ( "Perplex.Form.SortController" ,
2
+ function ( $scope , $routeParams , $http , formResource , perplexFormResource , navigationService , notificationsService ) {
3
+ $scope . folder = null ;
4
+ $scope . forms = [ ] ;
5
+
6
+ // If currentNode is undefined, use routeParams
7
+ // This is the case in the folder-view (folder.html, when a folder is clicked, it uses the same controller)
8
+ var nodeId ;
9
+ if ( $scope . currentNode ) {
10
+ nodeId = $scope . currentNode . id ;
11
+ } else {
12
+ nodeId = $routeParams . id ;
13
+ }
14
+
15
+ // Load all forms (required to display their names, we do not store form names)
16
+ formResource . getOverView ( )
17
+ . then ( function ( response ) {
18
+ $scope . forms = response . data ;
19
+
20
+ // Load this folder
21
+ perplexFormResource . getFolder ( nodeId ) . then ( function ( response ) {
22
+ $scope . folder = response . data ;
23
+
24
+ // Goto folder in tree
25
+ navigationService . syncTree ( { tree : "form" , path : $scope . folder . path , forceReload : false , activate : true } ) ;
26
+ } , function ( error ) { } ) ;
27
+ } ) ;
28
+
29
+ $scope . sort = function ( ) {
30
+ // We call it sort, but we actually update every aspect of this folder :)
31
+ perplexFormResource . update ( $scope . folder ) . then ( function ( response ) {
32
+ // Reload folder
33
+ navigationService . syncTree ( { tree : "form" , path : $scope . folder . path , forceReload : true } ) . then ( function ( syncArgs ) {
34
+ navigationService . reloadNode ( syncArgs . node ) ;
35
+
36
+ // Hide the tree
37
+ navigationService . hideNavigation ( ) ;
38
+
39
+ // Notify user
40
+ notificationsService . showNotification ( { type : 0 , header : "Sorting successful" } ) ;
41
+ } ) ;
42
+ } ) ;
43
+ } ;
44
+
45
+ $scope . getFormName = function ( formId ) {
46
+ var form = getForm ( formId ) ;
47
+ if ( form == null ) return "" ;
48
+
49
+ return form . name ;
50
+ } ;
51
+
52
+ $scope . getFormId = function ( formId ) {
53
+ var form = getForm ( formId ) ;
54
+ if ( form == null ) return "" ;
55
+
56
+ return form . id ;
57
+ }
58
+
59
+ function getForm ( formId ) {
60
+ return _ . find ( $scope . forms , { id : formId } ) ;
61
+ }
62
+
63
+ $scope . cancelSort = function ( ) {
64
+ navigationService . hideNavigation ( ) ;
65
+ } ;
66
+ } ) ;
0 commit comments