Merge pull request #8404 from howard-stearns/share-dialog

proper share dialog
This commit is contained in:
David Kelly 2016-08-09 17:17:24 -07:00 committed by GitHub
commit c487843f10
2 changed files with 101 additions and 5 deletions

View file

@ -0,0 +1,78 @@
<html>
<head>
<title>Share</title>
<link rel="stylesheet" type="text/css" href="edit-style.css">
<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script type="text/javascript" src="eventBridgeLoader.js"></script>
<script>
var paths = [], idCounter = 0;
function addImage(data) {
var div = document.createElement("DIV"),
input = document.createElement("INPUT"),
label = document.createElement("LABEL"),
img = document.createElement("IMG"),
id = "p" + idCounter++;
function toggle() { data.share = input.checked; }
img.src = data.localPath;
label.appendChild(img);
// Our stylesheet(?) requires input.id to match label.for. Otherwise input doesn't display the check state.
label.setAttribute('for', id); // cannot do label.for =
input.id = id;
input.type = "checkbox";
input.checked = data.share = true;
input.addEventListener('change', toggle);
div.class = "property checkbox";
div.appendChild(input);
div.appendChild(label);
document.getElementById("images").appendChild(div);
paths.push(data);
}
window.onload = function () {
// Something like the following will allow testing in a browser.
//addImage({localPath: 'c:/Users/howar/OneDrive/Pictures/hifi-snap-by--on-2016-07-27_12-58-43.jpg'});
openEventBridge(function () {
// Set up a handler for receiving the data, and tell the .js we are ready to receive it.
EventBridge.scriptEventReceived.connect(function (message) {
message.forEach(addImage);
});
EventBridge.emitWebEvent('ready');
});
};
// beware of bug: Cannot send objects at top level. (Nested in arrays is fine.)
shareSelected = function() {
EventBridge.emitWebEvent(paths);
};
doNotShare = function() {
EventBridge.emitWebEvent([]);
};
</script>
<style type="text/css">
div.columns div:first-child { width: 300px; }
div.columns div { float: left; }
div.clear { clear: both; }
img { width: 400; }
</style>
</head>
<body>
<div class="columns">
<div>
<div class="section-header">
<label>Snapshots sucessfully saved!</label>
</div>
<div class="sub-section-header">
<label>Would you like to share?</label>
</div>
<div class="sub-section-header">
<input type="button" id="share" value="SHARE IN FEED" onclick="shareSelected()"/>
</div>
<div class="sub-section-header">
<input type="button" class="red" id="close" value="DON'T SHARE" onclick="doNotShare()"/>
</div>
</div>
<div id="images" class="image-column"/>
</div>
<div class="clear"></div>
</body>
</html>

View file

@ -21,11 +21,27 @@ var button = toolBar.addButton({
});
function confirmShare(data) {
if (!Window.confirm("Share snapshot " + data.localPath + "?")) { // This dialog will be more elaborate...
return;
var dialog = new OverlayWebWindow('Snapshot', Script.resolvePath("html/ShareSnapshot.html"), 800, 300);
function onMessage(message) {
if (message == 'ready') { // The window can now receive data from us.
dialog.emitScriptEvent(data); // Send it.
return;
} // Rest is confirmation processing
dialog.webEventReceived.disconnect(onMessage); // I'm not certain that this is necessary. If it is, what do we do on normal close?
dialog.close();
dialog.deleteLater();
message = message.filter(function (picture) { return picture.share; });
if (message.length) {
print('sharing', message.map(function (picture) { return picture.localPath; }).join(', '));
message.forEach(function (data) {
Window.shareSnapshot(data.localPath);
});
} else {
print('declined to share', JSON.stringify(data));
}
}
Window.snapshotShared.connect(snapshotShared);
Window.shareSnapshot(data.localPath);
dialog.webEventReceived.connect(onMessage);
dialog.raise();
}
function snapshotShared(success) {
@ -74,12 +90,14 @@ function resetButtons(path, notify) {
button.writeProperty("defaultState", 1);
button.writeProperty("hoverState", 3);
Window.snapshotTaken.disconnect(resetButtons);
confirmShare({localPath: path});
confirmShare([{localPath: path}]);
}
button.clicked.connect(onClicked);
Window.snapshotShared.connect(snapshotShared);
Script.scriptEnding.connect(function () {
toolBar.removeButton("snapshot");
button.clicked.disconnect(onClicked);
Window.snapshotShared.disconnect(snapshotShared);
});