Fixed handling of message dialog response.

This finishes the implementation of clearing plugin metadata.
This commit is contained in:
WrinklyNinja
2014-08-12 12:59:15 +01:00
parent 1a7eab8c27
commit c04f97f594
3 changed files with 43 additions and 37 deletions
+41 -18
View File
@@ -46,24 +46,26 @@ 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 + '"?');
showMessageDialog('Clear Plugin Metadata', 'Are you sure you want to clear all existing user-added metadata from "' + pluginCard.querySelector('h1').textContent + '"?', function(result){
if (result) {
var request = JSON.stringify({
name: 'clearPluginMetadata',
args: [
pluginCard.getElementsByTagName('h1')[0].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;
}
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);
}
}).catch(processCefError);
});
}
}
},
@@ -386,6 +388,18 @@ var PluginListItem = document.registerElement('plugin-li', {
/* Create a <message-dialog> element type that extends from <dialog>. */
var messageDialogProto = Object.create(HTMLDialogElement.prototype, {
onClose: {
value: function(evt) {
var ret = evt.target.returnValue == 'true';
evt.target.parentElement.removeChild(evt.target);
if (evt.target.closeCallback != undefined) {
evt.target.closeCallback(ret);
}
}
},
onButtonClick: {
value: function(evt) {
var dialog = evt.currentTarget.parentElement.parentElement;
@@ -399,7 +413,9 @@ var messageDialogProto = Object.create(HTMLDialogElement.prototype, {
showModal: {
/* A type of 'error' or 'info' produces an 'OK'-only dialog box. */
value: function(type, title, text) {
value: function(type, title, text, closeCallback) {
this.closeCallback = closeCallback;
this.querySelector('h1').textContent = title;
this.querySelector('p').textContent = text;
@@ -443,8 +459,15 @@ var messageDialogProto = Object.create(HTMLDialogElement.prototype, {
cancel.className = 'cancel';
cancel.textContent = 'Cancel';
buttons.appendChild(cancel);
}
this.addEventListener('close', this.onClose, false);
}
},
detachedCallback: {
value: function() {
this.removeEventListener('close', this.onClose, false);
}
}
});
-1
View File
@@ -325,7 +325,6 @@ function Plugin(obj) {
Plugin.prototype.observer = function(changes) {
changes.forEach(function(change) {
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);
+2 -18
View File
@@ -185,31 +185,15 @@ function togglePlugins(evt) {
document.getElementById('hiddenPluginNo').textContent = hiddenPluginNo;
});
}
function closeMessageDialog(evt) {
var ret = evt.target.returnValue == 'true';
evt.target.removeEventListener('close', closeMessageDialog, false);
document.body.removeChild(evt.target);
if (ret) {
} else {
}
}
function showMessageDialog(title, text) {
function showMessageDialog(title, text, closeCallback) {
var dialog = new MessageDialog();
dialog.addEventListener('close', closeMessageDialog, false);
document.body.appendChild(dialog);
dialog.showModal('warn', title, text);
dialog.showModal('warn', title, text, closeCallback);
}
function showMessageBox(type, title, text) {
var dialog = new MessageDialog();
dialog.addEventListener('close', closeMessageDialog, false);
document.body.appendChild(dialog);
dialog.showModal(type, title, text);
}