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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEBUI-184: fix bulk delete of vocabulary entries in the spreadsheet #1135

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions addons/nuxeo-spreadsheet/app/lib/select2-editor.js
@@ -1,6 +1,29 @@
/* eslint-disable max-len */
const Select2Editor = Handsontable.editors.TextEditor.prototype.extend();

const onEntryDelete = function(event) {
const instance = this;
const keyCodes = Handsontable.helper.keyCode;
if (event.keyCode === keyCodes.BACKSPACE || event.keyCode === keyCodes.DELETE) {
event.stopImmediatePropagation();
// XXX - kind of overrides the empty function
const selectedRange = instance.getSelectedRange();
let topLeft = selectedRange.getTopLeftCorner();
let bottomRight = selectedRange.getBottomRightCorner();
let r;
let c;
let changes = [];
Comment on lines +14 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad indentation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, bad copy/paste 馃槵
Thanks

for (r = topLeft.row; r <= bottomRight.row; r++) {
for (c = topLeft.col; c <= bottomRight.col; c++) {
if (!instance.getCellMeta(r, c).readOnly) {
changes.push([r, c, null]);
}
}
}
instance.setDataAtCell(changes);
}
};

Select2Editor.prototype.prepare = function(td, row, col, prop, value, cellProperties) {
Handsontable.editors.TextEditor.prototype.prepare.apply(this, arguments);

Expand Down Expand Up @@ -48,6 +71,7 @@ Select2Editor.prototype.createElements = function() {
0,
);
});
this.instance.addHook('beforeKeyDown', onEntryDelete);
};

const onSelect2Changed = function() {
Expand Down Expand Up @@ -164,5 +188,9 @@ Select2Editor.prototype.finishEditing = function(...params) {
return Handsontable.editors.TextEditor.prototype.finishEditing.apply(this, params);
};

Select2Editor.prototype.destroyElements = function() {
this.instance.removeHook(onEntryDelete);
};

Handsontable.editors.Select2Editor = Select2Editor;
Handsontable.editors.registerEditor('select2', Select2Editor);