@@ -95,25 +95,42 @@ define([
9595 }
9696 }
9797
98- function modalDialog ( title , text , displayclass , body ) {
99- if ( ! body ) {
100- body = $ ( '<div/>' ) ;
101- }
102- if ( text ) {
103- body . text ( text ) ;
104- }
98+ function modalDialog ( title , body , displayclass , buttons ) {
10599 if ( displayclass ) {
106100 body . addClass ( displayclass ) ;
107101 }
102+ if ( ! buttons ) {
103+ buttons = {
104+ OK : { 'class' : 'btn-primary' }
105+ } ;
106+ }
108107 dialog . modal ( {
109108 title : title ,
110109 body : body ,
111- buttons : {
112- OK : { 'class' : 'btn-primary' }
113- }
110+ buttons : buttons
114111 } ) ;
115112 }
116113
114+ function formatRepoPathforDialog ( repoid , path ) {
115+ var displayRepoid = $ ( '<div/>' ) . append (
116+ $ ( '<span/>' , {
117+ 'text' : 'repoid: '
118+ } ) . append (
119+ $ ( '<b/>' , {
120+ 'text' : repoid
121+ } )
122+ ) ) ;
123+ var displayPath = $ ( '<div/>' ) . append (
124+ $ ( '<span/>' , {
125+ 'text' : 'path: '
126+ } ) . append (
127+ $ ( '<b/>' , {
128+ 'text' : path
129+ } )
130+ ) ) ;
131+ return displayRepoid . append ( displayPath ) ;
132+ }
133+
117134 function getNotebookFromBrowser ( ) {
118135 return Jupyter . notebook . toJSON ( ) ;
119136 }
@@ -122,6 +139,7 @@ define([
122139 var path = Jupyter . notebook . notebook_path ;
123140 var primaryKey = 'repoid:' + repoid + ' path:' + path ;
124141 var nb = getNotebookFromBrowser ( ) ;
142+ var repopathDisplay = formatRepoPathforDialog ( repoid , path ) ;
125143 getDb ( ) . offlinenotebook . put ( {
126144 'pk' : primaryKey ,
127145 'repoid' : repoid ,
@@ -132,16 +150,18 @@ define([
132150 'content' : nb
133151 } ) . then ( function ( key ) {
134152 console . log ( 'offline-notebook saved: ' , key ) ;
135- modalDialog ( 'Notebook saved to browser storage' , key ) ;
153+ modalDialog (
154+ 'Notebook saved to browser storage' ,
155+ repopathDisplay ) ;
136156 } ) . catch ( function ( e ) {
137- var body = $ ( '<div/>' ) . append (
138- $ ( '<div/>' , {
139- 'text' : primaryKey
140- } ) ) . append (
157+ var body = repopathDisplay . append (
141158 $ ( '<div/>' , {
142159 'text' : e
143160 } ) ) ;
144- modalDialog ( 'Local storage IndexedDB error' , null , 'alert alert-danger' , body ) ;
161+ modalDialog (
162+ 'Local storage IndexedDB error' ,
163+ body ,
164+ 'alert alert-danger' ) ;
145165 throw ( e ) ;
146166 } ) ;
147167 }
@@ -150,14 +170,31 @@ define([
150170 var path = Jupyter . notebook . notebook_path ;
151171 var primaryKey = 'repoid:' + repoid + ' path:' + path ;
152172 getDb ( ) . offlinenotebook . get ( primaryKey ) . then ( function ( nb ) {
173+ var repopathDisplay = formatRepoPathforDialog ( repoid , path ) ;
153174 if ( nb ) {
154- Jupyter . notebook . fromJSON ( nb ) ;
155- console . log ( 'offline-notebook loaded ' + primaryKey ) ;
156- modalDialog ( 'Loaded notebook from browser storage' , primaryKey ) ;
175+ console . log ( 'offline-notebook found ' + primaryKey ) ;
176+ modalDialog (
177+ 'This will replace your current notebook with' ,
178+ repopathDisplay ,
179+ null ,
180+ {
181+ OK : {
182+ class : 'btn-primary' ,
183+ click : function ( ) {
184+ Jupyter . notebook . fromJSON ( nb ) ;
185+ console . log ( 'offline-notebook loaded ' + primaryKey ) ;
186+ }
187+ } ,
188+ Cancel : { }
189+ }
190+ ) ;
157191 }
158192 else {
159193 console . log ( 'offline-notebook not found ' + primaryKey ) ;
160- modalDialog ( 'Notebook not found in browser storage' , primaryKey , 'alert alert-danger' ) ;
194+ modalDialog (
195+ 'Notebook not found in browser storage' ,
196+ repopathDisplay ,
197+ 'alert alert-danger' ) ;
161198 }
162199 } ) . catch ( function ( e ) {
163200 var body = $ ( '<div/>' ) . append (
@@ -167,7 +204,10 @@ define([
167204 $ ( '<div/>' , {
168205 'text' : e
169206 } ) ) ;
170- modalDialog ( 'Local storage IndexedDB error' , null , 'alert alert-danger' , body ) ;
207+ modalDialog (
208+ 'Local storage IndexedDB error' ,
209+ body ,
210+ 'alert alert-danger' ) ;
171211 throw ( e ) ;
172212 } ) ;
173213 }
@@ -228,7 +268,9 @@ define([
228268 'class' : 'fa fa-clipboard'
229269 } ) ) ;
230270 body . append ( button ) ;
231- modalDialog ( 'Link to this Binder' , null , null , body ) ;
271+ modalDialog (
272+ 'Link to this Binder' ,
273+ body ) ;
232274 }
233275
234276 // Run on start
0 commit comments