diff --git a/resources/report/js/custom.js b/resources/report/js/custom.js index 9024de09..82316d1e 100644 --- a/resources/report/js/custom.js +++ b/resources/report/js/custom.js @@ -47,6 +47,23 @@ var pluginMenuProto = Object.create(HTMLElement.prototype, { loot.query(request).catch(processCefError); } else if (evt.target.id == 'clearMetadata') { showMessageDialog('Clear Plugin Metadata', 'Are you sure you want to clear all existing user-added metadata from "' + pluginCard.querySelector('h1').textContent + '"?'); + + var request = JSON.stringify({ + name: 'clearPluginMetadata', + args: [ + pluginCard.getElementsByTagName('h1')[0].textContent + ] + }); + + loot.query(request).then(function(result){ + /* Need to also empty the UI-side user metadata. */ + for (var i = 0; i < loot.game.plugins.length; ++i) { + if (loot.game.plugins[i].id == pluginID) { + loot.game.plugins[i].userlist = undefined; + break; + } + } + }).catch(processCefError); } } }, diff --git a/resources/report/js/plugin.js b/resources/report/js/plugin.js index 04e9fec0..a0829ff8 100644 --- a/resources/report/js/plugin.js +++ b/resources/report/js/plugin.js @@ -323,20 +323,14 @@ function Plugin(obj) { document.getElementById('pluginsNav').appendChild(li); } - Plugin.prototype.changeAction = function(change) { - console.log(change); - } - Plugin.prototype.observer = function(changes) { - //console.log(changes); changes.forEach(function(change) { - //for (var i = 0; i < changes.length; ++i) { - - if (change.name == 'name') { - change.object.card.querySelector('h1').textContent = change.object[change.name]; + console.log(change); + if (change.name == 'userlist') { + change.object.li.setAttribute('data-edits', change.object[change.name] != undefined); + change.object.card.setAttribute('data-edits', change.object[change.name] != undefined); } }); - //changes.forEach(changeAction); } this.createCard(); diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index 61686a42..fb616359 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -260,6 +260,20 @@ namespace loot { #endif return true; } + else if (requestName == "clearPluginMetadata") { + // Has one arg, which is the name of the plugin to copy metadata for. + const string pluginName = req["args"][0].as(); + BOOST_LOG_TRIVIAL(debug) << "Clearing user metadata for plugin " << pluginName; + + auto pluginIt = find(g_app_state.CurrentGame().userlist.plugins.begin(), g_app_state.CurrentGame().userlist.plugins.end(), Plugin(pluginName)); + + if (pluginIt != g_app_state.CurrentGame().userlist.plugins.end()) { + g_app_state.CurrentGame().userlist.plugins.erase(pluginIt); + } + + callback->Success(""); + return true; + } } return false;