Show More
@@ -1,156 +1,156 b'' | |||||
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 |
this.notebook_name_re = /[ |
|
18 | this.notebook_name_blacklist_re = /[\/\\]/ | |
19 | this.last_saved_name = ''; |
|
19 | this.last_saved_name = ''; | |
20 | if (this.selector !== undefined) { |
|
20 | if (this.selector !== undefined) { | |
21 | this.element = $(selector); |
|
21 | this.element = $(selector); | |
22 | this.style(); |
|
22 | this.style(); | |
23 | this.bind_events(); |
|
23 | this.bind_events(); | |
24 | } |
|
24 | } | |
25 | }; |
|
25 | }; | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | SaveWidget.prototype.style = function () { |
|
28 | SaveWidget.prototype.style = function () { | |
29 | this.element.find('input#notebook_name').addClass('ui-widget ui-widget-content'); |
|
29 | this.element.find('input#notebook_name').addClass('ui-widget ui-widget-content'); | |
30 | this.element.find('input#notebook_name').attr('tabindex','1'); |
|
30 | this.element.find('input#notebook_name').attr('tabindex','1'); | |
31 | this.element.find('button#save_notebook').button(); |
|
31 | this.element.find('button#save_notebook').button(); | |
32 | var left_panel_width = $('div#left_panel').outerWidth(); |
|
32 | var left_panel_width = $('div#left_panel').outerWidth(); | |
33 | var left_panel_splitter_width = $('div#left_panel_splitter').outerWidth(); |
|
33 | var left_panel_splitter_width = $('div#left_panel_splitter').outerWidth(); | |
34 | $('span#save_widget').css({marginLeft:left_panel_width+left_panel_splitter_width}); |
|
34 | $('span#save_widget').css({marginLeft:left_panel_width+left_panel_splitter_width}); | |
35 |
|
35 | |||
36 | }; |
|
36 | }; | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | SaveWidget.prototype.bind_events = function () { |
|
39 | SaveWidget.prototype.bind_events = function () { | |
40 | var that = this; |
|
40 | var that = this; | |
41 | this.element.find('button#save_notebook').click(function () { |
|
41 | this.element.find('button#save_notebook').click(function () { | |
42 | that.save_notebook(); |
|
42 | that.save_notebook(); | |
43 | }); |
|
43 | }); | |
44 | this.element.find('input#notebook_name').keyup(function () { |
|
44 | this.element.find('input#notebook_name').keyup(function () { | |
45 | that.is_renaming(); |
|
45 | that.is_renaming(); | |
46 | }); |
|
46 | }); | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | SaveWidget.prototype.save_notebook = function () { |
|
50 | SaveWidget.prototype.save_notebook = function () { | |
51 | IPython.notebook.save_notebook(); |
|
51 | IPython.notebook.save_notebook(); | |
52 | }; |
|
52 | }; | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | SaveWidget.prototype.notebook_saved = function () { |
|
55 | SaveWidget.prototype.notebook_saved = function () { | |
56 | this.set_document_title(); |
|
56 | this.set_document_title(); | |
57 | this.last_saved_name = this.get_notebook_name(); |
|
57 | this.last_saved_name = this.get_notebook_name(); | |
58 | }; |
|
58 | }; | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | SaveWidget.prototype.is_renaming = function () { |
|
61 | SaveWidget.prototype.is_renaming = function () { | |
62 | if (this.get_notebook_name() !== this.last_saved_name) { |
|
62 | if (this.get_notebook_name() !== this.last_saved_name) { | |
63 | this.status_rename(); |
|
63 | this.status_rename(); | |
64 | } else { |
|
64 | } else { | |
65 | this.status_save(); |
|
65 | this.status_save(); | |
66 | }; |
|
66 | }; | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | SaveWidget.prototype.get_notebook_name = function () { |
|
70 | SaveWidget.prototype.get_notebook_name = function () { | |
71 | return this.element.find('input#notebook_name').attr('value'); |
|
71 | return this.element.find('input#notebook_name').attr('value'); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | SaveWidget.prototype.set_notebook_name = function (nbname) { |
|
75 | SaveWidget.prototype.set_notebook_name = function (nbname) { | |
76 | this.element.find('input#notebook_name').attr('value',nbname); |
|
76 | this.element.find('input#notebook_name').attr('value',nbname); | |
77 | this.set_document_title(); |
|
77 | this.set_document_title(); | |
78 | this.last_saved_name = nbname; |
|
78 | this.last_saved_name = nbname; | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | SaveWidget.prototype.set_document_title = function () { |
|
82 | SaveWidget.prototype.set_document_title = function () { | |
83 | nbname = this.get_notebook_name(); |
|
83 | nbname = this.get_notebook_name(); | |
84 | document.title = 'IPy: ' + nbname; |
|
84 | document.title = 'IPy: ' + nbname; | |
85 | }; |
|
85 | }; | |
86 |
|
86 | |||
87 |
|
87 | |||
88 | SaveWidget.prototype.get_notebook_id = function () { |
|
88 | SaveWidget.prototype.get_notebook_id = function () { | |
89 | return this.element.find('span#notebook_id').text() |
|
89 | return this.element.find('span#notebook_id').text() | |
90 | }; |
|
90 | }; | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | SaveWidget.prototype.update_url = function () { |
|
93 | SaveWidget.prototype.update_url = function () { | |
94 | var notebook_id = this.get_notebook_id(); |
|
94 | var notebook_id = this.get_notebook_id(); | |
95 | if (notebook_id !== '') { |
|
95 | if (notebook_id !== '') { | |
96 | window.history.replaceState({}, '', notebook_id); |
|
96 | window.history.replaceState({}, '', notebook_id); | |
97 | }; |
|
97 | }; | |
98 | }; |
|
98 | }; | |
99 |
|
99 | |||
100 |
|
100 | |||
101 | SaveWidget.prototype.test_notebook_name = function () { |
|
101 | SaveWidget.prototype.test_notebook_name = function () { | |
102 | var nbname = this.get_notebook_name(); |
|
102 | var nbname = this.get_notebook_name(); | |
103 | if (this.notebook_name_re.test(nbname)) { |
|
103 | if (this.notebook_name_blacklist_re.test(nbname) == false) { | |
104 | return true; |
|
104 | return true; | |
105 | } else { |
|
105 | } else { | |
106 | var bad_name = $('<div/>'); |
|
106 | var bad_name = $('<div/>'); | |
107 | bad_name.html( |
|
107 | bad_name.html( | |
108 | "The notebook name you entered (" + |
|
108 | "The notebook name you entered (" + | |
109 | nbname + |
|
109 | nbname + | |
110 | ") is not valid. Notebook names can contain any characters except / and \\" |
|
110 | ") is not valid. Notebook names can contain any characters except / and \\." | |
111 | ); |
|
111 | ); | |
112 | bad_name.dialog({title: 'Invalid name', modal: true}); |
|
112 | bad_name.dialog({title: 'Invalid name', modal: true}); | |
113 | return false; |
|
113 | return false; | |
114 | }; |
|
114 | }; | |
115 | }; |
|
115 | }; | |
116 |
|
116 | |||
117 |
|
117 | |||
118 | SaveWidget.prototype.reset_status = function () { |
|
118 | SaveWidget.prototype.reset_status = function () { | |
119 | this.is_renaming(); |
|
119 | this.is_renaming(); | |
120 | }; |
|
120 | }; | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | SaveWidget.prototype.status_save = function () { |
|
123 | SaveWidget.prototype.status_save = function () { | |
124 | this.element.find('button#save_notebook').button('option', 'label', '<u>S</u>ave'); |
|
124 | this.element.find('button#save_notebook').button('option', 'label', '<u>S</u>ave'); | |
125 | this.element.find('button#save_notebook').button('enable'); |
|
125 | this.element.find('button#save_notebook').button('enable'); | |
126 | IPython.print_widget.enable(); |
|
126 | IPython.print_widget.enable(); | |
127 | }; |
|
127 | }; | |
128 |
|
128 | |||
129 |
|
129 | |||
130 | SaveWidget.prototype.status_saving = function () { |
|
130 | SaveWidget.prototype.status_saving = function () { | |
131 | this.element.find('button#save_notebook').button('option', 'label', 'Saving'); |
|
131 | this.element.find('button#save_notebook').button('option', 'label', 'Saving'); | |
132 | this.element.find('button#save_notebook').button('disable'); |
|
132 | this.element.find('button#save_notebook').button('disable'); | |
133 | IPython.print_widget.disable(); |
|
133 | IPython.print_widget.disable(); | |
134 | }; |
|
134 | }; | |
135 |
|
135 | |||
136 |
|
136 | |||
137 | SaveWidget.prototype.status_loading = function () { |
|
137 | SaveWidget.prototype.status_loading = function () { | |
138 | this.element.find('button#save_notebook').button('option', 'label', 'Loading'); |
|
138 | this.element.find('button#save_notebook').button('option', 'label', 'Loading'); | |
139 | this.element.find('button#save_notebook').button('disable'); |
|
139 | this.element.find('button#save_notebook').button('disable'); | |
140 | IPython.print_widget.disable(); |
|
140 | IPython.print_widget.disable(); | |
141 | }; |
|
141 | }; | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | SaveWidget.prototype.status_rename = function () { |
|
144 | SaveWidget.prototype.status_rename = function () { | |
145 | this.element.find('button#save_notebook').button('option', 'label', 'Rename'); |
|
145 | this.element.find('button#save_notebook').button('option', 'label', 'Rename'); | |
146 | this.element.find('button#save_notebook').button('enable'); |
|
146 | this.element.find('button#save_notebook').button('enable'); | |
147 | IPython.print_widget.enable(); |
|
147 | IPython.print_widget.enable(); | |
148 | }; |
|
148 | }; | |
149 |
|
149 | |||
150 |
|
150 | |||
151 | IPython.SaveWidget = SaveWidget; |
|
151 | IPython.SaveWidget = SaveWidget; | |
152 |
|
152 | |||
153 | return IPython; |
|
153 | return IPython; | |
154 |
|
154 | |||
155 | }(IPython)); |
|
155 | }(IPython)); | |
156 |
|
156 |
General Comments 0
You need to be logged in to leave comments.
Login now