Show More
@@ -1,119 +1,130 b'' | |||
|
1 | 1 | //---------------------------------------------------------------------------- |
|
2 | 2 | // Copyright (C) 2008-2011 The IPython Development Team |
|
3 | 3 | // |
|
4 | 4 | // Distributed under the terms of the BSD License. The full license is in |
|
5 | 5 | // the file COPYING, distributed as part of this software. |
|
6 | 6 | //---------------------------------------------------------------------------- |
|
7 | 7 | |
|
8 | 8 | //============================================================================ |
|
9 | 9 | // SaveWidget |
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | 12 | var IPython = (function (IPython) { |
|
13 | 13 | |
|
14 | 14 | var utils = IPython.utils; |
|
15 | 15 | |
|
16 | 16 | var SaveWidget = function (selector) { |
|
17 | 17 | this.selector = selector; |
|
18 | 18 | this.notebook_name_re = /[^/\\]+/ |
|
19 | 19 | if (this.selector !== undefined) { |
|
20 | 20 | this.element = $(selector); |
|
21 | 21 | this.style(); |
|
22 | 22 | this.bind_events(); |
|
23 | 23 | } |
|
24 | 24 | }; |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | SaveWidget.prototype.style = function () { |
|
28 | 28 | this.element.find('input#notebook_name').addClass('ui-widget ui-widget-content'); |
|
29 | this.element.find('input#notebook_name').attr('tabindex','1'); | |
|
29 | 30 | this.element.find('button#save_notebook').button(); |
|
30 | 31 | var left_panel_width = $('div#left_panel').outerWidth(); |
|
31 | 32 | var left_panel_splitter_width = $('div#left_panel_splitter').outerWidth(); |
|
32 | 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 | 38 | SaveWidget.prototype.bind_events = function () { |
|
38 | 39 | var that = this; |
|
39 | 40 | this.element.find('button#save_notebook').click(function () { |
|
40 | 41 | IPython.notebook.save_notebook(); |
|
41 | 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 | 50 | SaveWidget.prototype.get_notebook_name = function () { |
|
47 | 51 | return this.element.find('input#notebook_name').attr('value'); |
|
48 | 52 | } |
|
49 | 53 | |
|
50 | 54 | |
|
51 | 55 | SaveWidget.prototype.set_notebook_name = function (nbname) { |
|
52 | 56 | this.element.find('input#notebook_name').attr('value',nbname); |
|
53 | 57 | this.set_document_title(); |
|
54 | 58 | } |
|
55 | 59 | |
|
56 | 60 | |
|
57 | 61 | SaveWidget.prototype.set_document_title = function () { |
|
58 | 62 | nbname = this.get_notebook_name(); |
|
59 | 63 | document.title = 'IPy: ' + nbname; |
|
60 | 64 | }; |
|
61 | 65 | |
|
62 | 66 | |
|
63 | 67 | SaveWidget.prototype.get_notebook_id = function () { |
|
64 | 68 | return this.element.find('span#notebook_id').text() |
|
65 | 69 | }; |
|
66 | 70 | |
|
67 | 71 | |
|
68 | 72 | SaveWidget.prototype.update_url = function () { |
|
69 | 73 | var notebook_id = this.get_notebook_id(); |
|
70 | 74 | if (notebook_id !== '') { |
|
71 | 75 | window.history.replaceState({}, '', notebook_id); |
|
72 | 76 | }; |
|
73 | 77 | }; |
|
74 | 78 | |
|
75 | 79 | |
|
76 | 80 | SaveWidget.prototype.test_notebook_name = function () { |
|
77 | 81 | var nbname = this.get_notebook_name(); |
|
78 | 82 | if (this.notebook_name_re.test(nbname)) { |
|
79 | 83 | return true; |
|
80 | 84 | } else { |
|
81 | 85 | var bad_name = $('<div/>'); |
|
82 | 86 | bad_name.html( |
|
83 | 87 | "The notebook name you entered (" + |
|
84 | 88 | nbname + |
|
85 | 89 | ") is not valid. Notebook names can contain any characters except / and \\" |
|
86 | 90 | ); |
|
87 | 91 | bad_name.dialog({title: 'Invalid name', modal: true}); |
|
88 | 92 | return false; |
|
89 | 93 | }; |
|
90 | 94 | }; |
|
91 | 95 | |
|
92 | 96 | |
|
93 | 97 | SaveWidget.prototype.status_save = function () { |
|
94 | 98 | this.element.find('button#save_notebook').button('option', 'label', 'Save'); |
|
95 | 99 | this.element.find('button#save_notebook').button('enable'); |
|
96 | 100 | IPython.print_widget.enable(); |
|
97 | 101 | }; |
|
98 | 102 | |
|
99 | 103 | |
|
100 | 104 | SaveWidget.prototype.status_saving = function () { |
|
101 | 105 | this.element.find('button#save_notebook').button('option', 'label', 'Saving'); |
|
102 | 106 | this.element.find('button#save_notebook').button('disable'); |
|
103 | 107 | IPython.print_widget.disable(); |
|
104 | 108 | }; |
|
105 | 109 | |
|
106 | 110 | |
|
107 | 111 | SaveWidget.prototype.status_loading = function () { |
|
108 | 112 | this.element.find('button#save_notebook').button('option', 'label', 'Loading'); |
|
109 | 113 | this.element.find('button#save_notebook').button('disable'); |
|
110 | 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 | 125 | IPython.SaveWidget = SaveWidget; |
|
115 | 126 | |
|
116 | 127 | return IPython; |
|
117 | 128 | |
|
118 | 129 | }(IPython)); |
|
119 | 130 |
General Comments 0
You need to be logged in to leave comments.
Login now