11
2- openNote . controller ( "folderController" , function ( $scope ,
3- $rootScope ,
4- $location ,
5- $routeParams ,
6- storageService ,
2+ openNote . controller ( "folderController" , function ( $scope ,
3+ $rootScope ,
4+ $location ,
5+ $routeParams ,
6+ storageService ,
77 config ,
88 $timeout ) {
99 $rootScope . buttons = [ ] ;
1010 $scope . folderEditMode = false ;
1111 $scope . currentFolder = { } ;
1212 $scope . parentFolder = null ;
13-
13+
1414 //add buttons
1515 if ( $routeParams . id != null )
1616 $rootScope . buttons . push ( {
@@ -22,43 +22,43 @@ openNote.controller("folderController", function( $scope,
2222 } ,
2323 helpText : $rootScope . helpContent . newNoteButton
2424 } ) ;
25-
25+
2626 //Create a folder
2727 $rootScope . buttons . push ( {
2828 text : "New folder" ,
2929 action : function ( ) {
3030 var prompt = "Please enter a name for the new folder" ;
31-
31+
3232 if ( $scope . currentFolder . name != null )
3333 prompt += "that will be created in " + $scope . currentFolder . name ;
34-
35- alertify . prompt (
34+
35+ alertify . prompt (
3636 prompt ,
3737 function ( confirm , data ) {
3838 if ( ! confirm )
3939 return ;
40-
40+
4141 var folder = {
4242 parentFolderID :$scope . currentFolder . _id ,
4343 name :data
4444 } ;
45-
45+
4646 createFolder ( folder ) ;
4747 } ,
4848 "" ) ;
4949 } ,
5050 helpText : $rootScope . helpContent . newFolderButton
5151 } ) ;
52-
52+
5353 $rootScope . buttons . push ( {
5454 text : "Search" ,
5555 action : function ( ) {
5656 $location . url ( "/search/" + $scope . currentFolder . id ) ;
5757 } ,
5858 helpText : $rootScope . helpContent . findButton
5959 } ) ;
60-
61- /**
60+
61+ /**
6262 * Load current folder contents
6363 */
6464 $scope . loadCurrentFolder = function ( ) {
@@ -73,41 +73,41 @@ openNote.controller("folderController", function( $scope,
7373 storageService . database ( ) . get ( $routeParams . id ) . then ( function ( doc ) {
7474 $scope . currentFolder = doc ;
7575 loadCurrentFolderContents ( ) ;
76-
76+
7777 if ( $scope . currentFolder . parentFolderID == null )
7878 $scope . parentFolder = { name :"Home" } ;
7979 else
8080 storageService . database ( ) . get ( $scope . currentFolder . parentFolderID ) . then ( function ( doc ) {
8181 $scope . parentFolder = doc ;
8282 $scope . $apply ( ) ;
8383 } ) ;
84- } ) ;
84+ } ) ;
8585 }
8686 } ;
87-
87+
8888 /**
8989 * Activate folder edit mode if we are not in the home folder
9090 */
9191 $scope . activateFolderEditMode = function ( ) {
9292 if ( $scope . currentFolder . _id != null )
9393 $scope . folderEditMode = ! $scope . folderEditMode ;
9494 } ;
95-
95+
9696 /**
9797 * fade out all folders
9898 */
9999 $scope . fadeOutFoldersAndNotes = function ( callback ) {
100- if ( ( $scope . currentFolder . foldersInside != null
100+ if ( ( $scope . currentFolder . foldersInside != null
101101 && $scope . currentFolder . foldersInside . length > 0 )
102- || ( $scope . currentFolder . notesInside != null
102+ || ( $scope . currentFolder . notesInside != null
103103 && $scope . currentFolder . notesInside . length > 0 ) ) {
104-
104+
105105 $ ( ".note" ) . fadeTo ( config . fadeSpeedShort ( ) , 0 , function ( ) {
106106 $scope . $apply ( function ( ) {
107107 callback ( ) ;
108108 } ) ;
109109 } ) ;
110-
110+
111111 $ ( ".folder" ) . fadeTo ( config . fadeSpeedShort ( ) , 0 , function ( ) {
112112 $scope . $apply ( function ( ) {
113113 callback ( ) ;
@@ -117,7 +117,7 @@ openNote.controller("folderController", function( $scope,
117117 else
118118 callback ( ) ;
119119 } ;
120-
120+
121121 /**
122122 * Load a folder
123123 * @param folder- the folder to load
@@ -127,7 +127,7 @@ openNote.controller("folderController", function( $scope,
127127 $location . url ( "/folder/" + folder . doc . _id ) ;
128128 } ) ;
129129 } ;
130-
130+
131131 /**
132132 * Load a note
133133 * @param note - load a note
@@ -137,7 +137,7 @@ openNote.controller("folderController", function( $scope,
137137 $location . url ( "/note/" + note . id ) ;
138138 } ) ;
139139 } ;
140-
140+
141141 /**
142142 * Rename the current folder
143143 */
@@ -146,7 +146,7 @@ openNote.controller("folderController", function( $scope,
146146 function ( confirm , data ) {
147147 if ( ! confirm )
148148 return ;
149-
149+
150150 $scope . currentFolder . name = data ;
151151 storageService . database ( ) . put ( $scope . currentFolder ) . then ( function ( result ) {
152152 $scope . currentFolder . _rev = result . rev
@@ -156,11 +156,11 @@ openNote.controller("folderController", function( $scope,
156156 throw error
157157 //FIXME conflict resolution
158158 } ) ;
159- } ,
159+ } ,
160160 $scope . currentFolder . name //show the current folder name
161161 ) ;
162162 } ;
163-
163+
164164 /**
165165 * Remove this folder and all sub items
166166 */
@@ -169,21 +169,21 @@ openNote.controller("folderController", function( $scope,
169169 function ( confirm ) {
170170 if ( ! confirm )
171171 return ;
172-
172+
173173 var parrentFolderID = $scope . currentFolder . parrentFolderID ;
174174 storageService . database ( ) . remove ( $scope . currentFolder ) . then ( function ( result ) {
175175 $rootScope . $emit ( "reloadListView" , { } ) ;
176-
176+
177177 if ( parrentFolderID == null )
178178 $location . url ( "/folder/" ) ;
179179 else
180180 $location . url ( "/folder/" + parrentFolderID ) ;
181-
181+
182182 $scope . $apply ( ) ;
183183 } ) ;
184184 } ) ;
185185 }
186-
186+
187187 /**
188188 * Listen to changed folder events to see if its the current open folder
189189 */
@@ -192,54 +192,64 @@ openNote.controller("folderController", function( $scope,
192192 $scope . loadCurrentFolder ( ) ; //reload
193193 }
194194 } ) ;
195-
195+
196196 /**
197197 * Create a folder object
198198 */
199199 var createFolder = function ( folder ) {
200200 folder . type = "folder" ;
201201 storageService . database ( ) . post ( folder ) . then ( function ( response ) {
202- if ( ! response . ok )
202+ if ( ! response . ok )
203203 throw "//FIXME" ;
204204 $rootScope . $emit ( "reloadListView" , { } ) ;
205205 $location . url ( "/folder/" + response . id ) ;
206206 $scope . $apply ( ) ;
207-
207+
208208 } ) . catch ( function ( error ) {
209209 console . log ( error ) ; //FIXME
210210 } ) ;
211211 }
212-
212+
213213 /**
214214 * Load the current folders contents
215215 */
216216 var loadCurrentFolderContents = function ( ) {
217217 storageService . loadFolderContents ( $scope . currentFolder . _id , function ( results ) {
218218 $scope . currentFolderContents = results . rows ;
219-
219+
220220 //Do they have anything to display?
221221 if ( $scope . currentFolder . _id == null && $scope . currentFolderContents . length == 0 ) {
222222 alertify . alert ( "It looks like you dont have any folders. You can create one using the \"New Folder\" button in the top right of the page. If you need to pull your remote notes <a href='#/settings/database'>click here</a>." ) ;
223223 } ;
224-
224+
225225 $scope . $apply ( ) ;
226226 } ) ;
227227 } ;
228-
228+
229229 /**
230230 * Filter out everything but type folder
231231 */
232232 $scope . folderFilter = function ( object ) {
233233 return storageService . typeFilter ( object , "folder" ) ;
234234 } ;
235-
235+
236236 /**
237237 * Filter out everything but type note
238238 */
239239 $scope . noteFilter = function ( object ) {
240240 return storageService . typeFilter ( object , "note" ) ;
241241 } ;
242-
242+
243+ //Up a folder function
244+ if ( parentFolder != null )
245+ dragula ( [ document . getElementById ( "parentFolder" ) , document . getElementById ( right ) ] ) . on ( "drag" , function ( el ) {
246+ el . className = el . className . replace ( ' animazing' , '' ) ;
247+ } ) . on ( 'drop' , function ( el ) {
248+ setTimeout ( function ( ) {
249+ el . className += ' animazing' ;
250+ } , 0 ) ;
251+ } ) ;
252+
243253 //Load current folder
244254 $timeout ( $scope . loadCurrentFolder ) ;
245- } ) ;
255+ } ) ;
0 commit comments