Skip to content

Commit 047b226

Browse files
committed
Merge commit 'ef5f5b35db25bd532c1f22424a7f17576cc219a4' into develop
2 parents 795dec7 + ef5f5b3 commit 047b226

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-21
lines changed

src/public/app/widgets/switch.js renamed to src/public/app/widgets/switch.ts

+24-15
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import NoteContextAwareWidget from "./note_context_aware_widget.js";
33

44
const TPL = `
55
<div class="switch-widget">
6-
<style>
6+
<style>
77
.switch-widget {
88
display: flex;
99
align-items: center;
1010
}
11-
11+
1212
/* The switch - the box around the slider */
1313
.switch-widget .switch {
1414
position: relative;
@@ -17,11 +17,11 @@ const TPL = `
1717
height: 24px;
1818
margin: 0;
1919
}
20-
20+
2121
.switch-on, .switch-off {
2222
display: flex;
2323
}
24-
24+
2525
/* The slider */
2626
.switch-widget .slider {
2727
border-radius: 24px;
@@ -34,7 +34,7 @@ const TPL = `
3434
background-color: var(--more-accented-background-color);
3535
transition: .4s;
3636
}
37-
37+
3838
.switch-widget .slider:before {
3939
border-radius: 50%;
4040
position: absolute;
@@ -47,20 +47,20 @@ const TPL = `
4747
-webkit-transition: .4s;
4848
transition: .4s;
4949
}
50-
50+
5151
.switch-widget .slider.checked {
5252
background-color: var(--main-text-color);
5353
}
54-
54+
5555
.switch-widget .slider.checked:before {
5656
transform: translateX(26px);
5757
}
58-
58+
5959
.switch-widget .switch-disabled {
6060
opacity: 70%;
6161
pointer-events: none;
6262
}
63-
63+
6464
.switch-widget .switch-help-button {
6565
font-weight: 900;
6666
border: 0;
@@ -72,29 +72,38 @@ const TPL = `
7272
7373
<div class="switch-on">
7474
<span class="switch-on-name"></span>
75-
75+
7676
&nbsp;
77-
77+
7878
<span class="switch-on-button">
7979
<label class="switch">
8080
<span class="slider"></span>
8181
</span>
8282
</div>
8383
<div class="switch-off">
8484
<span class="switch-off-name"></span>
85-
85+
8686
&nbsp;
87-
87+
8888
<span class="switch-off-button">
8989
<label class="switch">
9090
<span class="slider checked"></span>
9191
</span>
9292
</div>
93-
93+
9494
<button class="switch-help-button" type="button" data-help-page="" title="${t("open-help-page")}" style="display: none;">?</button>
9595
</div>`;
9696

9797
export default class SwitchWidget extends NoteContextAwareWidget {
98+
99+
protected $switchOn!: JQuery<HTMLElement>;
100+
protected $switchOnName!: JQuery<HTMLElement>;
101+
protected $switchOnButton!: JQuery<HTMLElement>;
102+
protected $switchOff!: JQuery<HTMLElement>;
103+
protected $switchOffName!: JQuery<HTMLElement>;
104+
protected $switchOffButton!: JQuery<HTMLElement>;
105+
protected $helpButton!: JQuery<HTMLElement>;
106+
98107
doRender() {
99108
this.$widget = $(TPL);
100109

@@ -113,7 +122,7 @@ export default class SwitchWidget extends NoteContextAwareWidget {
113122
this.$helpButton = this.$widget.find(".switch-help-button");
114123
}
115124

116-
toggle(state) {
125+
toggle(state: boolean) {
117126
if (state) {
118127
this.switchOn();
119128
} else {

src/public/app/widgets/template_switch.js renamed to src/public/app/widgets/template_switch.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import SwitchWidget from "./switch.js";
22
import attributeService from "../services/attributes.js";
33
import { t } from "../services/i18n.js";
4+
import type FNote from "../entities/fnote.js";
5+
import type { EventData } from "../components/app_context.js";
46

57
/**
68
* Switch for the basic properties widget which allows the user to select whether the note is a template or not, which toggles the `#template` attribute.
79
*/
810
export default class TemplateSwitchWidget extends SwitchWidget {
911
isEnabled() {
10-
return super.isEnabled() && !this.noteId.startsWith("_options");
12+
return super.isEnabled() && !this.noteId?.startsWith("_options");
1113
}
1214

1315
doRender() {
@@ -16,29 +18,35 @@ export default class TemplateSwitchWidget extends SwitchWidget {
1618
this.$switchOnName.text(t("template_switch.template"));
1719
this.$switchOnButton.attr("title", t("template_switch.toggle-on-hint"));
1820

19-
this.$switchOffName.text("Template");
21+
this.$switchOffName.text(t("template_switch.template"));
2022
this.$switchOffButton.attr("title", t("template_switch.toggle-off-hint"));
2123

2224
this.$helpButton.attr("data-help-page", "template.html").show();
2325
}
2426

2527
async switchOn() {
26-
await attributeService.setLabel(this.noteId, "template");
28+
if (this.noteId) {
29+
await attributeService.setLabel(this.noteId, "template");
30+
}
2731
}
2832

2933
async switchOff() {
34+
if (!this.note || !this.noteId) {
35+
return;
36+
}
37+
3038
for (const templateAttr of this.note.getOwnedLabels("template")) {
3139
await attributeService.removeAttributeById(this.noteId, templateAttr.attributeId);
3240
}
3341
}
3442

35-
async refreshWithNote(note) {
43+
async refreshWithNote(note: FNote) {
3644
const isTemplate = note.hasLabel("template");
3745
this.$switchOn.toggle(!isTemplate);
3846
this.$switchOff.toggle(!!isTemplate);
3947
}
4048

41-
entitiesReloadedEvent({ loadResults }) {
49+
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
4250
if (loadResults.getAttributeRows().find((attr) => attr.type === "label" && attr.name === "template" && attr.noteId === this.noteId)) {
4351
this.refresh();
4452
}

src/share/content_renderer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import assetPath from "../services/asset_path.js";
44
import shareRoot from "./share_root.js";
55
import escapeHtml from "escape-html";
66
import type SNote from "./shaca/entities/snote.js";
7+
import { t } from "i18next";
78

89
/**
910
* Represents the output of the content renderer.
@@ -43,7 +44,7 @@ function getContent(note: SNote) {
4344
} else if (note.type === "book") {
4445
result.isEmpty = true;
4546
} else {
46-
result.content = "<p>This note type cannot be displayed.</p>";
47+
result.content = `<p>${t("content_renderer.note-cannot-be-displayed")}</p>`;
4748
}
4849

4950
return result;

translations/en/server.json

+3
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,8 @@
250250
"backend_log": {
251251
"log-does-not-exist": "The backend log file '{{ fileName }}' does not exist (yet).",
252252
"reading-log-failed": "Reading the backend log file '{{ fileName }}' failed."
253+
},
254+
"content_renderer": {
255+
"note-cannot-be-displayed": "This note type cannot be displayed."
253256
}
254257
}

translations/ro/server.json

+3
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,8 @@
251251
},
252252
"geo-map": {
253253
"create-child-note-instruction": "Clic pe hartă pentru a crea o nouă notiță la acea poziție sau apăsați Escape pentru a renunța."
254+
},
255+
"content_renderer": {
256+
"note-cannot-be-displayed": "Acest tip de notiță nu poate fi afișat."
254257
}
255258
}

0 commit comments

Comments
 (0)