Adds a Move button to the notebooklist interface next to Rename.

With this button, you can now move files or directories to any path in
the notebook, including creating new directories (like 'mv -p'). To move
a file, you specify the new destination directory's path.

This achieves the same effect as renaming a file with a new relative
path, but is more clear to users unfamiliar with unix commands --
especially with regard to moving to a parent directory.

Can only move one file at a time currently.
This commit is contained in:
Nathan Daly 2016-01-07 23:13:35 -08:00
parent df964650fd
commit 4a9e31ed30
3 changed files with 82 additions and 0 deletions

View File

@ -129,6 +129,7 @@ define([
// Bind events for action buttons.
$('.rename-button').click($.proxy(this.rename_selected, this));
$('.move-button').click($.proxy(this.move_selected, this));
$('.shutdown-button').click($.proxy(this.shutdown_selected, this));
$('.duplicate-button').click($.proxy(this.duplicate_selected, this));
$('.delete-button').click($.proxy(this.delete_selected, this));
@ -550,6 +551,15 @@ define([
$('.rename-button').css('display', 'none');
}
// Move is only visible when one item is selected, and it is not a
// running notebook.
// TODO(nhdaly): Add support for moving multiple items at once.
if (selected.length === 1 && !has_running_notebook) {
$('.move-button').css('display', 'inline-block');
} else {
$('.move-button').css('display', 'none');
}
// Shutdown is only visible when one or more notebooks running notebooks
// are selected and no non-notebook items are selected.
if (has_running_notebook && !(has_file || has_directory)) {
@ -774,6 +784,73 @@ define([
});
};
NotebookList.prototype.move_selected = function() {
// TODO(nhdaly): Support moving multiple items at once.
if (this.selected.length !== 1){
return;
}
var that = this;
var item_path = this.selected[0].path;
var item_name = this.selected[0].name;
var item_type = this.selected[0].type;
// Open a dialog to enter the new path, with current path as default.
var input = $('<input/>').attr('type','text').attr('size','25').addClass('form-control')
.val(utils.url_path_join('/', that.notebook_path));
var dialog_body = $('<div/>').append(
$("<p/>").addClass("rename-message")
.text('Enter new destination directory path for '+ item_type + ':')
).append(
$("<br/>")
).append(input);
var d = dialog.modal({
title : "Move "+ item_type,
body : dialog_body,
buttons : {
OK : {
class: "btn-primary",
click: function() {
// Construct the new path using the user input and its name.
var new_path = utils.url_path_join(input.val(), item_name)
that.contents.rename(item_path, new_path).then(function() {
that.load_list();
}).catch(function(e) {
dialog.modal({
title: "Move Failed",
body: $('<div/>')
.text("An error occurred while moving \"" + item_name + "\" from \"" + item_path + "\" to \"" + new_path + "\".")
.append($('<div/>')
.addClass('alert alert-danger')
.text(e.message || e)),
buttons: {
OK: {'class': 'btn-primary'}
}
});
console.warn('Error durring moving :', e);
});
}
},
Cancel : {}
},
open : function () {
// Upon ENTER, click the OK button.
input.keydown(function (event) {
if (event.which === keyboard.keycodes.enter) {
d.find('.btn-primary').first().click();
return false;
}
});
input.focus();
if (input.val().indexOf(".") > 0) {
input[0].setSelectionRange(0,input.val().indexOf("."));
} else {
input.select();
}
}
});
};
NotebookList.prototype.delete_selected = function() {
var message;
if (this.selected.length === 1) {

View File

@ -327,6 +327,10 @@ ul#new-menu {
display: none;
}
.move-button {
display: none;
}
.shutdown-button {
display: none;
}

View File

@ -31,6 +31,7 @@ data-terminals-available="{{terminals_available}}"
<div class="dynamic-buttons">
<button title="Duplicate selected" class="duplicate-button btn btn-default btn-xs">Duplicate</button>
<button title="Rename selected" class="rename-button btn btn-default btn-xs">Rename</button>
<button title="Move selected" class="move-button btn btn-default btn-xs">Move</button>
<button title="Shutdown selected notebook(s)" class="shutdown-button btn btn-default btn-xs btn-warning">Shutdown</button>
<button title="Delete selected" class="delete-button btn btn-default btn-xs btn-danger"><i class="fa fa-trash"></i></button>
</div>