##// END OF EJS Templates
jslint 1
Matthias BUSSONNIER -
Show More
@@ -1,141 +1,141 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2012 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 // Notification widget
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13 "use strict";
14 14 var utils = IPython.utils;
15 15
16 16
17 17 var NotificationArea = function (selector) {
18 18 this.selector = selector;
19 19 if (this.selector !== undefined) {
20 20 this.element = $(selector);
21 21 }
22 22 this.widget_dict = {};
23 23 };
24 24
25 25 NotificationArea.prototype.temp_message = function (msg, timeout, css_class) {
26 26 var uuid = utils.uuid();
27 if( css_class == 'danger'){css_class = 'ui-state-error'}
28 if( css_class == 'warning'){css_class = 'ui-state-highlight'}
27 if( css_class == 'danger') {css_class = 'ui-state-error';}
28 if( css_class == 'warning') {css_class = 'ui-state-highlight';}
29 29 var tdiv = $('<div>')
30 30 .attr('id',uuid)
31 31 .addClass('notification_widget ui-widget ui-widget-content ui-corner-all')
32 32 .addClass('border-box-sizing')
33 33 .addClass(css_class)
34 34 .hide()
35 35 .text(msg);
36 36
37 37 $(this.selector).append(tdiv);
38 38 var tmout = Math.max(1500,(timeout||1500));
39 39 tdiv.fadeIn(100);
40 40
41 41 setTimeout(function () {
42 42 tdiv.fadeOut(100, function () {tdiv.remove();});
43 }, tmout)
43 }, tmout);
44 44 };
45 45
46 NotificationArea.prototype.widget = function(name){
47 if(this.widget_dict[name] == undefined){
48 return this.new_notification_widget(name)
46 NotificationArea.prototype.widget = function(name) {
47 if(this.widget_dict[name] == undefined) {
48 return this.new_notification_widget(name);
49 49 }
50 return this.get_widget(name)
51 }
50 return this.get_widget(name);
51 };
52 52
53 53 NotificationArea.prototype.get_widget = function(name) {
54 if(this.widget_dict[name] == undefined){
54 if(this.widget_dict[name] == undefined) {
55 55 throw('no widgets with this name');
56 56 }
57 57 return this.widget_dict[name];
58 }
58 };
59 59
60 60 NotificationArea.prototype.new_notification_widget = function(name) {
61 if(this.widget_dict[name] != undefined){
61 if(this.widget_dict[name] != undefined) {
62 62 throw('widget with that name already exists ! ');
63 63 }
64 64 var div = $('<div/>').attr('id','notification_'+name);
65 $(this.selector).append(div)
66 this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name)
65 $(this.selector).append(div);
66 this.widget_dict[name] = new IPython.NotificationWidget('#notification_'+name);
67 67 return this.widget_dict[name];
68 }
68 };
69 69
70 70 NotificationArea.prototype.init_notification_widgets = function() {
71 71 var knw = this.new_notification_widget('kernel');
72 72
73 73 // Kernel events
74 74 $([IPython.events]).on('status_idle.Kernel',function () {
75 75 IPython.save_widget.update_document_title();
76 76 knw.set_message('Kernel Idle',200);
77 77 }
78 78 );
79 79
80 80 $([IPython.events]).on('status_busy.Kernel',function () {
81 81 window.document.title='(Busy) '+window.document.title;
82 82 knw.set_message("Kernel busy");
83 83 });
84 84
85 85 $([IPython.events]).on('status_restarting.Kernel',function () {
86 86 IPython.save_widget.update_document_title();
87 87 knw.set_message("Restarting kernel",1000);
88 88 });
89 89
90 90 $([IPython.events]).on('status_interrupting.Kernel',function () {
91 91 knw.set_message("Interrupting kernel");
92 92 });
93 93
94 94 $([IPython.events]).on('status_dead.Kernel',function () {
95 95 var dialog = $('<div/>');
96 96 dialog.html('The kernel has died, would you like to restart it? If you do not restart the kernel, you will be able to save the notebook, but running code will not work until the notebook is reopened.');
97 97 $(document).append(dialog);
98 98 dialog.dialog({
99 99 resizable: false,
100 100 modal: true,
101 101 title: "Dead kernel",
102 102 buttons : {
103 103 "Restart": function () {
104 104 $([IPython.events]).trigger('status_restarting.Kernel');
105 105 IPython.notebook.start_kernel();
106 106 $(this).dialog('close');
107 107 },
108 108 "Continue running": function () {
109 109 $(this).dialog('close');
110 110 }
111 111 }
112 112 });
113 113 });
114 114
115 115 var nnw = this.new_notification_widget('notebook');
116 116
117 117 // Notebook events
118 118 $([IPython.events]).on('notebook_loading.Notebook', function () {
119 119 nnw.set_message("Loading notebook",500);
120 120 });
121 121 $([IPython.events]).on('notebook_loaded.Notebook', function () {
122 122 nnw.set_message("Notebook loaded",500);
123 123 });
124 124 $([IPython.events]).on('notebook_saving.Notebook', function () {
125 125 nnw.set_message("Saving notebook",500);
126 126 });
127 127 $([IPython.events]).on('notebook_saved.Notebook', function () {
128 128 nnw.set_message("Notebook saved",2000);
129 129 });
130 130 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
131 131 nnw.set_message("Notebook save failed");
132 132 });
133 133
134 }
134 };
135 135
136 136 IPython.NotificationArea = NotificationArea;
137 137
138 138 return IPython;
139 139
140 140 }(IPython));
141 141
General Comments 0
You need to be logged in to leave comments. Login now