sessionlist.js
56 lines
| 1.6 KiB
| application/javascript
|
JavascriptLexer
Jonathan Frederic
|
r17190 | // Copyright (c) IPython Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||||
Paul Ivanov
|
r15479 | |||
Jonathan Frederic
|
r17190 | define([ | ||
'base/js/namespace', | ||||
Jonathan Frederic
|
r17200 | 'jquery', | ||
Jonathan Frederic
|
r17190 | 'base/js/utils', | ||
Jonathan Frederic
|
r17198 | ], function(IPython, $, utils) { | ||
Paul Ivanov
|
r15479 | "use strict"; | ||
jon
|
r17211 | var SesssionList = function (options) { | ||
// Constructor | ||||
// | ||||
// Parameters: | ||||
// options: dictionary | ||||
// Dictionary of keyword arguments. | ||||
// events: $(Events) instance | ||||
// base_url : string | ||||
jon
|
r17210 | this.events = options.events; | ||
Paul Ivanov
|
r15479 | this.sessions = {}; | ||
Jonathan Frederic
|
r17198 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); | ||
Paul Ivanov
|
r15479 | }; | ||
SesssionList.prototype.load_sessions = function(){ | ||||
var that = this; | ||||
var settings = { | ||||
processData : false, | ||||
cache : false, | ||||
type : "GET", | ||||
dataType : "json", | ||||
MinRK
|
r16445 | success : $.proxy(that.sessions_loaded, this), | ||
Jonathan Frederic
|
r17198 | error : utils.log_ajax_error, | ||
Paul Ivanov
|
r15479 | }; | ||
Jonathan Frederic
|
r17198 | var url = utils.url_join_encode(this.base_url, 'api/sessions'); | ||
Paul Ivanov
|
r15518 | $.ajax(url, settings); | ||
Paul Ivanov
|
r15479 | }; | ||
SesssionList.prototype.sessions_loaded = function(data){ | ||||
this.sessions = {}; | ||||
var len = data.length; | ||||
Paul Ivanov
|
r15513 | var nb_path; | ||
for (var i=0; i<len; i++) { | ||||
Jonathan Frederic
|
r17198 | nb_path = utils.url_path_join( | ||
Paul Ivanov
|
r15513 | data[i].notebook.path, | ||
data[i].notebook.name | ||||
); | ||||
this.sessions[nb_path] = data[i].id; | ||||
Paul Ivanov
|
r15479 | } | ||
Jonathan Frederic
|
r17195 | this.events.trigger('sessions_loaded.Dashboard', this.sessions); | ||
Paul Ivanov
|
r15479 | }; | ||
Jonathan Frederic
|
r17190 | // Backwards compatability. | ||
IPython.SesssionList = SesssionList; | ||||
Paul Ivanov
|
r15479 | |||
Jonathan Frederic
|
r17201 | return {'SesssionList': SesssionList}; | ||
Jonathan Frederic
|
r17190 | }); | ||