Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expands "Move" button to support moving multiple files together. #1088

Merged
merged 2 commits into from
Feb 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 38 additions & 35 deletions notebook/static/tree/js/notebooklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ define([
OK: {'class': 'btn-primary'}
}
});
console.warn('Error durring New file creation', e);
console.warn('Error during New file creation', e);
});
that.load_sessions();
});
Expand All @@ -122,7 +122,7 @@ define([
OK: {'class': 'btn-primary'}
}
});
console.warn('Error durring New directory creation', e);
console.warn('Error during New directory creation', e);
});
that.load_sessions();
});
Expand Down Expand Up @@ -551,10 +551,9 @@ 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 is visible iff at least one item is selected, and none of them
// are a running notebook.
if (selected.length >= 1 && !has_running_notebook) {
$('.move-button').css('display', 'inline-block');
} else {
$('.move-button').css('display', 'none');
Expand Down Expand Up @@ -766,7 +765,7 @@ define([
OK: {'class': 'btn-primary'}
}
});
console.warn('Error durring renaming :', e);
console.warn('Error during renaming :', e);
});
}
}
Expand All @@ -792,52 +791,56 @@ define([

NotebookList.prototype.move_selected = function() {
var that = this;
var num_items = that.selected.length;

// TODO(nhdaly): Support moving multiple items at once.
if (that.selected.length !== 1){
// Can move one or more selected items.
if (!(num_items >= 1)) {
return;
}

var item_path = that.selected[0].path;
var item_name = that.selected[0].name;
var item_type = that.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 + ':')
.text('Enter new destination directory path for '+ num_items + ' items:')
).append(
$("<br/>")
).append(input);
var d = dialog.modal({
title : "Move "+ item_type,
title : "Move "+ num_items + " Items",
body : dialog_body,
default_button: "Cancel",
buttons : {
Cancel : {},
Move : {
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'}
}
// Move all the items.
that.selected.forEach(function(item) {
var item_path = item.path;
var item_name = item.name;
// Construct the new path using the user input and the item's name.
var new_path = utils.url_path_join(input.val(), item_name);
that.contents.rename(item_path, new_path).then(function() {
// After each move finishes, reload the list.
that.load_list();
}).catch(function(e) {
// If any of the moves fails, show this dialog for that move.
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 during moving :', e);
});
console.warn('Error durring moving :', e);
});
}); // End of forEach.
}
}
},
Expand Down Expand Up @@ -893,7 +896,7 @@ define([
OK: {'class': 'btn-primary'}
}
});
console.warn('Error durring content deletion:', e);
console.warn('Error during content deletion:', e);
});
});
}
Expand Down Expand Up @@ -936,7 +939,7 @@ define([
OK: {'class': 'btn-primary'}
}
});
console.warn('Error durring content duplication', e);
console.warn('Error during content duplication', e);
});
});
}
Expand Down Expand Up @@ -1010,7 +1013,7 @@ define([
}
}}
});
console.warn('Error durring notebook uploading', e);
console.warn('Error during notebook uploading', e);
return false;
}
content_type = 'application/json';
Expand Down