Skip to content
This repository was archived by the owner on May 13, 2018. It is now read-only.

Commit ca7d951

Browse files
committed
DB鯖からの投稿削除に対応
1 parent 8d43eda commit ca7d951

6 files changed

Lines changed: 91 additions & 112 deletions

File tree

Dialog.js

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,42 @@ window.addEventListener("DOMContentLoaded", () => {
99
if (event.ctrlKey && event.keyCode == 13) dialog.querySelector('Button[Data-Action="Dialog_Submit"]').click();
1010
});
1111
}
12-
});
13-
14-
DOM('@Dialog Button[Data-Action="Dialog_Close"]').forEach((btn) => {
15-
btn.addEventListener("click", () => {
16-
btn.offsetParent.close();
12+
13+
dialog.querySelectorAll('Dialog *[Required]').forEach((input) => {
14+
input.addEventListener("input", () => {
15+
let result = true;
16+
17+
dialog.querySelectorAll('Dialog *[Required]').forEach(requiredField => {
18+
if (requiredField.value.replace(/\s/g, "").length == 0) {
19+
result = false;
20+
return;
21+
}
22+
});
23+
24+
if (result) {
25+
dialog.querySelector('Button[Data-Action="Dialog_Submit"]').classList.remove("mdl-button--disabled");
26+
} else {
27+
dialog.querySelector('Button[Data-Action="Dialog_Submit"]').classList.add("mdl-button--disabled");
28+
}
29+
});
30+
});
31+
32+
dialog.querySelectorAll('Dialog Button[Data-Action="Dialog_Close"]').forEach((btn) => {
33+
btn.addEventListener("click", () => {
34+
btn.offsetParent.close();
35+
});
1736
});
1837
});
1938

2039

2140

22-
DOM("#Dialogs_Profile_DeleteConfirmer_Btns_Yes").addEventListener("click", () => {
23-
if (DOM("#Dialogs_Profile_DeleteConfirmer_Content_Email_Input").value == base.user.email) {
24-
base.delete();
25-
} else {
26-
DOM("#Dialogs_Profile_DeleteConfirmer_Content_Email").classList.add("is-invalid");
41+
DOM("#Dialogs_Profile_DeleteConfirmer_Btns_Yes").addEventListener("click", (event) => {
42+
if (!event.currentTarget.classList.contains("mdl-button--disabled")) {
43+
if (DOM("#Dialogs_Profile_DeleteConfirmer_Content_Email_Input").value == base.user.email) {
44+
base.delete();
45+
} else {
46+
DOM("#Dialogs_Profile_DeleteConfirmer_Content_Email").classList.add("is-invalid");
47+
}
2748
}
2849
});
2950

@@ -61,72 +82,54 @@ window.addEventListener("DOMContentLoaded", () => {
6182

6283

6384

64-
[DOM("#Dialogs_Thread_InfoInputer_Content_Name_Input"), DOM("#Dialogs_Thread_InfoInputer_Content_Overview_Input"), DOM("#Dialogs_Thread_InfoInputer_Content_Detail_Input")].forEach((textarea) => {
65-
textarea.addEventListener("input", (event) => {
66-
if (event.target.value.replace(/\s/g, "").length == 0) {
67-
DOM("#Dialogs_Thread_InfoInputer_Btns_OK").classList.add("mdl-button--disabled");
68-
} else {
69-
DOM("#Dialogs_Thread_InfoInputer_Btns_OK").classList.remove("mdl-button--disabled");
70-
}
71-
});
72-
});
85+
DOM("#Dialogs_Thread_InfoInputer_Btns_OK").addEventListener("click", (event) => {
86+
if (!event.currentTarget.classList.contains("mdl-button--disabled")) {
87+
base.Database.transaction("threads", (res) => {
88+
let now = new Date().getTime();
7389

74-
DOM("#Dialogs_Thread_InfoInputer_Btns_OK").addEventListener("click", () => {
75-
base.Database.transaction("threads", (res) => {
76-
let now = new Date().getTime();
90+
base.Database.set("threads/" + res.length, {
91+
title: DOM("#Dialogs_Thread_InfoInputer_Content_Name_Input").value,
92+
overview: DOM("#Dialogs_Thread_InfoInputer_Content_Overview_Input").value,
93+
detail: DOM("#Dialogs_Thread_InfoInputer_Content_Detail_Input").value,
7794

78-
base.Database.set("threads/" + res.length, {
79-
title: DOM("#Dialogs_Thread_InfoInputer_Content_Name_Input").value,
80-
overview: DOM("#Dialogs_Thread_InfoInputer_Content_Overview_Input").value,
81-
detail: DOM("#Dialogs_Thread_InfoInputer_Content_Detail_Input").value,
95+
jobs: {
96+
Owner: (() => {
97+
let owner = {}; owner[base.user.uid] = "";
98+
return owner;
99+
})(),
82100

83-
jobs: {
84-
Owner: (() => {
85-
let owner = {}; owner[base.user.uid] = "";
86-
return owner;
87-
})(),
101+
Admin: {
88102

89-
Admin: {
103+
}
104+
},
90105

91-
}
92-
},
106+
createdAt: now,
107+
108+
data: [
109+
{
110+
uid: base.user.uid,
111+
content: DOM("#Dialogs_Thread_InfoInputer_Content_Name_Input").value,
112+
plusCount: 0,
113+
createdAt: now
114+
}
115+
],
93116

94-
createdAt: now,
117+
password: ""
118+
});
95119

96-
data: [
97-
{
98-
uid: base.user.uid,
99-
content: DOM("#Dialogs_Thread_InfoInputer_Content_Name_Input").value,
100-
plusCount: 0,
101-
createdAt: now
102-
}
103-
],
104-
105-
password: ""
120+
DOM("#Dialogs_Thread_InfoInputer").close();
121+
parent.document.querySelector("IFrame.mdl-layout__content").src = "Thread/Viewer/?tid=" + res.length;
106122
});
107-
108-
DOM("#Dialogs_Thread_InfoInputer").close();
109-
parent.document.querySelector("IFrame.mdl-layout__content").src = "Thread/Viewer/?tid=" + res.length;
110-
});
111-
});
112-
113-
114-
115-
DOM("#Dialogs_Thread_Poster_Content_Value_Input").addEventListener("input", (event) => {
116-
if (event.target.value.replace(/\s/g, "").length == 0) {
117-
DOM("#Dialogs_Thread_Poster_Btns_OK").classList.add("mdl-button--disabled");
118-
} else {
119-
DOM("#Dialogs_Thread_Poster_Btns_OK").classList.remove("mdl-button--disabled");
120123
}
121124
});
122125

126+
127+
123128
DOM("#Dialogs_Thread_Poster_Btns_OK").addEventListener("click", (event) => {
124-
if (!DOM("#Dialogs_Thread_Poster_Btns_OK").classList.contains("mdl-button--disabled")) {
129+
if (!event.currentTarget.classList.contains("mdl-button--disabled")) {
125130
DOM("#Screens_Loading").removeAttribute("Disabled");
126131

127132
base.Database.transaction("threads/" + DOM("#Dialogs_Thread_Poster_Content_TID").value + "/data", (res) => {
128-
console.log(res);
129-
130133
base.Database.set("threads/" + DOM("#Dialogs_Thread_Poster_Content_TID").value + "/data/" + res.length, {
131134
uid: base.user.uid,
132135
content: DOM("#Dialogs_Thread_Poster_Content_Value_Input").value,

Thread/Viewer/Viewer.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,30 @@ window.addEventListener("DOMContentLoaded", () => {
4242
});
4343

4444
base.Database.get(base.Database.INTERVAL, "threads/" + querys.TID + "/data", (res) => {
45-
res = res.filter((post, index, parent) => {
45+
resForIncrease = res, resForDecrease = res;
46+
47+
resForIncrease = resForIncrease.filter((post, index, parent) => {
4648
if (post) {
4749
post.pid = index;
4850
return true;
4951
}
5052
});
5153

52-
if (DOM("#Thread").children.length < res.length) {
53-
for (let i = DOM("#Thread").children.length; i < res.length; i++) {
54+
resForDecrease.forEach((post, index, parent) => {
55+
post.pid = index;
56+
});
57+
58+
if (DOM("#Thread").children.length < resForIncrease.length) {
59+
for (let i = DOM("#Thread").children.length; i < resForIncrease.length; i++) {
5460
let rnd = new DOM.Randomizer(DOM.Randomizer.TYPE.LEVEL3).generate(16);
5561

56-
let post = new Components.Thread.Post(res[i].pid, res[i].uid, "", res[i].content, new Date(res[i].createdAt).toLocaleString(), rnd);
62+
let post = new Components.Thread.Post(resForIncrease[i].pid, resForIncrease[i].uid, "", resForIncrease[i].content, new Date(resForIncrease[i].createdAt).toLocaleString(), rnd);
5763
post.querySelector('A[UUID="Thread_Post_Header_ActorPhoto"]').addEventListener("click", () => {
58-
doc.querySelector("#Dialogs_Profile_InfoViewer_Content_UID").value = res[i].uid;
64+
doc.querySelector("#Dialogs_Profile_InfoViewer_Content_UID").value = resForIncrease[i].uid;
5965
doc.querySelector("#Dialogs_Profile_InfoViewer").showModal();
6066
});
6167

62-
base.Database.get(base.Database.ONCE, "users/" + res[i].uid, (userRes) => {
68+
base.Database.get(base.Database.ONCE, "users/" + resForIncrease[i].uid, (userRes) => {
6369
componentHandler.upgradeElement(post.querySelector(`Label#Thread_Post_Actions_Plus_${rnd}`));
6470
post.querySelector('Span[UUID="Thread_Post_Header_Actor"]').textContent = userRes.userName;
6571
});
@@ -71,7 +77,9 @@ window.addEventListener("DOMContentLoaded", () => {
7177
DOM("#Thread").appendChild(post);
7278
}
7379
} else {
74-
80+
DOM('@Div[UUID="Thread_Post"]').forEach((post) => {
81+
if (!resForDecrease[post.dataset.pid]) post.remove();
82+
});
7583
}
7684
});
7785

Thread/Viewer/index.html

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,7 @@
3939
<Body Style = 'Background: URL("/SimpleThread/Assets/Images/Back.jpg")'>
4040
<Div Class = "mdl-grid">
4141
<Div ID = "Thread" Class = "mdl-cell mdl-cell--2-offset mdl-cell--8-col mdl-shadow--4dp mdl-color--white mdl-color-text--grey-800">
42-
<!--<Div UUID = "Thread_Post" Class = "mdl-card mdl-shadow--2dp" Data-UID = "N4YbrYALWxeHLmhYx4bMfNDi7f22">
43-
<Div UUID = "Thread_Post_Header" Class = "mdl-card__title mdl-card--border">
44-
<A UUID = "Thread_Post_Header_ActorPhoto" Class = "mdl-button mdl-js-button mdl-button--icon mdl-js-ripple-effect" Data-UID = "N4YbrYALWxeHLmhYx4bMfNDi7f22"></A>
45-
<Span UUID = "Thread_Post_Header_Actor" Class = "mdl-card__title-text">プログラなーいGenboo</Span>
46-
<Div Class = "mdl-layout-spacer"></Div>
47-
48-
<Span UUID = "Thread_Post_Header_CreatedAt">2017/8/14 12:32:02</Span>
49-
</Div>
50-
51-
<Div UUID = "Thread_Post_Content" Class = "mdl-card__supporting-text">
52-
Thread for Debug
53-
</Div>
54-
55-
<Div UUID = "Thread_Post_Actions" Class = "mdl-card__actions">
56-
<Label ID = "Thread_Post_Actions_Plus" Class = "mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" For = "Input">
57-
<Input ID = "Thread_Post_Actions_Plus_Input" Class = "mdl-icon-toggle__input" Type = "Checkbox" />
58-
<Button ID = "Thread_Post_Actions_Plus_Btn" Class = "mdl-button mdl-js-button mdl-icon-toggle__label">+1</Button>
59-
60-
<Span ID = "Thread_Post_Actions_Plus_Count">0</Span>
61-
</Label>
62-
</Div>
63-
</Div>-->
42+
6443
</Div>
6544
</Div>
6645

debug/index.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

includes/Components.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ let doc = parent.document;
33
class Components {
44
static get componentsDoc () {
55
let doc = DOM("Body");
6+
7+
try {
68
doc.innerHTML = DOM.xhr({
79
type: "GET",
810
url: "/SimpleThread/includes/Components.html",
911
doesSync: false
1012
}).response;
13+
} catch (error) {}
1114

1215
return doc;
1316
}
@@ -115,7 +118,7 @@ class Components {
115118
componentWrapper.appendChild(component);
116119

117120
componentWrapper.firstElementChild.outerHTML = componentWrapper.firstElementChild.outerHTML.replaces([
118-
[/\${pid}/g, pid || ""],
121+
[/\${pid}/g, pid + "" || ""],
119122
[/\${uid}/g, uid || ""],
120123
[/\${userName}/g, userName || ""],
121124
[/\${content}/g, content || ""],

index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@
128128

129129
<Div ID = "Dialogs_Profile_DeleteConfirmer_Content_Email" Class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
130130
<Input ID = "Dialogs_Profile_DeleteConfirmer_Content_Email_Input" Class = "mdl-textfield__input" Type = "Email" Value = "" Required = "Required" />
131-
<Label ID = "Dialogs_Profile_DeleteConfirmer_Content_Email_Label" Class = "mdl-textfield__label" For = "Dialogs_Profile_DeleteConfirmer_Content_Email_Input">メールアドレス...</Label>
131+
<Label ID = "Dialogs_Profile_DeleteConfirmer_Content_Email_Label" Class = "mdl-textfield__label" For = "Dialogs_Profile_DeleteConfirmer_Content_Email_Input">メールアドレス...*</Label>
132132

133133
<Span Class = "mdl-textfield__error">無効なメールアドレスです</Span>
134134
</Div>
135135
</Div>
136136

137137
<Div ID = "Dialogs_Profile_DeleteConfirmer_Btns" Class = "mdl-dialog__actions">
138-
<Button ID = "Dialogs_Profile_DeleteConfirmer_Btns_Yes" Class = "mdl-button mdl-js-button mdl-js-ripple-effect" Type = "Button">はい</Button>
138+
<Button ID = "Dialogs_Profile_DeleteConfirmer_Btns_Yes" Class = "mdl-button mdl-js-button mdl-button--disabled mdl-js-ripple-effect" Type = "Button">はい</Button>
139139
<Button ID = "Dialogs_Profile_DeleteConfirmer_Btns_No" Class = "mdl-button mdl-js-button mdl-js-ripple-effect" Type = "Button" Data-Action = "Dialog_Close">いいえ</Button>
140140
</Div>
141141
</Dialog>
@@ -170,30 +170,30 @@
170170
<Div ID = "Dialogs_Thread_InfoInputer_Content" Class = "mdl-dialog__content">
171171
<Div ID = "Dialogs_Thread_InfoInputer_Content_Name" Class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
172172
<Input ID = "Dialogs_Thread_InfoInputer_Content_Name_Input" Class = "mdl-textfield__input" Type = "Text" Value = "" Required = "Required" />
173-
<Label ID = "Dialogs_Thread_InfoInputer_Content_Name_Label" Class = "mdl-textfield__label" For = "Dialogs_Thread_InfoInputer_Content_Name_Input">スレッド名...</Label>
173+
<Label ID = "Dialogs_Thread_InfoInputer_Content_Name_Label" Class = "mdl-textfield__label" For = "Dialogs_Thread_InfoInputer_Content_Name_Input">スレッド名...*</Label>
174174
</Div>
175175

176176
<Div ID = "Dialogs_Thread_InfoInputer_Content_Overview" Class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
177177
<Input ID = "Dialogs_Thread_InfoInputer_Content_Overview_Input" Class = "mdl-textfield__input" Type = "Text" Value = "" Required = "Required" />
178-
<Label ID = "Dialogs_Thread_InfoInputer_Content_Overview_Label" Class = "mdl-textfield__label" For = "Dialogs_Thread_InfoInputer_Content_Overview_Input">概要...</Label>
178+
<Label ID = "Dialogs_Thread_InfoInputer_Content_Overview_Label" Class = "mdl-textfield__label" For = "Dialogs_Thread_InfoInputer_Content_Overview_Input">概要...*</Label>
179179
</Div>
180180

181181
<Div ID = "Dialogs_Thread_InfoInputer_Content_Detail" Class = "mdl-textfield mdl-js-textfield">
182182
<Textarea ID = "Dialogs_Thread_InfoInputer_Content_Detail_Input" Class = "mdl-textfield__input" Rows = "10" MaxLength = "500"></Textarea>
183-
<Label Class = "mdl-textfield__label" For = "Dialogs_Thread_InfoInputer_Content_Detail_Input">詳細...(任意)</Label>
183+
<Label Class = "mdl-textfield__label" For = "Dialogs_Thread_InfoInputer_Content_Detail_Input">詳細...</Label>
184184
</Div>
185185
</Div>
186186

187187
<Div ID = "Dialogs_Thread_InfoInputer_Btns" Class = "mdl-dialog__actions">
188-
<Button ID = "Dialogs_Thread_InfoInputer_Btns_OK" Class = "mdl-button mdl-js-button mdl-js-ripple-effect" Type = "Button" Data-Action = "Dialog_Submit">作成</Button>
188+
<Button ID = "Dialogs_Thread_InfoInputer_Btns_OK" Class = "mdl-button mdl-js-button mdl-button--disabled mdl-js-ripple-effect" Type = "Button" Data-Action = "Dialog_Submit">作成</Button>
189189
<Button ID = "Dialogs_Thread_InfoInputer_Btns_Cancel" Class = "mdl-button mdl-js-button mdl-js-ripple-effect" Type = "Button" Data-Action = "Dialog_Close">キャンセル</Button>
190190
</Div>
191191
</Dialog>
192192

193193
<Dialog ID = "Dialogs_Thread_Poster" Class = "mdl-dialog">
194194
<Div ID = "Dialogs_Thread_Poster_Content" Class = "mdl-dialog__content">
195195
<Div ID = "Dialogs_Thread_Poster_Content_Value" Class = "mdl-textfield mdl-js-textfield">
196-
<Textarea ID = "Dialogs_Thread_Poster_Content_Value_Input" Class = "mdl-textfield__input" Rows = "15" MaxLength = "500"></Textarea>
196+
<Textarea ID = "Dialogs_Thread_Poster_Content_Value_Input" Class = "mdl-textfield__input" Rows = "15" MaxLength = "500" Required = "Required"></Textarea>
197197
<Label Class = "mdl-textfield__label" For = "Dialogs_Thread_Poster_Content_Value_Input">最近の出来事を共有してみましょう</Label>
198198
</Div>
199199

0 commit comments

Comments
 (0)