Skip to content

Commit

Permalink
Backport PR #1482: Respect 'editable' cell metadata
Browse files Browse the repository at this point in the history
- Readonly cells can not be split or merged or deleted
- Readonly cells can be executed
- End users can still modify this by editing the metadata
  themsevles directly

Fixes  1402
  • Loading branch information
Carreau authored and MeeseeksDev[bot] committed Jan 13, 2017
1 parent 4727efc commit 5302351
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
29 changes: 26 additions & 3 deletions notebook/static/notebook/js/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,20 @@ define([
if (data.metadata !== undefined) {
this.metadata = data.metadata;
}
// upgrade cell's editable metadata if not defined
if (this.metadata.editable === undefined) {
this.metadata.editable = this.is_editable();
}
// upgrade cell's deletable metadata if not defined
if (this.metadata.deletable === undefined) {
this.metadata.deletable = this.is_deletable();
}
};


/**
* can the cell be split into two cells (false if not deletable)
*
* @method is_splittable
**/
Cell.prototype.is_splittable = function () {
Expand All @@ -500,14 +509,28 @@ define([
};

/**
* is the cell deletable? only false (undeletable) if
* metadata.deletable is explicitly false -- everything else
* is the cell edtitable? only false (readonly) if
* metadata.editable is explicitly false -- everything else
* counts as true
*
* @method is_editable
**/
Cell.prototype.is_editable = function () {
if (this.metadata.editable === false) {
return false;
}
return true;
};

/**
* is the cell deletable? only false (undeletable) if
* metadata.deletable is explicitly false or if the cell is not
* editable -- everything else counts as true
*
* @method is_deletable
**/
Cell.prototype.is_deletable = function () {
if (this.metadata.deletable === false) {
if (this.metadata.deletable === false || !this.is_editable()) {
return false;
}
return true;
Expand Down
2 changes: 2 additions & 0 deletions notebook/static/notebook/js/codecell.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ define([
if (that.keyboard_manager) {
that.keyboard_manager.enable();
}

that.code_mirror.setOption('readOnly', !that.is_editable());
});
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this));
$(this.code_mirror.getInputField()).attr("spellcheck", "false");
Expand Down
1 change: 1 addition & 0 deletions notebook/static/notebook/js/textcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ define([
if (that.keyboard_manager) {
that.keyboard_manager.enable();
}
that.code_mirror.setOption('readOnly', !that.is_editable());
});
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this))
// The tabindex=-1 makes this div focusable.
Expand Down

0 comments on commit 5302351

Please sign in to comment.