");t.append(r),r.setData("comment",n)},this)},this),this.centerDialogue(),H.superclass.show.call(this)}},{NAME:P,ATTRS:{editor:{value:null}}}),e.Base.modifyAttrs(H,{modal:{getter:function(){return!0}}}),M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.commentsearch=H;var B=function(t,n,r,i,o,u,l,c){this.editor=t,this.gradeid=n||0,this.x=parseInt(i,10)||0,this.y=parseInt(o,10)||0,this.width=parseInt(u,10)||0,this.rawtext=c||"",this.pageno=r||0,this.colour=l||"yellow",this.drawable=!1,this.deleteme=!1,this.menulink=null,this.menu=null,this.clean=function(){return{gradeid:this.gradeid,x:parseInt(this.x,10),y:parseInt(this.y,10),width:parseInt(this.width,10),rawtext:this.rawtext,pageno:parseInt(this.pageno,10),colour:this.colour}},this.draw=function(n){var r=new M.assignfeedback_editpdf.drawable(this.editor),i,o=this.editor.get_dialogue_element(s.DRAWINGCANVAS),u,l,c,h,p,d;return i=e.Node.create(""),u=e.Node.create(''),l=e.Node.create(""),c=e.Node.create(''),h=e.Node.create(''),this.menulink=h,u.append(l),l.append(i),u.append(c),u.setAttribute("tabindex","-1"),l.setAttribute("tabindex","0"),i.setAttribute("tabindex","-1"),h.setAttribute("tabindex","0"),this.editor.get("readonly")?i.setAttribute("readonly","readonly"
):u.append(h),this.width<100&&(this.width=100),p=this.editor.get_window_coordinates(new M.assignfeedback_editpdf.point(this.x,this.y)),i.setStyles({width:this.width+"px",backgroundColor:f[this.colour],color:a}),o.append(u),u.setStyle("position","absolute"),u.setX(p.x),u.setY(p.y),r.store_position(u,p.x,p.y),r.nodes.push(u),i.set("value",this.rawtext),d=i.get("scrollHeight"),i.setStyles({height:d+"px",overflow:"hidden"}),c.setStyle("color",f[this.colour]),this.attach_events(i,h),n?i.focus():t.collapsecomments&&u.addClass("commentcollapsed"),this.drawable=r,r},this.delete_comment_later=function(){this.deleteme&&this.remove()},this.attach_events=function(n,r){var i=n.ancestor("div"),s=n.ancestor("label"),o=s.next("svg");n.collapse=function(r){n.collapse.delay=e.later(r,n,function(){t.collapsecomments&&i.addClass("commentcollapsed")})},n.expand=function(){n.getData("dragging")!==!0&&(n.collapse.delay&&n.collapse.delay.cancel(),i.removeClass("commentcollapsed"))},i.on("mouseenter",function(){(t.currentedit.tool==="comment"||t.currentedit.tool==="select"||this.editor.get("readonly"))&&n.expand()},this),i.on("click|tap",function(){n.expand(),n.focus()},this),n.on("keyup",function(e){e.keyCode===9&&e.shiftKey&&r.getAttribute("tabindex")==="0"&&r.focus(),r.setAttribute("tabindex","0")},this),r.on("keydown",function(e){e.keyCode===9&&e.shiftKey&&r.setAttribute("tabindex","-1")},this),s.on("focus",function(){n.active=!0,n.collapse.delay&&n.collapse.delay.cancel(),n.setAttribute("tabindex","0"),n.expand(),n.focus(),s.setAttribute("tabindex","-1")},this),r.on("focus",function(){n.active=!0,n.collapse.delay&&n.collapse.delay.cancel(),this.deleteme=!1,s.setAttribute("tabindex","0")},this),n.on("blur",function(){n.setAttribute("tabindex","-1")},this),s.on("blur",function(){s.setAttribute("tabindex","0")},this),i.on("mouseleave",function(){t.collapsecomments&&n.active!==!0&&n.collapse(400)},this),i.on("blur",function(){n.active=!1,n.collapse(800)},this),this.editor.get("readonly")||(n.on("blur",function(){this.rawtext=n.get("value"),this.width=parseInt(n.getStyle("width"),10),this.rawtext.replace(/^\s+|\s+$/g,"")===""&&(this.deleteme=!0,e.later(400,this,this.delete_comment_later)),this.editor.save_current_page(),this.editor.editingcomment=!1},this),r.setData("comment",this),n.on("keyup",function(){n.setStyle("height","auto");var e=n.get("scrollHeight"),t=parseInt(n.getStyle("height"),10);e===t+8&&(e-=8),n.setStyle("height",e+"px")}),n.on("gesturemovestart",function(e){t.currentedit.tool==="select"&&(e.preventDefault(),t.collapsecomments?(n.setData("offsetx",8),n.setData("offsety",8)):(n.setData("offsetx",e.clientX-i.getX()),n.setData("offsety",e.clientY-i.getY())))}),n.on("gesturemove",function(e){if(t.currentedit.tool==="select"){var r=e.clientX-n.getData("offsetx"),s=e.clientY-n.getData("offsety"),o,u,a;n.getData("dragging")!==!0&&(n.collapse(0),n.setData("dragging",!0)),o=this.editor.get_canvas_coordinates(new M.assignfeedback_editpdf.point(r,s)),a=this.editor.get_canvas_bounds(!0),a.x=0,a.y=0,a.width-=24,a.height-=24,o.clip(a),this.x=o.x,this.y=o.y,u=this.editor.get_window_coordinates(o),i.setX(u.x),i.setY(u.y),this.drawable.store_position(i,u.x,u.y)}},null,this),n.on("gesturemoveend",function(){t.currentedit.tool==="select"&&(n.getData("dragging")===!0&&n.setData("dragging",!1),this.editor.save_current_page())},null,this),o.on("gesturemovestart",function(e){t.currentedit.tool==="select"&&(e.preventDefault(),n.setData("offsetx",e.clientX-i.getX()),n.setData("offsety",e.clientY-i.getY()),n.expand())}),o.on("gesturemove",function(e){if(t.currentedit.tool==="select"){var r=e.clientX-n.getData("offsetx"),s=e.clientY-n.getData("offsety"),o,u,a;n.getData("dragging")!==!0&&(n.collapse(100),n.setData("dragging",!0)),o=this.editor.get_canvas_coordinates(new M.assignfeedback_editpdf.point(r,s)),a=this.editor.get_canvas_bounds(!0),a.x=0,a.y=0,a.width-=24,a.height-=24,o.clip(a),this.x=o.x,this.y=o.y,u=this.editor.get_window_coordinates(o),i.setX(u.x),i.setY(u.y),this.drawable.store_position(i,u.x,u.y)}},null,this),o.on("gesturemoveend",function(){t.currentedit.tool==="select"&&(n.getData("dragging")===!0&&n.setData("dragging",!1),this.editor.save_current_page())},null,this),this.menu=new M.assignfeedback_editpdf.commentmenu({buttonNode:this.menulink,comment:this}))},this.remove=function(){var e=0,t;t=this.editor.pages[this.editor.currentpage].comments;for(e=0;e=0&&this.comments.splice(e,1)},failure:function(e,t){return M.core.exception(t.responseText)}}},e.io(r,i)},this.load=function(){var t=n,r;r={method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"loadquicklist",userid:this.editor.get("userid"),attemptnumber:this.editor.get("attemptnumber"),assignmentid:this.editor.get("assignmentid")},on:{success:function(t,n){var r;try{r=e.JSON.parse(n.responseText);if(r.error)return new M.core.ajaxException(r);e.each(r,function(e){var t=new M.assignfeedback_editpdf.quickcomment(e.id,e.rawtext,e.width,e.colour);this.comments.push(t)},this),this.comments.sort(function(e,t){return e.rawtext.localeCompare(t.rawtext)})}catch(i){return new M.core.exception(i)}},failure:function(e,t){return M.core.exception(t.responseText)}}},e.io(t,r)}};M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.quickcommentlist=F;var I=function(){I.superclass.constructor.apply(this,arguments)};I.prototype={oldannotationcoordinates:null,dialogue:null,panel:null,pagecount:0,currentpage:0,pages:[],documentstatus:0,loadingicon:null,pageimage:null,graphic:null,currentedit:new M.assignfeedback_editpdf.edit,currentdrawable:!1,drawables:[],currentcomment:null,currentannotation:null,lastannotation:null,lastannotationtool:"pen",quicklist:null,searchcommentswindow:null,currentstamp:null,stamps:[],editingcomment:!1,collapsecomments:!0,initializer:function(){var t;t=e.one("#"+this.get("linkid")),t&&(t.on("click",this.link_handler,this),t.on("key",this.link_handler,"down:13",this),require(["mod_assign/grading_review_panel"],function(n){var r=new n,i=r.getReviewPanel("assignfeedback_editpdf");i&&(i=e.one(i),i.empty(),t.ancestor(".fitem").hide(),this.open_in_panel(i)),this.currentedit.start=!1,this.currentedit.end=!1,this.get("readonly")||(this.quicklist=new M.assignfeedback_editpdf.quickcommentlist(this))}.bind(this)))},refresh_button_state:function(){var e,t,n,r,i,o;e=this.get_dialogue_element(s.COMMENTCOLOURBUTTON),n=M.util.image_url("background_colour_"+this.currentedit.commentcolour,"assignfeedback_editpdf"),e.one("img").setAttribute("src",n),this.currentedit.commentcolour==="clear"?e.one("img").setStyle("borderStyle","dashed"):e.one("img").setStyle("borderStyle","solid"),e=this.get_dialogue_element(s.ANNOTATIONCOLOURBUTTON),n=M.util.image_url("colour_"+this.currentedit.annotationcolour,"assignfeedback_editpdf"),e.one("img").setAttribute("src",n),t=this.get_dialogue_element(h[this.currentedit.tool]),t.addClass("assignfeedback_editpdf_selectedbutton"),t.setAttribute("aria-pressed","true"),r=this.get_dialogue_element(s.DRAWINGREGION),r.setAttribute("data-currenttool",this.currentedit.tool),e=this.get_dialogue_element(s.STAMPSBUTTON),i=this.get_stamp_image_url(this.currentedit.stamp),e.one("img").setAttrs({src:i,height:"16",width:"16"}),o=this.get_dialogue_element(s.DRAWINGCANVAS);switch(this.currentedit.tool){case"drag":o.setStyle("cursor","move");break;case"highlight":o.setStyle("cursor","text");break;case"select":o.setStyle("cursor","default");break;case"stamp":o.setStyle("cursor","url("+i+"), crosshair");break;default:o.setStyle("cursor","crosshair")}},get_canvas_bounds:function(){var e=this.get_dialogue_element(s.DRAWINGCANVAS),t=e.getXY(),n=t[0],r=t[1],i=parseInt(e.getStyle("width"),10),o=parseInt(e.getStyle("height"),10);return new M.assignfeedback_editpdf.rect(n,r,i,o)},get_canvas_coordinates:function(e){var t=this.get_canvas_bounds(),n=new M.assignfeedback_editpdf.point(e.x-t.x,e.y-t.y);return t.x=t.y=0,n.clip(t),n},get_window_coordinates:function(e){var t=this.get_canvas_bounds(),n=new M.assignfeedback_editpdf.point(e.x+t.x,e.y+t.y);return n},open_in_panel:function(t){var n;this.panel=t,t.append(this.get("body")),t.addClass(i.DIALOGUE),this.loadingicon=this.get_dialogue_element(s.LOADINGICON),n=this.get_dialogue_element(s.DRAWINGCANVAS),this.graphic=new e.Graphic({render:n}),this.get("readonly")||(n.on("gesturemovestart",this.edit_start,null,this),n.on("gesturemove",this.edit_move,null,this),n.on("gesturemoveend",this.edit_end,null,this),this.refresh_button_state()),this.start_generation()},link_handler:function(t){var n,r=!0;t.preventDefault(),this.dialogue||(this.dialogue=new M.core.dialogue({headerContent:this.get("header"),bodyContent:this.get("body"),footerContent:this.get("footer"),modal:!0,width:"840px",visible:!1,draggable:!0}),this.dialogue.get("boundingBox").addClass(i.DIALOGUE),this.loadingicon=this.get_dialogue_element(s.LOADINGICON),n=this.get_dialogue_element(s.DRAWINGCANVAS),this.graphic=new e.Graphic({render:n}),this.get("readonly")||(n.on("gesturemovestart",this.edit_start,null
-,this),n.on("gesturemove",this.edit_move,null,this),n.on("gesturemoveend",this.edit_end,null,this),this.refresh_button_state()),this.start_generation(),n.on("windowresize",this.resize,this),r=!1),this.dialogue.centerDialogue(),this.dialogue.show(),this.dialogue.dd.on("drag:end",this.redraw,this),r&&this.resize()},start_generation:function(){this.poll_document_conversion_status()},poll_document_conversion_status:function(){var t=this.get("userid");e.io(n,{method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"pollconversions",userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),readonly:this.get("readonly")?1:0},on:{success:function(n,r){var i=e.one(s.USERINFOREGION);if(i){var o=i.getAttribute("data-userid");if(o&&o!=t)return}var u=this.handle_response_data(r),a=!1;if(u){this.documentstatus=u.status;if(u.status===0)a=!0;else if(u.status===1||u.status===3)a=!0;else if(u.status===2||u.status===-1)this.pagecount=u.pagecount,u.pageready==u.pagecount?this.prepare_pages_for_display(u):(this.update_page_load_progress(),this.start_document_to_image_conversion());a&&e.later(1e3,this,this.poll_document_conversion_status)}},failure:function(e,t){return new M.core.exception(t.responseText)}}})},start_document_to_image_conversion:function(){e.io(n,{method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"pollconversions",userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),readonly:this.get("readonly")?1:0},on:{success:function(e,t){var n=this.handle_response_data(t);n&&(this.documentstatus=n.status,n.status===2&&this.prepare_pages_for_display(n))},failure:function(e,t){return new M.core.exception(t.responseText)}}})},warning:function(t,n){var r=this.get_dialogue_element(s.ICONMESSAGECONTAINER),i=this.get_dialogue_element(s.WARNINGMESSAGECONTAINER),o=15,u=1,a="assignfeedback_editpdf_warningmessages alert alert-warning";n&&(o=4,a="assignfeedback_editpdf_warningmessages alert alert-info");var f=e.Node.create('');f.append(r.one("*").cloneNode()),f.append(t),i.prepend(f),f.transition({duration:u,delay:o,opacity:0},function(){f.remove()})},prepare_pages_for_display:function(e){var t,n,r,i,s,o;if(!e.pagecount){this.dialogue&&this.dialogue.hide(),i=new M.core.alert({message:M.util.get_string("cannotopenpdf","assignfeedback_editpdf")}),i.show();return}this.pages=e.pages;for(t=0;t0&&(r=e)},this),r},setup_toolbar:function(){var t,n,r,i,o,u,a,c,p,d,v;i=this.get_dialogue_element(s.SEARCHCOMMENTSBUTTON),i.on("click",this.open_search_comments,this),i.on("key",this.open_search_comments,"down:13",this),o=this.get_dialogue_element(s.EXPCOLCOMMENTSBUTTON),o.on("click",this.expandCollapseComments,this),o.on("key",this.expandCollapseComments,"down:13",this);if(this.get("readonly"))return;u=this.get_dialogue_element(s.ROTATELEFTBUTTON),u.on("click",this.rotatePDF,this,!0),u.on("key",this.rotatePDF,"down:13",this,!0),a=this.get_dialogue_element(s.ROTATERIGHTBUTTON),a.on("click",this.rotatePDF,this,!1),a.on("key",this.rotatePDF,"down:13",this,!1),this.disable_touch_scroll(),e.each(h,function(e,n){t=this.get_dialogue_element(e),t.on("click",this.handle_tool_button,this,n),t.on("key",this.handle_tool_button,"down:13",this,n),t.setAttribute("aria-pressed","false")},this),n=this.get_dialogue_element(s.COMMENTCOLOURBUTTON),d=new M.assignfeedback_editpdf.colourpicker({buttonNode:n,colours:f,iconprefix:"background_colour_",callback:function(e){var t=e.target.getAttribute("data-colour");t||(t=e.target.ancestor().getAttribute("data-colour")),this.currentedit.commentcolour=t,this.handle_tool_button(e,"comment")},context:this}),r=this.get_dialogue_element(s.ANNOTATIONCOLOURBUTTON),d=new M.assignfeedback_editpdf.colourpicker({buttonNode:r,iconprefix:"colour_",colours:l,callback:function(e){var t=e.target
-.getAttribute("data-colour");t||(t=e.target.ancestor().getAttribute("data-colour")),this.currentedit.annotationcolour=t,this.lastannotationtool?this.handle_tool_button(e,this.lastannotationtool):this.handle_tool_button(e,"pen")},context:this}),p=this.get("stampfiles"),p.length<=0?this.get_dialogue_element(h.stamp).ancestor().hide():(v=p[0].substr(p[0].lastIndexOf("/")+1),this.currentedit.stamp=v,c=this.get_dialogue_element(s.STAMPSBUTTON),d=new M.assignfeedback_editpdf.stamppicker({buttonNode:c,stamps:p,callback:function(e){var t=e.target.getAttribute("data-stamp"),n;t||(t=e.target.ancestor().getAttribute("data-stamp")),n=t.substr(t.lastIndexOf("/")),this.currentedit.stamp=n,this.handle_tool_button(e,"stamp")},context:this}),this.refresh_button_state())},handle_tool_button:function(e,t){var n;e.preventDefault(),n=this.get_dialogue_element(h[this.currentedit.tool]),n.removeClass("assignfeedback_editpdf_selectedbutton"),n.setAttribute("aria-pressed","false"),this.currentedit.tool=t,t!=="comment"&&t!=="select"&&t!=="drag"&&t!=="stamp"&&(this.lastannotationtool=t),this.refresh_button_state()},stringify_current_page:function(){var t=[],n=[],r,i=0;for(i=0;it.width||o.y<0||o.y>t.height)return;this.currentedit.tool==="pen"&&this.currentedit.path.push(o),this.currentedit.tool==="select"?this.currentannotation&&this.currentedit&&this.currentannotation.move(this.currentedit.annotationstart.x+o.x-this.currentedit.start.x,this.currentedit.annotationstart.y+o.y-this.currentedit.start.y):this.currentedit.tool==="drag"?(u=o.x-this.currentedit.start.x,a=o.y-this.currentedit.start.y,r.getDOMNode().scrollLeft-=u,r.getDOMNode().scrollTop-=a):this.currentedit.start&&(this.currentedit.end=o,this.redraw_current_edit())},edit_end:function(){var e,t,n;e=(new Date).getTime()-this.currentedit.start;if(e0)this.drawables.pop().erase();for(e=0;e0?n.removeAttribute("disabled"):n.setAttribute("disabled","true"),this.currentpage"),i.setAttribute("value",n),r={page:n+1,total:this.pages.length},i.setHTML(M.util.get_string("pagexofy","assignfeedback_editpdf",r)),t.append(i);t.removeAttribute("disabled"),t.on("change",function(){this.currentpage=t.get("value"),this.clear_warnings(!1),this.change_page()},this),o=this.get_dialogue_element(s.PREVIOUSBUTTON),u=this.get_dialogue_element(s.NEXTBUTTON),o.on("click",this.previous_page,this),o.on("key",this.previous_page,"down:13",this),u.on("click",this.next_page,this),u.on("key",this.next_page,"down:13",this)},previous_page:function(e){e.preventDefault(),this.currentpage--,this.currentpage<0&&(this.currentpage=0),this.clear_warnings(!1),this.change_page()},next_page:function(e){e.preventDefault(),this.currentpage++,this.currentpage>=this.pages.length&&(this.currentpage=this.pages.length-1),this.clear_warnings(!1),this.change_page()},move_canvas:function(){var e,t,n,r;e=this.get_dialogue_element(s.DRAWINGREGION),t=parseInt(e.get("scrollLeft"),10),n=parseInt(e.get("scrollTop"),10);for(r=0;r=0&&this.comments.splice(e,1)},failure:function(e,t){return M.core.exception(t.responseText)}}},e.io(r,i)},this.load=function(){var t=n,r;r={method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"loadquicklist",userid:this.editor.get("userid"),attemptnumber:this.editor.get("attemptnumber"),assignmentid:this.editor.get("assignmentid")},on:{success:function(t,n){var r;try{r=e.JSON.parse(n.responseText);if(r.error)return new M.core.ajaxException(r);e.each(r,function(e){var t=new M.assignfeedback_editpdf.quickcomment(e.id,e.rawtext,e.width,e.colour);this.comments.push(t)},this),this.comments.sort(function(e,t){return e.rawtext.localeCompare(t.rawtext)})}catch(i){return new M.core.exception(i)}},failure:function(e,t){return M.core.exception(t.responseText)}}},e.io(t,r)}};M.assignfeedback_editpdf=M.assignfeedback_editpdf||{},M.assignfeedback_editpdf.quickcommentlist=F;var I=function(){I.superclass.constructor.apply(this,arguments)};I.prototype={oldannotationcoordinates:null,dialogue:null,panel:null,pagecount:0,currentpage:0,pages:[],documentstatus:0,loadingicon:null,pageimage:null,graphic:null,currentedit:new M.assignfeedback_editpdf.edit,currentdrawable:!1,drawables:[],currentcomment:null,currentannotation:null,lastannotation:null,lastannotationtool:"pen",quicklist:null,searchcommentswindow:null,currentstamp:null,stamps:[],editingcomment:!1,simulatescroll:!1,scrollend:0,collapsecomments:!0,initializer:function(){var t;t=e.one("#"+this.get("linkid")),t&&(t.on("click",this.link_handler,this),t.on("key",this.link_handler,"down:13",this),require(["mod_assign/grading_review_panel"],function(n){var r=new n,i=r.getReviewPanel("assignfeedback_editpdf");i&&(i=e.one(i),i.empty(),t.ancestor(".fitem").hide(),this.open_in_panel(i)),this.currentedit.start=!1,this.currentedit.end=!1,this.get("readonly")||(this.quicklist=new M.assignfeedback_editpdf.quickcommentlist(this))}.bind(this)))},refresh_button_state:function(){var e,t,n,r,i,o;e=this.get_dialogue_element(s.COMMENTCOLOURBUTTON),n=M.util.image_url("background_colour_"+this.currentedit.commentcolour,"assignfeedback_editpdf"),e.one("img").setAttribute("src",n),this.currentedit.commentcolour==="clear"?e.one("img").setStyle("borderStyle","dashed"):e.one("img").setStyle("borderStyle","solid"),e=this.get_dialogue_element(s.ANNOTATIONCOLOURBUTTON),n=M.util.image_url("colour_"+this.currentedit.annotationcolour,"assignfeedback_editpdf"),e.one("img").setAttribute("src",n),t=this.get_dialogue_element(h[this.currentedit.tool]),t.addClass("assignfeedback_editpdf_selectedbutton"),t.setAttribute("aria-pressed","true"),r=this.get_dialogue_element(s.DRAWINGREGION),r.setAttribute("data-currenttool",this.currentedit.tool),e=this.get_dialogue_element(s.STAMPSBUTTON),i=this.get_stamp_image_url(this.currentedit.stamp),e.one("img").setAttrs({src:i,height:"16",width:"16"}),o=this.get_dialogue_element(s.DRAWINGCANVAS);switch(this.currentedit.tool){case"drag":o.setStyle("cursor","move");break;case"highlight":o.setStyle("cursor","text");break;case"select":o.setStyle("cursor","default");break;case"stamp":o.setStyle("cursor","url("+i+"), crosshair");break;default:o.setStyle("cursor","crosshair")}},get_canvas_bounds:function(){var e=this.get_dialogue_element(s.DRAWINGCANVAS),t=e.getXY(),n=t[0],r=t[1],i=parseInt(e.getStyle("width"),10),o=parseInt(e.getStyle("height"),10);return new M.assignfeedback_editpdf.rect(n,r,i,o)},get_canvas_coordinates:function(e){var t=this.get_canvas_bounds(),n=new M.assignfeedback_editpdf.point(e.x-t.x,e.y-t.y);return t.x=t.y=0,n.clip(t),n},get_window_coordinates:function(e){var t=this.get_canvas_bounds(),n=new M.assignfeedback_editpdf.point(e.x+t.x,e.y+t.y);return n},open_in_panel:function(t){var n,r;this.panel=t,t.append(this.get("body")),t.addClass(i.DIALOGUE),this.loadingicon=this.get_dialogue_element(s.LOADINGICON),n=this.get_dialogue_element(s.DRAWINGCANVAS),this.graphic=new e.Graphic({render:n}),r=this.get_dialogue_element(s.DRAWINGREGION),r.on("scroll",this.simulate_scroll,this),this.get("readonly")||(n.on("gesturemovestart",this.edit_start,null,this),n.on("gesturemove",this.edit_move,null,this),n.on("gesturemoveend",this.edit_end,null,this),this.refresh_button_state()),this.start_generation()},link_handler:function(t){var n,r,o=!0;t.preventDefault(),this.dialogue||(this.dialogue=new M.core.dialogue({headerContent:this.get("header"),bodyContent:this.get("body"),footerContent:this.get("footer"),modal:!0,width:"840px",visible:!1,draggable:!0}),this.dialogue.get("boundingBox").addClass(i.DIALOGUE),this.loadingicon=this.get_dialogue_element(s.LOADINGICON),n=this.get_dialogue_element(s
+.DRAWINGCANVAS),this.graphic=new e.Graphic({render:n}),r=this.get_dialogue_element(s.DRAWINGREGION),r.on("scroll",this.simulate_scroll,this),this.get("readonly")||(n.on("gesturemovestart",this.edit_start,null,this),n.on("gesturemove",this.edit_move,null,this),n.on("gesturemoveend",this.edit_end,null,this),this.refresh_button_state()),this.start_generation(),n.on("windowresize",this.resize,this),o=!1),this.dialogue.centerDialogue(),this.dialogue.show(),this.dialogue.dd.on("drag:end",this.redraw,this),o&&this.resize()},start_generation:function(){this.poll_document_conversion_status()},poll_document_conversion_status:function(){var t=this.get("userid");e.io(n,{method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"pollconversions",userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),readonly:this.get("readonly")?1:0},on:{success:function(n,r){var i=e.one(s.USERINFOREGION);if(i){var o=i.getAttribute("data-userid");if(o&&o!=t)return}var u=this.handle_response_data(r),a=!1;if(u){this.documentstatus=u.status;if(u.status===0)a=!0;else if(u.status===1||u.status===3)a=!0;else if(u.status===2||u.status===-1)this.pagecount=u.pagecount,u.pageready==u.pagecount?this.prepare_pages_for_display(u):(this.update_page_load_progress(),this.start_document_to_image_conversion());a&&e.later(1e3,this,this.poll_document_conversion_status)}},failure:function(e,t){return new M.core.exception(t.responseText)}}})},start_document_to_image_conversion:function(){e.io(n,{method:"get",context:this,sync:!1,data:{sesskey:M.cfg.sesskey,action:"pollconversions",userid:this.get("userid"),attemptnumber:this.get("attemptnumber"),assignmentid:this.get("assignmentid"),readonly:this.get("readonly")?1:0},on:{success:function(e,t){var n=this.handle_response_data(t);n&&(this.documentstatus=n.status,n.status===2&&this.prepare_pages_for_display(n))},failure:function(e,t){return new M.core.exception(t.responseText)}}})},warning:function(t,n){var r=this.get_dialogue_element(s.ICONMESSAGECONTAINER),i=this.get_dialogue_element(s.WARNINGMESSAGECONTAINER),o=15,u=1,a="assignfeedback_editpdf_warningmessages alert alert-warning";n&&(o=4,a="assignfeedback_editpdf_warningmessages alert alert-info");var f=e.Node.create('');f.append(r.one("*").cloneNode()),f.append(t),i.prepend(f),f.transition({duration:u,delay:o,opacity:0},function(){f.remove()})},prepare_pages_for_display:function(e){var t,n,r,i,s,o;if(!e.pagecount){this.dialogue&&this.dialogue.hide(),i=new M.core.alert({message:M.util.get_string("cannotopenpdf","assignfeedback_editpdf")}),i.show();return}this.pages=e.pages;for(t=0;t0&&(r=e)},this),r},setup_toolbar:function(){var t,n,r,i,o,u,a,c,p,d,v;i=this.get_dialogue_element(s.SEARCHCOMMENTSBUTTON),i.on("click",this.open_search_comments,this),i.on("key",this.open_search_comments,"down:13",this),o=this.get_dialogue_element(s.EXPCOLCOMMENTSBUTTON),o.on("click",this.expandCollapseComments,this),o.on("key",this.expandCollapseComments,"down:13",this);if(this.get("readonly"))return;u=this.get_dialogue_element(s.ROTATELEFTBUTTON),u.on("click",this.rotatePDF,this,!0),u.on("key",this.rotatePDF,"down:13",this,!0),a=this.get_dialogue_element(s.ROTATERIGHTBUTTON),a.on("click",this.rotatePDF,this,!1),a.on("key",this.rotatePDF,"down:13",this,!1),this.disable_touch_scroll(),e.each(h,function(e,n){t=this.get_dialogue_element(e),t.on("click",this.handle_tool_button,this,n),t.on("key",this.handle_tool_button,"down:13",this,n),t.setAttribute("aria-pressed","false")},this),n=this.get_dialogue_element(s.COMMENTCOLOURBUTTON),d=new M.assignfeedback_editpdf.colourpicker({buttonNode:n,colours:f,iconprefix:"background_colour_",callback:function(e){var t=e.target.getAttribute("data-colour");t||(t=e.target.ancestor().getAttribute("data-colour")),this.currentedit.commentcolour=t,this.handle_tool_button
+(e,"comment")},context:this}),r=this.get_dialogue_element(s.ANNOTATIONCOLOURBUTTON),d=new M.assignfeedback_editpdf.colourpicker({buttonNode:r,iconprefix:"colour_",colours:l,callback:function(e){var t=e.target.getAttribute("data-colour");t||(t=e.target.ancestor().getAttribute("data-colour")),this.currentedit.annotationcolour=t,this.lastannotationtool?this.handle_tool_button(e,this.lastannotationtool):this.handle_tool_button(e,"pen")},context:this}),p=this.get("stampfiles"),p.length<=0?this.get_dialogue_element(h.stamp).ancestor().hide():(v=p[0].substr(p[0].lastIndexOf("/")+1),this.currentedit.stamp=v,c=this.get_dialogue_element(s.STAMPSBUTTON),d=new M.assignfeedback_editpdf.stamppicker({buttonNode:c,stamps:p,callback:function(e){var t=e.target.getAttribute("data-stamp"),n;t||(t=e.target.ancestor().getAttribute("data-stamp")),n=t.substr(t.lastIndexOf("/")),this.currentedit.stamp=n,this.handle_tool_button(e,"stamp")},context:this}),this.refresh_button_state())},handle_tool_button:function(e,t){var n;e.preventDefault(),n=this.get_dialogue_element(h[this.currentedit.tool]),n.removeClass("assignfeedback_editpdf_selectedbutton"),n.setAttribute("aria-pressed","false"),this.currentedit.tool=t,t!=="comment"&&t!=="select"&&t!=="drag"&&t!=="stamp"&&(this.lastannotationtool=t),this.refresh_button_state()},stringify_current_page:function(){var t=[],n=[],r,i=0;for(i=0;it.width||o.y<0||o.y>t.height)return;this.currentedit.tool==="pen"&&this.currentedit.path.push(o),this.currentedit.tool==="select"?this.currentannotation&&this.currentedit&&this.currentannotation.move(this.currentedit.annotationstart.x+o.x-this.currentedit.start.x,this.currentedit.annotationstart.y+o.y-this.currentedit.start.y):this.currentedit.tool==="drag"?(u=o.x-this.currentedit.start.x,a=o.y-this.currentedit.start.y,r.getDOMNode().scrollLeft-=u,r.getDOMNode().scrollTop-=a):this.currentedit.start&&(this.currentedit.end=o,this.redraw_current_edit())},edit_end:function(){var e,t,n;e=(new Date).getTime()-this.currentedit.start;if(e0)this.drawables.pop().erase();for(e=0;e0?n.removeAttribute("disabled"):n.setAttribute("disabled","true"),this.currentpage"),i.setAttribute("value",n),r={page:n+1,total:this.pages.length},i.setHTML(M.util.get_string("pagexofy","assignfeedback_editpdf",r)),t.append(i);t.removeAttribute("disabled"),t.on("change",function(){this.currentpage=t.get("value"),this.clear_warnings(!1),this.change_page()},this),o=this.get_dialogue_element(s.PREVIOUSBUTTON),u=this.get_dialogue_element(s.NEXTBUTTON),o.on("click",this.previous_page,this),o.on("key",this.previous_page,"down:13",this),u.on("click",this.next_page,this),u.on("key",this.next_page,"down:13",this)},previous_page:function(e){e.preventDefault(),this.simulatescroll=!1,this.currentpage--,this.currentpage<0&&(this.currentpage=0),this.clear_warnings(!1),this.change_page()},next_page:function(e){e.preventDefault(),this.simulatescroll=!1,this.currentpage++,this.currentpage>=this.pages.length&&(this.currentpage=this.pages.length-1),this.clear_warnings(!1),this.change_page()},simulate_scroll:function(){var e,t,n,r;e=this.get_dialogue_element(s.DRAWINGREGION),t=parseInt(e.get("scrollTop"),10),t>0&&(this.simulatescroll=!0),e.get("scrollHeight")-e.get("scrollTop")==e.get("clientHeight")&&this.currentpage0&&(n=this.get_dialogue_element(s.PREVIOUSBUTTON),n.simulate("click"),e.set("scrollTop",this.scrollend-1))},move_canvas:function(){var e,t,n,r;e=this.get_dialogue_element(s.DRAWINGREGION),t=parseInt(e.get("scrollLeft"),10),n=parseInt(e.get("scrollTop"),10);for(r=0;rUTF-8
===================================================================
--- mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor.js (revision 9d29dbf4deb0ca3832365a5673cf82f74f122bc7)
+++ mod/assign/feedback/editpdf/yui/build/moodle-assignfeedback_editpdf-editor/moodle-assignfeedback_editpdf-editor.js (revision cd134c32707512b8df54b78758ee1ebbb3a351a4)
@@ -3519,6 +3519,22 @@
*/
editingcomment: false,
+ /**
+ * Prevent simulated scroll
+ * @property simulatescroll
+ * @type Boolean
+ * @protected
+ */
+ simulatescroll: false,
+
+ /**
+ * Extreme scroll position
+ * @property scrollend
+ * @type int
+ * @protected
+ */
+ scrollend: 0,
+
/**
* Should inactive comments be collapsed?
*
@@ -3663,7 +3679,7 @@
* @method open_in_panel
*/
open_in_panel: function(panel) {
- var drawingcanvas;
+ var drawingcanvas, drawingregion;
this.panel = panel;
panel.append(this.get('body'));
@@ -3674,6 +3690,9 @@
drawingcanvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS);
this.graphic = new Y.Graphic({render: drawingcanvas});
+ drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
+ drawingregion.on('scroll', this.simulate_scroll, this);
+
if (!this.get('readonly')) {
drawingcanvas.on('gesturemovestart', this.edit_start, null, this);
drawingcanvas.on('gesturemove', this.edit_move, null, this);
@@ -3690,7 +3709,7 @@
* @method link_handler
*/
link_handler: function(e) {
- var drawingcanvas;
+ var drawingcanvas, drawingregion;
var resize = true;
e.preventDefault();
@@ -3713,6 +3732,9 @@
drawingcanvas = this.get_dialogue_element(SELECTOR.DRAWINGCANVAS);
this.graphic = new Y.Graphic({render: drawingcanvas});
+ drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
+ drawingregion.on('scroll', this.simulate_scroll, this);
+
if (!this.get('readonly')) {
drawingcanvas.on('gesturemovestart', this.edit_start, null, this);
drawingcanvas.on('gesturemove', this.edit_move, null, this);
@@ -4736,6 +4758,7 @@
*/
previous_page: function(e) {
e.preventDefault();
+ this.simulatescroll = false;
this.currentpage--;
if (this.currentpage < 0) {
this.currentpage = 0;
@@ -4751,6 +4774,7 @@
*/
next_page: function(e) {
e.preventDefault();
+ this.simulatescroll = false;
this.currentpage++;
if (this.currentpage >= this.pages.length) {
this.currentpage = this.pages.length - 1;
@@ -4759,6 +4783,39 @@
this.change_page();
},
+ /**
+ * Simulate the transition to the next (previous) page
+ * when the canvas for drawing scrolls to extreme positions
+ * @protected
+ * @method simulate_scroll
+ */
+ simulate_scroll: function () {
+ var drawingregion, y, previousbutton, nextbutton;
+
+ drawingregion = this.get_dialogue_element(SELECTOR.DRAWINGREGION);
+ y = parseInt(drawingregion.get('scrollTop'), 10);
+
+ if (y > 0) {
+ this.simulatescroll = true;
+ }
+
+ // go to next page if it exists
+ if (drawingregion.get('scrollHeight') - drawingregion.get('scrollTop') == drawingregion.get('clientHeight')
+ && this.currentpage < this.pages.length -1) {
+ this.scrollend = y;
+ nextbutton = this.get_dialogue_element(SELECTOR.NEXTBUTTON);
+ nextbutton.simulate("click");
+ drawingregion.set('scrollTop', 1);
+ }
+
+ // go to previous page if it exists
+ if (y == 0 && this.simulatescroll == true && this.currentpage > 0) {
+ previousbutton = this.get_dialogue_element(SELECTOR.PREVIOUSBUTTON);
+ previousbutton.simulate("click");
+ drawingregion.set('scrollTop', this.scrollend - 1);
+ }
+ },
+
/**
* Update any absolutely positioned nodes, within each drawable, when the drawing canvas is scrolled
* @protected
Index: mod/assign/feedback/editpdf/tests/behat/behat_assignfeedback_editpdf.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- mod/assign/feedback/editpdf/tests/behat/behat_assignfeedback_editpdf.php (revision 7959ac59bc06271be27642f169a65c498100e3c7)
+++ mod/assign/feedback/editpdf/tests/behat/behat_assignfeedback_editpdf.php (revision 7b553b7318bc855c0abd2296a811683883f4f943)
@@ -102,4 +102,37 @@
$this->getSession()->wait(self::get_timeout() * 1000, "({$js})");
}
+
+ /**
+ * Scroll down to the bottom of the page
+ *
+ * @Given /^I scroll down$/
+ */
+ public function i_scroll_down()
+ {
+ $js = ' (function() {
+ var instance = M.assignfeedback_editpdf.instance;
+ var drawingregion = instance.get_dialogue_element(".drawingregion");
+ drawingregion.set("scrollTop", parseInt(drawingregion.get("scrollHeight"), 10) - parseInt(drawingregion.get("clientHeight"), 10));
+}()); ';
+ $this->getSession()->executeScript($js);
+ sleep(1);
+ }
+
+ /**
+ * Scroll up to the beginning of the page
+ *
+ * @Given /^I scroll up$/
+ */
+ public function i_scroll_up()
+ {
+ $js = ' (function() {
+ var instance = M.assignfeedback_editpdf.instance;
+ var drawingregion = instance.get_dialogue_element(".drawingregion");
+ drawingregion.set("scrollTop", 1);
+ drawingregion.set("scrollTop", 0);
+}()); ';
+ $this->getSession()->executeScript($js);
+ sleep(1);
+ }
}
Index: mod/assign/feedback/editpdf/tests/behat/scroll.feature
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- mod/assign/feedback/editpdf/tests/behat/scroll.feature (revision 7b553b7318bc855c0abd2296a811683883f4f943)
+++ mod/assign/feedback/editpdf/tests/behat/scroll.feature (revision 7b553b7318bc855c0abd2296a811683883f4f943)
@@ -0,0 +1,65 @@
+@mod @mod_assign @assignfeedback @assignfeedback_editpdf @_file_upload
+Feature: In an assignment, teacher can scroll PDF files during grading
+ As a teacher
+ I need to use the PDF editor
+
+ @javascript
+ Scenario: Submit a PDF files as a student and scroll the PDF as a teacher during grading
+ # Be sure to check out ghostscript
+ Given ghostscript is installed
+ And the following "courses" exist:
+ | fullname | shortname | category | groupmode |
+ | Course 1 | C1 | 0 | 1 |
+ And the following "users" exist:
+ | username | firstname | lastname | email |
+ | teacher1 | Teacher | 1 | teacher1@example.com |
+ | student1 | Student | 1 | student1@example.com |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher1 | C1 | editingteacher |
+ | student1 | C1 | student |
+ And I log in as "teacher1"
+ And I am on "Course 1" course homepage with editing mode on
+ And I add a "Assignment" to section "1" and I fill the form with:
+ | Assignment name | Test assignment name |
+ | Description | Submit your PDF file |
+ | assignsubmission_file_enabled | 1 |
+ | Maximum number of uploaded files | 2 |
+ And I log out
+ And I log in as "student1"
+ And I am on "Course 1" course homepage
+ And I follow "Test assignment name"
+ And I press "Add submission"
+ # student uploads pdf document
+ And I upload "mod/assign/feedback/editpdf/tests/fixtures/submission.pdf" file to "File submissions" filemanager
+ And I press "Save changes"
+ And I should see "Submitted for grading"
+ And I should see "submission.pdf"
+ And I should see "Not graded"
+ And I log out
+ And I log in as "teacher1"
+ And I am on "Course 1" course homepage
+ And I follow "Test assignment name"
+ And I navigate to "View all submissions" in current page administration
+ # The teacher views the documents uploaded by the student during grading
+ And I click on "Grade" "link" in the "Submitted for grading" "table_row"
+ # The process of converting a document takes a lot of time, so be sure to wait for it to complete
+ And I wait for the complete PDF to load
+ # I see the first page of the generated document
+ And I should see "Page 1 of 2"
+ # Scrolling down to the bottom of the current page
+ And I scroll down
+ # I see the next page
+ And I should see "Page 2 of 2"
+ # Scrolling down to the bottom of the current page again
+ And I scroll down
+ # Nothing happens because i'm on the last page
+ And I should see "Page 2 of 2"
+ # Scrolling up to the beginning of the current page
+ And I scroll up
+ # I see the previous page
+ And I should see "Page 1 of 2"
+ # Scrolling up to the beginning of the current page again
+ And I scroll up
+ # Nothing happens because i'm on the first page
+ And I should see "Page 1 of 2"
\ No newline at end of file