forked from SAFeSEA/openEssayist-slim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug SAFeSEA#30/SAFeSEA#22, Move validator Javascript from 'draft.hist…
…ory` TWIG [iet:10299492] * Plus, QA fixes to JS [iet:10289026][iet:10294465]
- Loading branch information
Showing
4 changed files
with
78 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
public_html/assets/openessayist/js/openessayist.validator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*! | ||
OpenEssayist javascript | © The Open University (IET). | ||
*/ | ||
|
||
// From: user/draft.submit.twig. | ||
|
||
window.jQuery(function ($) { | ||
$.blockUI.defaults.baseZ = 1100; // Z-index? | ||
|
||
var $form = $('form#post_essay'); | ||
var $essay = $form.find('textarea#text'); | ||
var $counts = $form.find('[ name = counts ]'); | ||
var minlength = $essay.data('minlength') || 200; | ||
var maxlength = $essay.data('maxlength') || (200 * 1000); // Characters. Big! | ||
|
||
console.warn('Essay validator (min/maxlength chars):', minlength, maxlength, $form, $essay, $counts); | ||
|
||
$form.validate({ | ||
rules: { | ||
text: | ||
{ | ||
required: true, | ||
minlength: minlength, | ||
maxlength: maxlength | ||
} | ||
}, | ||
submitHandler: function (form) { | ||
var essay = $essay.val(); | ||
var wcount = essay.match(/[^\s]+/g).length; | ||
var time = wcount / 100; | ||
var msg = ''; | ||
|
||
if (time < 30) { | ||
msg = 'it will take 15 to 30 seconds...'; | ||
} else if (time < 60) { | ||
msg = 'it will take up to one minute ...'; | ||
} else { | ||
msg = 'it will take one or two minutes ...'; | ||
} | ||
|
||
$.blockUI({ message: '<div class="ajax alert alert-info">Starting Analysis. Please wait, ' + msg + '</div>' }); | ||
form.submit(); | ||
}, | ||
highlight: function (element) { | ||
$(element).closest('.control-group').not('.help-block').removeClass('success').addClass('error'); | ||
}, | ||
success: function (element) { | ||
element | ||
.text('OK!').addClass('valid') | ||
.closest('.control-group').not('.help-block').removeClass('error').addClass('success'); | ||
} | ||
}); | ||
|
||
// NDF, 02-February-2018. | ||
window.Countable.on($essay.get(0), function (counter) { | ||
console.warn('Counts:', counter); | ||
|
||
$counts.val(JSON.stringify(counter)); | ||
}, | ||
{ hardReturns: true }); | ||
}); | ||
|
||
// End. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,7 +104,7 @@ | |
<input type="hidden" name="task" id="draft-task" value="{{ task.code }}"/> | ||
<input type="hidden" name="version" id="draft-version" value="{{ form.version }}"/> | ||
|
||
<input type="hidden" readonly name="counts" id="draft-counts" title="*** TO HIDE *** work-in-progress!" style="width:99%" /> | ||
<input type="hidden" name="counts" id="draft-counts"/> | ||
</div> | ||
</div> | ||
|
||
|
@@ -134,52 +134,17 @@ | |
<script src="{{ app_base }}/assets/jquery.validation/jquery.validate.min.js"></script> | ||
<script src="https://unpkg.com/[email protected]/Countable.min.js"></script> | ||
|
||
<script> | ||
<script src="{{ app_base }}/assets/openessayist/js/openessayist.validator.js"></script> | ||
|
||
{# <script> | ||
window.jQuery(function ($) { | ||
$.blockUI.defaults.baseZ = 1100; // Z-index? | ||
var $form = $('form#post_essay'); | ||
var $essay = $form.find('textarea#text'); | ||
var $counts = $form.find('[ name = counts ]'); | ||
var minlength = $essay.data('minlength') || 200; | ||
var maxlength = $essay.data('maxlength') || ( 200 * 1000 ); // Characters. Big! | ||
$('#post_essay').validate({ | ||
rules: { | ||
text: | ||
{ | ||
required: true, | ||
minlength: minlength, | ||
maxlength: maxlength | ||
} | ||
}, | ||
submitHandler: function(form) { | ||
var essay = $essay.val(); | ||
var wcount = essay.match(/[^\s]+/g).length; | ||
var time = wcount / 100; | ||
var msg = ""; | ||
if (time < 30) | ||
msg = "it will take 15 to 30 seconds..."; | ||
else if (time < 60) | ||
msg = "it will take up to one minute ..."; | ||
else | ||
msg = "it will take one or two minutes ..."; | ||
$.blockUI({ message: '<div class="ajax alert alert-info">Starting Analysis. Please wait, ' + msg + '</div>' }); | ||
form.submit(); | ||
}, | ||
highlight: function(element) { | ||
$(element).closest('.control-group').not(".help-block").removeClass('success').addClass('error'); | ||
}, | ||
success: function(element) { | ||
element | ||
.text('OK!').addClass('valid') | ||
.closest('.control-group').not(".help-block").removeClass('error').addClass('success'); | ||
} | ||
}); | ||
// ... | ||
// NDF, 02-February-2018. | ||
window.Countable.on($essay.get(0), function (counter) { | ||
|
@@ -191,6 +156,7 @@ window.jQuery(function ($) { | |
}); | ||
</script> | ||
#} | ||
{% endblock %} | ||
|
||
{% block injectCSS %} | ||
|