##// END OF EJS Templates
Close new window on error creating terminal
Thomas Kluyver -
Show More
@@ -1,117 +1,120
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 'base/js/utils',
7 7 'jquery',
8 8 'tree/js/notebooklist',
9 9 ], function(IPython, utils, $, notebooklist) {
10 10 "use strict";
11 11
12 12 var TerminalList = function (selector, options) {
13 13 // Constructor
14 14 //
15 15 // Parameters:
16 16 // selector: string
17 17 // options: dictionary
18 18 // Dictionary of keyword arguments.
19 19 // base_url: string
20 20 this.base_url = options.base_url || utils.get_body_data("baseUrl");
21 21 this.element_name = options.element_name || 'terminal';
22 22 this.selector = selector;
23 23 this.terminals = [];
24 24 if (this.selector !== undefined) {
25 25 this.element = $(selector);
26 26 this.style();
27 27 this.bind_events();
28 28 this.load_terminals();
29 29 }
30 30 };
31 31
32 32 TerminalList.prototype = Object.create(notebooklist.NotebookList.prototype);
33 33
34 34 TerminalList.prototype.bind_events = function () {
35 35 var that = this;
36 36 $('#refresh_' + this.element_name + '_list').click(function () {
37 37 that.load_terminals();
38 38 });
39 39 $('#new_terminal').click($.proxy(this.new_terminal, this));
40 40 };
41 41
42 42 TerminalList.prototype.new_terminal = function () {
43 43 var w = window.open();
44 44 var base_url = this.base_url;
45 45 var settings = {
46 46 type : "POST",
47 47 dataType: "json",
48 48 success : function (data, status, xhr) {
49 49 var name = data.name;
50 50 w.location = utils.url_join_encode(base_url, 'terminals', name);
51 51 },
52 error : utils.log_ajax_error,
52 error : function(jqXHR, status, error){
53 w.close();
54 utils.log_ajax_error(jqXHR, status, error);
55 },
53 56 };
54 57 var url = utils.url_join_encode(
55 58 this.base_url,
56 59 'api/terminals'
57 60 );
58 61 $.ajax(url, settings);
59 62 };
60 63
61 64 TerminalList.prototype.load_terminals = function() {
62 65 var that = this;
63 66 var url = utils.url_join_encode(this.base_url, 'api/terminals');
64 67 $.ajax(url, {
65 68 type: "GET",
66 69 cache: false,
67 70 dataType: "json",
68 71 success: $.proxy(this.terminals_loaded, this),
69 72 error : utils.log_ajax_error
70 73 });
71 74 };
72 75
73 76 TerminalList.prototype.terminals_loaded = function (data) {
74 77 this.terminals = data;
75 78 this.clear_list();
76 79 var item, path_name, term;
77 80 for (var i=0; i < this.terminals.length; i++) {
78 81 term = this.terminals[i];
79 82 item = this.new_item(-1);
80 83 this.add_link(term.name, item);
81 84 this.add_shutdown_button(term.name, item);
82 85 }
83 86 $('#terminal_list_header').toggle(data.length === 0);
84 87 };
85 88
86 89 TerminalList.prototype.add_link = function(name, item) {
87 90 item.data('term-name', name);
88 91 item.find(".item_name").text("terminals/" + name);
89 92 item.find(".item_icon").addClass("fa fa-terminal");
90 93 var link = item.find("a.item_link")
91 94 .attr('href', utils.url_join_encode(this.base_url, "terminals", name));
92 95 link.attr('target', '_blank');
93 96 this.add_shutdown_button(name, item);
94 97 };
95 98
96 99 TerminalList.prototype.add_shutdown_button = function(name, item) {
97 100 var that = this;
98 101 var shutdown_button = $("<button/>").text("Shutdown").addClass("btn btn-xs btn-danger").
99 102 click(function (e) {
100 103 var settings = {
101 104 processData : false,
102 105 type : "DELETE",
103 106 dataType : "json",
104 107 success : function () {
105 108 that.load_terminals();
106 109 },
107 110 error : utils.log_ajax_error,
108 111 };
109 112 var url = utils.url_join_encode(that.base_url, 'api/terminals', name);
110 113 $.ajax(url, settings);
111 114 return false;
112 115 });
113 116 item.find(".item_buttons").text("").append(shutdown_button);
114 117 };
115 118
116 119 return {TerminalList: TerminalList};
117 120 });
General Comments 0
You need to be logged in to leave comments. Login now