From 39d1a370437b839cb75d83da8839dfffc48dd2a4 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Sat, 9 Mar 2024 16:41:08 -0600 Subject: [PATCH] add compose box to email --- package-lock.json | 6 + package.json | 1 + src/app.js | 4 + src/controllers/event.js | 3 + src/controllers/eventlineup.js | 3 +- src/public/js/eventlineup.js | 64 +++++++- src/views/eventlineup/edit.hbs | 9 ++ src/views/eventlineup/email.hbs | 150 ++++++++---------- .../eventlineup/partials/email_table.hbs | 62 ++++++++ src/views/eventlineup/partials/emailmodal.hbs | 26 ++- 10 files changed, 231 insertions(+), 97 deletions(-) create mode 100644 src/views/eventlineup/partials/email_table.hbs diff --git a/package-lock.json b/package-lock.json index 431b71c..01931e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "pug": "^3.0.2", "sortablejs": "^1.15.0", "teamsnap.js": "github:anthonyscorrea/teamsnap-javascript-sdk#add-eventLineup-eventLineupEntry", + "tinymce": "^6.8.3", "underscore": "^1.13.6", "xhr2": "^0.2.1" }, @@ -4717,6 +4718,11 @@ "npm": ">=3.0.0" } }, + "node_modules/tinymce": { + "version": "6.8.3", + "resolved": "https://registry.npmjs.org/tinymce/-/tinymce-6.8.3.tgz", + "integrity": "sha512-3fCHKAeqT+xNwBVESf6iDbDV0VNwZNmfrkx9c/6Gz5iB8piMfaO6s7FvoiTrj1hf1gVbfyLTnz1DooI6DhgINQ==" + }, "node_modules/to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", diff --git a/package.json b/package.json index d682810..a3c5a19 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "pug": "^3.0.2", "sortablejs": "^1.15.0", "teamsnap.js": "github:anthonyscorrea/teamsnap-javascript-sdk#add-eventLineup-eventLineupEntry", + "tinymce": "^6.8.3", "underscore": "^1.13.6", "xhr2": "^0.2.1" }, diff --git a/src/app.js b/src/app.js index b472cbb..d78669f 100644 --- a/src/app.js +++ b/src/app.js @@ -90,6 +90,10 @@ app.use( "/js", express.static(path.join(__dirname, "../node_modules/sortablejs")) ); +app.use( + "/js", + express.static(path.join(__dirname, "../node_modules/tinymce")) +); app.use( "/js", express.static(path.join(__dirname, "../node_modules/teamsnap.js/lib/")) diff --git a/src/controllers/event.js b/src/controllers/event.js index 4668ee1..435976d 100644 --- a/src/controllers/event.js +++ b/src/controllers/event.js @@ -11,6 +11,9 @@ exports.helpers = { unknown: "playerUnknownCount" }[status.toLowerCase()] return (availabilitySummary[attribute]/availabilitySummary.team.playerMemberCount)*100.0 + }, + isAway: (event) => { + return event.gameType == "Away"; } } diff --git a/src/controllers/eventlineup.js b/src/controllers/eventlineup.js index 7be972e..a5b9687 100644 --- a/src/controllers/eventlineup.js +++ b/src/controllers/eventlineup.js @@ -125,8 +125,7 @@ exports.getEventLineupEmail = async (req, res)=>{ const {newEventLineupEntries} = processPostedEventLineupEntries(body, eventLineupEntries, event_lineup) attachBenchcoachPropertiesToMember(members, newEventLineupEntries, availabilities) members.sort(tsUtils.teamsnapMembersSortLineupAvailabilityLastName) - // eventLineup = await teamsnap.loadEventLineups(req.params.event_id) - res.status(200).render("eventlineup/email", {user, team, members, event, event_lineup, event_lineup_entries: newEventLineupEntries, availabilities, availabilitySummary}) + res.status(200).render("eventlineup/partials/email_table", {user, team, members, event, event_lineup, event_lineup_entries: newEventLineupEntries, availabilities, availabilitySummary}) } exports.getEventLineupEntries = async (req, res)=>{ diff --git a/src/public/js/eventlineup.js b/src/public/js/eventlineup.js index 995c083..c3a5e42 100644 --- a/src/public/js/eventlineup.js +++ b/src/public/js/eventlineup.js @@ -276,9 +276,13 @@ function emailModal(el, url) { return Promise.reject(response.text()); } }) - .then((html) => { - email_modal.classList.add("is-open"); - email_modal.querySelector(".Modal-body").innerHTML = html; + .then((lineup_table) => { + const email_textarea = document.querySelector('#email-editor') + const lineup_table_div = document.querySelector(".FieldGroup .lineup-email") + tinymce.activeEditor.setContent("Team,") + lineup_table_div.innerHTML = lineup_table + email_modal.classList.add("is-open"); + // email_modal.querySelector(".Modal-body").innerHTML = html; }); } @@ -505,3 +509,57 @@ function toggleChildSlots (element) { }) } } + +async function submitEmail () { + // range=document.createRange(); + // window.getSelection().removeAllRanges(); + // // range.selectNode(document.querySelector('.Modal').querySelector('.Modal-body')); + // tinymce.activeEditor.selection.select(tinymce.activeEditor.getBody()); + // // window.getSelection().addRange(range); + // document.execCommand('copy'); + // window.getSelection().removeAllRanges(); + const emailStyle = ` + + ` + html_content = emailStyle+tinymce.activeEditor.getContent() + console.log(html_content) + + navigator.clipboard.write( + [new ClipboardItem( + { + 'text/plain': new Blob([tinymce.activeEditor.getContent({format: "text"})], {type: 'text/plain'}), + 'text/html': new Blob([html_content], {type: 'text/html'}) + }) + ]) +} \ No newline at end of file diff --git a/src/views/eventlineup/edit.hbs b/src/views/eventlineup/edit.hbs index e79b51f..79b0f78 100644 --- a/src/views/eventlineup/edit.hbs +++ b/src/views/eventlineup/edit.hbs @@ -111,10 +111,19 @@ + diff --git a/src/views/eventlineup/email.hbs b/src/views/eventlineup/email.hbs index 9d245b5..d5bf6d7 100644 --- a/src/views/eventlineup/email.hbs +++ b/src/views/eventlineup/email.hbs @@ -1,90 +1,70 @@
- - - - - - - - {{#each members}} - {{#if (isInStartingLineup this)}} +
+

Team,

+

+
+
+
- STARTING LINEUP -
+ + + + + + + {{#each members}} + {{#if (isInStartingLineup this)}} + + + + + + {{/if}} + {{/each}} - - - - - {{/if}} - {{/each}} - - - - {{#each members}} - {{#if (isInPositionOnly this)}} + + + {{#each members}} + {{#if (isInPositionOnly this)}} + + + + + + {{/if}} + {{/each}} - - - - - {{/if}} - {{/each}} - - - - {{#each members}} - {{#if (isInBench this)}} + + + {{#each members}} + {{#if (isInBench this)}} + + + + + + {{/if}} + {{/each}} - - - - - {{/if}} - {{/each}} - - - - {{#each members}} - {{#if (isInOut this)}} - - - - - - {{/if}} - {{/each}} - {{!-- - - - - - - -
+ STARTING LINEUP +
+ {{plus1 this.benchcoach.eventLineupEntry.sequence}} + {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
- {{plus1 this.benchcoach.eventLineupEntry.sequence}} - {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
Starting (Pos. Only)
Starting (Pos. Only)
{{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
{{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
Subs
Subs
+ {{availabilityStatusShort this.benchcoach.availability}} + {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
- {{availabilityStatusShort this.benchcoach.availability}} - {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
Out
- {{availabilityStatusShort this.benchcoach.availability}} - {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
.title-cell colSpan=3 Subs - - for entry in event_lineup_entries.select{|e| e[:label].blank? and !(e[:availability_status_code] == "0" or e[:availability_status_code]== "")} -
.sequence-cell - - if entry[:availability_status_code] == "1" - | YES - - if entry[:availability_status_code] == "2" - | MAY - .name-cell - | #{entry[:member][:last_name]}, #{entry[:member][:first_name]} - ##{entry[:member][:jersey_number]} - -
.title-cell.out colSpan=3 Out - - for entry in event_lineup_entries.select{|e| e[:label].blank? and (e[:availability_status_code] == "0" or e[:availability_status_code]== "")} -
.sequence-cell - - if entry[:availability_status_code] == "0" - | NO - - if entry[:availability_status_code] == "" - | UNK - .name-cell - | #{entry[:member][:last_name]}, #{entry[:member][:first_name]} - ##{entry[:member][:jersey_number]} - --}} -
+ Out + + {{#each members}} + {{#if (isInOut this)}} + + + {{availabilityStatusShort this.benchcoach.availability}} + + {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}} + {{this.benchcoach.eventLineupEntry.label}} + + {{/if}} + {{/each}} + + +
\ No newline at end of file diff --git a/src/views/eventlineup/partials/email_table.hbs b/src/views/eventlineup/partials/email_table.hbs new file mode 100644 index 0000000..ff655b8 --- /dev/null +++ b/src/views/eventlineup/partials/email_table.hbs @@ -0,0 +1,62 @@ + + + + + + + + {{#each members}} + {{#if (isInStartingLineup this)}} + + + + + + {{/if}} + {{/each}} + + + + {{#each members}} + {{#if (isInPositionOnly this)}} + + + + + + {{/if}} + {{/each}} + + + + {{#each members}} + {{#if (isInBench this)}} + + + + + + {{/if}} + {{/each}} + + + + {{#each members}} + {{#if (isInOut this)}} + + + + + + {{/if}} + {{/each}} + +
+ STARTING LINEUP +
+ {{plus1 this.benchcoach.eventLineupEntry.sequence}} + {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
Starting (Pos. Only)
{{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
Subs
+ {{availabilityStatusShort this.benchcoach.availability}} + {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
Out
+ {{availabilityStatusShort this.benchcoach.availability}} + {{this.lastName}}, {{this.firstName}} – #{{this.jerseyNumber}}{{this.benchcoach.eventLineupEntry.label}}
\ No newline at end of file diff --git a/src/views/eventlineup/partials/emailmodal.hbs b/src/views/eventlineup/partials/emailmodal.hbs index 87db97a..f03ecea 100644 --- a/src/views/eventlineup/partials/emailmodal.hbs +++ b/src/views/eventlineup/partials/emailmodal.hbs @@ -4,13 +4,25 @@
{{{embeddedSvgFromPath "/teamsnap-ui/assets/icons/dismiss.svg" "Modal-iconDismiss"}}}
+ \ No newline at end of file