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