Skip to content

Commit 24dd9d6

Browse files
Mokkapati, Praneet(ES)Mokkapati, Praneet(ES)
authored andcommitted
Disabling Adding or Removing Tags, when a cell is not editable
1 parent 9d0ea1a commit 24dd9d6

File tree

1 file changed

+17
-13
lines changed
  • notebook/static/notebook/js/celltoolbarpresets

1 file changed

+17
-13
lines changed

notebook/static/notebook/js/celltoolbarpresets/tags.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ define([
6262

6363
if (changed) {
6464
// Make tag UI
65-
var tag = make_tag(name, on_remove);
65+
var tag = make_tag(name, on_remove, cell.is_editable());
6666
tag_container.append(tag);
6767
var tag_map = jQuery.data(tag_container, "tag_map") || {};
6868
tag_map[name] = tag;
@@ -84,7 +84,7 @@ define([
8484
};
8585
};
8686

87-
var init_tag_container = function(cell, tag_container, on_remove) {
87+
var init_tag_container = function(cell, tag_container, on_remove) {
8888
var tag_list = cell.metadata.tags || [];
8989
if (!Array.isArray(tag_list)) {
9090
// We cannot make tags UI for this cell!
@@ -99,27 +99,29 @@ define([
9999
// Unexpected type, disable toolbar for safety
100100
return false;
101101
}
102-
var tag = make_tag(tag_name, on_remove);
102+
var tag = make_tag(tag_name, on_remove, cell.is_editable());
103103
tag_container.append(tag);
104104
tag_map[tag_name] = tag;
105105
}
106106
jQuery.data(tag_container, 'tag_map', tag_map);
107107
return true;
108108
};
109109

110-
var make_tag = function(name, on_remove) {
110+
var make_tag = function(name, on_remove, is_editable) {
111111
var tag_UI = $('<span/>')
112112
.addClass('cell-tag')
113113
.text(name);
114114

115-
var remove_button = $('<i/>')
116-
.addClass('remove-tag-btn')
117-
.addClass('fa fa-times')
118-
.click(function () {
119-
on_remove(name);
120-
return false;
121-
});
122-
tag_UI.append(remove_button);
115+
if(is_editable){
116+
var remove_button = $('<i/>')
117+
.addClass('remove-tag-btn')
118+
.addClass('fa fa-times')
119+
.click(function () {
120+
on_remove(name);
121+
return false;
122+
});
123+
tag_UI.append(remove_button);
124+
}
123125
return tag_UI;
124126
};
125127

@@ -234,7 +236,9 @@ define([
234236
button_container.append(tag_container);
235237

236238
var on_add = add_tag(cell, tag_container, on_remove);
237-
add_tag_edit(div, cell, on_add, on_remove);
239+
if(cell.is_editable()){
240+
add_tag_edit(div, cell, on_add, on_remove);
241+
}
238242
};
239243

240244
var register = function(notebook) {

0 commit comments

Comments
 (0)