Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Update the update njk to be properly filled and update renderer calls

  • Loading branch information...
ColdHeat committed Apr 19, 2018
1 parent 72046e7 commit 6259e138d15ce1a7f3edb44c729b5d0a1ad6593e
@@ -1,23 +1,17 @@
// Markdown Preview
$('#desc-edit').on('shown.bs.tab', function (event) {
var md = window.markdownit({
html: true,
});
if (event.target.hash == '#desc-preview'){
var editor_value = $('#desc-editor').val();
$(event.target.hash).html(
md.render(editor_value)
window.challenge.render(editor_value)
);
}
});
$('#new-desc-edit').on('shown.bs.tab', function (event) {
var md = window.markdownit({
html: true,
});
if (event.target.hash == '#new-desc-preview'){
var editor_value = $('#new-desc-editor').val();
$(event.target.hash).html(
md.render(editor_value)
window.challenge.render(editor_value)
);
}
});
@@ -15,12 +15,17 @@ window.challenge.postRender = function () {

};

window.challenge.submit = function (cb) {
window.challenge.submit = function (cb, preview) {
var chal_id = $('#chal-id').val();
var answer = $('#answer-input').val();
var nonce = $('#nonce').val();

$.post(script_root + "/chal/" + chal_id, {
var url = "/chal/";
if (preview) {
url = "/admin/chal/";
}

$.post(script_root + url + chal_id, {
key: answer,
nonce: nonce
}, function (data) {
@@ -18,24 +18,18 @@ $('#limit_max_attempts').change(function() {

// Markdown Preview
$('#desc-edit').on('shown.bs.tab', function (event) {
var md = window.markdownit({
html: true,
});
if (event.target.hash == '#desc-preview'){
if (event.target.hash == '#desc-preview') {
var editor_value = $('#desc-editor').val();
$(event.target.hash).html(
md.render(editor_value)
window.challenge.render(editor_value)
);
}
});
$('#new-desc-edit').on('shown.bs.tab', function (event) {
var md = window.markdownit({
html: true,
});
if (event.target.hash == '#new-desc-preview'){
if (event.target.hash == '#new-desc-preview') {
var editor_value = $('#new-desc-editor').val();
$(event.target.hash).html(
md.render(editor_value)
window.challenge.render(editor_value)
);
}
});
@@ -19,85 +19,118 @@

<div class="form-group">
<label for="name">Name
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip" data-placement="right" title="The name of your challenge"></i>
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip"
data-placement="right" title="The name of your challenge"></i>
</label>
<input type="text" class="form-control chal-name" name="name" placeholder="Enter challenge name">
<input type="text" class="form-control chal-name" name="name" placeholder="Enter challenge name"
value="{{ name }}">
</div>
<div class="form-group">
<label for="category">Category
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip" data-placement="right" title="The category of your challenge"></i>
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip"
data-placement="right" title="The category of your challenge"></i>
</label>
<input type="text" class="form-control chal-category" name="category" placeholder="Enter challenge category">
<input type="text" class="form-control chal-category" name="category"
placeholder="Enter challenge category" value="{{ category }}">
</div>

<ul class="nav nav-tabs" role="tablist" id="desc-edit">
<li role="presentation" class="active"><a href="#desc-write" id="desc-write-link" aria-controls="home" role="tab" data-toggle="tab">Write</a></li>
<li role="presentation"><a href="#desc-preview" aria-controls="home" role="tab" data-toggle="tab">Preview</a></li>
<li class="nav-item">
<a class="nav-link active" href="#desc-write" id="desc-write-link" aria-controls="home"
role="tab" data-toggle="tab">
Write
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#desc-preview" aria-controls="home" role="tab" data-toggle="tab">
Preview
</a>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="desc-write">
<div class="form-group">
<label for="message-text" class="control-label">Message:
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip" data-placement="right" title="Use this to give a brief introduction to your challenge. The description supports HTML and Markdown."></i>
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip"
data-placement="right"
title="Use this to give a brief introduction to your challenge. The description supports HTML and Markdown."></i>
</label>
<textarea id="desc-editor" class="form-control chal-desc" name="description" rows="10"></textarea>
<textarea id="desc-editor" class="form-control chal-desc-editor" name="description"
rows="10">{{ description }}</textarea>
</div>
</div>
<div role="tabpanel" class="tab-pane content" id="desc-preview" style="height:214px; overflow-y: scroll;">
<div role="tabpanel" class="tab-pane content" id="desc-preview"
style="height:214px; overflow-y: scroll;">
</div>
</div>

<div class="form-group">
<label for="value">Current Value
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip" data-placement="right" title="This is how many points the challenge is worth right now."></i>
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip"
data-placement="right"
title="This is how many points the challenge is worth right now."></i>
</label>
<input type="number" class="form-control chal-value" name="value" placeholder="Enter value" required>
<input type="number" class="form-control chal-value" name="value" placeholder="Enter value"
value="{{ value }}" required>
</div>

<div class="form-group">
<label for="value">Initial Value
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip" data-placement="right" title="This is how many points the challenge was worth initially."></i>
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip"
data-placement="right"
title="This is how many points the challenge was worth initially."></i>
</label>
<input type="number" class="form-control chal-initial" name="initial" placeholder="Enter value" required>
<input type="number" class="form-control chal-initial" name="initial" placeholder="Enter value"
value="{{ initial }}" required>
</div>

<div class="form-group">
<label for="value">Decay Limit
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip" data-placement="right" title="The amount of solves before the challenge reaches its minimum value"></i>
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip"
data-placement="right"
title="The amount of solves before the challenge reaches its minimum value"></i>
</label>
<input type="number" class="form-control chal-decay" name="decay" placeholder="Enter decay limit" required>
<input type="number" class="form-control chal-decay" name="decay"
placeholder="Enter decay limit" value="{{ decay }}" required>
</div>

<div class="form-group">
<label for="value">Minimum Value
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip" data-placement="right" title="This is the lowest that the challenge can be worth"></i>
<i class="far fa-question-circle text-muted cursor-help" data-toggle="tooltip"
data-placement="right" title="This is the lowest that the challenge can be worth"></i>
</label>
<input type="number" class="form-control chal-minimum" name="minimum" placeholder="Enter minimum value" required>
<input type="number" class="form-control chal-minimum" name="minimum"
placeholder="Enter minimum value" value="{{ minimum }}" required>
</div>

<div class="checkbox">
<label>
<input class="chal-attempts-checkbox" id="limit_max_attempts" name="limit_max_attempts" type="checkbox">
<input class="chal-attempts-checkbox" id="limit_max_attempts" name="limit_max_attempts"
type="checkbox" {% if max_attempts %}checked{% endif %}>
Limit challenge attempts
</label>
</div>

<div class="form-group" id="chal-attempts-group" style="display:none;">
<div class="form-group" id="chal-attempts-group"
{% if not max_attempts %}style="display:none;"{% endif %}>
<label for="value">Max Attempts</label>
<input type="number" class="form-control chal-attempts" id="chal-attempts-input" name="max_attempts" placeholder="Enter value">
<input type="number" class="form-control chal-attempts" id="chal-attempts-input"
name="max_attempts" placeholder="Enter value" value="{{ max_attempts }}">
</div>
<input class="chal-id" type='hidden' name='id' placeholder='ID'>
<input class="chal-id" type='hidden' name='id' placeholder='ID' value="{{ id }}">

<div class="checkbox">
<label>
<input class="chal-hidden" name="hidden" type="checkbox">
<input class="chal-hidden" name="hidden" type="checkbox"
{% if hidden %}checked{% endif %}>
Hidden
</label>
</div>

<input type="hidden" value="{{ nonce }}" name="nonce" id="nonce">
<div style="text-align:center">
<button class="btn btn-success btn-outlined update-challenge-submit" type="submit">Update</button>
<button class="btn btn-success btn-outlined update-challenge-submit" type="submit">Update
</button>
</div>
</form>
</div>

0 comments on commit 6259e13

Please sign in to comment.
You can’t perform that action at this time.