Gitlab CSE Unil

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

init

parents
// 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 users quick comment.
*
* @namespace M.assignfeedback_editpdfplus
* @class quickcomment
*/
var QUICKCOMMENT = function(id, rawtext, width, colour) {
/**
* Quick comment text.
* @property rawtext
* @type String
* @public
*/
this.rawtext = rawtext || '';
/**
* ID of the comment
* @property id
* @type Int
* @public
*/
this.id = id || 0;
/**
* Width of the comment
* @property width
* @type Int
* @public
*/
this.width = width || 100;
/**
* Colour of the comment.
* @property colour
* @type String
* @public
*/
this.colour = colour || "yellow";
};
M.assignfeedback_editpdfplus = M.assignfeedback_editpdfplus || {};
M.assignfeedback_editpdfplus.quickcomment = QUICKCOMMENT;
// 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 users list of quick comments.
*
* @namespace M.assignfeedback_editpdfplus
* @class quickcommentlist
*/
var QUICKCOMMENTLIST = function(editor) {
/**
* Reference to M.assignfeedback_editpdfplus.editor.
* @property editor
* @type M.assignfeedback_editpdfplus.editor
* @public
*/
this.editor = editor;
/**
* Array of Comments
* @property shapes
* @type M.assignfeedback_editpdfplus.quickcomment[]
* @public
*/
this.comments = [];
/**
* Add a comment to the users quicklist.
*
* @protected
* @method add
*/
this.add = function(comment) {
var ajaxurl = AJAXBASE,
config;
// Do not save empty comments.
if (comment.rawtext === '') {
return;
}
config = {
method: 'post',
context: this,
sync: false,
data : {
'sesskey' : M.cfg.sesskey,
'action' : 'addtoquicklist',
'userid' : this.editor.get('userid'),
'commenttext' : comment.rawtext,
'width' : comment.width,
'colour' : comment.colour,
'attemptnumber' : this.editor.get('attemptnumber'),
'assignmentid' : this.editor.get('assignmentid')
},
on: {
success: function(tid, response) {
var jsondata, quickcomment;
try {
jsondata = Y.JSON.parse(response.responseText);
if (jsondata.error) {
return new M.core.ajaxException(jsondata);
} else {
quickcomment = new M.assignfeedback_editpdfplus.quickcomment(jsondata.id,
jsondata.rawtext,
jsondata.width,
jsondata.colour);
this.comments.push(quickcomment);
}
} catch (e) {
return new M.core.exception(e);
}
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
}
}
};
Y.io(ajaxurl, config);
};
/**
* Remove a comment from the users quicklist.
*
* @public
* @method remove
*/
this.remove = function(comment) {
var ajaxurl = AJAXBASE,
config;
// Should not happen.
if (!comment) {
return;
}
config = {
method: 'post',
context: this,
sync: false,
data : {
'sesskey' : M.cfg.sesskey,
'action' : 'removefromquicklist',
'userid' : this.editor.get('userid'),
'commentid' : comment.id,
'attemptnumber' : this.editor.get('attemptnumber'),
'assignmentid' : this.editor.get('assignmentid')
},
on: {
success: function() {
var i;
// Find and remove the comment from the quicklist.
i = this.comments.indexOf(comment);
if (i >= 0) {
this.comments.splice(i, 1);
}
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
}
}
};
Y.io(ajaxurl, config);
};
/**
* Load the users quick comments list.
*
* @protected
* @method load_quicklist
*/
this.load = function() {
var ajaxurl = AJAXBASE,
config;
config = {
method: 'get',
context: this,
sync: false,
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(tid, response) {
var jsondata;
try {
jsondata = Y.JSON.parse(response.responseText);
if (jsondata.error) {
return new M.core.ajaxException(jsondata);
} else {
Y.each(jsondata, function(comment) {
var quickcomment = new M.assignfeedback_editpdfplus.quickcomment(comment.id,
comment.rawtext,
comment.width,
comment.colour);
this.comments.push(quickcomment);
}, this);
}
} catch (e) {
return new M.core.exception(e);
}
},
failure: function(tid, response) {
return M.core.exception(response.responseText);
}
}
};
Y.io(ajaxurl, config);
};
};
M.assignfeedback_editpdfplus = M.assignfeedback_editpdfplus || {};
M.assignfeedback_editpdfplus.quickcommentlist = QUICKCOMMENTLIST;
// 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;
var STAMPPICKER_NAME = "Colourpicker",
STAMPPICKER;
/**
* Provides an in browser PDF editor.
*
* @module moodle-assignfeedback_editpdfplus-editor
*/
/**
* This is a drop down list of stamps.
*
* @namespace M.assignfeedback_editpdfplus
* @class stamppicker
* @constructor
* @extends M.assignfeedback_editpdfplus.dropdown
*/
STAMPPICKER = function(config) {
STAMPPICKER.superclass.constructor.apply(this, [config]);
};
Y.extend(STAMPPICKER, M.assignfeedback_editpdfplus.dropdown, {
/**
* Initialise the menu.
*
* @method initializer
* @return void
*/
initializer : function(config) {
var stamplist = Y.Node.create('<ul role="menu" class="assignfeedback_editpdfplus_menu"/>');
// Build a list of stamped buttons.
Y.each(this.get('stamps'), function(stamp) {
var button, listitem, title;
title = M.util.get_string('stamp', 'assignfeedback_editpdfplus');
button = Y.Node.create('<button><img height="16" width="16" alt="' + title + '" src="' + stamp + '"/></button>');
button.setAttribute('data-stamp', stamp);
button.setStyle('backgroundImage', 'none');
listitem = Y.Node.create('<li/>');
listitem.append(button);
stamplist.append(listitem);
}, this);
// Set the call back.
stamplist.delegate('click', this.callback_handler, 'button', this);
stamplist.delegate('key', this.callback_handler, 'down:13', 'button', this);
// Set the accessible header text.
this.set('headerText', M.util.get_string('stamppicker', 'assignfeedback_editpdfplus'));
// Set the body content.
this.set('bodyContent', stamplist);
STAMPPICKER.superclass.initializer.call(this, config);
},
callback_handler : function(e) {
e.preventDefault();
var callback = this.get('callback'),
callbackcontext = this.get('context'),
bind;
this.hide();
// Call the callback with the specified context.
bind = Y.bind(callback, callbackcontext, e);
bind();
}
}, {
NAME : STAMPPICKER_NAME,
ATTRS : {
/**
* The list of stamps this stamp picker supports.
*
* @attribute stamps
* @type String[] - the stamp filenames.
* @default {}
*/
stamps : {
value : []
},
/**
* The function called when a new stamp is chosen.
*
* @attribute callback
* @type function
* @default null
*/
callback : {
value : null
},
/**
* The context passed to the callback when a stamp is chosen.
*
* @attribute context
* @type Y.Node
* @default null
*/
context : {
value : null
}
}
});
M.assignfeedback_editpdfplus = M.assignfeedback_editpdfplus || {};
M.assignfeedback_editpdfplus.stamppicker = STAMPPICKER;
{
"moodle-assignfeedback_editpdfplus-editor": {
"requires": [
"base",
"event",
"node",
"io",
"graphics",
"json",
"event-move",
"event-resize",
"transition",
"querystring-stringify-simple",
"moodle-core-notification-dialog",
"moodle-core-notification-exception",
"moodle-core-notification-ajaxexception"
]
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment