Show More
@@ -46,7 +46,6 b' class NotebookManager(Configurable):' | |||||
46 | names = os.listdir(self.notebook_dir) |
|
46 | names = os.listdir(self.notebook_dir) | |
47 | names = [name.split(u'.')[0] \ |
|
47 | names = [name.split(u'.')[0] \ | |
48 | for name in names if name.endswith(self.filename_ext)] |
|
48 | for name in names if name.endswith(self.filename_ext)] | |
49 | print names |
|
|||
50 | data = [] |
|
49 | data = [] | |
51 | for name in names: |
|
50 | for name in names: | |
52 | if name not in self.rev_mapping: |
|
51 | if name not in self.rev_mapping: |
@@ -40,17 +40,62 b' var IPython = (function (IPython) {' | |||||
40 | NotebookList.prototype.list_loaded = function (data, status, xhr) { |
|
40 | NotebookList.prototype.list_loaded = function (data, status, xhr) { | |
41 | var len = data.length; |
|
41 | var len = data.length; | |
42 | for (var i=0; i<len; i++) { |
|
42 | for (var i=0; i<len; i++) { | |
43 | var div = $('<div/>').addClass('notebook_item ui-widget ui-widget-content ui-helper-clearfix'); |
|
43 | var notebook_id = data[i].notebook_id; | |
44 | var nbname = $('<span/>').addClass('item_name').append( |
|
44 | var nbname = data[i].name; | |
45 | $('<a/>').attr('href','/'+data[i].notebook_id). |
|
45 | ||
|
46 | var item = $('<div/>'); | |||
|
47 | item.addClass('notebook_item ui-widget ui-widget-content ui-helper-clearfix'); | |||
|
48 | var item_name = $('<span/>').addClass('item_name').append( | |||
|
49 | $('<a/>').attr('href','/'+notebook_id). | |||
46 | attr('target','_blank'). |
|
50 | attr('target','_blank'). | |
47 |
text( |
|
51 | text(nbname) | |
48 | ); |
|
52 | ); | |
49 | var buttons = $('<span/>').addClass('item_buttons').append( |
|
53 | // Store the nbname and notebook_id on the item for later usage. We have to do this | |
50 | $('<button>Delete</button>').button() |
|
54 | // because the loop over elements changes the values of the local nbname and notebook_id | |
51 |
|
|
55 | // variables. | |
52 | div.append(nbname).append(buttons); |
|
56 | item.data('notebook_id',notebook_id); | |
53 | this.element.append(div); |
|
57 | item.data('nbname',nbname); | |
|
58 | ||||
|
59 | var buttons = $('<span/>').addClass('item_buttons'); | |||
|
60 | var delete_button = $('<button>Delete</button>').button(). | |||
|
61 | click(function (e) { | |||
|
62 | // $(this) is the button that was clicked. | |||
|
63 | var that = $(this); | |||
|
64 | // We use the nbname and notebook_id from the parent notebook_item element's | |||
|
65 | // data because the outer scopes values change as we iterate through the loop. | |||
|
66 | var parent_item = that.parents('div.notebook_item'); | |||
|
67 | var nbname = parent_item.data('nbname'); | |||
|
68 | var notebook_id = parent_item.data('notebook_id'); | |||
|
69 | var dialog = $('<div/>'); | |||
|
70 | dialog.html('Are you sure you want to permanently delete the notebook: ' + nbname + '?'); | |||
|
71 | parent_item.append(dialog); | |||
|
72 | dialog.dialog({ | |||
|
73 | resizable: false, | |||
|
74 | modal: true, | |||
|
75 | title: "Delete notebook", | |||
|
76 | buttons : { | |||
|
77 | "Delete": function () { | |||
|
78 | var settings = { | |||
|
79 | processData : false, | |||
|
80 | cache : false, | |||
|
81 | type : "DELETE", | |||
|
82 | dataType : "json", | |||
|
83 | success : function (data, status, xhr) { | |||
|
84 | parent_item.remove(); | |||
|
85 | } | |||
|
86 | }; | |||
|
87 | $.ajax("/notebooks/" + notebook_id, settings); | |||
|
88 | $(this).dialog('close'); | |||
|
89 | }, | |||
|
90 | "Cancel": function () { | |||
|
91 | $(this).dialog('close'); | |||
|
92 | } | |||
|
93 | } | |||
|
94 | }); | |||
|
95 | }); | |||
|
96 | buttons.append(delete_button); | |||
|
97 | item.append(item_name).append(buttons); | |||
|
98 | this.element.append(item); | |||
54 | } |
|
99 | } | |
55 | }; |
|
100 | }; | |
56 |
|
101 |
General Comments 0
You need to be logged in to leave comments.
Login now