Notes/src/public/app/widgets/shared_info.js

58 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-12-20 17:30:47 +01:00
import NoteContextAwareWidget from "./note_context_aware_widget.js";
import options from "../services/options.js";
2021-12-22 10:57:02 +01:00
import attributeService from "../services/attributes.js";
2021-12-20 17:30:47 +01:00
const TPL = `
<div class="shared-info-widget alert alert-warning">
<style>
.shared-info-widget {
margin: 10px;
contain: none;
padding: 10px;
font-weight: bold;
}
</style>
<span class="shared-text"></span> <a class="shared-link external"></a>. For help visit <a href="https://github.com/zadam/trilium/wiki/Sharing">wiki</a>.
2021-12-20 17:30:47 +01:00
</div>`;
export default class SharedInfoWidget extends NoteContextAwareWidget {
isEnabled() {
return super.isEnabled() && this.noteId !== 'share' && this.note.hasAncestor('share');
2021-12-20 17:30:47 +01:00
}
doRender() {
this.$widget = $(TPL);
this.$sharedLink = this.$widget.find(".shared-link");
this.$sharedText = this.$widget.find(".shared-text");
2021-12-20 17:30:47 +01:00
this.contentSized();
}
async refreshWithNote(note) {
const syncServerHost = options.get("syncServerHost");
let link;
2021-12-22 10:57:02 +01:00
const shareId = note.getOwnedLabelValue('shareAlias') || note.noteId;
2021-12-20 17:30:47 +01:00
if (syncServerHost) {
2021-12-22 10:57:02 +01:00
link = syncServerHost + "/share/" + shareId;
this.$sharedText.text("This note is shared publicly on");
2021-12-20 17:30:47 +01:00
}
else {
2021-12-22 10:57:02 +01:00
link = location.protocol + '//' + location.host + location.pathname + "share/" + shareId;
this.$sharedText.text("This note is shared locally on");
2021-12-20 17:30:47 +01:00
}
this.$sharedLink.attr("href", link).text(link);
2021-12-20 17:30:47 +01:00
}
2021-12-22 10:57:02 +01:00
entitiesReloadedEvent({loadResults}) {
if (loadResults.getAttributes().find(attr => attr.name.startsWith("share") && attributeService.isAffecting(attr, this.note))) {
this.refresh();
}
2021-12-22 15:01:54 +01:00
else if (loadResults.getBranches().find(branch => branch.noteId === this.noteId)) {
this.refresh();
}
2021-12-22 10:57:02 +01:00
}
2021-12-20 17:30:47 +01:00
}