Started to implement clear plugin metadata.

Right now it doesn't care what your answer to the dialog is, I need to
event handle or promise that.
This commit is contained in:
WrinklyNinja
2014-08-12 12:05:32 +01:00
parent 354d284127
commit 1a7eab8c27
3 changed files with 35 additions and 10 deletions
+17
View File
@@ -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);
}
}
},
+4 -10
View File
@@ -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();
+14
View File
@@ -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<string>();
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;