Show More
@@ -290,23 +290,20 b' define([' | |||
|
290 | 290 | path |
|
291 | 291 | ) |
|
292 | 292 | ); |
|
293 | ||
|
294 | var can_duplicate = (model.type != 'directory'); | |
|
295 | var can_rename = (model.type == 'directory'); | |
|
296 | var can_delete = (model.type != 'notebook' || this.sessions[path] === undefined); | |
|
297 | if (!can_delete) { | |
|
298 | this.add_shutdown_button(item, this.sessions[path]); | |
|
299 | } | |
|
300 | this.add_actions_button(item, can_delete, can_duplicate, can_rename); | |
|
301 | ||
|
293 | 302 | // directory nav doesn't open new tabs |
|
294 | 303 | // files, notebooks do |
|
295 | 304 | if (model.type !== "directory") { |
|
296 | 305 | link.attr('target','_blank'); |
|
297 | 306 | } |
|
298 | if (model.type !== 'directory') { | |
|
299 | this.add_duplicate_button(item); | |
|
300 | } | |
|
301 | if (model.type == 'file') { | |
|
302 | this.add_delete_button(item); | |
|
303 | } else if (model.type == 'notebook') { | |
|
304 | if (this.sessions[path] === undefined){ | |
|
305 | this.add_delete_button(item); | |
|
306 | } else { | |
|
307 | this.add_shutdown_button(item, this.sessions[path]); | |
|
308 | } | |
|
309 | } | |
|
310 | 307 | }; |
|
311 | 308 | |
|
312 | 309 | |
@@ -357,40 +354,100 b' define([' | |||
|
357 | 354 | item.find(".item_buttons").append(shutdown_button); |
|
358 | 355 | }; |
|
359 | 356 | |
|
360 |
NotebookList.prototype.add_ |
|
|
357 | NotebookList.prototype.add_actions_button = function (item, can_delete, can_duplicate, can_rename) { | |
|
358 | var group = $("<div/>") | |
|
359 | .addClass('btn-group') | |
|
360 | .css('float', 'none') | |
|
361 | .appendTo(item.find(".item_buttons")); | |
|
362 | ||
|
363 | var actions_button = $("<button/>") | |
|
364 | .html("Actions <span class='caret'></span>") | |
|
365 | .addClass("btn btn-default btn-xs dropdown-toggle") | |
|
366 | .attr('data-toggle', 'dropdown') | |
|
367 | .attr('aria-expanded', 'false') | |
|
368 | .appendTo(group); | |
|
369 | ||
|
370 | var actions_list = $('<ul/>') | |
|
371 | .addClass('dropdown-menu') | |
|
372 | .attr('role', 'menu') | |
|
373 | .appendTo(group); | |
|
374 | ||
|
375 | var create_action = function(label, callback) { | |
|
376 | var item = $('<li/>') | |
|
377 | .click(callback) | |
|
378 | .appendTo(actions_list); | |
|
379 | ||
|
380 | var link = $('<a/>') | |
|
381 | .attr('href', '#') | |
|
382 | .html(label) | |
|
383 | .appendTo(item); | |
|
384 | }; | |
|
385 | ||
|
386 | if (can_delete) create_action('Delete', this.make_delete_callback(item)); | |
|
387 | if (can_duplicate) create_action('Duplicate', this.make_duplicate_callback(item)); | |
|
388 | if (can_rename) create_action('Rename', this.make_rename_callback(item)); | |
|
389 | }; | |
|
390 | ||
|
391 | NotebookList.prototype.make_rename_callback = function (item) { | |
|
361 | 392 | var notebooklist = this; |
|
362 | var duplicate_button = $("<button/>").text("Duplicate").addClass("btn btn-default btn-xs"). | |
|
363 | click(function (e) { | |
|
393 | return function (e) { | |
|
364 | 394 |
|
|
365 | 395 |
|
|
366 | var name = item.data('name'); | |
|
367 | var path = item.data('path'); | |
|
368 | var message = 'Are you sure you want to duplicate ' + name + '?'; | |
|
369 | var copy_from = {copy_from : path}; | |
|
370 | IPython.dialog.modal({ | |
|
371 | title : "Duplicate " + name, | |
|
372 | body : message, | |
|
396 | // We use the filename from the parent list_item element's | |
|
397 | // data because the outer scope's values change as we iterate through the loop. | |
|
398 | var parent_item = that.parents('div.list_item'); | |
|
399 | var name = parent_item.data('name'); | |
|
400 | var path = parent_item.data('path'); | |
|
401 | var input = $('<input/>').attr('type','text').attr('size','25').addClass('form-control') | |
|
402 | .val(path); | |
|
403 | var dialog_body = $('<div/>').append( | |
|
404 | $("<p/>").addClass("rename-message") | |
|
405 | .text('Enter a new directory name:') | |
|
406 | ).append( | |
|
407 | $("<br/>") | |
|
408 | ).append(input); | |
|
409 | var d = dialog.modal({ | |
|
410 | title : "Rename directory", | |
|
411 | body : dialog_body, | |
|
373 | 412 |
|
|
374 |
|
|
|
413 | OK : { | |
|
375 | 414 |
|
|
376 | 415 |
|
|
377 |
|
|
|
416 | notebooklist.contents.rename(path, input.val()).then(function() { | |
|
378 | 417 |
|
|
418 | }).catch(function(e) { | |
|
419 | dialog.modal({ | |
|
420 | title : "Error", | |
|
421 | body : $('<div/>') | |
|
422 | .text("An error occurred while renaming \"" + path + "\" to \"" + input.val() + "\".") | |
|
423 | .append($('<div/>').addClass('alert alert-danger').text(String(e))), | |
|
424 | buttons : { | |
|
425 | OK : {} | |
|
426 | } | |
|
427 | }); | |
|
379 | 428 |
|
|
380 | 429 |
|
|
381 | 430 |
|
|
382 | 431 |
|
|
432 | }, | |
|
433 | open : function () { | |
|
434 | // Upon ENTER, click the OK button. | |
|
435 | input.keydown(function (event) { | |
|
436 | if (event.which === keyboard.keycodes.enter) { | |
|
437 | d.find('.btn-primary').first().click(); | |
|
438 | return false; | |
|
383 | 439 | } |
|
384 | 440 | }); |
|
385 | return false; | |
|
441 | input.focus().select(); | |
|
442 | } | |
|
386 | 443 | }); |
|
387 | item.find(".item_buttons").append(duplicate_button); | |
|
444 | return false; | |
|
445 | }; | |
|
388 | 446 | }; |
|
389 | 447 | |
|
390 |
NotebookList.prototype. |
|
|
448 | NotebookList.prototype.make_delete_callback = function (item) { | |
|
391 | 449 | var notebooklist = this; |
|
392 | var delete_button = $("<button/>").text("Delete").addClass("btn btn-default btn-xs"). | |
|
393 | click(function (e) { | |
|
450 | return function (e) { | |
|
394 | 451 |
|
|
395 | 452 |
|
|
396 | 453 |
|
@@ -398,27 +455,62 b' define([' | |||
|
398 | 455 |
|
|
399 | 456 |
|
|
400 | 457 |
|
|
401 |
|
|
|
458 | var message = 'Are you sure you want to permanently delete: ' + name + '?'; | |
|
402 | 459 |
|
|
403 |
|
|
|
460 | title : "Delete", | |
|
404 | 461 |
|
|
405 | 462 |
|
|
406 | 463 |
|
|
407 | 464 |
|
|
408 | 465 |
|
|
409 |
|
|
|
410 | function() { | |
|
466 | notebooklist.contents.delete(path).then(function() { | |
|
411 | 467 |
|
|
468 | }).catch(function(e) { | |
|
469 | dialog.modal({ | |
|
470 | title : "Error", | |
|
471 | body : $('<div/>') | |
|
472 | .text("An error occurred while deleting \"" + path + "\".") | |
|
473 | .append($('<div/>').addClass('alert alert-danger').text(String(e))), | |
|
474 | buttons : { | |
|
475 | OK : {} | |
|
412 | 476 | } |
|
413 | ); | |
|
477 | }); | |
|
478 | }); | |
|
414 | 479 |
|
|
415 | 480 |
|
|
416 | 481 |
|
|
417 | 482 |
|
|
418 | 483 |
|
|
419 | 484 |
|
|
485 | }; | |
|
486 | }; | |
|
487 | ||
|
488 | NotebookList.prototype.make_duplicate_callback = function (item) { | |
|
489 | var notebooklist = this; | |
|
490 | return function (e) { | |
|
491 | // $(this) is the button that was clicked. | |
|
492 | var that = $(this); | |
|
493 | var name = item.data('name'); | |
|
494 | var path = item.data('path'); | |
|
495 | var message = 'Are you sure you want to duplicate ' + name + '?'; | |
|
496 | var copy_from = {copy_from : path}; | |
|
497 | IPython.dialog.modal({ | |
|
498 | title : "Duplicate " + name, | |
|
499 | body : message, | |
|
500 | buttons : { | |
|
501 | Duplicate : { | |
|
502 | class: "btn-primary", | |
|
503 | click: function() { | |
|
504 | notebooklist.contents.copy(path, notebooklist.notebook_path).then(function () { | |
|
505 | notebooklist.load_list(); | |
|
506 | }); | |
|
507 | } | |
|
508 | }, | |
|
509 | Cancel : {} | |
|
510 | } | |
|
420 | 511 | }); |
|
421 | item.find(".item_buttons").append(delete_button); | |
|
512 | return false; | |
|
513 | } | |
|
422 | 514 | }; |
|
423 | 515 | |
|
424 | 516 | NotebookList.prototype.notebook_deleted = function(path) { |
General Comments 0
You need to be logged in to leave comments.
Login now