summaryrefslogtreecommitdiff
path: root/views/eventgroup.handlebars
blob: 0643ed6f518efec3e46e307a04003c897b9a63bc (plain)
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
{{#if eventGroupHasCoverImage}}
  <div id="eventImageContainer" style="background-image: url(/events/{{eventGroupData.image}});"></div>
{{else}}
  <div id="genericEventImageContainer" style="background-image: url(/images/seigaiha.png);"></div>
{{/if}}
<div class="row">
  <div class="col-lg">
    <h3 id="eventGroupName" data-event-id="{{eventGroupData.id}}">{{eventGroupData.name}}</h3>
  </div>
  <div class="col-lg-2 ml-2 edit-buttons">
    {{#if editingEnabled}}
      <button type="button" id="editEvent" class="btn btn-success text-nowrap" data-event-id="{{eventGroupData.id}}" data-toggle="modal" data-target="#editModal"><i class="fas fa-edit"></i> Edit group</button>
    {{else}}
      <button type="button" id="editEvent" class="btn btn-success text-nowrap" data-event-id="{{eventGroupData.id}}" data-toggle="modal" data-target="#editTokenModal"><i class="fas fa-edit"></i> Edit group</button>
    {{/if}}
  </div>
</div>
{{#if firstLoad}}
<div class="alert alert-success alert-dismissible fade show mt-4" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
  Welcome to your event group! We've just sent you an email with your secret editing link, which you can also see in the address bar above. Haven't got the email? Check your spam or junk folder. To share your event group, use the link you can see just below this message - that way your attendees won't be able to edit or delete your event group!
</div>
{{/if}}
<div class="container my-4 pr-0">
  <div class="row">
    <div class="col-lg-9 card p-0">
      <div class="card">
        <div class="card-body">
          <ul class="fa-ul eventInformation">
            {{#if eventGroupHasHost}}
              <li id="hostName">
                <span class="fa-li">
                  <i class="fas fa-fw fa-user-circle"></i>
                </span>
                <span class="text-muted">Hosted by</span> {{eventGroupData.hostName}}
              </li>
            {{/if}}
            {{#if eventGroupData.url}}
              <li id="eventGroupURL">
                <span class="fa-li">
                  <i class="fas fa-link"></i>
                </span>
                <a href="{{eventGroupData.url}}">
                  {{eventGroupData.url}}
                </a>
              </li>
            {{/if}}
            <li>
              <span class="fa-li">
                <i class="fas fa-share-square"></i>
              </span>
              <a href="https://{{domain}}/group/{{eventGroupData.id}}">https://{{domain}}/group/{{eventGroupData.id}}</a>
              <button type="button" id="copyEventLink" class="eventInformationAction btn btn-outline-secondary btn-sm" data-clipboard-text="https://{{domain}}/group/{{eventGroupData.id}}">
                <i class="fas fa-copy"></i> Copy
              </button>
            </li>
            <li>
              <span class="fa-li">
                <i class="fas fa-rss"></i>
              </span>
              <a
                href="https://{{domain}}/group/{{eventGroupData.id}}/feed.ics">https://{{domain}}/group/{{eventGroupData.id}}/feed.ics</a>&nbsp;
              <button type="button" id="copyFeedLink"
                class="eventInformationAction btn btn-outline-secondary btn-sm"
                data-clipboard-text="https://{{domain}}/group/{{eventGroupData.id}}/feed.ics">
                <i class="fas fa-copy"></i> Copy
              </button>
              <p class="text-muted small">Paste this URL into your calendar app
                to subscribe to a live feed of events from this group.</p>
            </li>
          </ul>
        </div>
      </div> <!-- /card -->
    </div>
    <div class="col-lg-3" id="eventActions">
      <aside class="btn-group-vertical d-flex" role="group" aria-label="Event actions">
        <button type="button" class="btn btn-outline-secondary btn-sm"
          data-event-id="{{eventGroupData.id}}" data-toggle="modal"
          data-target="#subscribeModal">
          <i class="fas fa-envelope"></i> Subscribe to updates
        </button>
        <button type="button" id="exportICS" class="btn btn-outline-secondary
          btn-sm" data-event-id="{{eventGroupData.id}}">
          <i class="fas fa-download"></i> Export as ICS
        </button>
      </aside>
    </div>
  </div>
</div>

{{#if editingEnabled}}
  <div class="alert alert-info">
    <p>To add an event to this group, copy and paste the two codes below into the 'Event Group' box when creating a new event or editing an existing event.</p>
    <div class="table-responsive">
      <table style="width:100%">
        <tr style="border-bottom:1px solid rgba(0,0,0,0.2)">
          <td><strong>Event group ID</strong></td>
          <td><span class="code" id="eventGroupID">{{eventGroupData.id}}</span></td>
        </tr>
        <tr>
          <td><strong>Event group editing password</strong></td>
          <td><span class="code" id="eventGroupEditToken">{{eventGroupData.editToken}}</span></td>
        </tr>
      </table>
    </div>
    
  </div>
{{/if}}

<div class="card mb-4" id="eventDescription">
    <h5 class="card-header">About</h5>  
  <div class="card-body">
    {{{parsedDescription}}}
  </div>
</div>
<div class="card mt-4 mb-4" id="upcomingEvents">
  <h5 class="card-header">Upcoming events</h5>
  <div class="list-group list-group-flush">
  {{#if upcomingEventsExist}}
    {{#each events}}
      {{#unless this.eventHasConcluded}}
        <a href="/{{this.id}}" class="list-group-item list-group-item-action" target="_blank">
          <i class="fas fa-fw fa-calendar-day"></i>
          <strong>{{this.name}}</strong>
          <span class="ml-2 text-muted">{{this.displayDate}}</span>
        </a>
      {{/unless}}
    {{/each}}
  {{else}}
      <div class="list-group-item">No events!</div>
  {{/if}}
  </div>
</div>

{{#if editingEnabled}}
{{> editeventgroupmodal }}

<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="deleteModalLabel">Delete '{{eventGroupData.name}}'</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form id="deleteEventGroupForm" action="/deleteeventgroup/{{eventGroupData.id}}/{{eventGroupData.editToken}}" method="post">
      <div class="modal-body">
        <p>Are you sure you want to delete this event group? This action cannot be undone.</p>
        <p>This will <strong>not</strong> delete the individual events contained in this group. They can be linked to another group later.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-danger">Delete event group</button>
      </div>
      </form>
    </div>
  </div>
</div>

{{/if}}

<div class="modal fade" id="subscribeModal" tabindex="-1" role="dialog"
  aria-labelledby="subscribeModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="subscribeModalLabel">Subscribe to '{{eventGroupData.name}}'</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form id="subscribeForm" action="/subscribe/{{eventGroupData.id}}" method="post">
      <div class="modal-body">
        <div class="form-group">
          <p class="form-text small">Enter your email address to receive updates
            whenever a new event is created in this group.</p>
        </div>
        <div class="form-group">
          <input type="email" class="form-control" id="emailAddress"
          name="emailAddress" placeholder="email@example.com" data-validation="required">
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-success">Subscribe</button>
      </div>
      </form>
    </div>
  </div>
</div>

<div class="modal fade" id="editTokenModal" tabindex="-1" role="dialog" aria-labelledby="editTokenModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="editTokenModalLabel">Enter editing password</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form id="verifyTokenForm" action="/verifytoken/group/{{eventGroupData.id}}" method="post">
      <div class="modal-body">
        <div class="form-group">
          <p class="form-text small">Enter the editing password you received by email or were shown when the event was created.</p>
          <div class="form-group">
            <input type="text" class="form-control" id="editToken" name="editToken" placeholder="Get it right!" data-validation="required">
          </div>
          <div class="form-group">
              <div class="alert alert-danger" style="display:none;"></div>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Edit group</button>
      </div>
      </form>
    </div>
  </div>
</div>

<script>
window.groupData = {{{ json jsonData }}};
</script>

<script>
  $(document).ready(function() {
    // Save the editing token from the URL, if it is valid
    const eventID = $('#eventName').attr('data-event-id');
    const urlParams = new URLSearchParams(window.location.search);
    if (urlParams.has('e')) {
      $.ajax({
        type: "POST",
        url: `/verifytoken/group/${eventID}`,
        data: { editToken: urlParams.get('e') },
        success: function(response, status, xhr) {
          if (xhr.status === 200) {
            addStoredToken(eventID, urlParams.get('e'));
          }
        },
        error: function(response, status, xhr) {
          // The editing token is wrong - remove it
          removeStoredToken(eventID);
          window.location = window.location.pathname;
        }
      });
    } else if (getStoredToken(eventID)) {
      const editToken = getStoredToken(eventID);
      $.ajax({
        type: "POST",
        url: `/verifytoken/group/${eventID}`,
        data: { editToken },
        success: function(response, status, xhr) {
          if (xhr.status === 200) {
            window.location.search = `?e=${editToken}`;
          }
        },
        error: function(response, status, xhr) {
          // The editing token is wrong - remove it
          removeStoredToken(eventID);
        }
      });
    }

    if (urlParams.has('show_edit')) {
      $('#editModal').modal('show');
    }

    new ClipboardJS('#copyEventLink');
    new ClipboardJS('#copyFeedLink');
    autosize($('textarea'));
    $("#exportICS").click(function(){
      let eventGroupID = $(this).attr('data-event-id');
      $.get('/export/group/' + eventGroupID, function(response) {
        downloadFile(response, eventGroupID + '.ics');
      })
    })
    $("#copyEventLink").click(function(){
      $(this).html('<i class="fas fa-copy"></i> Copied!');
      setTimeout(function(){ $("#copyEventLink").html('<i class="fas fa-copy"></i> Copy');}, 5000);
    });
    $("#copyFeedLink").click(function(){
      $(this).html('<i class="fas fa-copy"></i> Copied!');
      setTimeout(function(){ $("#copyFeedLink").html('<i class="fas fa-copy"></i> Copy');}, 5000);
    });

      $('#verifyTokenForm').on('submit', function(e) {
        e.preventDefault();
        let form = $(this);
        $.ajax({
            type: "POST",
            url: form.attr('action'),
            data: form.serialize(),
            success: function(response, status, xhr) {
                if (xhr.status === 200) {
                    // Save the token to localStorage for later
                    addStoredToken($('#eventName').attr('data-event-id'), new FormData(form[0]).get('editToken'));
                    window.location.search = `?e=${new FormData(form[0]).get('editToken')}&show_edit=true`;
                }
            },
            error: function(response, status, xhr) {
               form.find('.alert').text('That editing password is incorrect. Try again.').show();
            }
        });
      });

    $('#deleteEvent').on('click', function() {
        $('#editModal').modal('hide');
    })

    // From https://davidwalsh.name/javascript-download
    function downloadFile(data, fileName, type="text/plain") {
      // Create an invisible A element
      const a = document.createElement("a");
      a.style.display = "none";
      document.body.appendChild(a);

      // Set the HREF to a Blob representation of the data to be downloaded
      a.href = window.URL.createObjectURL(
        new Blob([data], { type })
      );

      // Use download attribute to set set desired file name
      a.setAttribute("download", fileName);

      // Trigger the download by simulating click
      a.click();

      // Cleanup
      window.URL.revokeObjectURL(a.href);
      document.body.removeChild(a);
    }

  });
</script>