Show More
@@ -1,158 +1,158 | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
2 | // Copyright (C) 2008-2011 The IPython Development Team | |
3 | // |
|
3 | // | |
4 | // Distributed under the terms of the BSD License. The full license is in |
|
4 | // Distributed under the terms of the BSD License. The full license is in | |
5 | // the file COPYING, distributed as part of this software. |
|
5 | // the file COPYING, distributed as part of this software. | |
6 | //---------------------------------------------------------------------------- |
|
6 | //---------------------------------------------------------------------------- | |
7 |
|
7 | |||
8 | //============================================================================ |
|
8 | //============================================================================ | |
9 | // SaveWidget |
|
9 | // SaveWidget | |
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
13 |
|
13 | |||
14 | var utils = IPython.utils; |
|
14 | var utils = IPython.utils; | |
15 |
|
15 | |||
16 | var SaveWidget = function (selector) { |
|
16 | var SaveWidget = function (selector) { | |
17 | this.selector = selector; |
|
17 | this.selector = selector; | |
18 | if (this.selector !== undefined) { |
|
18 | if (this.selector !== undefined) { | |
19 | this.element = $(selector); |
|
19 | this.element = $(selector); | |
20 | this.style(); |
|
20 | this.style(); | |
21 | this.bind_events(); |
|
21 | this.bind_events(); | |
22 | } |
|
22 | } | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | SaveWidget.prototype.style = function () { |
|
26 | SaveWidget.prototype.style = function () { | |
27 | this.element.find('span#save_widget').addClass('ui-widget'); |
|
27 | this.element.find('span#save_widget').addClass('ui-widget'); | |
28 | this.element.find('span#notebook_name').addClass('ui-widget'); |
|
28 | this.element.find('span#notebook_name').addClass('ui-widget'); | |
29 | this.element.find('span#autosave_status').addClass('ui-widget') |
|
29 | this.element.find('span#autosave_status').addClass('ui-widget') | |
30 | .css({border: 'none'}); |
|
30 | .css({border: 'none'}); | |
31 | this.element.find('span#checkpoint_status').addClass('ui-widget') |
|
31 | this.element.find('span#checkpoint_status').addClass('ui-widget') | |
32 | .css({border: 'none', 'margin-left': '20px'}); |
|
32 | .css({border: 'none', 'margin-left': '20px'}); | |
33 | }; |
|
33 | }; | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | SaveWidget.prototype.bind_events = function () { |
|
36 | SaveWidget.prototype.bind_events = function () { | |
37 | var that = this; |
|
37 | var that = this; | |
38 | this.element.find('span#notebook_name').click(function () { |
|
38 | this.element.find('span#notebook_name').click(function () { | |
39 | that.rename_notebook(); |
|
39 | that.rename_notebook(); | |
40 | }); |
|
40 | }); | |
41 | this.element.find('span#notebook_name').hover(function () { |
|
41 | this.element.find('span#notebook_name').hover(function () { | |
42 | $(this).addClass("ui-state-hover"); |
|
42 | $(this).addClass("ui-state-hover"); | |
43 | }, function () { |
|
43 | }, function () { | |
44 | $(this).removeClass("ui-state-hover"); |
|
44 | $(this).removeClass("ui-state-hover"); | |
45 | }); |
|
45 | }); | |
46 | $([IPython.events]).on('notebook_loaded.Notebook', function () { |
|
46 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
47 | that.set_last_saved(); |
|
47 | that.set_last_saved(); | |
48 | that.update_notebook_name(); |
|
48 | that.update_notebook_name(); | |
49 | that.update_document_title(); |
|
49 | that.update_document_title(); | |
50 | }); |
|
50 | }); | |
51 | $([IPython.events]).on('notebook_saved.Notebook', function () { |
|
51 | $([IPython.events]).on('notebook_saved.Notebook', function () { | |
52 | that.set_last_saved(); |
|
52 | that.set_last_saved(); | |
53 | that.update_notebook_name(); |
|
53 | that.update_notebook_name(); | |
54 | that.update_document_title(); |
|
54 | that.update_document_title(); | |
55 | }); |
|
55 | }); | |
56 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { |
|
56 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
57 | that.set_save_status('Last Save Failed!'); |
|
57 | that.set_save_status('Last Save Failed!'); | |
58 | }); |
|
58 | }); | |
59 | $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { |
|
59 | $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { | |
60 | that.set_last_checkpoint(data); |
|
60 | that.set_last_checkpoint(data); | |
61 | }); |
|
61 | }); | |
62 |
|
62 | |||
63 | $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { |
|
63 | $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { | |
64 | that.set_last_checkpoint(data); |
|
64 | that.set_last_checkpoint(data); | |
65 | }); |
|
65 | }); | |
66 | }; |
|
66 | }; | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | SaveWidget.prototype.rename_notebook = function () { |
|
69 | SaveWidget.prototype.rename_notebook = function () { | |
70 | var that = this; |
|
70 | var that = this; | |
71 | var dialog = $('<div/>'); |
|
71 | var dialog = $('<div/>'); | |
72 | dialog.append( |
|
72 | dialog.append( | |
73 | $('<p/>').html('Enter a new notebook name:') |
|
73 | $('<p/>').html('Enter a new notebook name:') | |
74 | .css({'margin-bottom': '10px'}) |
|
74 | .css({'margin-bottom': '10px'}) | |
75 | ); |
|
75 | ); | |
76 | dialog.append( |
|
76 | dialog.append( | |
77 | $('<input/>').attr('type','text').attr('size','25') |
|
77 | $('<input/>').attr('type','text').attr('size','25') | |
78 | .addClass('ui-widget ui-widget-content') |
|
78 | .addClass('ui-widget ui-widget-content') | |
79 | .attr('value',IPython.notebook.get_notebook_name()) |
|
79 | .attr('value',IPython.notebook.get_notebook_name()) | |
80 | ); |
|
80 | ); | |
81 | // $(document).append(dialog); |
|
81 | // $(document).append(dialog); | |
82 | dialog.dialog({ |
|
82 | dialog.dialog({ | |
83 | resizable: false, |
|
83 | resizable: false, | |
84 | modal: true, |
|
84 | modal: true, | |
85 | title: "Rename Notebook", |
|
85 | title: "Rename Notebook", | |
86 | closeText: "", |
|
86 | closeText: "", | |
87 | close: function(event, ui) {$(this).dialog('destroy').remove();}, |
|
87 | close: function(event, ui) {$(this).dialog('destroy').remove();}, | |
88 | buttons : { |
|
88 | buttons : { | |
89 | "OK": function () { |
|
89 | "OK": function () { | |
90 | var new_name = $(this).find('input').attr('value'); |
|
90 | var new_name = $(this).find('input').attr('value'); | |
91 | if (!IPython.notebook.test_notebook_name(new_name)) { |
|
91 | if (!IPython.notebook.test_notebook_name(new_name)) { | |
92 | $(this).find('h3').html( |
|
92 | $(this).find('h3').html( | |
93 | "Invalid notebook name. Notebook names must "+ |
|
93 | "Invalid notebook name. Notebook names must "+ | |
94 | "have 1 or more characters and can contain any characters " + |
|
94 | "have 1 or more characters and can contain any characters " + | |
95 | "except :/\\. Please enter a new notebook name:" |
|
95 | "except :/\\. Please enter a new notebook name:" | |
96 | ); |
|
96 | ); | |
97 | } else { |
|
97 | } else { | |
98 | IPython.notebook.set_notebook_name(new_name); |
|
98 | IPython.notebook.set_notebook_name(new_name); | |
99 |
IPython.notebook.save_ |
|
99 | IPython.notebook.save_notebook(); | |
100 | $(this).dialog('close'); |
|
100 | $(this).dialog('close'); | |
101 | } |
|
101 | } | |
102 | }, |
|
102 | }, | |
103 | "Cancel": function () { |
|
103 | "Cancel": function () { | |
104 | $(this).dialog('close'); |
|
104 | $(this).dialog('close'); | |
105 | } |
|
105 | } | |
106 | }, |
|
106 | }, | |
107 | open : function (event, ui) { |
|
107 | open : function (event, ui) { | |
108 | var that = $(this); |
|
108 | var that = $(this); | |
109 | // Upon ENTER, click the OK button. |
|
109 | // Upon ENTER, click the OK button. | |
110 | that.find('input[type="text"]').keydown(function (event, ui) { |
|
110 | that.find('input[type="text"]').keydown(function (event, ui) { | |
111 | if (event.which === utils.keycodes.ENTER) { |
|
111 | if (event.which === utils.keycodes.ENTER) { | |
112 | that.parent().find('button').first().click(); |
|
112 | that.parent().find('button').first().click(); | |
113 | } |
|
113 | } | |
114 | }); |
|
114 | }); | |
115 | } |
|
115 | } | |
116 | }); |
|
116 | }); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 |
|
119 | |||
120 | SaveWidget.prototype.update_notebook_name = function () { |
|
120 | SaveWidget.prototype.update_notebook_name = function () { | |
121 | var nbname = IPython.notebook.get_notebook_name(); |
|
121 | var nbname = IPython.notebook.get_notebook_name(); | |
122 | this.element.find('span#notebook_name').html(nbname); |
|
122 | this.element.find('span#notebook_name').html(nbname); | |
123 | }; |
|
123 | }; | |
124 |
|
124 | |||
125 |
|
125 | |||
126 | SaveWidget.prototype.update_document_title = function () { |
|
126 | SaveWidget.prototype.update_document_title = function () { | |
127 | var nbname = IPython.notebook.get_notebook_name(); |
|
127 | var nbname = IPython.notebook.get_notebook_name(); | |
128 | document.title = nbname; |
|
128 | document.title = nbname; | |
129 | }; |
|
129 | }; | |
130 |
|
130 | |||
131 |
|
131 | |||
132 | SaveWidget.prototype.set_save_status = function (msg) { |
|
132 | SaveWidget.prototype.set_save_status = function (msg) { | |
133 | this.element.find('span#autosave_status').html(msg); |
|
133 | this.element.find('span#autosave_status').html(msg); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | SaveWidget.prototype.set_checkpoint_status = function (msg) { |
|
136 | SaveWidget.prototype.set_checkpoint_status = function (msg) { | |
137 | this.element.find('span#checkpoint_status').html(msg); |
|
137 | this.element.find('span#checkpoint_status').html(msg); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | SaveWidget.prototype.set_last_checkpoint = function (checkpoint) { |
|
140 | SaveWidget.prototype.set_last_checkpoint = function (checkpoint) { | |
141 | var d = new Date(checkpoint.last_modified); |
|
141 | var d = new Date(checkpoint.last_modified); | |
142 | this.set_checkpoint_status( |
|
142 | this.set_checkpoint_status( | |
143 | "Last Checkpoint: " + d.format('mmm dd HH:MM') |
|
143 | "Last Checkpoint: " + d.format('mmm dd HH:MM') | |
144 | ); |
|
144 | ); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | SaveWidget.prototype.set_last_saved = function () { |
|
147 | SaveWidget.prototype.set_last_saved = function () { | |
148 | var d = new Date(); |
|
148 | var d = new Date(); | |
149 | this.set_save_status('(autosaved: '+d.format('mmm dd HH:MM') + ')'); |
|
149 | this.set_save_status('(autosaved: '+d.format('mmm dd HH:MM') + ')'); | |
150 | }; |
|
150 | }; | |
151 |
|
151 | |||
152 |
|
152 | |||
153 | IPython.SaveWidget = SaveWidget; |
|
153 | IPython.SaveWidget = SaveWidget; | |
154 |
|
154 | |||
155 | return IPython; |
|
155 | return IPython; | |
156 |
|
156 | |||
157 | }(IPython)); |
|
157 | }(IPython)); | |
158 |
|
158 |
General Comments 0
You need to be logged in to leave comments.
Login now