summaryrefslogtreecommitdiff
path: root/views/eventgroup.handlebars
blob: d7726bd98a9dd0bd67f75d4072f4ef74db4fc6ae (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
{{#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="eventName" 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" 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="card mt-4 mb-4">
  <div class="card-body">
    <ul class="fa-ul eventInformation">
      {{#if eventGroupHasHost}}
        <li>
          <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>
          <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}}">
          {{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>
    </ul>
  </div>
</div>

{{#if editingEnabled}}
  <div class="alert alert-success">
    <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">{{eventGroupData.id}}</span></td>
        </tr>
        <tr>
          <td><strong>Event group editing password</strong></td>
          <td><span class="code">{{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="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>
  $.validate({
    lang: 'en',
    errorElementClass: "is-invalid",
    errorMessageClass: "text-danger",
    successElementClass: "is-valid"
  });

  $(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');
    }

    $.uploadPreview({
      input_field: "#eventGroupImageUpload",
      preview_box: "#eventGroupImagePreview",
      label_field: "#eventGroupImageLabel",
      label_default: "Choose file",
      label_selected: "Change file",
      no_label: false
    });
    $("#eventGroupImagePreview").css("background-image", "url('/events/{{eventGroupData.image}}')");
    $("#eventGroupImagePreview").css("background-size", "cover");
    $("#eventGroupImagePreview").css("background-position", "center center");
    new ClipboardJS('#copyEventLink');
    autosize($('textarea'));
    $("#copyEventLink").click(function(){
      $(this).html('<i class="fas fa-copy"></i> Copied!');
      setTimeout(function(){ $("#copyEventLink").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');
    })

  });
</script>