-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangeCRM.js
524 lines (519 loc) · 20.2 KB
/
changeCRM.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
var options = document.getElementById("people");
var personOption;
var allPeople = [];
var rowCount = 2;
var rowChainCount = 2;
var size = 0;
var chosenCol = "";
var chosenRow = 0;
var chosenChainRow=0;
var url =
"https://script.google.com/macros/s/AKfycbz1TcC9joZ1TGGWuk44ul5FfLPbS7BObGmYnGoujKiKl9RRSepodwWEsOQ2AfeHpL4zKg/exec";
var newPerson = {};
var chainOption;
var allChains = [];
var newChain = {};
var currChain = {};
var chainDataURL =
"https://script.google.com/macros/s/AKfycbye8Aq8q9R5EHO6_S1pwc71ogwBCt2XSYe5TVBbodwwuGc2ypMLBAvKi2IH749aP-Y78g/exec";
var taskurl =
"https://script.google.com/macros/s/AKfycbxkrk_yRhO2mlPgHi8KuzvKY9B0UXH34bMTqw-7UAScxJp1OXaWXAZiHAq4UUMp7UmRVg/exec";
getChainData();
getData();
function getData() {
fetch(url)
.then((res) => {
return res.json();
})
.then((json) => {
json.data.forEach((ele) => {
newPerson = {
name: ele.name,
guestphone: ele.phone,
chain: ele.chain,
order: ele.order,
mess: ele.datelastmess,
email: ele.email,
title: ele.topicofstory,
subtitle: ele.subtitle,
virtue: ele.virtue,
abouttheguest: ele.abouttheguest,
interphone: ele.interviewerphone,
interviewername: ele.interviewername,
date: ele.recordingdate,
hour: ele.recordinghour,
link555: ele.linkfive,
link55drive: ele.linkshort,
link55yt: ele.linkshortyt,
linkfull: ele.linkfull,
linkspotify: ele.linkspotify,
linksc: ele.linksc,
linkpic: ele.linkpic,
linkexplain: ele.linkexplain,
linkpre: ele.preptalk,
meta:ele.meta,
id: ele.id,
clip1: ele.clip1,
clip2: ele.clip2,
clip3: ele.clip3,
clip4: ele.clip4,
clip5: ele.clip5,
clip6: ele.clip6,
row: rowCount,
};
if (ele.fixedname !== "") newPerson.name = ele.fixedname;
if (ele.fixedphone !== "") newPerson.guestphone = ele.fixedphone;
if (newPerson.chain === "") {
if (ele.chaintwo !== "") newPerson.chain = ele.chaintwo;
if (ele.chainthree !== "") newPerson.chain = ele.chainthree;
if (ele.chainfour !== "") newPerson.chain = ele.chainfour;
}
if (ele.fixedchain !== "") newPerson.chain = ele.fixedchain;
if (ele.fixedemail !== "") newPerson.email = ele.fixedemail;
if (ele.fixedtopicofstory !== "")
newPerson.title = ele.fixedtopicofstory;
if (ele.fixedsubtitle !== "") newPerson.subtitle = ele.fixedsubtitle;
if (ele.fixedvirtue !== "") newPerson.virtue = ele.fixedvirtue;
if (ele.fixedabouttheguest !== "")
newPerson.abouttheguest = ele.fixedabouttheguest;
if (ele.fixedinterviewername !== "")
newPerson.interviewername = ele.fixedinterviewername;
if (ele.fixedinterviewerphone !== "")
newPerson.interphone = ele.fixedinterviewerphone;
if (ele.recordingdate !== "")
newPerson.date = changeTimeZone(new Date(ele.recordingdate), 'Asia/Jerusalem');
if (ele.meta !== "")
newPerson.meta = changeTimeZone(new Date(ele.meta), 'Asia/Jerusalem');
if (ele.recordinghour !== "")
newPerson.hour = changeTimeZone(new Date(ele.recordinghour), 'Asia/Jerusalem');
if (ele.fixedrecordingdate !== ""&&ele.fixedrecordingdate!=="ללא תאריך")
newPerson.date = changeTimeZone(new Date(ele.fixedrecordingdate), 'Asia/Jerusalem');
if (ele.fixedrecordingdate==="ללא תאריך"){
newPerson.date = "ללא תאריך";
}
if (ele.fixedrecordinghour !== "")
newPerson.hour = changeTimeZone(new Date(ele.fixedrecordinghour), 'Asia/Jerusalem');
allPeople.push(newPerson);
console.log(allPeople[size]);
personOption = document.createElement("option");
personOption.value =
newPerson.name + " + " + fixChainFromData(newPerson.chain);
personOption.id = rowCount;
if (newPerson.name !== "" || newPerson.chain !== "") {
options.append(personOption);
}
rowCount++;
size++;
});
});
}
function getChainData() {
fetch(chainDataURL)
.then((res) => {
return res.json();
})
.then((json) => {
json.data.chains.forEach((ele) => {
newChain = {
name: ele.name,
altName:ele.othername,
participants:ele.participants,
chainExplain:ele.about,
row:rowChainCount
};
allChains.push(newChain);
chainOption = document.createElement("option");
chainOption.value = "555-" + newChain.name;
document.getElementById("chainsNames").append(chainOption);
rowChainCount++;
});
});
}
setTimeout(() => {
const loader = document.getElementById("loader");
loader.style.display = "none";
}, 2050);
function clearValues() {
document.getElementById("metaAllChange").style.visibility="hidden";
document.getElementById("deleteDate").style.visibility="visible";
document.getElementById("link555").value = "";
document.getElementById("linkfull").value = "";
document.getElementById("link55drive").value = "";
document.getElementById("link55yt").value = "";
document.getElementById("linkspotify").value = "";
document.getElementById("linksc").value = "";
document.getElementById("linkexplain").value = "";
document.getElementById("linkpre").value = "";
document.getElementById("clip1").value = "";
document.getElementById("clip2").value = "";
document.getElementById("name").value = "";
document.getElementById("guestphone").value = "";
document.getElementById("email").value = "";
document.getElementById("chain").value = "";
document.getElementById("order").value = "";
document.getElementById("mess").value = "";
document.getElementById("title").value = "";
document.getElementById("subtitle").value = "";
document.getElementById("virtue").value = "";
document.getElementById("about").value = "";
document.getElementById("intername").value = "";
document.getElementById("interphone").value = "";
document.getElementById("id").value = "";
document.getElementById("date").value = "";
document.getElementById("hour").value = "";
document.getElementById("participants").value = "";
document.getElementById("link555Change").innerHTML="הוספת סרט555";
document.getElementById("linkfullChange").innerHTML="הוספת הראיון המלא";
document.getElementById("link55driveChange").innerHTML="הוספת לינק לסרט 55-דרייב";
document.getElementById("link55ytChange").innerHTML="הוספת סרט קצר 55-יוטיוב";
document.getElementById("linkspotifyChange").innerHTML="הוספת לינק לספוטיפיי";
document.getElementById("linkscChange").innerHTML="הוספת לינק לסאונדקלאוד";
document.getElementById("linkexplainChange").innerHTML="הוספת סרט הסבר לשרשרת";
document.getElementById("linkpreChange").innerHTML="הוספת סרט הכנה לפתיחת שרשרת";
document.getElementById("clip1Change").innerHTML="הוספת קליפ1";
document.getElementById("clip2Change").innerHTML="הוספת קליפ2";
document.getElementById("nameChange").innerHTML="תיקון שם";
document.getElementById("guestphoneChange").innerHTML="תיקון נייד אורח";
document.getElementById("emailChange").innerHTML="תיקון כתובת מייל";
document.getElementById("chainChange").innerHTML="תיקון שרשרת";
document.getElementById("orderChange").innerHTML="הוספת מספר חרוז בשרשרת";
document.getElementById("titleChange").innerHTML="תיקון כותרת";
document.getElementById("subtitleChange").innerHTML="תיקון מסר";
document.getElementById("virtueChange").innerHTML="תיקון סגולה";
document.getElementById("aboutChange").innerHTML="תיקון הצגה";
document.getElementById("aboutAdd").innerHTML="הוספת הצגה";
document.getElementById("internameChange").innerHTML="תיקון שם מראיין";
document.getElementById("interphoneChange").innerHTML="תיקון נייד מראיין";
document.getElementById("idChange").innerHTML="הוספת מספר פרק פודקאסט";
document.getElementById("dateChange").innerHTML="תיקון תאריך (והחזרת חרוז שנמחק)";
document.getElementById("hourChange").innerHTML="תיקון שעה";
document.getElementById("participantsChange").innerHTML="הוספת תיאור משתתפי השרשרת";
document.getElementById("metaChange").innerHTML="ניקוי שדה פרסום מטא והחזרת החרוז להגרלה";
}
function submitData() {
clearValues();
for (var i = 0; i < allPeople.length; i++) {
var nameAndChain = document.getElementById("peopleList").value.split(" + ");
if (
allPeople[i].name === nameAndChain[0] &&
fixChainFromData(allPeople[i].chain) === nameAndChain[1]
) {
chosenRow = allPeople[i].row;
for(var j=0;j<allChains.length;j++){
if((allChains[j].name===fixChainFromData(allPeople[i].chain)||
allChains[j].altName===fixChainFromData(allPeople[i].chain))&&
allChains[j].name!==""){
currChain=allChains[j];
chosenChainRow=allChains[j].row;
console.log("chain row:"+chosenChainRow);
}
}
document.getElementById("link555B4").innerHTML = allPeople[i].link555;
document.getElementById("linkfullB4").innerHTML = allPeople[i].linkfull;
document.getElementById("link55driveB4").innerHTML =
allPeople[i].link55drive;
document.getElementById("link55ytB4").innerHTML = allPeople[i].link55yt;
document.getElementById("linkspotifyB4").innerHTML =
allPeople[i].linkspotify;
document.getElementById("linkscB4").innerHTML = allPeople[i].linksc;
document.getElementById("linkexplainB4").innerHTML =
currChain.chainExplain;
document.getElementById("linkpreB4").innerHTML = allPeople[i].linkpre;
document.getElementById("nameB4").innerHTML = allPeople[i].name;
document.getElementById("nameB4also").innerHTML = allPeople[i].name+" - "+fixChainFromData(allPeople[i].chain);
document.getElementById("internameB4").innerHTML =
allPeople[i].interviewername;
document.getElementById("emailB4").innerHTML = allPeople[i].email;
document.getElementById("guestPhoneB4").innerHTML =
allPeople[i].guestphone;
document.getElementById("chainB4").innerHTML = allPeople[i].chain;
document.getElementById("orderB4").innerHTML = allPeople[i].order;
document.getElementById("messB4").innerHTML = allPeople[i].mess;
document.getElementById("titleB4").innerHTML = allPeople[i].title;
document.getElementById("subtitleB4").innerHTML = allPeople[i].subtitle;
document.getElementById("virtueB4").innerHTML = allPeople[i].virtue;
document.getElementById("aboutB4").innerHTML = allPeople[i].abouttheguest;
document.getElementById("dateB4").innerHTML = allPeople[i].date;
document.getElementById("metaB4").innerHTML=allPeople[i].meta;
document.getElementById("idB4").innerHTML = allPeople[i].id;
document.getElementById("clip1B4").innerHTML = allPeople[i].clip1;
document.getElementById("clip2B4").innerHTML = allPeople[i].clip2;
if(allPeople[i].meta!==""){
document.getElementById("metaB4").innerHTML = allPeople[i].meta.getDate() +
"/" +
(allPeople[i].meta.getMonth() + 1) +
"/" +
allPeople[i].meta.getFullYear();
}
document.getElementById("participantsB4").innerHTML=currChain.participants;
document.getElementById("hourB4").innerHTML = allPeople[i].hour;
document.getElementById("interPhoneB4").innerHTML =
allPeople[i].interphone;
if (allPeople[i].date !== ""&&allPeople[i].date !== "ללא תאריך") {
document.getElementById("dateB4").innerHTML =
allPeople[i].date.getDate() +
"/" +
(allPeople[i].date.getMonth() + 1) +
"/" +
allPeople[i].date.getFullYear();
}
if (allPeople[i].date === "ללא תאריך") {
document.getElementById("dateB4").innerHTML ="ללא תאריך";
}
if (allPeople[i].hour !== "") {
document.getElementById("hourB4").innerHTML =
allPeople[i].hour.getHours() + ":" + allPeople[i].hour.getMinutes();
if (allPeople[i].hour.getMinutes() < 10)
document.getElementById("hourB4").innerHTML =
allPeople[i].hour.getHours() +
":0" +
allPeople[i].hour.getMinutes();
}
console.log("row:" + chosenRow);
}
}
}
function sendData(obj, ele,whichSheet) {
console.log(obj);
let formData = new FormData();
formData.append("data", JSON.stringify(obj));
console.log(obj);
var urlUsed=url;
if(whichSheet==="crm"){
urlUsed=url;
}
if(whichSheet==="chains"){
urlUsed=chainDataURL;
}
if(whichSheet==="tasks"){
urlUsed=taskurl;
}
fetch(urlUsed, {
method: "POST",
body: formData,
})
.then((rep) => {
console.log(obj);
return rep.json();
})
.then((json) => {
console.log(obj);
console.log(json);
});
}
function change(id){
var dataElement=document.getElementById(id+"Change");
chosenCol=id;
console.log("col: "+chosenCol);
if (chosenRow === 0) {
alert("נא לבחור מישהו מהטבלה כדי לשנות");
}
const temp = {
text: document.getElementById(id).value,
row: chosenRow,
col: chosenCol,
};
if (chosenRow > 0) {
sendData(temp, dataElement,"crm");
dataElement.innerHTML="התעדכן";
}
}
function changeMeta(id){
var dataElement=document.getElementById(id+"Change");
chosenCol=id;
console.log("col: "+chosenCol);
if (chosenRow === 0) {
alert("נא לבחור מישהו מהטבלה כדי לשנות");
}
const temp = {
text: "",
row: chosenRow,
col: chosenCol,
};
if (chosenRow > 0) {
sendData(temp, dataElement,"crm");
dataElement.innerHTML="התעדכן";
}
}
function changeMetaAll(id){
if(confirm("האם את באמת רוצה לאפס את מערכת הגרלת הפוסטים לפרסום?")){
var dataElement=document.getElementById(id+"Change");
chosenCol="meta";
console.log("col: "+chosenCol);
for(var j=0;j<3;j++){
for(var i=2;i<rowCount;i++){
const temp = {
text: "",
row: i,
col: "meta",
};
sendData(temp, dataElement,"crm");
}
}
dataElement.innerHTML="התעדכן";
console.log("בוצע");
}
else{
console.log("לא בוצע שינוי");
}
}
function changeChainInfo(id){
var dataElement=document.getElementById(id+"Change");
chosenCol=id;
console.log("col: "+chosenCol);
if (chosenRow === 0) {
alert("נא לבחור מישהו מהטבלה כדי לשנות");
}
const temp = {
text: document.getElementById(id).value,
row: chosenChainRow,
col: chosenCol,
};
if (chosenRow > 0) {
sendData(temp, dataElement,"chains");
dataElement.innerHTML="התעדכן";
}
}
function changeChainExplain(){
console.log("col: linkexplain");
console.log("col: about");
if (chosenRow === 0) {
alert("נא לבחור מישהו מהטבלה כדי לשנות");
}
const obj1 = {
text: document.getElementById("linkexplain").value,
row: chosenRow,
col: "linkexplain",
};
const obj2 = {
text: document.getElementById("linkexplain").value,
row: chosenChainRow,
col: "about",
};
if (chosenRow > 0) {
console.log(obj1);
console.log(obj2);
let formData1 = new FormData();
formData1.append("data", JSON.stringify(obj1));
let formData2 = new FormData();
formData2.append("data", JSON.stringify(obj2));
fetch(url, {
method: "POST",
body: formData1,
})
.then((rep) => {
console.log(obj1);
return rep.json();
})
.then((json) => {
console.log(obj1);
console.log(json);
});
fetch(chainDataURL, {
method: "POST",
body: formData2,
})
.then((rep) => {
console.log(obj2);
return rep.json();
})
.then((json) => {
console.log(obj2);
console.log(json);
});
document.getElementById("linkexplainChange").innerHTML="התעדכן";
}
}
function addAbout(id) {
var textEntered=document.getElementById(id).value;
if(document.getElementById("aboutB4").innerHTML!==""){
var textEntered=document.getElementById("aboutB4").innerHTML+"\n"+document.getElementById(id).value;
}
var dataElement=document.getElementById(id+"Add");
chosenCol=id;
console.log("col: " + chosenCol);
if (chosenRow === 0) {
alert("נא לבחור מישהו מהטבלה כדי לשנות");
}
var temp = {
text: textEntered,
row: chosenRow,
col: chosenCol,
};
if (chosenRow > 0) {
sendData(temp, dataElement,"crm");
dataElement.innerHTML="התעדכן";
}
}
function changeDate(){
var dataElement=document.getElementById("dateChange");
change('date');
if (chosenRow === 0) {
alert("נא לבחור מישהו מהטבלה כדי לשנות");
}
var messesTypes=[
"premess","rightaftermess","postmess","postmessinvite","socialpost","clipscreate","clip1send","clip2send","subs","clip3send","premessemail"
];
for(var i=0;i<messesTypes.length;i++){
console.log("col: "+messesTypes[i]);
var temp = {
text: "not yet",
row: chosenRow,
col: messesTypes[i],
};
if (chosenRow > 0) {
sendData(temp, dataElement,"tasks");
dataElement.innerHTML="התעדכן";
}
}
}
function deleteDate(id){
var dataElement=document.getElementById("deleteDate");
chosenCol=id;
console.log("col: "+chosenCol);
if (chosenRow === 0) {
alert("נא לבחור מישהו מהטבלה כדי לשנות");
}
var temp = {
text: "ללא תאריך",
row: chosenRow,
col: chosenCol,
};
if (chosenRow > 0) {
sendData(temp, dataElement,"crm");
}
var messesTypes=[
"premess","rightaftermess","postmess","postmessinvite","socialpost","confirm","addcreator","clipscreate","clip1send","clip2send","subs","clip3send","premessemail"
];
for(var i=0;i<messesTypes.length;i++){
console.log("col: "+messesTypes[i]);
var temp2 = {
text: "completed",
row: chosenRow,
col: messesTypes[i],
};
if (chosenRow > 0) {
sendData(temp2, dataElement,"tasks");
dataElement.innerHTML="התעדכן";
}
}
}
function fixChainFromData(chain) {
var splittedChain; //
if (chain.includes(" (") || chain.includes("-")) {
splittedChain = chain.split(" (");
var moresplitted;
if (splittedChain[0].includes("-")) {
moresplitted = splittedChain[0].split("-");
return moresplitted[1].trim();
}
return splittedChain[0].trim();
}
return chain;
}
function changeTimeZone(date, timeZone) {
if (typeof date === 'string') {
return new Date(new Date(date).toLocaleString('en-US', { timeZone }));
}
return new Date(date.toLocaleString('en-US', { timeZone }));
}