Gitlab CSE Unil

Commit 9e4edd46 authored by M. Chardon's avatar M. Chardon
Browse files

init

parents
YUI.add('moodle-assignfeedback_editpdfplus-editor', function (Y, NAME) {
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A list of globals used by this module.
*
* @module moodle-assignfeedback_editpdfplus-editor
*/
var AJAXBASE = M.cfg.wwwroot + '/mod/assign/feedback/editpdfplus/ajax.php',
AJAXBASEPROGRESS = M.cfg.wwwroot + '/mod/assign/feedback/editpdfplus/ajax_progress.php',
CSS = {
DIALOGUE : 'assignfeedback_editpdfplus_widget'
},
SELECTOR = {
PREVIOUSBUTTON : '.navigate-previous-button',
NEXTBUTTON : ' .navigate-next-button',
SEARCHCOMMENTSBUTTON : '.searchcommentsbutton',
SEARCHFILTER : '.assignfeedback_editpdfplus_commentsearch input',
SEARCHCOMMENTSLIST : '.assignfeedback_editpdfplus_commentsearch ul',
PAGESELECT : '.navigate-page-select',
LOADINGICON : '.loading',
PROGRESSBARCONTAINER : '.progress-info.progress-striped',
DRAWINGREGION : '.drawingregion',
DRAWINGCANVAS : '.drawingcanvas',
SAVE : '.savebutton',
COMMENTCOLOURBUTTON : '.commentcolourbutton',
COMMENTMENU : '.commentdrawable a',
ANNOTATIONCOLOURBUTTON : '.annotationcolourbutton',
DELETEANNOTATIONBUTTON : '.deleteannotationbutton',
UNSAVEDCHANGESDIV : '.assignfeedback_editpdfplus_unsavedchanges',
UNSAVEDCHANGESINPUT : 'input[name="assignfeedback_editpdfplus_haschanges"]',
STAMPSBUTTON : '.currentstampbutton',
DIALOGUE : '.' + CSS.DIALOGUE
},
SELECTEDBORDERCOLOUR = 'rgba(200, 200, 255, 0.9)',
SELECTEDFILLCOLOUR = 'rgba(200, 200, 255, 0.5)',
COMMENTTEXTCOLOUR = 'rgb(51, 51, 51)',
COMMENTCOLOUR = {
'white' : 'rgb(255,255,255)',
'yellow' : 'rgb(255,236,174)',
'red' : 'rgb(249,181,179)',
'green' : 'rgb(214,234,178)',
'blue' : 'rgb(203,217,237)',
'clear' : 'rgba(255,255,255, 0)'
},
ANNOTATIONCOLOUR = {
'white' : 'rgb(255,255,255)',
'yellow' : 'rgb(255,207,53)',
'red' : 'rgb(239,69,64)',
'green' : 'rgb(152,202,62)',
'blue' : 'rgb(125,159,211)',
'black' : 'rgb(51,51,51)'
},
CLICKTIMEOUT = 300,
TOOLSELECTOR = {
//'comment': '.commentbutton',
'pen': '.penbutton',
'line': '.linebutton',
'rectangle': '.rectanglebutton',
'oval': '.ovalbutton',
//'stamp': '.stampbutton',
'select': '.selectbutton',
'drag': '.dragbutton',
'highlight': '.highlightbutton'
},
TOOLTYPE = {
'PEN' : 8,
'LINE' : 9,
'RECTANGLE' : 10,
'OVAL' : 11,
'HIGHLIGHT' : 12
},
STROKEWEIGHT = 4;// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides an in browser PDF editor.
*
* @module moodle-assignfeedback_editpdfplus-editor
*/
/**
* Class representing a 2d point.
*
* @namespace M.assignfeedback_editpdfplus
* @param Number x
* @param Number y
* @class point
*/
var POINT = function(x, y) {
/**
* X coordinate.
* @property x
* @type int
* @public
*/
this.x = parseInt(x, 10);
/**
* Y coordinate.
* @property y
* @type int
* @public
*/
this.y = parseInt(y, 10);
/**
* Clip this point to the rect
* @method clip
* @param M.assignfeedback_editpdfplus.point
* @public
*/
this.clip = function(bounds) {
if (this.x < bounds.x) {
this.x = bounds.x;
}
if (this.x > (bounds.x + bounds.width)) {
this.x = bounds.x + bounds.width;
}
if (this.y < bounds.y) {
this.y = bounds.y;
}
if (this.y > (bounds.y + bounds.height)) {
this.y = bounds.y + bounds.height;
}
// For chaining.
return this;
};
};
M.assignfeedback_editpdfplus = M.assignfeedback_editpdfplus || {};
M.assignfeedback_editpdfplus.point = POINT;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides an in browser PDF editor.
*
* @module moodle-assignfeedback_editpdfplus-editor
*/
/**
* Class representing a 2d rect.
*
* @namespace M.assignfeedback_editpdfplus
* @param int x
* @param int y
* @param int width
* @param int height
* @class rect
*/
var RECT = function(x, y, width, height) {
/**
* X coordinate.
* @property x
* @type int
* @public
*/
this.x = x;
/**
* Y coordinate.
* @property y
* @type int
* @public
*/
this.y = y;
/**
* Width
* @property width
* @type int
* @public
*/
this.width = width;
/**
* Height
* @property height
* @type int
* @public
*/
this.height = height;
/**
* Set this rect to represent the smallest possible rectangle containing this list of points.
* @method bounds
* @param M.assignfeedback_editpdfplus.point[]
* @public
*/
this.bound = function(points) {
var minx = 0,
maxx = 0,
miny = 0,
maxy = 0,
i = 0,
point;
for (i = 0; i < points.length; i++) {
point = points[i];
if (point.x < minx || i === 0) {
minx = point.x;
}
if (point.x > maxx || i === 0) {
maxx = point.x;
}
if (point.y < miny || i === 0) {
miny = point.y;
}
if (point.y > maxy || i === 0) {
maxy = point.y;
}
}
this.x = minx;
this.y = miny;
this.width = maxx - minx;
this.height = maxy - miny;
// Allow chaining.
return this;
};
/**
* Checks if rect has min width.
* @method has_min_width
* @return bool true if width is more than 5px.
* @public
*/
this.has_min_width = function() {
return (this.width >= 5);
};
/**
* Checks if rect has min height.
* @method has_min_height
* @return bool true if height is more than 5px.
* @public
*/
this.has_min_height = function() {
return (this.height >= 5);
};
/**
* Set min. width of annotation bound.
* @method set_min_width
* @public
*/
this.set_min_width = function() {
this.width = 5;
};
/**
* Set min. height of annotation bound.
* @method set_min_height
* @public
*/
this.set_min_height = function() {
this.height = 5;
};
};
M.assignfeedback_editpdfplus = M.assignfeedback_editpdfplus || {};
M.assignfeedback_editpdfplus.rect = RECT;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides an in browser PDF editor.
*
* @module moodle-assignfeedback_editpdfplus-editor
*/
/**
* EDIT
*
* @namespace M.assignfeedback_editpdfplus
* @class edit
*/
var EDIT = function() {
/**
* Starting point for the edit.
* @property start
* @type M.assignfeedback_editpdfplus.point|false
* @public
*/
this.start = false;
/**
* Finishing point for the edit.
* @property end
* @type M.assignfeedback_editpdfplus.point|false
* @public
*/
this.end = false;
/**
* Starting time for the edit.
* @property starttime
* @type int
* @public
*/
this.starttime = 0;
/**
* Starting point for the currently selected annotation.
* @property annotationstart
* @type M.assignfeedback_editpdfplus.point|false
* @public
*/
this.annotationstart = false;
/**
* The currently selected tool
* @property tool
* @type String
* @public
*/
this.tool = "drag";
/**
* The currently comment colour
* @property commentcolour
* @type String
* @public
*/
this.commentcolour = 'yellow';
/**
* The currently annotation colour
* @property annotationcolour
* @type String
* @public
*/
this.annotationcolour = 'red';
/**
* The current stamp image.
* @property stamp
* @type String
* @public
*/
this.stamp = '';
/**
* List of points the the current drawing path.
* @property path
* @type M.assignfeedback_editpdfplus.point[]
* @public
*/
this.path = [];
};
M.assignfeedback_editpdfplus = M.assignfeedback_editpdfplus || {};
M.assignfeedback_editpdfplus.edit = EDIT;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides an in browser PDF editor.
*
* @module moodle-assignfeedback_editpdfplus-editor
*/
/**
* Class representing a drawable thing which contains both Y.Nodes, and Y.Shapes.
*
* @namespace M.assignfeedback_editpdfplus
* @param M.assignfeedback_editpdfplus.editor editor
* @class drawable
*/
var DRAWABLE = function(editor) {
/**
* Reference to M.assignfeedback_editpdfplus.editor.
* @property editor
* @type M.assignfeedback_editpdfplus.editor
* @public
*/
this.editor = editor;
/**
* Array of Y.Shape
* @property shapes
* @type Y.Shape[]
* @public
*/
this.shapes = [];
/**
* Array of Y.Node
* @property nodes
* @type Y.Node[]
* @public
*/
this.nodes = [];
/**
* Delete the shapes from the drawable.
* @protected
* @method erase_drawable
*/
this.erase = function() {
if (this.shapes) {
while (this.shapes.length > 0) {
this.editor.graphic.removeShape(this.shapes.pop());
}
}
if (this.nodes) {
while (this.nodes.length > 0) {
this.nodes.pop().remove();
}
}
};
/**
* Update the positions of all absolutely positioned nodes, when the drawing canvas is scrolled
* @public
* @method scroll_update
* @param scrollx int
* @param scrolly int
*/
this.scroll_update = function(scrollx, scrolly) {
var i, x, y;
for (i = 0; i < this.nodes.length; i++) {
x = this.nodes[i].getData('x');
y = this.nodes[i].getData('y');
if (x !== undefined && y !== undefined) {
this.nodes[i].setX(parseInt(x, 10) - scrollx);
this.nodes[i].setY(parseInt(y, 10) - scrolly);
}
}
};
/**
* Store the initial position of the node, so it can be updated when the drawing canvas is scrolled
* @public
* @method store_position
* @param container
* @param x
* @param y
*/
this.store_position = function(container, x, y) {
var drawingregion, scrollx, scrolly;
drawingregion = this.editor.get_dialogue_element(SELECTOR.DRAWINGREGION);
scrollx = parseInt(drawingregion.get('scrollLeft'), 10);
scrolly = parseInt(drawingregion.get('scrollTop'), 10);
container.setData('x', x + scrollx);
container.setData('y', y + scrolly);
};
};
M.assignfeedback_editpdfplus = M.assignfeedback_editpdfplus || {};
M.assignfeedback_editpdfplus.drawable = DRAWABLE;
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Provides an in browser PDF editor.
*
* @module moodle-assignfeedback_editpdfplus-editor
*/
/**
* Class representing a highlight.
*
* @namespace M.assignfeedback_editpdfplus
* @class annotation
* @constructor
*/
var ANNOTATION = function(config) {
ANNOTATION.superclass.constructor.apply(this, [config]);
};
ANNOTATION.NAME = "annotation";
ANNOTATION.ATTRS = {};
Y.extend(ANNOTATION, Y.Base, {
/**
* Reference to M.assignfeedback_editpdfplus.editor.
* @property editor
* @type M.assignfeedback_editpdfplus.editor
* @public
*/
editor : null,
/**
* Grade id
* @property gradeid
* @type Int
* @public