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 | "use strict"; |
|
13 | "use strict"; | |
14 |
|
14 | |||
15 | var utils = IPython.utils; |
|
15 | var utils = IPython.utils; | |
16 |
|
16 | |||
17 | var SaveWidget = function (selector) { |
|
17 | var SaveWidget = function (selector) { | |
18 | this.selector = selector; |
|
18 | this.selector = selector; | |
19 | if (this.selector !== undefined) { |
|
19 | if (this.selector !== undefined) { | |
20 | this.element = $(selector); |
|
20 | this.element = $(selector); | |
21 | this.style(); |
|
21 | this.style(); | |
22 | this.bind_events(); |
|
22 | this.bind_events(); | |
23 | } |
|
23 | } | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | SaveWidget.prototype.style = function () { |
|
27 | SaveWidget.prototype.style = function () { | |
28 | }; |
|
28 | }; | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | SaveWidget.prototype.bind_events = function () { |
|
31 | SaveWidget.prototype.bind_events = function () { | |
32 | var that = this; |
|
32 | var that = this; | |
33 | this.element.find('span#notebook_name').click(function () { |
|
33 | this.element.find('span#notebook_name').click(function () { | |
34 | that.rename_notebook(); |
|
34 | that.rename_notebook(); | |
35 | }); |
|
35 | }); | |
36 | this.element.find('span#notebook_name').hover(function () { |
|
36 | this.element.find('span#notebook_name').hover(function () { | |
37 | $(this).addClass("ui-state-hover"); |
|
37 | $(this).addClass("ui-state-hover"); | |
38 | }, function () { |
|
38 | }, function () { | |
39 | $(this).removeClass("ui-state-hover"); |
|
39 | $(this).removeClass("ui-state-hover"); | |
40 | }); |
|
40 | }); | |
41 | $([IPython.events]).on('notebook_loaded.Notebook', function () { |
|
41 | $([IPython.events]).on('notebook_loaded.Notebook', function () { | |
42 | that.update_notebook_name(); |
|
42 | that.update_notebook_name(); | |
43 | that.update_document_title(); |
|
43 | that.update_document_title(); | |
44 | }); |
|
44 | }); | |
45 | $([IPython.events]).on('notebook_saved.Notebook', function () { |
|
45 | $([IPython.events]).on('notebook_saved.Notebook', function () { | |
46 | that.update_notebook_name(); |
|
46 | that.update_notebook_name(); | |
47 | that.update_document_title(); |
|
47 | that.update_document_title(); | |
48 | }); |
|
48 | }); | |
49 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { |
|
49 | $([IPython.events]).on('notebook_save_failed.Notebook', function () { | |
50 | that.set_save_status('Autosave Failed!'); |
|
50 | that.set_save_status('Autosave Failed!'); | |
51 | }); |
|
51 | }); | |
52 | $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { |
|
52 | $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) { | |
53 | that.set_last_checkpoint(data[0]); |
|
53 | that.set_last_checkpoint(data[0]); | |
54 | }); |
|
54 | }); | |
55 |
|
55 | |||
56 | $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { |
|
56 | $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) { | |
57 | that.set_last_checkpoint(data); |
|
57 | that.set_last_checkpoint(data); | |
58 | }); |
|
58 | }); | |
59 | $([IPython.events]).on('set_dirty.Notebook', function (event, data) { |
|
59 | $([IPython.events]).on('set_dirty.Notebook', function (event, data) { | |
60 | that.set_autosaved(data.value); |
|
60 | that.set_autosaved(data.value); | |
61 | }); |
|
61 | }); | |
62 | }; |
|
62 | }; | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | SaveWidget.prototype.rename_notebook = function () { |
|
65 | SaveWidget.prototype.rename_notebook = function () { | |
66 | var that = this; |
|
66 | var that = this; | |
67 | var dialog = $('<div/>').append( |
|
67 | var dialog = $('<div/>').append( | |
68 | $("<p/>").addClass("rename-message") |
|
68 | $("<p/>").addClass("rename-message") | |
69 | .html('Enter a new notebook name:') |
|
69 | .html('Enter a new notebook name:') | |
70 | ).append( |
|
70 | ).append( | |
71 | $("<br/>") |
|
71 | $("<br/>") | |
72 | ).append( |
|
72 | ).append( | |
73 | $('<input/>').attr('type','text').attr('size','25') |
|
73 | $('<input/>').attr('type','text').attr('size','25') | |
74 | .val(IPython.notebook.get_notebook_name()) |
|
74 | .val(IPython.notebook.get_notebook_name()) | |
75 | ); |
|
75 | ); | |
76 | IPython.dialog.modal({ |
|
76 | IPython.dialog.modal({ | |
77 | title: "Rename Notebook", |
|
77 | title: "Rename Notebook", | |
78 | body: dialog, |
|
78 | body: dialog, | |
79 | buttons : { |
|
79 | buttons : { | |
80 | "Cancel": {}, |
|
80 | "Cancel": {}, | |
81 | "OK": { |
|
81 | "OK": { | |
82 | class: "btn-primary", |
|
82 | class: "btn-primary", | |
83 | click: function () { |
|
83 | click: function () { | |
84 | var new_name = $(this).find('input').val(); |
|
84 | var new_name = $(this).find('input').val(); | |
85 | if (!IPython.notebook.test_notebook_name(new_name)) { |
|
85 | if (!IPython.notebook.test_notebook_name(new_name)) { | |
86 | $(this).find('.rename-message').html( |
|
86 | $(this).find('.rename-message').html( | |
87 | "Invalid notebook name. Notebook names must "+ |
|
87 | "Invalid notebook name. Notebook names must "+ | |
88 | "have 1 or more characters and can contain any characters " + |
|
88 | "have 1 or more characters and can contain any characters " + | |
89 | "except :/\\. Please enter a new notebook name:" |
|
89 | "except :/\\. Please enter a new notebook name:" | |
90 | ); |
|
90 | ); | |
91 | return false; |
|
91 | return false; | |
92 | } else { |
|
92 | } else { | |
93 | IPython.notebook.set_notebook_name(new_name); |
|
93 | IPython.notebook.set_notebook_name(new_name); | |
94 | IPython.notebook.save_notebook(); |
|
94 | IPython.notebook.save_notebook(); | |
95 | } |
|
95 | } | |
96 | }} |
|
96 | }} | |
97 | }, |
|
97 | }, | |
98 | open : function (event, ui) { |
|
98 | open : function (event, ui) { | |
99 | var that = $(this); |
|
99 | var that = $(this); | |
100 | // Upon ENTER, click the OK button. |
|
100 | // Upon ENTER, click the OK button. | |
101 | that.find('input[type="text"]').keydown(function (event, ui) { |
|
101 | that.find('input[type="text"]').keydown(function (event, ui) { | |
102 | if (event.which === utils.keycodes.ENTER) { |
|
102 | if (event.which === utils.keycodes.ENTER) { | |
103 | that.find('.btn-primary').first().click(); |
|
103 | that.find('.btn-primary').first().click(); | |
104 | return false; |
|
104 | return false; | |
105 | } |
|
105 | } | |
106 | }); |
|
106 | }); | |
107 | that.find('input[type="text"]').focus(); |
|
107 | that.find('input[type="text"]').focus().select(); | |
108 | } |
|
108 | } | |
109 | }); |
|
109 | }); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 |
|
112 | |||
113 | SaveWidget.prototype.update_notebook_name = function () { |
|
113 | SaveWidget.prototype.update_notebook_name = function () { | |
114 | var nbname = IPython.notebook.get_notebook_name(); |
|
114 | var nbname = IPython.notebook.get_notebook_name(); | |
115 | this.element.find('span#notebook_name').html(nbname); |
|
115 | this.element.find('span#notebook_name').html(nbname); | |
116 | }; |
|
116 | }; | |
117 |
|
117 | |||
118 |
|
118 | |||
119 | SaveWidget.prototype.update_document_title = function () { |
|
119 | SaveWidget.prototype.update_document_title = function () { | |
120 | var nbname = IPython.notebook.get_notebook_name(); |
|
120 | var nbname = IPython.notebook.get_notebook_name(); | |
121 | document.title = nbname; |
|
121 | document.title = nbname; | |
122 | }; |
|
122 | }; | |
123 |
|
123 | |||
124 |
|
124 | |||
125 | SaveWidget.prototype.set_save_status = function (msg) { |
|
125 | SaveWidget.prototype.set_save_status = function (msg) { | |
126 | this.element.find('span#autosave_status').html(msg); |
|
126 | this.element.find('span#autosave_status').html(msg); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | SaveWidget.prototype.set_checkpoint_status = function (msg) { |
|
129 | SaveWidget.prototype.set_checkpoint_status = function (msg) { | |
130 | this.element.find('span#checkpoint_status').html(msg); |
|
130 | this.element.find('span#checkpoint_status').html(msg); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | SaveWidget.prototype.set_last_checkpoint = function (checkpoint) { |
|
133 | SaveWidget.prototype.set_last_checkpoint = function (checkpoint) { | |
134 | if (!checkpoint) { |
|
134 | if (!checkpoint) { | |
135 | this.set_checkpoint_status(""); |
|
135 | this.set_checkpoint_status(""); | |
136 | return; |
|
136 | return; | |
137 | } |
|
137 | } | |
138 | var d = new Date(checkpoint.last_modified); |
|
138 | var d = new Date(checkpoint.last_modified); | |
139 | this.set_checkpoint_status( |
|
139 | this.set_checkpoint_status( | |
140 | "Last Checkpoint: " + d.format('mmm dd HH:MM') |
|
140 | "Last Checkpoint: " + d.format('mmm dd HH:MM') | |
141 | ); |
|
141 | ); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | SaveWidget.prototype.set_autosaved = function (dirty) { |
|
144 | SaveWidget.prototype.set_autosaved = function (dirty) { | |
145 | if (dirty) { |
|
145 | if (dirty) { | |
146 | this.set_save_status("(unsaved changes)"); |
|
146 | this.set_save_status("(unsaved changes)"); | |
147 | } else { |
|
147 | } else { | |
148 | this.set_save_status("(autosaved)"); |
|
148 | this.set_save_status("(autosaved)"); | |
149 | } |
|
149 | } | |
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