Gitlab CSE Unil

Commit e2efc00d authored by M. Chardon's avatar M. Chardon
Browse files

js documentation and optimisation

parent 8353e3d3
define(["jquery","mod_audioannotation/justWave","mod_audioannotation/editor","mod_audioannotation/rightMenu"],function(a,b,c,d){function e(a){e.currentUser="userid"in a?a.userid:null,e.courseid="course"in a?a.course:null,e.audioannotation="audioannotation"in a?a.audioannotation:null,e.eval="eval"in a?a.eval:0,e.iswriting="iswriting"in a?a.iswriting:0,e.pairing="pairing"in a?a.pairing:0;var f="repo"in a?a.repo:null,g="assignparts"in a?a.assignparts:null,h=null;if(g)try{h=JSON.parse(g)}catch(i){window.console.error(i)}var j="tags"in a?a.tags:null,k=null;if(j)try{k=JSON.parse(j)}catch(i){window.console.error(i)}if(e.wavePlayer=new b(this),e.editors=[],h)for(var l=0;l<h.length;l++){e.editors[h[l].id]=new c({controler:this,courseid:e.courseid,assignpart:h[l],audioannotation:e.audioannotation,tags:k,repo:f});var m=new b(this,e.editors[h[l].id]);e.editors[h[l].id].setWavePlayer(m),this.initWave(m,"justwave",h[l].id)}this.initTrigger(),e.rightMenu=new d({controler:this}),this.initDisplay()}return e.courseid=-1,e.audioannotation=-1,e.wavePlayer=null,e.prototype.editors=null,e.rightMenu=null,e.lastP=null,e.eval=0,e.iswriting=0,e.pairing=0,e.currentUser=null,e.prototype.initTrigger=function(){1!=e.eval&&1!=e.iswriting||(a(".btn_add_annotation").on("click",function(){e.editors[a(this).data("assignpart")].notify("add")}),a(".btn_add_annotation").on("mouseout",function(){a(this).blur(),a(this).parents('div[data-parent="#accordionAssignPart"]').focus()})),a(".select_tqs").on("change",function(){var b=a(this).data("assignpart");e.editors[b].notify("displaytqs",{tag:a("#select_tag"+b).val(),question:a("#select_question"+b).val(),statut:a("#select_statut"+b).val(),author:a("#select_author"+b).val()})}),a("li[data-annotation]").on("click",function(){var b=a(this).data("annotation"),c=a(this).parents(".annotationGroupAccordion").data("assignpart");b&&e.editors[c].notify("view",{annotation:b})}),a("#id_grade").on("change",function(){a(this).val()?a("input[name=gradeempty]").val(0):a("input[name=gradeempty]").val(1)}),a("div[data-parent='#accordionAssignPart']").on("show.bs.collapse",function(){var b=a("div[data-target='#"+a(this).attr("id")+"']"),c=b.find("i.fa-caret-right");c.removeClass("fa-caret-right"),c.addClass("fa-caret-down")}),a("div[data-parent='#accordionAssignPart']").on("hide.bs.collapse",function(){var b=a("div[data-target='#"+a(this).attr("id")+"']"),c=b.find("i.fa-caret-down");c.removeClass("fa-caret-down"),c.addClass("fa-caret-right")});var b=a("input[name$='mod_audioannotation_form_assignaudio_eval_form']");a("div.feedback > form").on("submit",function(){a("div.feedback > form").append(b)})},e.prototype.initWave=function(b,c,d){b.init(c),b.drawWaveDisplay(a(".justwave"+d+" audio"))},e.prototype.initAnnotations=function(){for(var a=0;a<e.editors.length;a++)e.editors[a]&&e.editors[a].initAnnotationsDisplay()},e.prototype.initDisplay=function(){},e.prototype.notify=function(a,b,c){switch(a){case"loadedmetadata":this.initAnnotations();break;case"addannotation":for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("add");break;case"editannotation":for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("edit");break;case"viewannotation":for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("view");break;case"deleteannotation":if("rightMenu"===b)for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].notify("delete",c);else for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("delete")}},e.prototype.getEval=function(){return e.eval},e.prototype.isWriting=function(){return e.iswriting},e.prototype.getPairing=function(){return e.pairing},e.prototype.getCurrentUser=function(){return e.currentUser},e});
\ No newline at end of file
define(["jquery","mod_audioannotation/justWave","mod_audioannotation/editor","mod_audioannotation/rightMenu"],function(a,b,c,d){function e(a){e.currentUser="userid"in a?a.userid:null,e.courseid="course"in a?a.course:null,e.audioannotation="audioannotation"in a?a.audioannotation:null,e.eval="eval"in a?a.eval:0,e.iswriting="iswriting"in a?a.iswriting:0,e.pairing="pairing"in a?a.pairing:0;var f="repo"in a?a.repo:null,g="assignparts"in a?a.assignparts:null,h=null;if(g)try{h=JSON.parse(g)}catch(i){window.console.error(i)}var j="tags"in a?a.tags:null,k=null;if(j)try{k=JSON.parse(j)}catch(i){window.console.error(i)}if(e.editors=[],h)for(var l=0;l<h.length;l++){e.editors[h[l].id]=new c({controler:this,courseid:e.courseid,assignpart:h[l],audioannotation:e.audioannotation,tags:k,repo:f});var m=new b(this,e.editors[h[l].id]);e.editors[h[l].id].setWavePlayer(m),this.initWave(m,"justwave",h[l].id)}this.initTrigger(),e.rightMenu=new d({controler:this}),this.initDisplay()}return e.courseid=-1,e.audioannotation=-1,e.prototype.editors=null,e.rightMenu=null,e.eval=0,e.iswriting=0,e.pairing=0,e.currentUser=null,e.prototype.initTrigger=function(){1!=e.eval&&1!=e.iswriting||(a(".btn_add_annotation").on("click",function(){e.editors[a(this).data("assignpart")].notify("add")}),a(".btn_add_annotation").on("mouseout",function(){a(this).blur(),a(this).parents('div[data-parent="#accordionAssignPart"]').focus()})),a(".select_tqs").on("change",function(){var b=a(this).data("assignpart");e.editors[b].notify("displaytqs",{tag:a("#select_tag"+b).val(),question:a("#select_question"+b).val(),statut:a("#select_statut"+b).val(),author:a("#select_author"+b).val()})}),a("li[data-annotation]").on("click",function(){var b=a(this).data("annotation"),c=a(this).parents(".annotationGroupAccordion").data("assignpart");b&&e.editors[c].notify("view",{annotation:b})}),a("#id_grade").on("change",function(){a(this).val()?a("input[name=gradeempty]").val(0):a("input[name=gradeempty]").val(1)}),a("div[data-parent='#accordionAssignPart']").on("show.bs.collapse",function(){var b=a("div[data-target='#"+a(this).attr("id")+"']"),c=b.find("i.fa-caret-right");c.removeClass("fa-caret-right"),c.addClass("fa-caret-down")}),a("div[data-parent='#accordionAssignPart']").on("hide.bs.collapse",function(){var b=a("div[data-target='#"+a(this).attr("id")+"']"),c=b.find("i.fa-caret-down");c.removeClass("fa-caret-down"),c.addClass("fa-caret-right")});var b=a("input[name$='mod_audioannotation_form_assignaudio_eval_form']");a("div.feedback > form").on("submit",function(){a("div.feedback > form").append(b)})},e.prototype.initWave=function(b,c,d){b.init(c),b.drawWaveDisplay(a(".justwave"+d+" audio"))},e.prototype.initAnnotations=function(){for(var a=0;a<e.editors.length;a++)e.editors[a]&&e.editors[a].initAnnotationsDisplay()},e.prototype.notify=function(a,b,c){switch(a){case"loadedmetadata":this.initAnnotations();break;case"addannotation":for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("add");break;case"editannotation":for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("edit");break;case"viewannotation":for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("view");break;case"deleteannotation":if("rightMenu"===b)for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].notify("delete",c);else for(var d=0;d<e.editors.length;d++)e.editors[d]&&e.editors[d].setEditorStatus("delete")}},e.prototype.getEval=function(){return e.eval},e.prototype.isWriting=function(){return e.iswriting},e.prototype.getPairing=function(){return e.pairing},e.prototype.getCurrentUser=function(){return e.currentUser},e});
\ No newline at end of file
define(["jquery","mod_audioannotation/record"],function(a,b){function c(a){c.repo="repo"in a?a.repo:null,c.limit="limit"in a&&a.limit>0?1e3*a.limit:null,c.nbRendu="nbRendu"in a&&a.nbRendu>0?a.nbRendu:1,this.init(),this.initDisplay()}c.constraints={audio:!0},c.sourceBuffer=null,c.mediaRecorder=null,c.recordedBlobs=null,c.repo=-1,c.limit=null,c.nbRendu=1,c.records=null,c.statut="off",c.prototype.mediaSource=null,c.pauseTimestamp=0,c.prototype.RECORDINGTOOLS=".record-tool",c.prototype.VALIDATIONBUTTON="input[type=submit]",c.prototype.init=function(){c.records=[];for(var f=0;f<c.nbRendu;f++){var g=[];g.manager=this,g.limit=c.limit,g.repo=c.repo,g.indice=f,c.records[f]=new b(g)}if(a("#audioworkspace").remove(),c.mediaSource=new MediaSource,c.mediaSource.addEventListener("sourceopen",e,!1),!navigator.mediaDevices||!window.MediaRecorder)return a(".webrtcsupport").show(),void a(c.prototype.RECORDINGTOOLS).hide();if(!navigator.mediaDevices.getUserMedia)return a(".webrtcsupport").show(),a(c.prototype.RECORDINGTOOLS).hide(),void window.console.log("getUserMedia is not supported by your browser");navigator.permissions.query({name:"microphone"}).then(function(a){window.console.log(a.state),window.stream&&window.stream.getTracks().forEach(function(a){a.stop()})})["catch"](function(a){window.console.log("Got error :",a)}),c.mediaRecorder&&"inactive"!==c.mediaRecorder.state&&c.mediaRecorder.stop(),window.stream&&window.stream.getTracks().forEach(function(a){"ended"!==a.readyState&&a.stop()});var h=null;navigator.mediaDevices.enumerateDevices().then(function(b){function e(a){window.console.log("Got stream, time diff :",Date.now()-l),d(a)}function f(a){m++;var b={audio:{deviceId:{exact:a}}};navigator.mediaDevices.getUserMedia(b).then(e)["catch"](g)}function g(b){i&&m<i.length?f(i[m]):(a(".microphone").show(),a(c.prototype.RECORDINGTOOLS).hide(),window.console.log("GUM failed with error, time diff: ",Date.now()-l),window.console.error("navigator.getUserMedia error:",b.name+": "+b.message),a(c.errorMsgElement).html("navigator.getUserMedia error:"+b.toString()))}var i=[];window.console.log(b);for(var j=0;j!==b.length;++j){var k=b[j];"audioinput"===k.kind&&(h=k.deviceId,window.console.log(h),i.push(h))}if(!h)return a(".microphone").show(),void a(c.prototype.RECORDINGTOOLS).hide();var l=Date.now(),m=0;navigator.mediaDevices.getUserMedia({audio:!0}).then(e)["catch"](g)})},c.prototype.initDisplay=function(){a.fn.justtext=function(){return a(this).clone().children().remove().end().text()},a(".audiofilepicker .form-filetypes-descriptions > ul").each(function(){var b=a(this).children("li");if(b&&!(b.length<2)){var c=a("<li></li>"),d=b[0],e=a(d).justtext();e=e.replace(/\ \((.*)\)/g,""),c.append(e);var f=a(d).children(),g="";f.each(function(){g=a(this).clone(),g.html("")}),b.each(function(){a(this).children().each(function(){g.append(a(this).text()+" ")}),a(this).remove()}),c.append(g),a(this).append(c)}})};var d=function(b){a(".btn-record").each(function(){a(this).prop("indice")>=0&&c.records[a(this).prop("indice")].initDisplayRecordButton(!0)}),window.console.log("getUserMedia() got stream:",b),window.stream=b},e=function(){window.console.log("MediaSource opened"),c.sourceBuffer=c.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",c.sourceBuffer)};c.prototype.startRecording=function(b){if("off"!==c.statut)return!1;c.statut="on",c.recordedBlobs=[],c.initTimestamp=-1,c.pauseTimestamp=0;var d=null;try{c.mediaRecorder=new MediaRecorder(window.stream,d)}catch(e){return window.console.error("Exception while creating MediaRecorder:",e),void a(this.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(e))}return window.console.log("Created MediaRecorder",c.mediaRecorder,"with options",d),c.mediaRecorder.addEventListener("stop",function(d){a("#audiotime"+b).text(""),c.timestampStop=0,window.console.log("Recorder stopped: ",d)},!1),c.mediaRecorder.addEventListener("dataavailable",function(a){f(a,b)},!1),c.mediaRecorder.start(10),window.console.log("MediaRecorder started",c.mediaRecorder),!0};var f=function(b,d){if(b.data&&b.data.size>0){c.initTimestamp<0&&(c.initTimestamp=b.timeStamp);var e=b.timeStamp-c.initTimestamp-c.pauseTimestamp,f=new Date(e);f.setHours(f.getHours()-1);var g=f.getHours()<10?"0"+f.getHours():f.getHours(),h=f.getMinutes()<10?"0"+f.getMinutes():f.getMinutes(),i=f.getSeconds()<10?"0"+f.getSeconds():f.getSeconds(),j=g+":"+h+":"+i;a("#audiotime"+d).text(j),c.limit&&e>c.limit&&(c.timestampStop&&0!==c.timestampStop||(c.timestampStop=1,c.records[d].stopRecord())),c.recordedBlobs.push(b.data)}};return c.prototype.stopRecording=function(a){c.statut="off",c.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",c.recordedBlobs);var b=c.recordedBlobs;c.records[a].sendBlob(b),this.sendFile(b,a)},c.prototype.sendFile=function(b,d){a("#sending"+d).show(),a(c.prototype.VALIDATIONBUTTON).addClass("disabled"),a(c.prototype.VALIDATIONBUTTON).attr("disabled","disabled"),a(c.prototype.VALIDATIONBUTTON).prop("disabled",!0);var e=new Blob(b),f=new window.FormData,g=(1e3*Math.random()).toString().replace(".","");f.append("repo_upload_file",e,g),f.append("itemid",g),f.append("title",g),f.append("repo_id",c.repo),f.append("env","editor"),f.append("sesskey",M.cfg.sesskey),f.append("savepath","/"),f.append("ctx_id",M.cfg.contextid);var h=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",i=new XMLHttpRequest;i.addEventListener("readystatechange",function(){if(4===this.readyState&&200===this.status){a("#sending"+d).hide(),a(c.prototype.VALIDATIONBUTTON).removeClass("disabled"),a(c.prototype.VALIDATIONBUTTON).attr("disabled","false"),a(c.prototype.VALIDATIONBUTTON).prop("disabled",!1);var b=i.response,e=JSON.parse(b);a("input[name='filerecord"+d+"']").val(e.file),a("input[name='file"+d+"']").parent().parent().addClass("disabled"),a("#sendok"+d).show()}else this.readyState>200&&(a("#sending"+d).hide(),a(c.prototype.VALIDATIONBUTTON).removeClass("disabled"),a(c.prototype.VALIDATIONBUTTON).attr("disabled","false"),a(c.prototype.VALIDATIONBUTTON).prop("disabled",!1),a("#sendko"+d).show())},!1),i.open("POST",h,!0),i.send(f)},c.prototype.pauseRecording=function(a){c.mediaRecorder&&(c.pauseBeginTimestamp=a.timeStamp,c.mediaRecorder.pause(),window.console.log("MediaRecorder paused",c.mediaRecorder))},c.prototype.resumeRecording=function(a){c.mediaRecorder&&(c.pauseTimestamp+=a.timeStamp-c.pauseBeginTimestamp,c.mediaRecorder.resume(),window.console.log("MediaRecorder resumed",c.mediaRecorder))},c.prototype.reset=function(){for(var a=0;a<c.records.length;a++)c.records[a].reset()},c});
\ No newline at end of file
define(["jquery","mod_audioannotation/record"],function(a,b){function c(a){c.repo="repo"in a?a.repo:null,c.limit="limit"in a&&a.limit>0?1e3*a.limit:null,c.nbRendu="nbRendu"in a&&a.nbRendu>0?a.nbRendu:1,this.init(),this.initDisplay()}c.constraints={audio:!0},c.sourceBuffer=null,c.mediaRecorder=null,c.recordedBlobs=null,c.prototype.mediaSource=null,c.repo=-1,c.limit=null,c.nbRendu=1,c.records=null,c.statut="off",c.pauseTimestamp=0,c.prototype.RECORDINGTOOLS=".record-tool",c.prototype.VALIDATIONBUTTON="input[type=submit]",c.prototype.init=function(){c.records=[];for(var f=0;f<c.nbRendu;f++){var g=[];g.manager=this,g.limit=c.limit,g.repo=c.repo,g.indice=f,c.records[f]=new b(g)}if(a("#audioworkspace").remove(),c.mediaSource=new MediaSource,c.mediaSource.addEventListener("sourceopen",e,!1),!navigator.mediaDevices||!window.MediaRecorder)return a(".webrtcsupport").show(),void a(c.prototype.RECORDINGTOOLS).hide();if(!navigator.mediaDevices.getUserMedia)return a(".webrtcsupport").show(),a(c.prototype.RECORDINGTOOLS).hide(),void window.console.log("getUserMedia is not supported by your browser");navigator.permissions.query({name:"microphone"}).then(function(a){window.console.log(a.state),window.stream&&window.stream.getTracks().forEach(function(a){a.stop()})})["catch"](function(a){window.console.log("Got error :",a)}),c.mediaRecorder&&"inactive"!==c.mediaRecorder.state&&c.mediaRecorder.stop(),window.stream&&window.stream.getTracks().forEach(function(a){"ended"!==a.readyState&&a.stop()});var h=null;navigator.mediaDevices.enumerateDevices().then(function(b){function e(a){window.console.log("Got stream, time diff :",Date.now()-l),d(a)}function f(a){m++;var b={audio:{deviceId:{exact:a}}};navigator.mediaDevices.getUserMedia(b).then(e)["catch"](g)}function g(b){i&&m<i.length?f(i[m]):(a(".microphone").show(),a(c.prototype.RECORDINGTOOLS).hide(),window.console.log("GUM failed with error, time diff: ",Date.now()-l),window.console.error("navigator.getUserMedia error:",b.name+": "+b.message),a(c.errorMsgElement).html("navigator.getUserMedia error:"+b.toString()))}var i=[];window.console.log(b);for(var j=0;j!==b.length;++j){var k=b[j];"audioinput"===k.kind&&(h=k.deviceId,window.console.log(h),i.push(h))}if(!h)return a(".microphone").show(),void a(c.prototype.RECORDINGTOOLS).hide();var l=Date.now(),m=0;navigator.mediaDevices.getUserMedia({audio:!0}).then(e)["catch"](g)})},c.prototype.initDisplay=function(){a.fn.justtext=function(){return a(this).clone().children().remove().end().text()},a(".audiofilepicker .form-filetypes-descriptions > ul").each(function(){var b=a(this).children("li");if(b&&!(b.length<2)){var c=a("<li></li>"),d=b[0],e=a(d).justtext();e=e.replace(/\ \((.*)\)/g,""),c.append(e);var f=a(d).children(),g="";f.each(function(){g=a(this).clone(),g.html("")}),b.each(function(){a(this).children().each(function(){g.append(a(this).text()+" ")}),a(this).remove()}),c.append(g),a(this).append(c)}})};var d=function(b){a(".btn-record").each(function(){a(this).prop("indice")>=0&&c.records[a(this).prop("indice")].initDisplayRecordButton(!0)}),window.console.log("getUserMedia() got stream:",b),window.stream=b},e=function(){window.console.log("MediaSource opened"),c.sourceBuffer=c.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",c.sourceBuffer)};c.prototype.startRecording=function(b){if("off"!==c.statut)return!1;c.statut="on",c.recordedBlobs=[],c.initTimestamp=-1,c.pauseTimestamp=0;var d=null;try{c.mediaRecorder=new MediaRecorder(window.stream,d)}catch(e){return window.console.error("Exception while creating MediaRecorder:",e),void a(this.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(e))}return window.console.log("Created MediaRecorder",c.mediaRecorder,"with options",d),c.mediaRecorder.addEventListener("stop",function(d){a("#audiotime"+b).text(""),c.timestampStop=0,window.console.log("Recorder stopped: ",d)},!1),c.mediaRecorder.addEventListener("dataavailable",function(a){f(a,b)},!1),c.mediaRecorder.start(10),window.console.log("MediaRecorder started",c.mediaRecorder),!0};var f=function(b,d){if(b.data&&b.data.size>0){c.initTimestamp<0&&(c.initTimestamp=b.timeStamp);var e=b.timeStamp-c.initTimestamp-c.pauseTimestamp,f=new Date(e);f.setHours(f.getHours()-1);var g=f.getHours()<10?"0"+f.getHours():f.getHours(),h=f.getMinutes()<10?"0"+f.getMinutes():f.getMinutes(),i=f.getSeconds()<10?"0"+f.getSeconds():f.getSeconds(),j=g+":"+h+":"+i;a("#audiotime"+d).text(j),c.limit&&e>c.limit&&(c.timestampStop&&0!==c.timestampStop||(c.timestampStop=1,c.records[d].stopRecord())),c.recordedBlobs.push(b.data)}};return c.prototype.stopRecording=function(a){c.statut="off",c.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",c.recordedBlobs);var b=c.recordedBlobs;c.records[a].sendBlob(b),this.sendFile(b,a)},c.prototype.sendFile=function(b,d){a("#sending"+d).show(),a(c.prototype.VALIDATIONBUTTON).addClass("disabled"),a(c.prototype.VALIDATIONBUTTON).attr("disabled","disabled"),a(c.prototype.VALIDATIONBUTTON).prop("disabled",!0);var e=new Blob(b),f=new window.FormData,g=(1e3*Math.random()).toString().replace(".","");f.append("repo_upload_file",e,g),f.append("itemid",g),f.append("title",g),f.append("repo_id",c.repo),f.append("env","editor"),f.append("sesskey",M.cfg.sesskey),f.append("savepath","/"),f.append("ctx_id",M.cfg.contextid);var h=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",i=new XMLHttpRequest;i.addEventListener("readystatechange",function(){if(4===this.readyState&&200===this.status){a("#sending"+d).hide(),a(c.prototype.VALIDATIONBUTTON).removeClass("disabled"),a(c.prototype.VALIDATIONBUTTON).attr("disabled","false"),a(c.prototype.VALIDATIONBUTTON).prop("disabled",!1);var b=i.response,e=JSON.parse(b);a("input[name='filerecord"+d+"']").val(e.file),a("input[name='file"+d+"']").parent().parent().addClass("disabled"),a("#sendok"+d).show()}else this.readyState>200&&(a("#sending"+d).hide(),a(c.prototype.VALIDATIONBUTTON).removeClass("disabled"),a(c.prototype.VALIDATIONBUTTON).attr("disabled","false"),a(c.prototype.VALIDATIONBUTTON).prop("disabled",!1),a("#sendko"+d).show())},!1),i.open("POST",h,!0),i.send(f)},c.prototype.pauseRecording=function(a){c.mediaRecorder&&(c.pauseBeginTimestamp=a.timeStamp,c.mediaRecorder.pause(),window.console.log("MediaRecorder paused",c.mediaRecorder))},c.prototype.resumeRecording=function(a){c.mediaRecorder&&(c.pauseTimestamp+=a.timeStamp-c.pauseBeginTimestamp,c.mediaRecorder.resume(),window.console.log("MediaRecorder resumed",c.mediaRecorder))},c.prototype.reset=function(){for(var a=0;a<c.records.length;a++)c.records[a].reset()},c});
\ No newline at end of file
......@@ -50,6 +50,7 @@ define(['jquery'],
* @type {Editor}
*/
Annotation.editor = null;
/**
* Div which represents the annotation on the audio graph
* @type {Jquery}
......@@ -73,6 +74,7 @@ define(['jquery'],
* @param {object} data initial parameters
*/
function Annotation(data) {
//init each variable with default value
this.editor = data.editor;
this.id = null;
this.timeposition = null;
......
......@@ -36,14 +36,48 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
*************/
Controler.courseid = -1;
/**
* audio annotation id
* @type {int}
*/
Controler.audioannotation = -1;
Controler.wavePlayer = null;
/**
* List of each editors related to this controler
* - one by record
* @type {array<editor>}
*/
Controler.prototype.editors = null;
/**
* Right Menu object dedicated to this controler
* @type {RightMenu}
*/
Controler.rightMenu = null;
Controler.lastP = null;
/**
* say if environement is in eval mode (reserve to teacher)
* @type {int}
*/
Controler.eval = 0;
/**
* say if environement is in write mode (reserve to pair or teacher)
* @type {int}
*/
Controler.iswriting = 0;
/**
* say if environement is in pairing mode
* @type {int}
*/
Controler.pairing = 0;
/**
* current user id
* @type {int}
*/
Controler.currentUser = null;
/********************************
......@@ -85,7 +119,6 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
}
}
//init composants
Controler.wavePlayer = new JustwavePlayer(this);
Controler.editors = [];
if (assignParts) {
for (var i = 0; i < assignParts.length; i++) {
......@@ -112,7 +145,6 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
/**
* Initialize listeners on html objects
* @returns {undefined}
*/
Controler.prototype.initTrigger = function () {
if (Controler.eval == 1 || Controler.iswriting == 1) {
......@@ -175,7 +207,9 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
/**
* Init waveplayer picture and web player with waveform
* @param {array} opt Array with init parameters
* @param {JustwavePlayer} playerwave wave player for a given editor
* @param {string} opt classe for html player
* @param {int} assignpartid assign part id for the given editor
*/
Controler.prototype.initWave = function (playerwave, opt, assignpartid) {
playerwave.init(opt);
......@@ -195,24 +229,6 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
}
};
/**
* Init global dispay
*/
Controler.prototype.initDisplay = function () {
/*function initVisuNotification() {
var val = $('input[name="remediation"]:checked').val();
if (val == 1) {
$('input[name="notification"]').parents('div.fitem').show();
} else {
$('input[name="notification"]').parents('div.fitem').hide();
}
}*/
//initVisuNotification();
/*$('input[name="remediation"]').on('change', function () {
initVisuNotification();
});*/
};
/**
* Notify controleur and children from events
* @param {String} event Event label to execute
......
......@@ -46,46 +46,69 @@ define(['jquery', 'mod_audioannotation/annotation', 'mod_audioannotation/records
* List of all annotations in the editor
* @type {array} annotations
*/
Editor.annotations = [];
/**
* Controler of the editor
* @type {Controler} controler
*/
Editor.controler = null;
/**
* Id of the course which the editor depends to
* @type {int} courseid
*/
Editor.courseid = null;
/**
* Controler of the editor
* @type {Controler} controler
*/
Editor.waveplayer = null;
/**
* Id of the assign part which the editor depends to
* @type {int} assignpartid
*/
Editor.assignpartid = null;
/**
* Id of the audiannotation activity which the editor depends to
* @type {int} audioannotation
*/
Editor.audioannotation = null;
/**
* Record object associate to the assign part
* @type {record} record
*/
Editor.record = null;
/**
* List of all annotations in the editor
* @type {array} tags
*/
Editor.tags = null;
/**
* Moodle repo id for dowloading
* @type {int} repo
*/
Editor.repo = null;
//statut
Editor.isaddopen = false;
Editor.iseditopen = false;
Editor.isviewopen = false;
/**
* Current opened annotation in this editor
* @type {annotation}
*/
Editor.currentAnnotation = null;
//filter parameters
Editor.filtretag = null;
Editor.filtrequestion = null;
Editor.filtrestatut = null;
......@@ -105,6 +128,8 @@ define(['jquery', 'mod_audioannotation/annotation', 'mod_audioannotation/records
10: "#c5000b",
11: "#0084d1"
};
//CONSTANTS
Editor.prototype.TAGDEFAULTCOLOR = "blue";
Editor.prototype.ADDANNOTATIONCLASS = ".annotation_add";
Editor.prototype.VIEWANNOTATIONCLASS = ".annotation_view";
......@@ -206,6 +231,10 @@ define(['jquery', 'mod_audioannotation/annotation', 'mod_audioannotation/records
}
};
/**
* Set dedicated wave player for the current assign part
* @param {JustWave} waveplayer
*/
Editor.prototype.setWavePlayer = function (waveplayer) {
this.waveplayer = waveplayer;
};
......@@ -367,9 +396,8 @@ define(['jquery', 'mod_audioannotation/annotation', 'mod_audioannotation/records
/**
* Display a form to add an annotation, with associated actions
* @param {JustWave} player
*/
Editor.prototype.addAnnotation = function (/*player*/) {
Editor.prototype.addAnnotation = function () {
//an other editor workspace is open, we close it
closeAddForm();
closeEditForm();
......@@ -555,7 +583,7 @@ define(['jquery', 'mod_audioannotation/annotation', 'mod_audioannotation/records
* 1- create an edit form
* 2- click on delete button
* 3- destroy the form and refresh display
* @param {type} annotationid
* @param {int} annotationid
*/
Editor.prototype.deleteAnnotation = function (annotationid) {
var annotation = this.getAnnotation(annotationid);
......@@ -580,6 +608,7 @@ define(['jquery', 'mod_audioannotation/annotation', 'mod_audioannotation/records
/**
* Delete the annotation with ajax and refresh display
* @param {array} listAnnotations list of editor's annotations
* @param {Annotation} annotation
*/
var deleteAnnotationAction = function (listAnnotations, annotation) {
......
......@@ -74,14 +74,33 @@ define(['jquery'],
* CONSTANTES *
*************/
/**
* Global controler object
* @type {Controler} controler
*/
JustWave.controler = null;
/**
* linked assign part
* @type {int} assignpart
*/
JustWave.assignpart = -1;
/**
* True if an annotation is clicked
* @type {bool} clickAnnotation
*/
JustWave.clickAnnotation = 0;
/**
* Number of seconds to position cursor before an annotation
* @type {bool} delayBeforeAnnotation
*/
JustWave.delayBeforeAnnotation = 2;
JustWave.options = null;
//html constant elements
JustWave.prototype.PLAYPAUSEBUTTON = ".justwave_playpause";
JustWave.prototype.PLAYPAUSEBUTTONBEFORE = ".justwave_playpause_before";
JustWave.prototype.CURRENTFOCUS = ".justwave_curfocus";
......@@ -97,7 +116,7 @@ define(['jquery'],
* @class JustWave
*
* @param {Controler} controler Master class of the class
* @param {string} tmpdir Path to tmp dir
* @param {int} assignpart Assign part id
*/
function JustWave(controler, assignpart) {
this.controler = controler;
......@@ -123,6 +142,11 @@ define(['jquery'],
song.find('.audio_annotations').append(html);
};
/**
* Position the cursor before an annotation when user call it
* @param {JustWave} player
* @param {Annotation} annotation
*/
JustWave.prototype.goBeforeAnnotation = function (player, annotation) {
if (!player) {
return;
......@@ -133,6 +157,11 @@ define(['jquery'],
JustWave.clickAnnotation = 1;
};
/**
* Get wave player design options
* @param {JustWave} p
* @returns {object} opts
*/
JustWave.prototype.getWaveOpts = function (p) {
// default options, see descriptions above
var opts = {
......@@ -411,7 +440,7 @@ define(['jquery'],
/**
* Move cursor and show current time of a track
* @param {type} p audio element
* @param {Element} p audio element
*/
var updatePlayhead = function (p) {
var newWidth = p.currentTime / p.xduration * 100,
......@@ -454,8 +483,6 @@ define(['jquery'],
}
};
// clear waveforms by backgroundand set size of the palyer
// p - audio element
/**
* clear waveforms by backgroundand set size of the palyer
* @param {Element} p audio element
......@@ -488,6 +515,11 @@ define(['jquery'],
song.find(JustWave.prototype.PLAYPAUSEBUTTON + ' i.fa').removeClass('fa-pause');
};
/**
* Build and display wave player
* @param {Element} p
* @returns {undefined}
*/
JustWave.prototype.drawWaveDisplay = function (p) {
var assignpart = this.assignpart;
p.opts = this.getWaveOpts(p);
......
......@@ -25,6 +25,10 @@
*
* @module mod_audioannotation/Record
* @param {Jquery} $
* @param {core/modal_factory} ModalFactory
* @param {core/modal_events} ModalEvents
* @param {core/str} str
*
* inspired by https://github.com/webrtc/samples/blob/gh-pages/src/content/getusermedia/record/js/main.js
*/
define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
......@@ -36,6 +40,8 @@ define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
Record.mediaRecorder = null;
Record.recordedBlobs = null;
// html constant elements
Record.errorMsgElement = '#errorMsg';
Record.recordButton = '#record';
Record.pauseRecordButton = '#pauseRecord';
......@@ -44,12 +50,40 @@ define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
Record.sending = '#sending';
Record.sendok = '#sendok';
/**
* Moodle repository id
* @type {int} repo
*/
Record.repo = -1;
/**
* timestamp of begining's record
* @type {int} initTimestamp
*/
Record.initTimestamp = -1;
/**
* timestamp of end's record
* @type {int} timestampStop
*/
Record.timestampStop = 0;
/**
* Limit of record (in seconds)
* @type {int} limit
*/
Record.limit = null;
/**
* editor's indice
* @type {int} indice
*/
Record.indice = '';
/**
* Main record manager controler
* @type {RecordsManager} manager
*/
Record.manager = null;
/********************************
......@@ -129,12 +163,18 @@ define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
$(this.recordButton).data('statut', 'stop');
};
/**
* Init record button's display according to context
*/
Record.prototype.initDisplayRecordButton = function () {
if (typeof $(this.recordedVideo).attr("src") === "undefined") {
$(this.recordButton).attr('disabled', false);
}
};
/**
* Init htlm5 audio's display, according to context
*/
Record.prototype.initDisplayAudio = function () {
//if audio already here, display it
if ($(this.recordedVideo).attr("src")) {
......@@ -143,6 +183,7 @@ define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
}
var indice = this.indice;
//on remet a zero car moodle va envoyer une valeur mm si le champ est sense etre vide
$("input[name='file" + indice + "']").on('change', function () {
if ($(this).val() && $(this).val() > 0) {
$("input[name='filerecord" + indice + "']").val($(this).val());
......@@ -150,6 +191,9 @@ define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
});
};
/**
* Reset global display
*/
Record.prototype.reset = function () {
this.initDisplayAudio();
$(this.recordButton).data('statut', 'stop');
......@@ -232,6 +276,10 @@ define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
});
};
/**
* Display audio just after a recording
* Create audio media with browser buffer
*/
Record.prototype.displayAudio = function () {
var recordedVideo = this.recordedVideo;
//play the stream
......@@ -246,10 +294,17 @@ define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/str'],
$(recordedVideo).attr('autoplay', false);
};
/**
* Register audio recording
* @param {data} blob
*/
Record.prototype.sendBlob = function (blob) {
Record.recordedBlobs = blob;
};
/**
* Action for stopping recording
*/
Record.prototype.stopRecord = function () {
$(this.recordButton).click();
};
......
......@@ -25,6 +25,8 @@
*
* @module mod_audioannotation/RecordsManager
* @param {Jquery} $
* @param {mod_audioannotation/record} Record
*
* inspired by https://github.com/webrtc/samples/blob/gh-pages/src/content/getusermedia/record/js/main.js
*/
define(['jquery', 'mod_audioannotation/record'],
......@@ -33,20 +35,53 @@ define(['jquery', 'mod_audioannotation/record'],
/*************
* CONSTANTES *
*************/
//webrtc objects
RecordsManager.constraints = {
audio: true
};
RecordsManager.sourceBuffer = null;
RecordsManager.mediaRecorder = null;
RecordsManager.recordedBlobs = null;
RecordsManager.prototype.mediaSource = null;
/**
* Moodle repository id (for upload)
* @type int repo
*/
RecordsManager.repo = -1;
/**
* max time limit for recording
* @type int limit
*/
RecordsManager.limit = null;
/**
* number of assignements to process
* @type int nbRendu
*/
RecordsManager.nbRendu = 1;
/**
* set of records (one record for one assignement part)
* @type array records
*/
RecordsManager.records = null;
/**
* Statut of record (on -> the recording is begin)
* @type string statut
*/
RecordsManager.statut = 'off';
RecordsManager.prototype.mediaSource = null;
/**
* sum of timestamp when user use pause button
* @type int pauseTimestamp
*/
RecordsManager.pauseTimestamp = 0;
//html constant elements
RecordsManager.prototype.<