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