Gitlab CSE Unil

Commit 97ae814b authored by M. Chardon's avatar M. Chardon
Browse files

Merge branch 'V1' into 'master'

V1

See merge request !1
parents bfaa8f27 672a27c5
define(["jquery"],function(a){function b(a){b.editor=a.editor,this.id=null,this.timeposition=null,this.isquestion=0,this.validationens=0,this.assignementpart=null,this.typevalidation=null,this.statut=0,this.mainmessage=null,this.tag=-1}return b.id=null,b.timeposition=null,b.isquestion=0,b.validationens=0,b.assignementpart=null,b.typevalidation=null,b.statut=0,b.mainmessage=null,b.tag=-1,b.editor=null,b.divDisplay=null,b.DEFAULTCOLOR="yellow",b.prototype.init=function(a){a.timeposition&&(this.timeposition=a.timeposition),a.id&&(this.id=a.id),a.isquestion&&(this.isquestion=a.isquestion),a.validationens&&(this.validationens=a.validationens),a.assignementpart&&(this.assignementpart=a.assignementpart),a.typevalidation&&(this.typevalidation=a.typevalidation),a.statut&&(this.statut=a.statut),a.mainmessage&&(this.mainmessage=a.mainmessage),a.tag&&(this.tag=a.tag)},b.prototype.initListener=function(){if(this.divDisplay){var a=this;this.divDisplay.on("click",function(){1==b.editor.getEval()?b.editor.notify("edit",a):b.editor.notify("view",a)})}},b.prototype.serialize=function(a,b,c){return{courseid:a,action:b,audioannotation:c,timeposition:this.timeposition,id:this.id,isquestion:this.isquestion,validationens:this.validationens,assignementpart:this.assignementpart,typevalidation:this.typevalidation,statut:this.statut,mainmessage:this.mainmessage,tag:this.tag}},b.prototype.displayDiv=function(a,b,c){return this.divDisplay&&!c||this.buildDiv(a,b),this.divDisplay},b.prototype.buildDiv=function(c,d){var e=b.editor.getTagColor();d&&(e=b.DEFAULTCOLOR),this.tag>-1&&(e=b.editor.getTagColor(this.tag));var f="<div style='background-color:"+e+";";f+="margin-left:"+c+"%;' ",f+="class='audio_annotation' ",f+=d?"data-annotation='draft' ":"data-annotation='"+this.id+"' ",f+="></div>",this.divDisplay=a(f)},b.prototype.hide=function(){this.divDisplay.hide()},b.prototype.show=function(){this.divDisplay.show()},b.prototype.refreshDiv=function(a){a?this.divDisplay.css("background-color",b.DEFAULTCOLOR):this.divDisplay.css("background-color",b.editor.getTagColor(this.tag)),this.divDisplay.data("annotation",this.id)},b.prototype.delDisplay=function(){this.divDisplay&&this.divDisplay.remove()},b});
\ No newline at end of file
define(["jquery"],function(a){function b(a){b.editor=a.editor,this.id=null,this.timeposition=null,this.isquestion=0,this.assignementpart=null,this.validation=0,this.statut=0,this.mainmessage=null,this.tag=-1}return b.id=null,b.timeposition=null,b.isquestion=0,b.assignementpart=null,b.validation=0,b.statut=0,b.mainmessage=null,b.tag=-1,b.editor=null,b.divDisplay=null,b.DEFAULTCOLOR="yellow",b.prototype.init=function(a){a.timeposition&&(this.timeposition=a.timeposition),a.id&&(this.id=a.id),a.isquestion&&(this.isquestion=a.isquestion),a.assignementpart&&(this.assignementpart=a.assignementpart),a.validation&&(this.validation=a.validation),a.statut&&(this.statut=a.statut),a.mainmessage&&(this.mainmessage=a.mainmessage),a.tag&&(this.tag=a.tag)},b.prototype.initListener=function(){if(this.divDisplay){var a=this;this.divDisplay.on("click",function(){1==b.editor.getEval()?b.editor.notify("edit",a):b.editor.notify("view",a)})}},b.prototype.serialize=function(a,b,c){return{courseid:a,action:b,audioannotation:c,timeposition:this.timeposition,id:this.id,isquestion:this.isquestion,assignementpart:this.assignementpart,validation:this.validation,statut:this.statut,mainmessage:this.mainmessage,tag:this.tag}},b.prototype.displayDiv=function(a,b,c){return this.divDisplay&&!c||this.buildDiv(a,b),this.divDisplay},b.prototype.buildDiv=function(c,d){var e=b.editor.getTagColor();d&&(e=b.DEFAULTCOLOR),this.tag>-1&&(e=b.editor.getTagColor(this.tag));var f="<div style='background-color:"+e+";";f+="margin-left:"+c+"%;' ",f+="class='audio_annotation' ",f+=d?"data-annotation='draft' ":"data-annotation='"+this.id+"' ",f+="></div>",this.divDisplay=a(f)},b.prototype.hide=function(){this.divDisplay.hide()},b.prototype.show=function(){this.divDisplay.show()},b.prototype.refreshDiv=function(a){a?this.divDisplay.css("background-color",b.DEFAULTCOLOR):this.divDisplay.css("background-color",b.editor.getTagColor(this.tag)),this.divDisplay.data("annotation",this.id)},b.prototype.delDisplay=function(){this.divDisplay&&this.divDisplay.remove()},b});
\ 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.contextid="context"in a?a.context:null,e.courseid="course"in a?a.course:null,e.assignpartid="assignpart"in a?a.assignpart:null,e.audioannotation="audioannotation"in a?a.audioannotation:null,e.eval="eval"in a?a.eval:0;var f="annotations"in a?a.annotations:null,g=null;f&&(g=JSON.parse(f));var h="tags"in a?a.tags:null,i=null;h&&(i=JSON.parse(h)),e.wavePlayer=new b(this),e.editor=new c({controler:this,contextid:e.contextid,courseid:e.courseid,assignpartid:e.assignpartid,annotations:g,audioannotation:e.audioannotation,tags:i}),this.initTrigger(),this.initWave("justwave"),e.rightMenu=new d({controler:this})}e.contextid=-1,e.courseid=-1,e.assignpartid=-1,e.audioannotation=-1,e.wavePlayer=null,e.editor=null,e.rightMenu=null,e.lastP=null,e.eval=0,e.prototype.initTrigger=function(){1==e.eval&&a("#btn_add_annotation").on("click",function(){e.editor.notify("add",e.lastP)}),a("#select_tag").on("change",f),a("#select_question").on("change",f),a("#select_statut").on("change",f),a("li[data-annotation]").on("click",function(){var b=a(this).data("annotation");b&&e.editor.notify("view",{annotation:b})})};var f=function(){e.editor.notify("displaytqs",{tag:a("#select_tag").val(),question:a("#select_question").val(),statut:a("#select_statut").val()})};return e.prototype.initWave=function(b){e.wavePlayer.init(b),a(".justwave_playpause").click(),a(".justwave_playpause").click()},e.prototype.initAnnotations=function(){e.editor.initAnnotationsDisplay()},e.prototype.notify=function(a,b,c){switch("player"===b&&(e.lastP=c),a){case"loadedmetadata":this.initAnnotations();break;case"drawannotation_draft":e.wavePlayer.drawAnnotation(e.lastP,c,1);break;case"drawannotation":e.wavePlayer.drawAnnotation(e.lastP,c,0);break;case"addannotation":e.editor.setEditorStatus("add");break;case"editannotation":e.editor.setEditorStatus("edit");break;case"viewannotation":e.editor.setEditorStatus("view");break;case"deleteannotation":"rightMenu"===b?e.editor.notify("delete",c):e.editor.setEditorStatus("delete")}},e.prototype.getEval=function(){return e.eval},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.courseid="course"in a?a.course:null,e.assignpartid="assignpart"in a?a.assignpart:null,e.audioannotation="audioannotation"in a?a.audioannotation:null,e.eval="eval"in a?a.eval:0;var f="repo"in a?a.repo:null,g="annotations"in a?a.annotations:null,h=null;g&&(h=JSON.parse(g));var i="tags"in a?a.tags:null,j=null;i&&(j=JSON.parse(i)),e.wavePlayer=new b(this),e.editor=new c({controler:this,courseid:e.courseid,assignpartid:e.assignpartid,annotations:h,audioannotation:e.audioannotation,tags:j,repo:f}),this.initTrigger(),this.initWave("justwave"),e.rightMenu=new d({controler:this})}e.courseid=-1,e.assignpartid=-1,e.audioannotation=-1,e.wavePlayer=null,e.editor=null,e.rightMenu=null,e.lastP=null,e.eval=0,e.prototype.initTrigger=function(){1==e.eval&&a("#btn_add_annotation").on("click",function(){e.editor.notify("add",e.lastP)}),a("#select_tag").on("change",f),a("#select_question").on("change",f),a("#select_statut").on("change",f),a("li[data-annotation]").on("click",function(){var b=a(this).data("annotation");b&&e.editor.notify("view",{annotation:b})})};var f=function(){e.editor.notify("displaytqs",{tag:a("#select_tag").val(),question:a("#select_question").val(),statut:a("#select_statut").val()})};return e.prototype.initWave=function(b){e.wavePlayer.init(b),a(".justwave_playpause").click(),a(".justwave_playpause").click()},e.prototype.initAnnotations=function(){e.editor.initAnnotationsDisplay()},e.prototype.notify=function(a,b,c){switch("player"===b&&(e.lastP=c),a){case"loadedmetadata":this.initAnnotations();break;case"drawannotation_draft":e.wavePlayer.drawAnnotation(e.lastP,c,1);break;case"drawannotation":e.wavePlayer.drawAnnotation(e.lastP,c,0);break;case"addannotation":e.editor.setEditorStatus("add");break;case"editannotation":e.editor.setEditorStatus("edit");break;case"viewannotation":e.editor.setEditorStatus("view");break;case"deleteannotation":"rightMenu"===b?e.editor.notify("delete",c):e.editor.setEditorStatus("delete")}},e.prototype.getEval=function(){return e.eval},e});
\ No newline at end of file
define(["jquery","mod_audioannotation/annotation","core/notification","core/templates","core/fragment","core/ajax","core/str"],function(a,b,c,d,e,f,g){function h(c){this.controler="controler"in c?c.controler:null,this.contextid="contextid"in c?c.contextid:null,this.courseid="courseid"in c?c.courseid:null,this.assignpartid="assignpartid"in c?c.assignpartid:null,this.audioannotation="audioannotation"in c?c.audioannotation:null;var d="annotations"in c?c.annotations:[],e="tags"in c?c.tags:[];this.tags=[];for(var f=0;f<e.length;f++)f in this.TAGSCOLOR?e[f].color=this.TAGSCOLOR[f]:e[f].color=this.TAGDEFAULTCOLOR,this.tags[e[f].id]=e[f],a("button[data-tag='"+e[f].id+"']").css("color",e[f].color);var g=new Object;g.editor=this;for(var j=0;j<d.length;j++){var k=new b(g);k.init(d[j]),h.annotations[h.annotations.length]=k}i()}h.annotations=[],h.controler=null,h.contextid=null,h.courseid=null,h.assignpartid=null,h.audioannotation=null,h.tags=null,h.isaddopen=!1,h.iseditopen=!1,h.isviewopen=!1,h.currentAnnotation=null,h.filtretag=null,h.filtrequestion=null,h.filtrestatut=null,h.prototype.TAGSCOLOR={0:"#004586",1:"#ff420e",2:"#ffd320",3:"#579d1c",4:"#7e0021",5:"#83caf",6:"#314004",7:"#aecf00",8:"#4b1f6f",9:"#ff950e",10:"#c5000b",11:"#0084d1"},h.prototype.TAGDEFAULTCOLOR="blue",h.messageErrorSave="error",h.messageErrorDelete="error";var i=function(){g.get_string("ajaxsave_messageko","audioannotation").done(function(a){h.messageErrorSave=a}).fail(c.exception),g.get_string("ajaxdel_messageko","audioannotation").done(function(a){h.messageErrorDelete=a}).fail(c.exception)};h.prototype.initAnnotationsDisplay=function(){for(var a=0;a<h.annotations.length;a++)this.controler.notify("drawannotation","editor",h.annotations[a]),h.annotations[a].initListener()},h.prototype.setEditorStatus=function(a){switch(a){case"add":h.isaddopen=!0,h.iseditopen&&k(this.currentAnnotation);break;case"edit":h.iseditopen=!0,h.isaddopen&&j();break;case"view":h.isviewopen=!0;break;case"delete":h.iseditopen&&k(this.currentAnnotation),h.isaddopen&&j()}};var j=function(b){a("#annotation_add").hide(),a("#annotation_add").html(""),b&&b.id?b.refreshDiv():a("div").find("[data-annotation='draft']").remove(),h.isaddopen=!1},k=function(b){a("#annotation_edit").hide(),a("#annotation_edit").html(""),b&&b.refreshDiv(),h.iseditopen=!1},l=function(b){a("#annotation_view").hide(),a("#annotation_view").html(""),a("#annotation_view").css("border","none"),b&&b.refreshDiv(),h.isviewopen=!1};h.prototype.viewAnnotation=function(b){(this.currentAnnotation||this.isviewopen)&&l(this.currentAnnotation),this.currentAnnotation=b;var g=this.getTagColor(b.tag),h=this.controler,i=b.serialize(this.courseid,"view",this.audioannotation);e.loadFragment("mod_audioannotation","annotation",this.contextid,i).done(function(e,i){a("#annotation_view").show(),d.replaceNodeContents("#annotation_view",e,i),b.refreshDiv(!0),a("#annotation_view").css("border","solid 4px "+g),a("input[name=statutradio][value='"+b.statut+"']").attr("checked",!0),h.notify("viewannotation","editor",null),a("#annot_form_btn_cancel").on("click",function(){l(b)}),a("#annot_form_btn_valid").on("click",function(){var d=a("#mod_audioanntation_annotation"),e=d.serialize();f.call([{methodname:"mod_audioannotation_submit_annotation_reply_form",args:{jsonformdata:JSON.stringify(e)}}])[0].done(function(c){"error"!==c.message&&(b.statut=a("input[name=statutradio]:checked").val(),l(b))}).fail(c.exception)})}.bind(this)).fail(c.exception)},h.prototype.addAnnotation=function(g){h.isaddopen&&j();var i=this.controler,k=new Object;k.editor=this;var l=new b(k),m=new Object;m.timeposition=g.currentTime,m.assignementpart=this.assignpartid,l.init(m),this.controler.notify("drawannotation_draft","editor",l),a("#annotation_add").html("");var n=l.serialize(this.courseid,"add",this.audioannotation);e.loadFragment("mod_audioannotation","annotation",this.contextid,n).done(function(b,e){a("#annotation_add").show(),d.replaceNodeContents("#annotation_add",b,e),i.notify("addannotation","editor",null),p(),o(),a("#annot_form_btn_cancel").on("click",function(){j()}),a("#annot_form_btn_valid").on("click",function(){var b=a("#mod_audioanntation_annotation"),d=b.serialize();f.call([{methodname:"mod_audioannotation_submit_annotation_add_form",args:{jsonformdata:JSON.stringify(d)}}])[0].done(function(b){"error"!==b.message&&(l.divDisplay.attr("data-annotation",b.annotationid),l.id=b.annotationid,l.tag=a("#id_tag").val(),l.initListener(),h.annotations[h.annotations.length]=l,j(l))}).fail(c.exception)})}.bind(this)).fail(c.exception)},h.prototype.editAnnotation=function(b){(this.currentAnnotation||this.iseditopen)&&k(this.currentAnnotation),this.currentAnnotation=b;var g=this.controler,i=b.serialize(this.courseid,"edit",this.audioannotation);e.loadFragment("mod_audioannotation","annotation",this.contextid,i).done(function(e,i){a("#annotation_edit").show(),d.replaceNodeContents("#annotation_edit",e,i),g.notify("editannotation","editor",null),b.refreshDiv(!0),p(),n(),o(),a("#annot_form_btn_cancel").on("click",function(){k(b)}),a("#annot_form_btn_valid").on("click",function(){var d=a("#mod_audioanntation_annotation"),e=d.serialize();f.call([{methodname:"mod_audioannotation_submit_annotation_edit_form",args:{jsonformdata:JSON.stringify(e)}}])[0].done(function(c){return"error"===c.message?(a("#annotationError").text(h.messageErrorSave),void a("#annotationError").addClass("alert-danger")):(b.tag=a("#id_tag").val(),b.refreshDiv(),void k(b))}).fail(c.exception)}),a("#annot_form_btn_delete").on("click",m),a("#message_pj_btn_delete").on("click",function(){var b=a("#mod_audioanntation_annotation"),d=b.serialize();f.call([{methodname:"mod_audioannotation_submit_message_pj_del_form",args:{jsonformdata:JSON.stringify(d)}}])[0].done(function(b){return"error"===b.message?(a("#annotationError").text(h.messageErrorDelete),void a("#annotationError").addClass("alert-danger")):(a("#fileuploadA").hide(),void a("#fileuploadA").html(""))}).fail(c.exception)})}.bind(this)).fail(c.exception)},h.prototype.deleteAnnotation=function(b){var f=this.getAnnotation(b);if(null!==f){a("#annotation_delete").html(""),(this.currentAnnotation||this.iseditopen)&&k(this.currentAnnotation);var g=this.controler,h=f.serialize(this.courseid,"edit",this.audioannotation);e.loadFragment("mod_audioannotation","annotation",this.contextid,h).done(function(a,b){d.replaceNodeContents("#annotation_delete",a,b),g.notify("deleteannotation","editor",null),m(f)}.bind(this)).fail(c.exception)}};var m=function(b){var d=a("#mod_audioanntation_annotation"),e=d.serialize();f.call([{methodname:"mod_audioannotation_submit_annotation_del_form",args:{jsonformdata:JSON.stringify(e)}}])[0].done(function(c){if("error"===c.message)return a("#annotationError").text(h.messageErrorDelete),void a("#annotationError").addClass("alert-danger");b.delDisplay();var d=h.annotations.indexOf(b);h.annotations.splice(d,1),k(),a("#annotation_delete").html("")}).fail(c.exception)};h.prototype.getAnnotation=function(a){for(var b=0;b<h.annotations.length;b++)if(h.annotations[b].id==a)return h.annotations[b];return null},h.prototype.notify=function(a,b){if("edit"===a)this.editAnnotation(b);else if("add"===a)this.addAnnotation(b);else if("view"===a){var c=b;!b.hasOwnProperty("id")&&b.hasOwnProperty("annotation")&&(c=this.getAnnotation(b.annotation)),c&&this.viewAnnotation(c)}else"displaytqs"===a?this.displayAnnotationByTagQuestionStatut(b):"delete"===a&&this.deleteAnnotation(b)},h.prototype.displayAnnotationByTagQuestionStatut=function(a){var b=a.tag,c=a.question,d=a.statut;if(b==-2&&c==-1&&d==-1)for(var e=0;e<h.annotations.length;e++)h.annotations[e].show();else for(var f=0;f<h.annotations.length;f++){var g=h.annotations[f].isquestion,i=h.annotations[f].statut,j=h.annotations[f].tag;b==-2&&c==-1&&i==d||b==-2&&g==c&&d==-1||j==b&&c==-1&&d==-1||b==-2&&g==c&&i==d||j==b&&c==-1&&i==d||j==b&&g==c&&d==-1||j==b&&g==c&&i==d?h.annotations[f].show():h.annotations[f].hide()}l(this.currentAnnotation)};var n=function(){var b=parseInt(a("[name='isquestion']").val());0===b?a("#annot_form_btn_question .fa-ban").show():a("#annot_form_btn_question .fa-ban").hide()},o=function(){a("#annot_form_btn_question").on("click",function(){var b=parseInt(a("[name='isquestion']").val());0===b?(a("[name='isquestion']").val(1),a("#annot_form_btn_question .fa-ban").hide()):(a("[name='isquestion']").val(0),a("#annot_form_btn_question .fa-ban").show())})},p=function(){a("#fileinput").append(a('[data-fieldtype="filepicker"]')),a('[data-fieldtype="filepicker"]').removeClass("col-md-9"),a(".form-filetypes-descriptions").hide(),a("#fileinput").append(a("input[name*='_qf__mod_audioannotation']")),a("#fileinput").find("p").remove(),a("#fileinput").find(".femptylabel").css("margin-bottom","0"),a("#mform1").remove()};return h.prototype.getTagColor=function(a){return a>-1?this.tags[a].color:this.TAGDEFAULTCOLOR},h.prototype.getEval=function(){return this.controler.getEval()},h});
\ No newline at end of file
define(["jquery","mod_audioannotation/annotation","mod_audioannotation/record","core/notification","core/templates","core/fragment","core/ajax","core/str"],function(a,b,c,d,e,f,g,h){function i(c){this.controler="controler"in c?c.controler:null,this.courseid="courseid"in c?c.courseid:null,this.assignpartid="assignpartid"in c?c.assignpartid:null,this.repo="repo"in c?c.repo:null,this.audioannotation="audioannotation"in c?c.audioannotation:null;var d="annotations"in c?c.annotations:[],e="tags"in c?c.tags:[];this.tags=[];for(var f=0;f<e.length;f++)f in this.TAGSCOLOR?e[f].color=this.TAGSCOLOR[f]:e[f].color=this.TAGDEFAULTCOLOR,this.tags[e[f].id]=e[f],a("button[data-tag='"+e[f].id+"']").css("color",e[f].color);var g=new Object;g.editor=this;for(var h=0;h<d.length;h++){var k=new b(g);k.init(d[h]),i.annotations[i.annotations.length]=k}j()}i.annotations=[],i.controler=null,i.courseid=null,i.assignpartid=null,i.audioannotation=null,i.record=null,i.tags=null,i.repo=null,i.isaddopen=!1,i.iseditopen=!1,i.isviewopen=!1,i.currentAnnotation=null,i.filtretag=null,i.filtrequestion=null,i.filtrestatut=null,i.prototype.TAGSCOLOR={0:"#004586",1:"#ff420e",2:"#ffd320",3:"#579d1c",4:"#7e0021",5:"#83caf",6:"#314004",7:"#aecf00",8:"#4b1f6f",9:"#ff950e",10:"#c5000b",11:"#0084d1"},i.prototype.TAGDEFAULTCOLOR="blue",i.messageErrorSave="error",i.messageErrorDelete="error";var j=function(){h.get_string("ajaxsave_messageko","audioannotation").done(function(a){i.messageErrorSave=a}).fail(d.exception),h.get_string("ajaxdel_messageko","audioannotation").done(function(a){i.messageErrorDelete=a}).fail(d.exception)};i.prototype.initAnnotationsDisplay=function(){for(var a=0;a<i.annotations.length;a++)this.controler.notify("drawannotation","editor",i.annotations[a]),i.annotations[a].initListener()},i.prototype.setEditorStatus=function(a){switch(a){case"add":i.isaddopen=!0,i.iseditopen&&l(this.currentAnnotation);break;case"edit":i.iseditopen=!0,i.isaddopen&&k();break;case"view":i.isviewopen=!0;break;case"delete":i.iseditopen&&l(this.currentAnnotation),i.isaddopen&&k()}};var k=function(b){a("#annotation_add").hide(),a("#annotation_add").html(""),b&&b.id?b.refreshDiv():a("div").find("[data-annotation='draft']").remove(),i.isaddopen=!1},l=function(b){a("#annotation_edit").hide(),a("#annotation_edit").html(""),b&&b.refreshDiv(),i.iseditopen=!1},m=function(b){a("#annotation_view").hide(),a("#annotation_view").html(""),a("#annotation_view").css("border","none"),b&&b.refreshDiv(),i.isviewopen=!1};i.prototype.viewAnnotation=function(b){(this.currentAnnotation||this.isviewopen)&&m(this.currentAnnotation),this.currentAnnotation=b;var c=this.getTagColor(b.tag),h=this.controler,i=b.serialize(this.courseid,"view",this.audioannotation);f.loadFragment("mod_audioannotation","annotation",M.cfg.contextid,i).done(function(f,i){a("#annotation_view").show(),e.replaceNodeContents("#annotation_view",f,i),b.refreshDiv(!0),a("#annotation_view").css("border","solid 4px "+c),a("input[name=statutradio][value='"+b.statut+"']").attr("checked",!0),h.notify("viewannotation","editor",null),a("#annot_form_btn_cancel").on("click",function(){m(b)}),a("#annot_form_btn_valid").on("click",function(){var c=a("form[name=mod_audioannotation_form_message_form]"),e=c.serialize();g.call([{methodname:"mod_audioannotation_submit_annotation_reply_form",args:{jsonformdata:JSON.stringify(e)}}])[0].done(function(c){"error"!==c.message&&(b.statut=a("input[name=statutradio]:checked").val(),m(b))}).fail(d.exception)})}.bind(this)).fail(d.exception)},i.prototype.addAnnotation=function(c){i.isaddopen&&k();var h=this.controler,j=new Object;j.editor=this;var l=new b(j),m=new Object;m.timeposition=c.currentTime,m.assignementpart=this.assignpartid,l.init(m),this.controler.notify("drawannotation_draft","editor",l),a("#annotation_add").html("");var n=this.repo,o=l.serialize(this.courseid,"add",this.audioannotation);f.loadFragment("mod_audioannotation","annotation",M.cfg.contextid,o).done(function(b,c){a("#annotation_add").show(),e.replaceNodeContents("#annotation_add",b,c),h.notify("addannotation","editor",null),s(),p(),q(),r(n),a("#annot_form_btn_cancel").on("click",function(){k()}),a("#annot_form_btn_valid").on("click",function(){var b=a("form[name=mod_audioannotation_form_annotation_form]"),c=b.serialize();g.call([{methodname:"mod_audioannotation_submit_annotation_add_form",args:{jsonformdata:JSON.stringify(c)}}])[0].done(function(b){"error"!==b.message&&(l.divDisplay.attr("data-annotation",b.annotationid),l.id=b.annotationid,l.tag=a("#id_tag").val(),l.initListener(),i.annotations[i.annotations.length]=l,k(l))}).fail(d.exception)})}.bind(this)).fail(d.exception)},i.prototype.editAnnotation=function(b){(this.currentAnnotation||this.iseditopen)&&l(this.currentAnnotation),this.currentAnnotation=b;var c=this.controler,h=this.repo,j=b.serialize(this.courseid,"edit",this.audioannotation);f.loadFragment("mod_audioannotation","annotation",M.cfg.contextid,j).done(function(f,j){a("#annotation_edit").show(),e.replaceNodeContents("#annotation_edit",f,j),c.notify("editannotation","editor",null),b.refreshDiv(!0),s(),o(),p(),q(),r(h),a("#annot_form_btn_cancel").on("click",function(){l(b)}),a("#annot_form_btn_valid").on("click",function(){var c=a("form[name=mod_audioannotation_form_annotation_form]"),e=c.serialize();g.call([{methodname:"mod_audioannotation_submit_annotation_edit_form",args:{jsonformdata:JSON.stringify(e)}}])[0].done(function(c){return"error"===c.message?(a("#annotationError").text(i.messageErrorSave),void a("#annotationError").addClass("alert-danger")):(b.tag=a("#id_tag").val(),b.refreshDiv(),void l(b))}).fail(d.exception)}),a("#annot_form_btn_delete").on("click",function(){n(b)}),a("#message_pj_btn_delete").on("click",function(){var b=a("#mod_audioanntation_annotation"),c=b.serialize();g.call([{methodname:"mod_audioannotation_submit_message_pj_del_form",args:{jsonformdata:JSON.stringify(c)}}])[0].done(function(b){return"error"===b.message?(a("#annotationError").text(i.messageErrorDelete),void a("#annotationError").addClass("alert-danger")):(a("#fileuploadA").hide(),void a("#fileuploadA").html(""))}).fail(d.exception)}),a("input[name=validationradio][value='"+b.validation+"']").attr("checked",!0),a("#message_form_btn_valid").on("click",function(){var c=a("form[name=mod_audioannotation_form_message_form]"),e=c.serialize();g.call([{methodname:"mod_audioannotation_submit_annotation_reply_form",args:{jsonformdata:JSON.stringify(e)}}])[0].done(function(c){return"error"===c.message?(a("#annotationError").text(i.messageErrorSave),void a("#annotationError").addClass("alert-danger")):(b.validation=a("input[name=validationradio]:checked").val(),void l(b))}).fail(d.exception)})}.bind(this)).fail(d.exception)},i.prototype.deleteAnnotation=function(b){var c=this.getAnnotation(b);if(null!==c){a("#annotation_delete").html(""),(this.currentAnnotation||this.iseditopen)&&l(this.currentAnnotation);var g=this.controler,h=c.serialize(this.courseid,"edit",this.audioannotation);f.loadFragment("mod_audioannotation","annotation",M.cfg.contextid,h).done(function(a,b){e.replaceNodeContents("#annotation_delete",a,b),g.notify("deleteannotation","editor",null),n(c)}.bind(this)).fail(d.exception)}};var n=function(b){var c=a("#mod_audioanntation_annotation"),e=c.serialize();g.call([{methodname:"mod_audioannotation_submit_annotation_del_form",args:{jsonformdata:JSON.stringify(e)}}])[0].done(function(c){if("error"===c.message)return a("#annotationError").text(i.messageErrorDelete),void a("#annotationError").addClass("alert-danger");b.delDisplay();var d=i.annotations.indexOf(b);i.annotations.splice(d,1),l(),a("#annotation_delete").html("")}).fail(d.exception)};i.prototype.getAnnotation=function(a){for(var b=0;b<i.annotations.length;b++)if(i.annotations[b].id==a)return i.annotations[b];return null},i.prototype.notify=function(a,b){if("edit"===a)this.editAnnotation(b);else if("add"===a)this.addAnnotation(b);else if("view"===a){var c=b;!b.hasOwnProperty("id")&&b.hasOwnProperty("annotation")&&(c=this.getAnnotation(b.annotation)),c&&this.viewAnnotation(c)}else"displaytqs"===a?this.displayAnnotationByTagQuestionStatut(b):"delete"===a&&this.deleteAnnotation(b)},i.prototype.displayAnnotationByTagQuestionStatut=function(b){var c=b.tag,d=b.question,e=b.statut;if(c==-2&&d==-1&&e==-1)for(var f=0;f<i.annotations.length;f++){i.annotations[f].show();var g=a("li[data-annotation="+i.annotations[f].id+"]");g.show(),g.data("display","1")}else for(var h=0;h<i.annotations.length;h++){var j=i.annotations[h].isquestion,k=i.annotations[h].statut,l=i.annotations[h].tag,g=a("li[data-annotation="+i.annotations[h].id+"]");c==-2&&d==-1&&k==e||c==-2&&j==d&&e==-1||l==c&&d==-1&&e==-1||c==-2&&j==d&&k==e||l==c&&d==-1&&k==e||l==c&&j==d&&e==-1||l==c&&j==d&&k==e?(i.annotations[h].show(),g.show(),g.data("display","1")):(i.annotations[h].hide(),g.hide(),g.data("display","0"))}a("#accordion div.card").each(function(){for(var b=a(this).find("li[data-annotation]"),c=b.length,d=0,e=0;e<b.length;e++)a(b[e]).data("display")>0&&(d+=1);var f=a(this).find("button"),g=f.text();g=g.replace(/\([0-9]*\/*[0-9]*\)\s*$/,""),g+=" ("+d+"/"+c+")",f.text(g)}),m(this.currentAnnotation)};var o=function(){var b=parseInt(a("[name='isquestion']").val());0===b?a("#annot_form_btn_question .fa-ban").show():a("#annot_form_btn_question .fa-ban").hide()},p=function(){a("#annot_form_btn_question").on("click",function(){var b=parseInt(a("[name='isquestion']").val());0===b?(a("[name='isquestion']").val(1),a("#annot_form_btn_question .fa-ban").hide()):(a("[name='isquestion']").val(0),a("#annot_form_btn_question .fa-ban").show())})},q=function(){a(".bt[title]").css("font-weight","bold"),a(".bt[title]").css("font-size","larger"),a(".bt").on("click",function(){var b=a(this).data("alpha"),c=a("#id_comment");if(c[0].selectionStart||"0"===c[0].selectionStart){var d=c[0].selectionStart,e=c[0].selectionEnd,f=d,g=c[0].scrollTop;c[0].value=c[0].value.substring(0,d)+b+c[0].value.substring(e,c[0].value.length),f+=b.length,c.focus(),c[0].selectionStart=f,c[0].selectionEnd=f,c[0].scrollTop=g}else c.val(c.val()+b),c.focus()})},r=function(b){return b?void a("#audioPanel").on("show.bs.collapse",function(){i.record?i.record.reset():i.record=new c({repo:b})}):void a("#audioWorskpace").hide()},s=function(){a("#fileinput").append(a('[data-fieldtype="filepicker"]')),a('[data-fieldtype="filepicker"]').removeClass("col-md-9"),a(".form-filetypes-descriptions").hide(),a("#fileinput").append(a("input[name*='_qf__mod_audioannotation']")),a("#fileinput").find("p").remove(),a("#fileinput").find(".femptylabel").css("margin-bottom","0"),a("#mform1").remove()};return i.prototype.getTagColor=function(a){return a>-1?this.tags[a].color:this.TAGDEFAULTCOLOR},i.prototype.getEval=function(){return this.controler.getEval()},i});
\ No newline at end of file
define(["jquery"],function(a){function b(a){b.context="context"in a?a.context:null,b.user="user"in a?a.user:null,this.init(),this.initTrigger()}b.mediaSource=null,b.constraints={audio:!0},b.sourceBuffer=null,b.mediaRecorder=null,b.recordedBlobs=null,b.errorMsgElement="#errorMsg",b.recordButton="#record",b.playButton="#play",b.removeButton="#remove",b.recordedVideo="#recorded",b.context=-1,b.user=-1;var c=function(){window.console.log("MediaSource opened"),b.sourceBuffer=b.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",b.sourceBuffer)},d=function(c){a(b.recordButton).attr("disabled",!1),window.console.log("getUserMedia() got stream:",c),window.stream=c};b.prototype.init=function(){a("#audio").html(a("#audioworkspace").html()),a("#audioworkspace").remove(),b.mediaSource=new MediaSource,b.mediaSource.addEventListener("sourceopen",c,!1);try{navigator.mediaDevices.getUserMedia(b.constraints).then(function(a){d(a)})}catch(e){window.console.error("navigator.getUserMedia error:",e),a(b.errorMsgElement).html("navigator.getUserMedia error:"+e.toString())}},b.prototype.initTrigger=function(){a(b.recordButton).on("click",function(){"stop"===a(b.recordButton).data("statut")?(h(),a(b.recordButton).data("statut","start")):(g(),a(b.recordButton).data("statut","stop"),a(b.recordButton).find("i").addClass("fa-microphone"),a(b.recordButton).find("i").removeClass("fa-microphone-slash"),a(b.recordButton).addClass("btn-primary"),a(b.recordButton).removeClass("btn-danger"),a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1),e())}),a(b.playButton).on("click",function(){var c=new Blob(b.recordedBlobs);a(b.recordedVideo).show(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null),a(b.recordedVideo).attr("src",window.URL.createObjectURL(c)),a(b.recordedVideo).attr("controls",!0),a(b.recordedVideo).attr("autoplay",!0)}),a(b.removeButton).on("click",function(){a("input[name='filerecord']").val(-1),a("input[name='file']").parent().parent().removeClass("disabled"),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordedVideo).hide(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null)})};var e=function(){var c=new Blob(b.recordedBlobs),d=new window.FormData,e=(1e3*Math.random()).toString().replace(".","");d.append("repo_upload_file",c,e),d.append("itemid",e),d.append("title",e),d.append("repo_id",b.user),d.append("env","editor"),d.append("sesskey",M.cfg.sesskey),d.append("savepath","/"),d.append("ctx_id",b.context);var f=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",g=new XMLHttpRequest;g.onreadystatechange=function(){if(4===this.readyState&&200===this.status){var b=g.response,c=JSON.parse(b);a("input[name='filerecord']").val(c.file),a("input[name='file']").parent().parent().addClass("disabled"),a("#sendok").show().fadeOut(3e3)}else this.readyState>200&&a("#sendko").show()},g.open("POST",f,!0),g.send(d)},f=function(a){a.data&&a.data.size>0&&b.recordedBlobs.push(a.data)},g=function(){b.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",b.recordedBlobs)},h=function(){b.recordedBlobs=[];var c=null;try{b.mediaRecorder=new MediaRecorder(window.stream,c)}catch(d){return window.console.error("Exception while creating MediaRecorder:",d),void a(b.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(d))}window.console.log("Created MediaRecorder",b.mediaRecorder,"with options",c),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordButton).find("i").removeClass("fa-microphone"),a(b.recordButton).find("i").addClass("fa-microphone-slash"),a(b.recordButton).removeClass("btn-primary"),a(b.recordButton).addClass("btn-danger"),b.mediaRecorder.onstop=function(a){window.console.log("Recorder stopped: ",a)},b.mediaRecorder.ondataavailable=f,b.mediaRecorder.start(10),window.console.log("MediaRecorder started",b.mediaRecorder)};return b});
\ No newline at end of file
define(["jquery"],function(a){function b(a){b.repo="repo"in a?a.repo:null,b.limit="limit"in a&&a.limit>0?1e3*a.limit:null,this.init(),this.initTrigger()}b.mediaSource=null,b.constraints={audio:!0},b.sourceBuffer=null,b.mediaRecorder=null,b.recordedBlobs=null,b.errorMsgElement="#errorMsg",b.recordButton="#record",b.pauseRecordButton="#pauseRecord",b.playButton="#play",b.removeButton="#remove",b.recordedVideo="#recorded",b.repo=-1,b.initTimestamp=-1,b.timestampStop=0,b.limit=null;var c=function(){window.console.log("MediaSource opened"),b.sourceBuffer=b.mediaSource.addSourceBuffer("audio/ogg"),window.console.log("Source buffer: ",b.sourceBuffer)},d=function(c){a(b.recordButton).attr("disabled",!1),window.console.log("getUserMedia() got stream:",c),window.stream=c};b.prototype.init=function(){a("#audio").html(a("#audioworkspace").html()),a("#audioworkspace").remove(),a(b.recordedVideo).attr("src")&&(a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1),a("input[name='file']").parent().parent().addClass("disabled")),b.mediaSource=new MediaSource,b.mediaSource.addEventListener("sourceopen",c,!1);try{navigator.mediaDevices.getUserMedia(b.constraints).then(function(a){d(a)})}catch(e){window.console.error("navigator.getUserMedia error:",e),a(b.errorMsgElement).html("navigator.getUserMedia error:"+e.toString())}},b.prototype.reset=function(){a(b.recordButton).attr("disabled",!1),a(b.recordedVideo).attr("src")&&(a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1)),this.initTrigger()},b.prototype.initTrigger=function(){a(b.recordButton).on("click",function(){"stop"===a(b.recordButton).data("statut")?(a(b.recordedVideo).attr("src",null),h(),a(b.recordButton).data("statut","start"),a(b.pauseRecordButton).attr("disabled",!1),a(b.pauseRecordButton).data("statut","off"),a(b.pauseRecordButton).find(".fa-ban").hide()):(g(),a(b.recordButton).data("statut","stop"),a(b.recordButton).find("i").addClass("fa-microphone"),a(b.recordButton).find("i").removeClass("fa-microphone-slash"),a(b.recordButton).addClass("btn-primary"),a(b.recordButton).removeClass("btn-danger"),a(b.playButton).attr("disabled",!1),a(b.removeButton).attr("disabled",!1),a(b.pauseRecordButton).attr("disabled",!0),e())}),a(b.pauseRecordButton).on("click",function(){window.console.log(a(b.pauseRecordButton).data("statut")),"off"===a(b.pauseRecordButton).data("statut")?(i(),a(b.pauseRecordButton).data("statut","on"),a(b.pauseRecordButton).find(".fa-ban").show()):(j(),a(b.pauseRecordButton).data("statut","off"),a(b.pauseRecordButton).find(".fa-ban").hide())}),a(b.playButton).on("click",function(){if(!a(b.recordedVideo).attr("src")){var c=new Blob(b.recordedBlobs);a(b.recordedVideo).show(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null),a(b.recordedVideo).attr("src",window.URL.createObjectURL(c))}a(b.recordedVideo).attr("controls",!0),a(b.recordedVideo).attr("autoplay",!0)}),a(b.removeButton).on("click",function(){a("input[name='filerecord']").val(-1),a("input[name='file']").parent().parent().removeClass("disabled"),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordedVideo).hide(),a(b.recordedVideo).attr("src",null),a(b.recordedVideo).attr("srcObject",null)})};var e=function(){var c=new Blob(b.recordedBlobs),d=new window.FormData,e=(1e3*Math.random()).toString().replace(".","");d.append("repo_upload_file",c,e),d.append("itemid",e),d.append("title",e),d.append("repo_id",b.repo),d.append("env","editor"),d.append("sesskey",M.cfg.sesskey),d.append("savepath","/"),d.append("ctx_id",M.cfg.contextid);var f=M.cfg.wwwroot+"/repository/repository_ajax.php?action=upload",g=new XMLHttpRequest;g.onreadystatechange=function(){if(4===this.readyState&&200===this.status){var b=g.response,c=JSON.parse(b);a("input[name='filerecord']").val(c.file),a("input[name='file']").parent().parent().addClass("disabled"),a("#sendok").show().fadeOut(3e3)}else this.readyState>200&&a("#sendko").show()},g.open("POST",f,!0),g.send(d)},f=function(c){if(c.data&&c.data.size>0){b.initTimestamp<0&&(b.initTimestamp=c.timeStamp);var d=c.timeStamp-b.initTimestamp,e=new Date(d);e.setHours(e.getHours()-1);var f=e.getHours()<10?"0"+e.getHours():e.getHours(),g=e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes(),h=e.getSeconds()<10?"0"+e.getSeconds():e.getSeconds(),i=f+":"+g+":"+h;a("#audiotime").text(i),b.limit&&d>b.limit&&0===b.timestampStop&&(b.timestampStop=1,a(b.recordButton).click()),b.recordedBlobs.push(c.data)}},g=function(){b.mediaRecorder.stop(),window.console.log("Recorded Blobs: ",b.recordedBlobs)},h=function(){b.recordedBlobs=[],b.initTimestamp=-1;var c=null;try{b.mediaRecorder=new MediaRecorder(window.stream,c)}catch(d){return window.console.error("Exception while creating MediaRecorder:",d),void a(b.errorMsgElement).html("Exception while creating MediaRecorder: "+JSON.stringify(d))}window.console.log("Created MediaRecorder",b.mediaRecorder,"with options",c),a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordButton).find("i").removeClass("fa-microphone"),a(b.recordButton).find("i").addClass("fa-microphone-slash"),a(b.recordButton).removeClass("btn-primary"),a(b.recordButton).addClass("btn-danger"),b.mediaRecorder.onstop=function(c){a("#audiotime").text(""),b.timestampStop=0,window.console.log("Recorder stopped: ",c)},b.mediaRecorder.ondataavailable=f,b.mediaRecorder.start(10),window.console.log("MediaRecorder started",b.mediaRecorder)},i=function(){b.mediaRecorder&&(b.mediaRecorder.pause(),window.console.log("MediaRecorder paused",b.mediaRecorder))},j=function(){b.mediaRecorder&&(a(b.playButton).attr("disabled",!0),a(b.removeButton).attr("disabled",!0),a(b.recordButton).find("i").removeClass("fa-microphone"),a(b.recordButton).find("i").addClass("fa-microphone-slash"),a(b.recordButton).removeClass("btn-primary"),a(b.recordButton).addClass("btn-danger"),b.mediaRecorder.resume(),window.console.log("MediaRecorder resumed",b.mediaRecorder))};return b});
\ No newline at end of file
......@@ -38,9 +38,8 @@ define(['jquery'],
Annotation.id = null;
Annotation.timeposition = null;
Annotation.isquestion = 0;
Annotation.validationens = 0;
Annotation.assignementpart = null;
Annotation.typevalidation = null;
Annotation.validation = 0;
Annotation.statut = 0;
Annotation.mainmessage = null;
Annotation.tag = -1;
......@@ -77,9 +76,8 @@ define(['jquery'],
this.id = null;
this.timeposition = null;
this.isquestion = 0;
this.validationens = 0;
this.assignementpart = null;
this.typevalidation = null;
this.validation = 0;
this.statut = 0;
this.mainmessage = null;
this.tag = -1;
......@@ -103,14 +101,11 @@ define(['jquery'],
if (opt.isquestion) {
this.isquestion = opt.isquestion;
}
if (opt.validationens) {
this.validationens = opt.validationens;
}
if (opt.assignementpart) {
this.assignementpart = opt.assignementpart;
}
if (opt.typevalidation) {
this.typevalidation = opt.typevalidation;
if (opt.validation) {
this.validation = opt.validation;
}
if (opt.statut) {
this.statut = opt.statut;
......@@ -150,9 +145,8 @@ define(['jquery'],
Annotation.prototype.serialize = function (courseid, action, audioannotation) {
return {'courseid': courseid, 'action': action, 'audioannotation': audioannotation,
'timeposition': this.timeposition, 'id': this.id, 'isquestion': this.isquestion,
'validationens': this.validationens, 'assignementpart': this.assignementpart,
'typevalidation': this.typevalidation, 'statut': this.statut, 'mainmessage': this.mainmessage,
'tag': this.tag};
'assignementpart': this.assignementpart, 'validation': this.validation,
'statut': this.statut, 'mainmessage': this.mainmessage, 'tag': this.tag};
};
/**
......
......@@ -35,7 +35,6 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
* CONSTANTES *
*************/
Controler.contextid = -1;
Controler.courseid = -1;
Controler.assignpartid = -1;
Controler.audioannotation = -1;
......@@ -57,11 +56,11 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
*/
function Controler(data) {
//get data
Controler.contextid = 'context' in data ? data['context'] : null;
Controler.courseid = 'course' in data ? data['course'] : null;
Controler.assignpartid = 'assignpart' in data ? data['assignpart'] : null;
Controler.audioannotation = 'audioannotation' in data ? data['audioannotation'] : null;
Controler.eval = 'eval' in data ? data['eval'] : 0;
var repoid = 'repo' in data ? data['repo'] : null;
//parse elements
var annotationsRaw = 'annotations' in data ? data['annotations'] : null;
var annotations = null;
......@@ -75,10 +74,10 @@ define(['jquery', 'mod_audioannotation/justWave', 'mod_audioannotation/editor',
}
//init composants
Controler.wavePlayer = new JustwavePlayer(this);
Controler.editor = new Editor({'controler': this, 'contextid': Controler.contextid,
Controler.editor = new Editor({'controler': this,
'courseid': Controler.courseid, 'assignpartid': Controler.assignpartid,
'annotations': annotations, 'audioannotation': Controler.audioannotation,
'tags': tags});
'tags': tags, 'repo': repoid});
//init listener and object
this.initTrigger();
this.initWave('justwave');
......
......@@ -18,6 +18,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/* global M */
/**
* Editor class, manage all annotations and graphical interactions about them
*
......@@ -25,15 +27,16 @@
*
* @param {Jquery} $
* @param {Annotation} Annotation
* @param {Record} Record
* @param {core/notification} notification
* @param {core/templates} templates
* @param {core/fragment} fragment
* @param {core/ajax} ajax
* @param {core/str} str
*/
define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/templates', 'core/fragment',
'core/ajax', 'core/str'],
function ($, Annotation, notification, templates, fragment, ajax, str) {
define(['jquery', 'mod_audioannotation/annotation', 'mod_audioannotation/record', 'core/notification', 'core/templates',
'core/fragment', 'core/ajax', 'core/str'],
function ($, Annotation, Record, notification, templates, fragment, ajax, str) {
/*************
* CONSTANTES *
......@@ -49,11 +52,6 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
* @type {Controler} controler
*/
Editor.controler = null;
/**
* Id of the context which the editor depends to
* @type {int} contextid
*/
Editor.contextid = null;
/**
* Id of the course which the editor depends to
* @type {int} courseid
......@@ -69,12 +67,15 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
* @type {int} audioannotation
*/
Editor.audioannotation = null;
Editor.record = null;
/**
* List of all annotations in the editor
* @type {array} tags
*/
Editor.tags = null;
Editor.repo = null;
//statut
Editor.isaddopen = false;
Editor.iseditopen = false;
......@@ -119,9 +120,9 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
function Editor(data) {
//set init data
this.controler = 'controler' in data ? data['controler'] : null;
this.contextid = 'contextid' in data ? data['contextid'] : null;
this.courseid = 'courseid' in data ? data['courseid'] : null;
this.assignpartid = 'assignpartid' in data ? data['assignpartid'] : null;
this.repo = 'repo' in data ? data['repo'] : null;
this.audioannotation = 'audioannotation' in data ? data['audioannotation'] : null;
var annotationsTmp = 'annotations' in data ? data['annotations'] : [];
var tagsTmp = 'tags' in data ? data['tags'] : [];
......@@ -269,7 +270,7 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
var control = this.controler;
//load annotation's proprieties and form
var params = annotation.serialize(this.courseid, 'view', this.audioannotation);
fragment.loadFragment('mod_audioannotation', 'annotation', this.contextid, params)
fragment.loadFragment('mod_audioannotation', 'annotation', M.cfg.contextid, params)
.done(function (html, js) {
//display div and highlight annotation
$("#annotation_view").show();
......@@ -285,7 +286,7 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
});
//edit action
$("#annot_form_btn_valid").on("click", function () {
var form = $('#mod_audioanntation_annotation');
var form = $('form[name=mod_audioannotation_form_message_form]');
var data = form.serialize();
ajax.call([
{
......@@ -324,8 +325,9 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
//notify controler
this.controler.notify('drawannotation_draft', "editor", annotation);
$("#annotation_add").html("");
var repoId = this.repo;
var params = annotation.serialize(this.courseid, "add", this.audioannotation);
fragment.loadFragment('mod_audioannotation', 'annotation', this.contextid, params)
fragment.loadFragment('mod_audioannotation', 'annotation', M.cfg.contextid, params)
.done(function (html, js) {
//display form
$("#annotation_add").show();
......@@ -335,13 +337,20 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
moveFileForm();
//question button
initQuestionTrigger();
//phonetic keyboard
initPhoneticKeayboard();
//init audio feedback
initAudioFeedback(repoId);
//cancel action
$("#annot_form_btn_cancel").on("click", function () {
closeAddForm();
});
//valid action
$("#annot_form_btn_valid").on("click", function () {
var form = $('#mod_audioanntation_annotation');
var form = $('form[name=mod_audioannotation_form_annotation_form]');
var data = form.serialize();
ajax.call([
{
......@@ -374,8 +383,9 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
}
this.currentAnnotation = annotation;
var control = this.controler;
var repoId = this.repo;
var params = annotation.serialize(this.courseid, 'edit', this.audioannotation);
fragment.loadFragment('mod_audioannotation', 'annotation', this.contextid, params)
fragment.loadFragment('mod_audioannotation', 'annotation', M.cfg.contextid, params)
.done(function (html, js) {
//display form
$("#annotation_edit").show();
......@@ -386,13 +396,20 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
//question button
initQuestionButton();
initQuestionTrigger();
//phonetic keyboard
initPhoneticKeayboard();
//init audio feedback
initAudioFeedback(repoId);
//cancel action
$("#annot_form_btn_cancel").on("click", function () {
closeEditForm(annotation);
});
//edit action
$("#annot_form_btn_valid").on("click", function () {
var form = $('#mod_audioanntation_annotation');
var form = $('form[name=mod_audioannotation_form_annotation_form]');
var data = form.serialize();
ajax.call([
{
......@@ -411,7 +428,9 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
}).fail(notification.exception);
});
//delete action
$("#annot_form_btn_delete").on("click", deleteAnnotationAction);
$("#annot_form_btn_delete").on("click", function () {
deleteAnnotationAction(annotation);
});
//delete pj action
$("#message_pj_btn_delete").on("click", function () {
var form = $('#mod_audioanntation_annotation');
......@@ -431,6 +450,29 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
$("#fileuploadA").html("");
}).fail(notification.exception);
});
//message part
$("input[name=validationradio][value='" + annotation.validation + "']").attr('checked', true);
$("#message_form_btn_valid").on("click", function () {
var form = $('form[name=mod_audioannotation_form_message_form]');
var data = form.serialize();
ajax.call([
{
methodname: 'mod_audioannotation_submit_annotation_reply_form',
args: {jsonformdata: JSON.stringify(data)}
}
])[0].done(function (reponse) {
if (reponse["message"] === "error") {
$("#annotationError").text(Editor.messageErrorSave);
$("#annotationError").addClass("alert-danger");
return;
}
annotation.validation = $("input[name=validationradio]:checked").val();
closeEditForm(annotation);
}).fail(notification.exception);
});
}.bind(this)).fail(notification.exception);
};
......@@ -453,7 +495,7 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
}
var control = this.controler;
var params = annotation.serialize(this.courseid, 'edit', this.audioannotation);
fragment.loadFragment('mod_audioannotation', 'annotation', this.contextid, params)
fragment.loadFragment('mod_audioannotation', 'annotation', M.cfg.contextid, params)
.done(function (html, js) {
templates.replaceNodeContents('#annotation_delete', html, js);
control.notify('deleteannotation', "editor", null);
......@@ -539,12 +581,16 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
if (tagid == -2 && question == -1 && statut == -1) {
for (var i = 0; i < Editor.annotations.length; i++) {
Editor.annotations[i].show();
var elemlist = $('li[data-annotation=' + Editor.annotations[i].id + ']');
elemlist.show();
elemlist.data('display', '1');
}
} else {
for (var j = 0; j < Editor.annotations.length; j++) {
var annotQ = Editor.annotations[j].isquestion;
var annotS = Editor.annotations[j].statut;
var annotT = Editor.annotations[j].tag;
var elemlist = $('li[data-annotation=' + Editor.annotations[j].id + ']');
if ((tagid == -2 && question == -1 && annotS == statut)
|| (tagid == -2 && annotQ == question && statut == -1)
|| (annotT == tagid && question == -1 && statut == -1)
......@@ -553,11 +599,30 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
|| (annotT == tagid && annotQ == question && statut == -1)
|| (annotT == tagid && annotQ == question && annotS == statut)) {
Editor.annotations[j].show();
elemlist.show();
elemlist.data('display', '1');
} else {
Editor.annotations[j].hide();
elemlist.hide();
elemlist.data('display', '0');
}
}
}
$("#accordion div.card").each(function () {
var list = $(this).find("li[data-annotation]");
var maxLi = list.length;
var nbVisible = 0;
for (var i = 0; i < list.length; i++) {
if ($(list[i]).data("display") > 0) {
nbVisible += 1;
}
}
var btn = $(this).find("button");
var text = btn.text();
text = text.replace(/\([0-9]*\/*[0-9]*\)\s*$/, "");
text += " (" + nbVisible + "/" + maxLi + ")";
btn.text(text);
});
closeViewForm(this.currentAnnotation);
};
......@@ -589,6 +654,49 @@ define(['jquery', 'mod_audioannotation/annotation', 'core/notification', 'core/t
});
};
/**
* Initialize a listener for the phonetic keyboard input
*/
var initPhoneticKeayboard = function () {
$(".bt[title]").css('font-weight', 'bold');
$(".bt[title]").css('font-size', 'larger');
$(".bt").on("click", function () {
var item = $(this).data('alpha');
var input = $("#id_comment");
if (input[0].selectionStart || input[0].selectionStart === '0') {
var startPos = input[0].selectionStart;
var endPos = input[0].selectionEnd;
var cursorPos = startPos;
var scrollTop = input[0].scrollTop;
input[0].value = input[0].value.substring(0, startPos)
+ item
+ input[0].value.substring(endPos, input[0].value.length);
cursorPos += item.length;
input.focus();
input[0].selectionStart = cursorPos;
input[0].selectionEnd = cursorPos;
input[0].scrollTop = scrollTop;
} else {
input.val(input.val() + item);
input.focus();
}
});
};
var initAudioFeedback = function (repo) {
if (!repo) {
$('#audioWorskpace').hide();
return;
}
$("#audioPanel").on("show.bs.collapse", function () {
if (!Editor.record) {
Editor.record = new Record({'repo': repo});
} else {
Editor.record.reset();
}
});