##// END OF EJS Templates
Use NotificationArea in the text editor
Thomas Kluyver -
Show More
@@ -0,0 +1,83
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
3
4 define([
5 'jquery',
6 'base/js/notificationwidget',
7 ], function($, notificationwidget) {
8 "use strict";
9
10 // store reference to the NotificationWidget class
11 var NotificationWidget = notificationwidget.NotificationWidget;
12
13 /**
14 * Construct the NotificationArea object. Options are:
15 * events: $(Events) instance
16 * save_widget: SaveWidget instance
17 * notebook: Notebook instance
18 * keyboard_manager: KeyboardManager instance
19 *
20 * @constructor
21 * @param {string} selector - a jQuery selector string for the
22 * notification area element
23 * @param {Object} [options] - a dictionary of keyword arguments.
24 */
25 var NotificationArea = function (selector, options) {
26 this.selector = selector;
27 this.events = options.events;
28 if (this.selector !== undefined) {
29 this.element = $(selector);
30 }
31 this.widget_dict = {};
32 };
33
34 /**
35 * Get a widget by name, creating it if it doesn't exist.
36 *
37 * @method widget
38 * @param {string} name - the widget name
39 */
40 NotificationArea.prototype.widget = function (name) {
41 if (this.widget_dict[name] === undefined) {
42 return this.new_notification_widget(name);
43 }
44 return this.get_widget(name);
45 };
46
47 /**
48 * Get a widget by name, throwing an error if it doesn't exist.
49 *
50 * @method get_widget
51 * @param {string} name - the widget name
52 */
53 NotificationArea.prototype.get_widget = function (name) {
54 if(this.widget_dict[name] === undefined) {
55 throw('no widgets with this name');
56 }
57 return this.widget_dict[name];
58 };
59
60 /**
61 * Create a new notification widget with the given name. The
62 * widget must not already exist.
63 *
64 * @method new_notification_widget
65 * @param {string} name - the widget name
66 */
67 NotificationArea.prototype.new_notification_widget = function (name) {
68 if (this.widget_dict[name] !== undefined) {
69 throw('widget with that name already exists!');
70 }
71
72 // create the element for the notification widget and add it
73 // to the notification aread element
74 var div = $('<div/>').attr('id', 'notification_' + name);
75 $(this.selector).append(div);
76
77 // create the widget object and return it
78 this.widget_dict[name] = new NotificationWidget('#notification_' + name);
79 return this.widget_dict[name];
80 };
81
82 return {'NotificationArea': NotificationArea};
83 });
@@ -0,0 +1,34
1 define([
2 'base/js/namespace',
3 'jquery',
4 'base/js/utils',
5 'base/js/dialog',
6 'base/js/notificationarea',
7 'moment'
8 ], function(IPython, $, utils, dialog, notificationarea, moment) {
9 "use strict";
10 var NotificationArea = notificationarea.NotificationArea;
11
12 var EditorNotificationArea = function(selector, options) {
13 NotificationArea.apply(this, [selector, options]);
14 }
15
16 EditorNotificationArea.prototype = Object.create(NotificationArea.prototype);
17
18 /**
19 * Initialize the default set of notification widgets.
20 *
21 * @method init_notification_widgets
22 */
23 EditorNotificationArea.prototype.init_notification_widgets = function () {
24 var that = this;
25 var enw = this.new_notification_widget('editor');
26
27 this.events.on("save_succeeded.TextEditor", function() {
28 enw.set_message("File saved", 2000);
29 });
30 };
31
32
33 return {EditorNotificationArea: EditorNotificationArea};
34 });
1 NO CONTENT: file renamed from IPython/html/static/notebook/js/notificationwidget.js to IPython/html/static/base/js/notificationwidget.js
@@ -98,7 +98,7 require([
98 98 save_widget: save_widget,
99 99 quick_help: quick_help},
100 100 common_options));
101 var notification_area = new notificationarea.NotificationArea(
101 var notification_area = new notificationarea.NotebookNotificationArea(
102 102 '#notification_area', {
103 103 events: events,
104 104 save_widget: save_widget,
@@ -1,97 +1,29
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
3
4 1 define([
5 2 'base/js/namespace',
6 3 'jquery',
7 4 'base/js/utils',
8 5 'base/js/dialog',
9 'notebook/js/notificationwidget',
6 'base/js/notificationarea',
10 7 'moment'
11 ], function(IPython, $, utils, dialog, notificationwidget, moment) {
8 ], function(IPython, $, utils, dialog, notificationarea, moment) {
12 9 "use strict";
13
14 // store reference to the NotificationWidget class
15 var NotificationWidget = notificationwidget.NotificationWidget;
16
17 /**
18 * Construct the NotificationArea object. Options are:
19 * events: $(Events) instance
20 * save_widget: SaveWidget instance
21 * notebook: Notebook instance
22 * keyboard_manager: KeyboardManager instance
23 *
24 * @constructor
25 * @param {string} selector - a jQuery selector string for the
26 * notification area element
27 * @param {Object} [options] - a dictionary of keyword arguments.
28 */
29 var NotificationArea = function (selector, options) {
30 this.selector = selector;
31 this.events = options.events;
10 var NotificationArea = notificationarea.NotificationArea;
11
12 var NotebookNotificationArea = function(selector, options) {
13 NotificationArea.apply(this, [selector, options]);
32 14 this.save_widget = options.save_widget;
33 15 this.notebook = options.notebook;
34 16 this.keyboard_manager = options.keyboard_manager;
35 if (this.selector !== undefined) {
36 this.element = $(selector);
37 }
38 this.widget_dict = {};
39 };
40
41 /**
42 * Get a widget by name, creating it if it doesn't exist.
43 *
44 * @method widget
45 * @param {string} name - the widget name
46 */
47 NotificationArea.prototype.widget = function (name) {
48 if (this.widget_dict[name] === undefined) {
49 return this.new_notification_widget(name);
50 }
51 return this.get_widget(name);
52 };
53
54 /**
55 * Get a widget by name, throwing an error if it doesn't exist.
56 *
57 * @method get_widget
58 * @param {string} name - the widget name
59 */
60 NotificationArea.prototype.get_widget = function (name) {
61 if(this.widget_dict[name] === undefined) {
62 throw('no widgets with this name');
63 }
64 return this.widget_dict[name];
65 };
66
67 /**
68 * Create a new notification widget with the given name. The
69 * widget must not already exist.
70 *
71 * @method new_notification_widget
72 * @param {string} name - the widget name
73 */
74 NotificationArea.prototype.new_notification_widget = function (name) {
75 if (this.widget_dict[name] !== undefined) {
76 throw('widget with that name already exists!');
77 }
78
79 // create the element for the notification widget and add it
80 // to the notification aread element
81 var div = $('<div/>').attr('id', 'notification_' + name);
82 $(this.selector).append(div);
83
84 // create the widget object and return it
85 this.widget_dict[name] = new NotificationWidget('#notification_' + name);
86 return this.widget_dict[name];
87 };
88
17 }
18
19 NotebookNotificationArea.prototype = Object.create(NotificationArea.prototype);
20
89 21 /**
90 22 * Initialize the default set of notification widgets.
91 23 *
92 24 * @method init_notification_widgets
93 25 */
94 NotificationArea.prototype.init_notification_widgets = function () {
26 NotebookNotificationArea.prototype.init_notification_widgets = function () {
95 27 this.init_kernel_notification_widget();
96 28 this.init_notebook_notification_widget();
97 29 };
@@ -101,7 +33,7 define([
101 33 *
102 34 * @method init_kernel_notification_widget
103 35 */
104 NotificationArea.prototype.init_kernel_notification_widget = function () {
36 NotebookNotificationArea.prototype.init_kernel_notification_widget = function () {
105 37 var that = this;
106 38 var knw = this.new_notification_widget('kernel');
107 39 var $kernel_ind_icon = $("#kernel_indicator_icon");
@@ -324,7 +256,7 define([
324 256 *
325 257 * @method init_notebook_notification_widget
326 258 */
327 NotificationArea.prototype.init_notebook_notification_widget = function () {
259 NotebookNotificationArea.prototype.init_notebook_notification_widget = function () {
328 260 var nnw = this.new_notification_widget('notebook');
329 261
330 262 // Notebook events
@@ -381,7 +313,8 define([
381 313 });
382 314 };
383 315
384 IPython.NotificationArea = NotificationArea;
385
386 return {'NotificationArea': NotificationArea};
316 // Backwards compatibility.
317 IPython.NotificationArea = NotebookNotificationArea;
318
319 return {'NotebookNotificationArea': NotebookNotificationArea};
387 320 });
@@ -63,10 +63,8 function($,
63 63 content: this.codemirror.getValue(),
64 64 };
65 65 var that = this;
66 this.contents.save(this.file_path, model, {
67 success: function() {
68 that.events.trigger("save_succeeded.TextEditor");
69 }
66 this.contents.save(this.file_path, model).then(function() {
67 that.events.trigger("save_succeeded.TextEditor");
70 68 });
71 69 };
72 70
@@ -10,6 +10,7 require([
10 10 'contents',
11 11 'texteditor/js/editor',
12 12 'texteditor/js/menubar',
13 'texteditor/js/notificationarea',
13 14 'custom/custom',
14 15 ], function(
15 16 $,
@@ -19,7 +20,8 require([
19 20 events,
20 21 contents,
21 22 editor,
22 menubar
23 menubar,
24 notificationarea
23 25 ){
24 26 page = new page.Page();
25 27
@@ -41,6 +43,12 require([
41 43 base_url: base_url,
42 44 editor: editor,
43 45 });
46
47 var notification_area = new notificationarea.EditorNotificationArea(
48 '#notification_area', {
49 events: events,
50 });
51 notification_area.init_notification_widgets();
44 52
45 53 editor.load();
46 54 page.show();
@@ -27,12 +27,6 data-file-path="{{file_path}}"
27 27 <span class="navbar-text">Menu</span>
28 28 </button>
29 29 <ul class="nav navbar-nav navbar-right">
30 <li id="kernel_indicator">
31 <i id="kernel_indicator_icon"></i>
32 </li>
33 <li id="modal_indicator">
34 <i id="modal_indicator_icon"></i>
35 </li>
36 30 <li id="notification_area"></li>
37 31 </ul>
38 32 <div class="navbar-collapse collapse">
General Comments 0
You need to be logged in to leave comments. Login now