##// END OF EJS Templates
remove empty style function of save widget
Matthias BUSSONNIER -
Show More
@@ -1,177 +1,173 b''
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 define([
5 5 'base/js/namespace',
6 6 'jquery',
7 7 'base/js/utils',
8 8 'base/js/dialog',
9 9 'base/js/keyboard',
10 10 'dateformat',
11 11 ], function(IPython, $, utils, dialog, keyboard) {
12 12 "use strict";
13 13
14 14 var SaveWidget = function (selector, options) {
15 15 // TODO: Remove circulat ref.
16 16 this.notebook = undefined;
17 17 this.selector = selector;
18 18 this.events = options.events;
19 19 this.keyboard_manager = options.keyboard_manager;
20 20 if (this.selector !== undefined) {
21 21 this.element = $(selector);
22 this.style();
23 22 this.bind_events();
24 23 }
25 24 };
26 25
27 SaveWidget.prototype.style = function () {
28 };
29
30 26
31 27 SaveWidget.prototype.bind_events = function () {
32 28 var that = this;
33 29 this.element.find('span#notebook_name').click(function () {
34 30 that.rename_notebook();
35 31 });
36 32 this.element.find('span#notebook_name').hover(function () {
37 33 $(this).addClass("ui-state-hover");
38 34 }, function () {
39 35 $(this).removeClass("ui-state-hover");
40 36 });
41 37 this.events.on('notebook_loaded.Notebook', function () {
42 38 that.update_notebook_name();
43 39 that.update_document_title();
44 40 });
45 41 this.events.on('notebook_saved.Notebook', function () {
46 42 that.update_notebook_name();
47 43 that.update_document_title();
48 44 });
49 45 this.events.on('notebook_renamed.Notebook', function () {
50 46 that.update_notebook_name();
51 47 that.update_document_title();
52 48 that.update_address_bar();
53 49 });
54 50 this.events.on('notebook_save_failed.Notebook', function () {
55 51 that.set_save_status('Autosave Failed!');
56 52 });
57 53 this.events.on('checkpoints_listed.Notebook', function (event, data) {
58 54 that.set_last_checkpoint(data[0]);
59 55 });
60 56
61 57 this.events.on('checkpoint_created.Notebook', function (event, data) {
62 58 that.set_last_checkpoint(data);
63 59 });
64 60 this.events.on('set_dirty.Notebook', function (event, data) {
65 61 that.set_autosaved(data.value);
66 62 });
67 63 };
68 64
69 65
70 66 SaveWidget.prototype.rename_notebook = function (options) {
71 67 options = options || {};
72 68 var that = this;
73 69 var dialog_body = $('<div/>').append(
74 70 $("<p/>").addClass("rename-message")
75 71 .text('Enter a new notebook name:')
76 72 ).append(
77 73 $("<br/>")
78 74 ).append(
79 75 $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
80 76 .val(that.notebook.get_notebook_name())
81 77 );
82 78 dialog.modal({
83 79 title: "Rename Notebook",
84 80 body: dialog_body,
85 81 notebook: options.notebook,
86 82 keyboard_manager: this.keyboard_manager,
87 83 buttons : {
88 84 "Cancel": {},
89 85 "OK": {
90 86 class: "btn-primary",
91 87 click: function () {
92 88 var new_name = $(this).find('input').val();
93 89 if (!that.notebook.test_notebook_name(new_name)) {
94 90 $(this).find('.rename-message').text(
95 91 "Invalid notebook name. Notebook names must "+
96 92 "have 1 or more characters and can contain any characters " +
97 93 "except :/\\. Please enter a new notebook name:"
98 94 );
99 95 return false;
100 96 } else {
101 97 that.notebook.rename(new_name);
102 98 }
103 99 }}
104 100 },
105 101 open : function (event, ui) {
106 102 var that = $(this);
107 103 // Upon ENTER, click the OK button.
108 104 that.find('input[type="text"]').keydown(function (event, ui) {
109 105 if (event.which === keyboard.keycodes.enter) {
110 106 that.find('.btn-primary').first().click();
111 107 return false;
112 108 }
113 109 });
114 110 that.find('input[type="text"]').focus().select();
115 111 }
116 112 });
117 113 };
118 114
119 115
120 116 SaveWidget.prototype.update_notebook_name = function () {
121 117 var nbname = this.notebook.get_notebook_name();
122 118 this.element.find('span#notebook_name').text(nbname);
123 119 };
124 120
125 121
126 122 SaveWidget.prototype.update_document_title = function () {
127 123 var nbname = this.notebook.get_notebook_name();
128 124 document.title = nbname;
129 125 };
130 126
131 127 SaveWidget.prototype.update_address_bar = function(){
132 128 var base_url = this.notebook.base_url;
133 129 var nbname = this.notebook.notebook_name;
134 130 var path = this.notebook.notebook_path;
135 131 var state = {path : path, name: nbname};
136 132 window.history.replaceState(state, "", utils.url_join_encode(
137 133 base_url,
138 134 "notebooks",
139 135 path,
140 136 nbname)
141 137 );
142 138 };
143 139
144 140
145 141 SaveWidget.prototype.set_save_status = function (msg) {
146 142 this.element.find('span#autosave_status').text(msg);
147 143 };
148 144
149 145 SaveWidget.prototype.set_checkpoint_status = function (msg) {
150 146 this.element.find('span#checkpoint_status').text(msg);
151 147 };
152 148
153 149 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
154 150 if (!checkpoint) {
155 151 this.set_checkpoint_status("");
156 152 return;
157 153 }
158 154 var d = new Date(checkpoint.last_modified);
159 155 this.set_checkpoint_status(
160 156 "Last Checkpoint: " + d.format('mmm dd HH:MM')
161 157 );
162 158 };
163 159
164 160 SaveWidget.prototype.set_autosaved = function (dirty) {
165 161 if (dirty) {
166 162 this.set_save_status("(unsaved changes)");
167 163 } else {
168 164 this.set_save_status("(autosaved)");
169 165 }
170 166 };
171 167
172 168 // Backwards compatability.
173 169 IPython.SaveWidget = SaveWidget;
174 170
175 171 return {'SaveWidget': SaveWidget};
176 172
177 173 });
General Comments 0
You need to be logged in to leave comments. Login now