@@ -104,7 +104,7 @@ function MainController($scope, $http, $window, $location, DoSerial) {
104104}
105105
106106function ProjectController ( $scope , $browser , $http , $routeParams , $window ,
107- $log , DoSerial , DomElementById ) {
107+ $dialog , $ log, DoSerial , DomElementById ) {
108108
109109 // TODO: remove once file contents are returned in JSON response
110110 $scope . no_json_transform = function ( data ) { return data ; } ;
@@ -240,36 +240,26 @@ function ProjectController($scope, $browser, $http, $routeParams, $window,
240240*/
241241 } ;
242242
243- $scope . $on ( 'new_file' , function ( evt , path ) {
244- $scope . insert_path ( path ) ;
245- } ) ;
246-
247243 $scope . prompt_new_file = function ( ) {
248- $scope . $broadcast ( 'prompt_new_file' ) ;
244+ $dialog . dialog ( {
245+ controller : 'NewFileController' ,
246+ templateUrl : '/playground/new_file_modal.html' ,
247+ } )
248+ . open ( ) . then ( function ( path ) {
249+ if ( path ) {
250+ // remove leading and trailing slash(es)
251+ path = path . replace ( / ^ \/ * ( .* ?) \/ * $ / , '$1' )
252+ $scope . insert_path ( path ) ;
253+ }
254+ } ) ;
249255 } ;
250256
251257}
252258
253- function NewFileController ( $scope , $log ) {
254-
255- // TODO: avoid DOM access
256- var new_file_modal = $ ( '#new-file-modal' ) ;
257-
258- $scope . $on ( 'prompt_new_file' , function ( ) {
259- $scope . filename = '' ;
260- new_file_modal . modal ( 'show' ) ;
261- // TODO: avoid DOM access
262- $ ( '#new_filename' ) [ 0 ] . focus ( ) ;
263- } ) ;
264-
265- $scope . create_file = function ( ) {
266- // remove leading and trailing slash(es)
267- var path = $scope . filename . replace ( / ^ \/ * ( .* ?) \/ * $ / , '$1' )
268- $scope . $emit ( 'new_file' , path ) ;
269- }
259+ function NewFileController ( $scope , $log , dialog ) {
270260
271- $scope . close = function ( ) {
272- new_file_modal . modal ( 'hide' ) ;
261+ $scope . close = function ( path ) {
262+ dialog . close ( path ) ;
273263 }
274264
275265}
0 commit comments