##// END OF EJS Templates
review pass on multidir js
MinRK -
Show More
@@ -36,8 +36,8 b' var IPython = (function (IPython) {'
36 * does not support change for now is set through this option
36 * does not support change for now is set through this option
37 */
37 */
38 var MenuBar = function (selector, options) {
38 var MenuBar = function (selector, options) {
39 var options = options || {};
39 options = options || {};
40 if(options.baseProjectUrl!= undefined){
40 if (options.baseProjectUrl !== undefined) {
41 this._baseProjectUrl = options.baseProjectUrl;
41 this._baseProjectUrl = options.baseProjectUrl;
42 }
42 }
43 this.selector = selector;
43 this.selector = selector;
@@ -55,7 +55,7 b' var IPython = (function (IPython) {'
55 MenuBar.prototype.notebookPath = function() {
55 MenuBar.prototype.notebookPath = function() {
56 var path = $('body').data('notebookPath');
56 var path = $('body').data('notebookPath');
57 path = decodeURIComponent(path);
57 path = decodeURIComponent(path);
58 return path
58 return path;
59 };
59 };
60
60
61 MenuBar.prototype.style = function () {
61 MenuBar.prototype.style = function () {
@@ -77,7 +77,11 b' var IPython = (function (IPython) {'
77 IPython.notebook.new_notebook();
77 IPython.notebook.new_notebook();
78 });
78 });
79 this.element.find('#open_notebook').click(function () {
79 this.element.find('#open_notebook').click(function () {
80 window.open(that.baseProjectUrl() + 'tree' + that.notebookPath());
80 window.open(utils.url_path_join(
81 that.baseProjectUrl(),
82 'tree',
83 that.notebookPath()
84 ));
81 });
85 });
82 this.element.find('#copy_notebook').click(function () {
86 this.element.find('#copy_notebook').click(function () {
83 IPython.notebook.copy_notebook();
87 IPython.notebook.copy_notebook();
@@ -260,7 +264,7 b' var IPython = (function (IPython) {'
260 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
264 MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
261 var ul = this.element.find("#restore_checkpoint").find("ul");
265 var ul = this.element.find("#restore_checkpoint").find("ul");
262 ul.empty();
266 ul.empty();
263 if (! checkpoints || checkpoints.length == 0) {
267 if (!checkpoints || checkpoints.length === 0) {
264 ul.append(
268 ul.append(
265 $("<li/>")
269 $("<li/>")
266 .addClass("disabled")
270 .addClass("disabled")
@@ -270,7 +274,7 b' var IPython = (function (IPython) {'
270 )
274 )
271 );
275 );
272 return;
276 return;
273 };
277 }
274
278
275 checkpoints.map(function (checkpoint) {
279 checkpoints.map(function (checkpoint) {
276 var d = new Date(checkpoint.last_modified);
280 var d = new Date(checkpoint.last_modified);
@@ -128,8 +128,12 b' var IPython = (function (IPython) {'
128 SaveWidget.prototype.update_address_bar = function(){
128 SaveWidget.prototype.update_address_bar = function(){
129 var nbname = IPython.notebook.notebook_name;
129 var nbname = IPython.notebook.notebook_name;
130 var path = IPython.notebook.notebookPath();
130 var path = IPython.notebook.notebookPath();
131 var state = {"path": path+nbname}
131 var state = {path : utils.url_path_join(path,nbname)};
132 window.history.replaceState(state, "", "/notebooks" + path+nbname);
132 window.history.replaceState(state, "", utils.url_path_join(
133 "/notebooks",
134 path,
135 nbname)
136 );
133 }
137 }
134
138
135
139
@@ -72,18 +72,17 b' var IPython = (function (IPython) {'
72 * Start the Python kernel
72 * Start the Python kernel
73 * @method start
73 * @method start
74 */
74 */
75 Kernel.prototype.start = function (params) {
75 Kernel.prototype.start = function (params) {
76 var that = this;
76 params = params || {};
77 params = params || {};
77 if (!this.running) {
78 if (!this.running) {
78 var qs = $.param(params);
79 var qs = $.param(params);
79 var url = this.base_url + '?' + qs;
80 var url = this.base_url + '?' + qs;
80 $.post(url,
81 $.post(url,
81 $.proxy(this._kernel_started, this),
82 $.proxy(that._kernel_started,that),
82 'json'
83 'json'
83 );
84 );
84 };
85 };
85 };
86 };
87
86
88 /**
87 /**
89 * Restart the python kernel.
88 * Restart the python kernel.
@@ -95,12 +94,11 b' var IPython = (function (IPython) {'
95 */
94 */
96 Kernel.prototype.restart = function () {
95 Kernel.prototype.restart = function () {
97 $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
96 $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this});
98 var that = this;
99 if (this.running) {
97 if (this.running) {
100 this.stop_channels();
98 this.stop_channels();
101 var url = this.kernel_url + "/restart";
99 var url = utils.url_path_join(this.kernel_url, "restart");
102 $.post(url,
100 $.post(url,
103 $.proxy(that._kernel_started, that),
101 $.proxy(this._kernel_started, this),
104 'json'
102 'json'
105 );
103 );
106 };
104 };
@@ -118,14 +116,14 b' var IPython = (function (IPython) {'
118 ws_url = prot + location.host + ws_url;
116 ws_url = prot + location.host + ws_url;
119 };
117 };
120 this.ws_url = ws_url;
118 this.ws_url = ws_url;
121 this.kernel_url = this.base_url + "/" + this.kernel_id;
119 this.kernel_url = utils.url_path_join(this.base_url, this.kernel_id);
122 this.start_channels();
120 this.start_channels();
123 };
121 };
124
122
125
123
126 Kernel.prototype._websocket_closed = function(ws_url, early) {
124 Kernel.prototype._websocket_closed = function(ws_url, early) {
127 this.stop_channels();
125 this.stop_channels();
128 $([IPython.events]).trigger('websocket_closed.Kernel',
126 $([IPython.events]).trigger('websocket_closed.Kernel',
129 {ws_url: ws_url, kernel: this, early: early}
127 {ws_url: ws_url, kernel: this, early: early}
130 );
128 );
131 };
129 };
@@ -1,5 +1,5 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2013 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
@@ -10,45 +10,58 b''
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13 "use strict";
13
14
14 var Session = function(notebook_name, notebook_path, Notebook){
15 var utils = IPython.utils;
16
17 var Session = function(notebook_name, notebook_path, notebook){
15 this.kernel = null;
18 this.kernel = null;
16 this.id = null;
19 this.id = null;
17 this.name = notebook_name;
20 this.name = notebook_name;
18 this.path = notebook_path;
21 this.path = notebook_path;
19 this.notebook = Notebook;
22 this.notebook = notebook;
20 this._baseProjectUrl = Notebook.baseProjectUrl()
23 this._baseProjectUrl = notebook.baseProjectUrl();
21 };
24 };
22
25
23 Session.prototype.start = function() {
26 Session.prototype.start = function() {
24 var that = this
27 var that = this;
25 var notebook = {'notebook':{'name': this.name, 'path': this.path}}
28 var model = {
29 notebook : {
30 name : this.name,
31 path : this.path
32 }
33 };
26 var settings = {
34 var settings = {
27 processData : false,
35 processData : false,
28 cache : false,
36 cache : false,
29 type : "POST",
37 type : "POST",
30 data: JSON.stringify(notebook),
38 data: JSON.stringify(model),
31 dataType : "json",
39 dataType : "json",
32 success : $.proxy(this.start_kernel, that),
40 success : $.proxy(this.start_kernel, that),
33 };
41 };
34 var url = this._baseProjectUrl + 'api/sessions';
42 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions');
35 $.ajax(url, settings);
43 $.ajax(url, settings);
36 };
44 };
37
45
38 Session.prototype.notebook_rename = function (name, path) {
46 Session.prototype.notebook_rename = function (name, path) {
39 this.name = name;
47 this.name = name;
40 this.path = path;
48 this.path = path;
41 var notebook = {'notebook':{'name':name, 'path': path}};
49 var model = {
50 notebook : {
51 name : this.name,
52 path : this.path
53 }
54 };
42 var settings = {
55 var settings = {
43 processData : false,
56 processData : false,
44 cache : false,
57 cache : false,
45 type : "PATCH",
58 type : "PATCH",
46 data: JSON.stringify(notebook),
59 data: JSON.stringify(model),
47 dataType : "json",
60 dataType : "json",
48 };
61 };
49 var url = this._baseProjectUrl + 'api/sessions/' + this.session_id;
62 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.session_id);
50 $.ajax(url, settings);
63 $.ajax(url, settings);
51 }
64 };
52
65
53 Session.prototype.delete_session = function() {
66 Session.prototype.delete_session = function() {
54 var settings = {
67 var settings = {
@@ -57,7 +70,7 b' var IPython = (function (IPython) {'
57 type : "DELETE",
70 type : "DELETE",
58 dataType : "json",
71 dataType : "json",
59 };
72 };
60 var url = this._baseProjectUrl + 'api/sessions/' + this.session_id;
73 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.session_id);
61 $.ajax(url, settings);
74 $.ajax(url, settings);
62 };
75 };
63
76
@@ -70,7 +83,7 b' var IPython = (function (IPython) {'
70 Session.prototype.start_kernel = function (json) {
83 Session.prototype.start_kernel = function (json) {
71 this.id = json.id;
84 this.id = json.id;
72 this.kernel_content = json.kernel;
85 this.kernel_content = json.kernel;
73 var base_url = $('body').data('baseKernelUrl') + "api/kernels";
86 var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels");
74 this.kernel = new IPython.Kernel(base_url, this.session_id);
87 this.kernel = new IPython.Kernel(base_url, this.session_id);
75 this.kernel._kernel_started(this.kernel_content);
88 this.kernel._kernel_started(this.kernel_content);
76 };
89 };
@@ -90,12 +103,11 b' var IPython = (function (IPython) {'
90
103
91
104
92 Session.prototype.kill_kernel = function() {
105 Session.prototype.kill_kernel = function() {
93 this.kernel.kill();
106 this.kernel.kill();
94 };
107 };
95
108
96 IPython.Session = Session;
109 IPython.Session = Session;
97
110
98
99 return IPython;
111 return IPython;
100
112
101 }(IPython));
113 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now