Skip to content

Instantly share code, notes, and snippets.

@ademers
Last active September 29, 2021 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ademers/81c949418cfde8d776d59662e3d6afcc to your computer and use it in GitHub Desktop.
Save ademers/81c949418cfde8d776d59662e3d6afcc to your computer and use it in GitHub Desktop.
<form-validation inline-template>
<form ref="form"
class="uk-form-stacked"
id="score-image"
method="post"
accept-charset="UTF-8"
enctype="multipart/form-data"
novalidate
>
{{ csrfInput() }}
{# Save entry #}
<input type="hidden" name="action" id="action" value="entries/save-entry">
{# Redirect to entry #}
{{ redirectInput(entry.url) }}
{# Site ID for Dynamic Range #}
<input type="hidden" name="siteId" value="1">
{# Section ID #}
<input type="hidden" name="sectionId" value="{{ section.id }}">
{# If entry enabled and doesn't require moderation #}
<input type="hidden" name="enabled" value="1">
{# Required to edit entry #}
<input type="hidden" name="entryId" value="{{ entry.id }}">
{# Get existing matrix blocks, if any #}
{# NOTE: Required so that judges don't override other judges' matrix blocks! #}
<!-- Matrix blocks exist -->
{% if entry.judgeSelections|length %}
{% for block in entry.judgeSelections.all() %}
<input type="hidden"
name="fields[judgeSelections][{{ block.id }}][type]"
value="judgeSelection"
>
<input type="hidden"
name="fields[judgeSelections][{{ block.id }}][enabled]"
value="1"
>
{% endfor %}
{# If not Matrix blocks, add new one for current user #}
{% else %}
<input type="hidden"
name="fields[judgeSelections][new1][type]"
value="judgeSelection"
>
<input type="hidden"
name="fields[judgeSelections][new1][enabled]"
value="1"
>
<input type="hidden"
name="fields[judgeSelections][new1][fields][member][user.id]"
value="{{ currentUser.id }}"
>
<input type="hidden"
name="fields[judgeSelections][new1][fields][memberId]"
value="{{ currentUser.id }}"
>
{% endif %}
<!-- /Matrix blocks exist -->
{# Check if current user has selected this image as either IN or OUT #}
{% if currentUser.id in judgesSelected %}
{% for block in entry.judgeSelections.all() %}
{# If current user has selected entry as IN or OUT, edit user's existing block #}
{% if currentUser and (currentUser.id == block.memberId) %}
<input type="hidden"
name="fields[judgeSelections][{{ block.id }}][type]"
value="judgeSelection"
>
<input type="hidden"
name="fields[judgeSelections][{{ block.id }}][enabled]"
value="1"
>
<input type="hidden"
name="fields[judgeSelections][{{ block.id }}][fields][member][user.id]"
value="{{ currentUser.id }}"
>
<input type="hidden"
name="fields[judgeSelections][{{ block.id }}][fields][memberId]"
value="{{ currentUser.id }}"
>
{% endif %}
{% endfor %}
{# If current user hasn't selected entry as IN or OUT add new block #}
{% else %}
<input type="hidden"
name="fields[judgeSelections][new1][type]"
value="judgeSelection"
>
<input type="hidden"
name="fields[judgeSelections][new1}][enabled]"
value="1"
>
<input type="hidden"
name="fields[judgeSelections][new1][fields][member][user.id]"
value="{{ currentUser.id }}"
>
<input type="hidden"
name="fields[judgeSelections][new1][fields][memberId]"
value="{{ currentUser.id }}"
>
{% endif %}
{# Error macro #}
{% import '_macros' as siteMacros %}
{# Select In/Out radio buttons #}
{% if currentUser.id in judgesSelected %}
{% for block in entry.judgeSelections.all() %}
{# If current user has scored entry, allow edit #}
{% if currentUser and (currentUser.id == block.memberId) %}
{# In/Out radio buttons #}
<label class="uk-margin-small-right" for="in">
<input class="uk-radio"
type="radio" id="in"
name="fields[judgeSelections][{{ block.id }}][fields][selected]"
data-vv-name="Image score"
value="1"
{# {% if entry is defined and entry.id in currentUserSelectedIn %}
checked
{% endif %} #}
{% if entry is defined and block.selected == true %}
checked
{% endif %}
>
In
</label>
<label for="out">
<input class="uk-radio"
type="radio"
id="out"
name="fields[judgeSelections][{{ block.id }}][fields][selected]"
data-vv-name="Image score"
value="0"
{# {% if entry is defined and entry.id in currentUserSelectedOut %}
checked
{% endif %} #}
{% if entry is defined and block.selected == false %}
checked
{% endif %}
>
Out
</label>
{% endif %}
{% endfor %}
{% else %}
{# In/Out radio buttons #}
<label class="uk-margin-small-right" for="in">
<input class="uk-radio"
type="radio" id="in"
name="fields[judgeSelections][new1][fields][selected]"
data-vv-name="Image score"
value="1"
{% if entry is defined and entry.id in currentUserSelectedIn %}
checked
{% endif %}
>
In
</label>
<label for="out">
<input class="uk-radio"
type="radio"
id="out"
name="fields[judgeSelections][new1][fields][selected]"
data-vv-name="Image score"
value="0"
{% if entry is defined and entry.id in currentUserSelectedOut %}
checked
{% endif %}
>
Out
</label>
{% endif %}
{# Save Button #}
<button v-show="!submitClicked" @click="clickSubmit" class="uk-button uk-button-primary uk-margin uk-width-1-1" type="submit" value="submit" :disabled="errors.any() || !formValid || submitClicked"><span :data-uk-icon="'icon: upload'"></span> Save selection status</button>
<button v-show="submitClicked" @click="clickSubmit" class="uk-button uk-button-primary uk-margin uk-width-1-1" disabled><span :data-uk-spinner="''"></span> Saving selection status...</button>
{# /Save Button #}
</form>
</form-validation>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment