##// END OF EJS Templates
Add actions dropdown to tree view
Jonathan Frederic -
Show More
@@ -290,23 +290,20 b' define(['
290 path
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 // directory nav doesn't open new tabs
302 // directory nav doesn't open new tabs
294 // files, notebooks do
303 // files, notebooks do
295 if (model.type !== "directory") {
304 if (model.type !== "directory") {
296 link.attr('target','_blank');
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,68 +354,163 b' define(['
357 item.find(".item_buttons").append(shutdown_button);
354 item.find(".item_buttons").append(shutdown_button);
358 };
355 };
359
356
360 NotebookList.prototype.add_duplicate_button = function (item) {
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 var notebooklist = this;
392 var notebooklist = this;
362 var duplicate_button = $("<button/>").text("Duplicate").addClass("btn btn-default btn-xs").
393 return function (e) {
363 click(function (e) {
394 // $(this) is the button that was clicked.
364 // $(this) is the button that was clicked.
395 var that = $(this);
365 var that = $(this);
396 // We use the filename from the parent list_item element's
366 var name = item.data('name');
397 // data because the outer scope's values change as we iterate through the loop.
367 var path = item.data('path');
398 var parent_item = that.parents('div.list_item');
368 var message = 'Are you sure you want to duplicate ' + name + '?';
399 var name = parent_item.data('name');
369 var copy_from = {copy_from : path};
400 var path = parent_item.data('path');
370 IPython.dialog.modal({
401 var input = $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
371 title : "Duplicate " + name,
402 .val(path);
372 body : message,
403 var dialog_body = $('<div/>').append(
373 buttons : {
404 $("<p/>").addClass("rename-message")
374 Duplicate : {
405 .text('Enter a new directory name:')
375 class: "btn-primary",
406 ).append(
376 click: function() {
407 $("<br/>")
377 notebooklist.contents.copy(path, notebooklist.notebook_path).then(function () {
408 ).append(input);
378 notebooklist.load_list();
409 var d = dialog.modal({
410 title : "Rename directory",
411 body : dialog_body,
412 buttons : {
413 OK : {
414 class: "btn-primary",
415 click: function() {
416 notebooklist.contents.rename(path, input.val()).then(function() {
417 notebooklist.load_list();
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 }
379 });
427 });
380 }
428 });
381 },
429 }
382 Cancel : {}
430 },
383 }
431 Cancel : {}
384 });
432 },
385 return false;
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;
439 }
440 });
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.add_delete_button = function (item) {
448 NotebookList.prototype.make_delete_callback = function (item) {
391 var notebooklist = this;
449 var notebooklist = this;
392 var delete_button = $("<button/>").text("Delete").addClass("btn btn-default btn-xs").
450 return function (e) {
393 click(function (e) {
451 // $(this) is the button that was clicked.
394 // $(this) is the button that was clicked.
452 var that = $(this);
395 var that = $(this);
453 // We use the filename from the parent list_item element's
396 // We use the filename from the parent list_item element's
454 // data because the outer scope's values change as we iterate through the loop.
397 // data because the outer scope's values change as we iterate through the loop.
455 var parent_item = that.parents('div.list_item');
398 var parent_item = that.parents('div.list_item');
456 var name = parent_item.data('name');
399 var name = parent_item.data('name');
457 var path = parent_item.data('path');
400 var path = parent_item.data('path');
458 var message = 'Are you sure you want to permanently delete: ' + name + '?';
401 var message = 'Are you sure you want to permanently delete the file: ' + name + '?';
459 dialog.modal({
402 dialog.modal({
460 title : "Delete",
403 title : "Delete file",
461 body : message,
404 body : message,
462 buttons : {
405 buttons : {
463 Delete : {
406 Delete : {
464 class: "btn-danger",
407 class: "btn-danger",
465 click: function() {
408 click: function() {
466 notebooklist.contents.delete(path).then(function() {
409 notebooklist.contents.delete(path).then(
467 notebooklist.notebook_deleted(path);
410 function() {
468 }).catch(function(e) {
411 notebooklist.notebook_deleted(path);
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 });
414 }
478 });
415 },
479 }
416 Cancel : {}
480 },
417 }
481 Cancel : {}
418 });
482 }
419 return false;
420 });
483 });
421 item.find(".item_buttons").append(delete_button);
484 return false;
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 }
511 });
512 return false;
513 }
422 };
514 };
423
515
424 NotebookList.prototype.notebook_deleted = function(path) {
516 NotebookList.prototype.notebook_deleted = function(path) {
General Comments 0
You need to be logged in to leave comments. Login now