##// END OF EJS Templates
ENTER submits the rename notebook dialog.
Brian Granger -
Show More
@@ -1,139 +1,148
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 this.element.find('span#save_widget').addClass('ui-widget');
28 28 this.element.find('span#notebook_name').addClass('ui-widget ui-widget-content');
29 29 this.element.find('span#save_status').addClass('ui-widget ui-widget-content')
30 30 .css({border: 'none', 'margin-left': '20px'});
31 31 };
32 32
33 33
34 34 SaveWidget.prototype.bind_events = function () {
35 35 var that = this;
36 36 this.element.find('span#notebook_name').click(function () {
37 37 that.rename_notebook();
38 38 });
39 39 this.element.find('span#notebook_name').hover(function () {
40 40 $(this).addClass("ui-state-hover");
41 41 }, function () {
42 42 $(this).removeClass("ui-state-hover");
43 43 });
44 44 $([IPython.events]).on('notebook_loaded.Notebook', function () {
45 45 that.set_last_saved();
46 46 that.update_notebook_name();
47 47 that.update_document_title();
48 48 });
49 49 $([IPython.events]).on('notebook_saved.Notebook', function () {
50 50 that.set_last_saved();
51 51 that.update_notebook_name();
52 52 that.update_document_title();
53 53 });
54 54 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
55 55 that.set_save_status('');
56 56 });
57 57 };
58 58
59 59
60 60 SaveWidget.prototype.rename_notebook = function () {
61 61 var that = this;
62 62 var dialog = $('<div/>');
63 63 dialog.append(
64 64 $('<h3/>').html('Enter a new notebook name:')
65 65 .css({'margin-bottom': '10px'})
66 66 );
67 67 dialog.append(
68 68 $('<input/>').attr('type','text').attr('size','25')
69 69 .addClass('ui-widget ui-widget-content')
70 70 .attr('value',IPython.notebook.get_notebook_name())
71 71 );
72 72 // $(document).append(dialog);
73 73 dialog.dialog({
74 74 resizable: false,
75 75 modal: true,
76 76 title: "Rename Notebook",
77 77 closeText: "",
78 78 close: function(event, ui) {$(this).dialog('destroy').remove();},
79 79 buttons : {
80 80 "OK": function () {
81 81 var new_name = $(this).find('input').attr('value');
82 82 if (!IPython.notebook.test_notebook_name(new_name)) {
83 83 $(this).find('h3').html(
84 84 "Invalid notebook name. Notebook names must "+
85 85 "have 1 or more characters and can contain any characters " +
86 86 "except / and \\. Please enter a new notebook name:"
87 87 );
88 88 } else {
89 89 IPython.notebook.set_notebook_name(new_name);
90 90 IPython.notebook.save_notebook();
91 91 $(this).dialog('close');
92 92 }
93 93 },
94 94 "Cancel": function () {
95 95 $(this).dialog('close');
96 96 }
97 },
98 open : function (event, ui) {
99 var that = $(this);
100 // Upon ENTER, click the OK button.
101 that.keydown(function (event, ui) {
102 if (event.which === 13) {
103 that.parent().find('button').first().click();
104 }
105 });
97 106 }
98 107 });
99 108 }
100 109
101 110
102 111 SaveWidget.prototype.update_notebook_name = function () {
103 112 var nbname = IPython.notebook.get_notebook_name();
104 113 this.element.find('span#notebook_name').html(nbname);
105 114 };
106 115
107 116
108 117 SaveWidget.prototype.update_document_title = function () {
109 118 var nbname = IPython.notebook.get_notebook_name();
110 119 document.title = nbname;
111 120 };
112 121
113 122
114 123 SaveWidget.prototype.update_url = function () {
115 124 var notebook_id = IPython.notebook.get_notebook_id();
116 125 if (notebook_id !== null) {
117 126 var new_url = $('body').data('baseProjectUrl') + notebook_id;
118 127 window.history.replaceState({}, '', new_url);
119 128 };
120 129 };
121 130
122 131
123 132 SaveWidget.prototype.set_save_status = function (msg) {
124 133 this.element.find('span#save_status').html(msg);
125 134 }
126 135
127 136
128 137 SaveWidget.prototype.set_last_saved = function () {
129 138 var d = new Date();
130 139 this.set_save_status('Last saved: '+d.format('mmm dd h:MM TT'));
131 140 };
132 141
133 142
134 143 IPython.SaveWidget = SaveWidget;
135 144
136 145 return IPython;
137 146
138 147 }(IPython));
139 148
General Comments 0
You need to be logged in to leave comments. Login now