From c49c8ea72ad2c86028bc4dae85bb536c536028b3 Mon Sep 17 00:00:00 2001 From: Vidar Tonaas Fauske Date: Fri, 20 Jan 2017 12:28:17 +0000 Subject: [PATCH] Set dirty flag when changing tags --- .../notebook/js/celltoolbarpresets/tags.js | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/notebook/static/notebook/js/celltoolbarpresets/tags.js b/notebook/static/notebook/js/celltoolbarpresets/tags.js index ae7ec53d3..b2fbb54c1 100644 --- a/notebook/static/notebook/js/celltoolbarpresets/tags.js +++ b/notebook/static/notebook/js/celltoolbarpresets/tags.js @@ -8,14 +8,24 @@ define([ var CellToolbar = celltoolbar.CellToolbar; - var remove_tag = function(cell) { - return function(tag_name) { + var write_tag = function(cell, name, add) { + if (add) { + // Add to metadata + if (cell.metadata.tags === undefined) { + cell.metadata.tags = []; + } else if (cell.metadata.tags.indexOf(name) !== -1) { + // Tag already exists + return; + } + cell.metadata.tags.push(name); + } else { + // Remove from metadata if (!cell.metadata || !cell.metadata.tags) { // No tags to remove return; } // Remove tag from tags list - var index = cell.metadata.tags.indexOf(tag_name); + var index = cell.metadata.tags.indexOf(name); if (index !== -1) { cell.metadata.tags.splice(index, 1); } @@ -23,6 +33,13 @@ define([ if (cell.metadata.tags.length === 0) { delete cell.metadata.tags; } + } + cell.events.trigger('set_dirty.Notebook', {value: true}); + } + + var remove_tag = function(cell) { + return function(tag_name) { + return write_tag(cell, tag_name, false); }; }; @@ -114,14 +131,8 @@ define([ button_container.append(tag_container); add_tag_edit(div, cell, function(name) { - // Add to metadata - if (cell.metadata.tags === undefined) { - cell.metadata.tags = []; - } else if (cell.metadata.tags.indexOf(name) !== -1) { - // Tag already exists - return; - } - cell.metadata.tags.push(name); + // Write tag to metadata + write_tag(cell, name, true); // Make tag visual var tag = make_tag(name, on_remove); tag_container.append(tag);