Allow stop and save oral expresion question - refs BT#13920

pull/2458/head
Angel Fernando Quiroz Campos 8 years ago
parent 8ed61f4eaa
commit b55835b7c8
  1. 107
      main/inc/lib/javascript/record_audio/record_audio.js
  2. 6
      main/template/default/exercise/oral_expression.tpl

@ -10,9 +10,56 @@ window.RecordAudio = (function () {
btnPause = $(rtcInfo.btnPauseId), btnPause = $(rtcInfo.btnPauseId),
btnPlay = $(rtcInfo.btnPlayId), btnPlay = $(rtcInfo.btnPlayId),
btnStop = $(rtcInfo.btnStopId), btnStop = $(rtcInfo.btnStopId),
btnSave = $(rtcInfo.btnSaveId), btnSave = rtcInfo.btnSaveId ? $(rtcInfo.btnSaveId) : null,
tagAudio = $(rtcInfo.plyrPreviewId); tagAudio = $(rtcInfo.plyrPreviewId);
function saveAudio () {
var recordedBlob = recordRTC.getBlob();
if (!recordedBlob) {
return;
}
var btnSaveText = btnSave ? btnSave.html() : '';
var fileExtension = '.' + recordedBlob.type.split('/')[1];
var formData = new FormData();
formData.append('audio_blob', recordedBlob, fileName + fileExtension);
formData.append('audio_dir', rtcInfo.directory);
$.ajax({
url: _p.web_ajax + 'record_audio_rtc.ajax.php?tool=' + (!!txtName.length ? 'document' : 'exercise'),
data: formData,
processData: false,
contentType: false,
type: 'POST',
beforeSend: function () {
btnStart.prop('disabled', true);
btnPause.prop('disabled', true);
btnPlay.prop('disabled', true);
btnStop.prop('disabled', true);
if (btnSave) {
btnSave.prop('disabled', true).text(btnSave.data('loadingtext'));
}
}
}).done(function (response) {
if (!!txtName.length) {
window.location.reload();
return;
}
$(response.message).insertAfter($(rtcInfo.blockId).find('.well'));
}).always(function () {
if (btnSave) {
btnSave.prop('disabled', true).addClass('hidden').html(btnSaveText);
}
btnStop.prop('disabled', true).addClass('hidden');
btnPause.prop('disabled', true).addClass('hidden');
btnStart.prop('disabled', false).removeClass('hidden');
txtName.prop('readonly', false);
});
}
btnStart.on('click', function () { btnStart.on('click', function () {
if (!fileName) { if (!fileName) {
fileName = txtName.val(); fileName = txtName.val();
@ -32,7 +79,9 @@ window.RecordAudio = (function () {
recordRTC.startRecording(); recordRTC.startRecording();
txtName.prop('readonly', true); txtName.prop('readonly', true);
btnSave.prop('disabled', true).addClass('hidden'); if (btnSave) {
btnSave.prop('disabled', true).addClass('hidden');
}
btnStop.prop('disabled', false).removeClass('hidden'); btnStop.prop('disabled', false).removeClass('hidden');
btnStart.prop('disabled', true).addClass('hidden'); btnStart.prop('disabled', true).addClass('hidden');
btnPause.prop('disabled', false).removeClass('hidden'); btnPause.prop('disabled', false).removeClass('hidden');
@ -83,7 +132,12 @@ window.RecordAudio = (function () {
btnStart.prop('disabled', false).removeClass('hidden'); btnStart.prop('disabled', false).removeClass('hidden');
btnPause.prop('disabled', true).addClass('hidden'); btnPause.prop('disabled', true).addClass('hidden');
btnStop.prop('disabled', true).addClass('hidden'); btnStop.prop('disabled', true).addClass('hidden');
btnSave.prop('disabled', false).removeClass('hidden');
if (btnSave) {
btnSave.prop('disabled', false).removeClass('hidden');
} else {
saveAudio();
}
tagAudio tagAudio
.removeClass('hidden') .removeClass('hidden')
@ -92,52 +146,15 @@ window.RecordAudio = (function () {
}); });
}); });
btnSave.on('click', function () { if (btnSave) {
if (!recordRTC) { btnSave.on('click', function () {
return; if (!recordRTC) {
}
var recordedBlob = recordRTC.getBlob();
if (!recordedBlob) {
return;
}
var btnSaveText = btnSave.html();
var fileExtension = '.' + recordedBlob.type.split('/')[1];
var formData = new FormData();
formData.append('audio_blob', recordedBlob, fileName + fileExtension);
formData.append('audio_dir', rtcInfo.directory);
$.ajax({
url: _p.web_ajax + 'record_audio_rtc.ajax.php?tool=' + (!!txtName.length ? 'document' : 'exercise'),
data: formData,
processData: false,
contentType: false,
type: 'POST',
beforeSend: function () {
btnStart.prop('disabled', true);
btnPause.prop('disabled', true);
btnPlay.prop('disabled', true);
btnStop.prop('disabled', true);
btnSave.prop('disabled', true).text(btnSave.data('loadingtext'));
}
}).done(function (response) {
if (!!txtName.length) {
window.location.reload();
return; return;
} }
$(response.message).insertAfter($(rtcInfo.blockId).find('.well')); saveAudio();
}).always(function () {
btnSave.prop('disabled', true).addClass('hidden').html(btnSaveText);
btnStop.prop('disabled', true).addClass('hidden');
btnPause.prop('disabled', true).addClass('hidden');
btnStart.prop('disabled', false).removeClass('hidden');
txtName.prop('readonly', false);
}); });
}); }
} }
function useWami(wamiInfo, fileName) { function useWami(wamiInfo, fileName) {

@ -1,3 +1,4 @@
<div id="record-audio-recordrtc-{{ question_id }}" class="row"> <div id="record-audio-recordrtc-{{ question_id }}" class="row">
<div class="col-sm-4 col-sm-offset-4"> <div class="col-sm-4 col-sm-offset-4">
<div class="form-group text-center"> <div class="form-group text-center">
@ -52,7 +53,6 @@ $(document).on('ready', function () {
btnPauseId: '#btn-pause-record-{{ question_id }}', btnPauseId: '#btn-pause-record-{{ question_id }}',
btnPlayId: '#btn-play-record-{{ question_id }}', btnPlayId: '#btn-play-record-{{ question_id }}',
btnStopId: '#btn-stop-record-{{ question_id }}', btnStopId: '#btn-stop-record-{{ question_id }}',
btnSaveId: '#btn-save-record-{{ question_id }}',
plyrPreviewId: '#record-preview-{{ question_id }}', plyrPreviewId: '#record-preview-{{ question_id }}',
directory: '{{ directory }}' directory: '{{ directory }}'
}, { }, {
@ -61,5 +61,9 @@ $(document).on('ready', function () {
directory: '{{ directory }}', directory: '{{ directory }}',
userId: {{ user_id }} userId: {{ user_id }}
}, '{{ file_name }}'); }, '{{ file_name }}');
if (0 === $('#hide_description_{{ question_id }}_options').length) {
$('#hide_description_{{ question_id }}').remove();
}
}); });
</script> </script>

Loading…
Cancel
Save