Gitlab CSE Unil

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

introduction tool type

parent 2554939c
......@@ -96,7 +96,9 @@ if ($action == 'loadallpages') {
}
$tools = page_editor::get_tools();
$typetools = page_editor::get_typetools();
$response->tools = $tools;
$response->typetools = $typetools;
echo json_encode($response);
die();
......
......@@ -159,6 +159,20 @@ class page_editor {
return $tools;
}
public static function get_typetools($contextidlist) {
global $DB;
$typetools = array();
if ($contextidlist) {
$records = $DB->get_records_list('assignfeedback_editpp_typet', 'contextid', $contextidlist);
} else {
$records = $DB->get_records('assignfeedback_editpp_typet');
}
foreach ($records as $record) {
array_push($typetools, new type_tool($record));
}
return $typetools;
}
/**
* Get all tools for a page.
* @param int $contextid
......
......@@ -25,7 +25,7 @@ class tool {
public $axis = 0;
/** @var int type */
public $type = 0;
public $type = null;
/** @var string colors used */
public $colors = '';
......
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace assignfeedback_editpdfplus;
/**
* Description of type_tool
*
* @author kury
*/
class type_tool {
/** @var int unique id for this annotation */
public $id = 0;
/** @var int contextid for this annotation */
public $contextid = 0;
/** @var string label of this annotation */
public $label = '';
/** @var string colors used */
public $color = '';
/** @var string colors used */
public $cartridge_color = '';
public $cartridge_x = 0;
public $cartridge_y = 0;
/**
* Convert a compatible stdClass into an instance of this class.
* @param stdClass $record
*/
public function __construct(\stdClass $record = null) {
if ($record) {
$intcols = array('reply');
foreach ($this as $key => $value) {
if (isset($record->$key)) {
if (in_array($key, $intcols)) {
$this->$key = intval($record->$key);
} else {
$this->$key = $record->$key;
}
}
}
}
}
}
......@@ -101,6 +101,22 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
<KEY NAME="axis" TYPE="foreign" FIELDS="axis" REFTABLE="editpdfpp_axis" REFFIELDS="id"/>
<KEY NAME="type" TYPE="foreign" FIELDS="type" REFTABLE="editpdfpp_typet" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="assignfeedback_editpp_typet" COMMENT="assignfeedback_editpp_typet table retrofitted from MySQL">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="18" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="label" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="color" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="cartridge_color" TYPE="char" LENGTH="200" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="cartridge_x" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="cartridge_y" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
......
......@@ -71,22 +71,13 @@ ANNOTATIONCOLOUR = {
},
CLICKTIMEOUT = 300,
TOOLSELECTOR = {
//'comment': '.commentbutton',
'pen': '.penbutton',
'line': '.linebutton',
'rectangle': '.rectanglebutton',
'oval': '.ovalbutton',
//'stamp': '.stampbutton',
'select': '.selectbutton',
'drag': '.dragbutton',
'highlight': '.highlightbutton'/*,
/*'highlightplus': '.highlightplusbutton',
'lineplus': '.lineplusbutton',
'stampplus': '.stampplusbutton',
'frame': '.framebutton',
'verticalline': '.verticallinebutton',
'stampcomment': '.stampcommentbutton',
'commentplus': '.commentplusbutton'*/
'highlight': '.highlightbutton'
},
TOOLTYPEID = {
'PEN': 8,
......@@ -679,6 +670,7 @@ Y.extend(ANNOTATION, Y.Base, {
*/
drawable: false,
tooltype: null,
tooltypefamille: null,
divcartridge: '',
textannot: '',
displaylock: 0,
......@@ -741,6 +733,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.parent_annot = config.parent_annot;
this.id = config.id;
}
this.tooltypefamille = this.editor.typetools[this.tooltype.type];
},
/**
* Clean a comment record, returning an oject with only fields that are valid.
......@@ -1970,10 +1963,10 @@ Y.extend(ANNOTATIONHIGHLIGHTPLUS, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -2724,12 +2717,13 @@ Y.extend(ANNOTATIONSTAMPCOMMENT, M.assignfeedback_editpdfplus.annotation, {
}
diveditiondisplay.append(divpropositiondisplay);
Y.log('draw_cartridge : ' + this.editor.typetools[this.toolid].label);
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -3213,10 +3207,10 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -3714,10 +3708,10 @@ Y.extend(ANNOTATIONVERTICALLINE, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -5796,6 +5790,12 @@ EDITOR.prototype = {
this.tools[tooltmp.id] = tooltmp;
}
this.typetools = [];
for (i = 0; i < data.typetools.length; i++) {
var typetooltmp = data.typetools[i];
this.typetools[typetooltmp.id] = typetooltmp;
}
for (i = 0; i < this.pages.length; i++) {
for (j = 0; j < this.pages[i].comments.length; j++) {
comment = this.pages[i].comments[j];
......@@ -5813,13 +5813,8 @@ EDITOR.prototype = {
data = this.pages[i].annotations[j];
if (data.parent_annot) {
data.parent_annot_element = parentannot[data.parent_annot];
/*for (var k = 0; k < j; k++) {
if (this.pages[i].annotations[k].id === data.parent_annot) {
data.parent_annot_element = this.pages[i].annotations[k];
}
}*/
}
var newannot = this.create_annotation(this.tools[data.toolid].type, data.toolid, data, this.tools[data.toolid]);
var newannot = this.create_annotation(this.typetools[this.tools[data.toolid].type].label, data.toolid, data, this.tools[data.toolid]);
parentannot[data.id] = newannot;
this.pages[i].annotations[j] = newannot;
}
......@@ -5927,33 +5922,6 @@ EDITOR.prototype = {
},
context: this
});
/*stampfiles = this.get('stampfiles');
if (stampfiles.length <= 0) {
this.get_dialogue_element(TOOLSELECTOR.stamp).ancestor().hide();
} else {
filename = stampfiles[0].substr(stampfiles[0].lastIndexOf('/') + 1);
this.currentedit.stamp = filename;
currentstampbutton = this.get_dialogue_element(SELECTOR.STAMPSBUTTON);
picker = new M.assignfeedback_editpdfplus.stamppicker({
buttonNode: currentstampbutton,
stamps: stampfiles,
callback: function (e) {
var stamp = e.target.getAttribute('data-stamp'),
filename;
if (!stamp) {
stamp = e.target.ancestor().getAttribute('data-stamp');
}
filename = stamp.substr(stamp.lastIndexOf('/'));
this.currentedit.stamp = filename;
this.handle_tool_button(e, "stamp");
},
context: this
});
this.refresh_button_state();
}*/
},
update_custom_toolbars: function () {
Y.all(SELECTOR.CUSTOMTOOLBARS).each(function (toolbar) {
......@@ -6273,6 +6241,12 @@ EDITOR.prototype = {
* Factory method for creating annotations of the correct subclass.
* @public
* @method create_annotation
*
* @param {type} type label du type de tool
* @param {type} toolid id du tool en cours
* @param {type} data annotation complete si elle existe
* @param {type} toolobjet le tool
* @returns {M.assignfeedback_editpdfplus.annotationrectangle|M.assignfeedback_editpdfplus.annotationhighlight|M.assignfeedback_editpdfplus.annotationoval|Boolean|M.assignfeedback_editpdfplus.annotationstampplus|M.assignfeedback_editpdfplus.annotationframe|M.assignfeedback_editpdfplus.annotationline|M.assignfeedback_editpdfplus.annotationstampcomment|M.assignfeedback_editpdfplus.annotationhighlightplus|M.assignfeedback_editpdfplus.annotationverticalline|M.assignfeedback_editpdfplus.annotationpen}
*/
create_annotation: function (type, toolid, data, toolobjet) {
Y.log('create_annotation : ' + type + ' - ' + toolid);
......@@ -6293,6 +6267,7 @@ EDITOR.prototype = {
} else if (toolid !== null && toolid[0] === 'c') {
data.toolid = toolid.substr(8);
}
data.tool = type;
data.editor = this;
Y.log('create_annotation post analyse : ' + data.tool + ' - ' + data.toolid + ' - ' + data.parent_annot);
......@@ -6462,6 +6437,7 @@ EDITOR.prototype = {
}
for (i = 0; i < page.annotations.length; i++) {
Y.log('redraw : ' + page.annotations[i].tooltypefamille.label);
this.drawables.push(page.annotations[i].draw());
}
for (i = 0; i < page.comments.length; i++) {
......
......@@ -71,22 +71,13 @@ ANNOTATIONCOLOUR = {
},
CLICKTIMEOUT = 300,
TOOLSELECTOR = {
//'comment': '.commentbutton',
'pen': '.penbutton',
'line': '.linebutton',
'rectangle': '.rectanglebutton',
'oval': '.ovalbutton',
//'stamp': '.stampbutton',
'select': '.selectbutton',
'drag': '.dragbutton',
'highlight': '.highlightbutton'/*,
/*'highlightplus': '.highlightplusbutton',
'lineplus': '.lineplusbutton',
'stampplus': '.stampplusbutton',
'frame': '.framebutton',
'verticalline': '.verticallinebutton',
'stampcomment': '.stampcommentbutton',
'commentplus': '.commentplusbutton'*/
'highlight': '.highlightbutton'
},
TOOLTYPEID = {
'PEN': 8,
......@@ -679,6 +670,7 @@ Y.extend(ANNOTATION, Y.Base, {
*/
drawable: false,
tooltype: null,
tooltypefamille: null,
divcartridge: '',
textannot: '',
displaylock: 0,
......@@ -741,6 +733,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.parent_annot = config.parent_annot;
this.id = config.id;
}
this.tooltypefamille = this.editor.typetools[this.tooltype.type];
},
/**
* Clean a comment record, returning an oject with only fields that are valid.
......@@ -1969,10 +1962,10 @@ Y.extend(ANNOTATIONHIGHLIGHTPLUS, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -2719,10 +2712,10 @@ Y.extend(ANNOTATIONSTAMPCOMMENT, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -3199,10 +3192,10 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -3691,10 +3684,10 @@ Y.extend(ANNOTATIONVERTICALLINE, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......@@ -5763,6 +5756,12 @@ EDITOR.prototype = {
this.tools[tooltmp.id] = tooltmp;
}
this.typetools = [];
for (i = 0; i < data.typetools.length; i++) {
var typetooltmp = data.typetools[i];
this.typetools[typetooltmp.id] = typetooltmp;
}
for (i = 0; i < this.pages.length; i++) {
for (j = 0; j < this.pages[i].comments.length; j++) {
comment = this.pages[i].comments[j];
......@@ -5780,13 +5779,8 @@ EDITOR.prototype = {
data = this.pages[i].annotations[j];
if (data.parent_annot) {
data.parent_annot_element = parentannot[data.parent_annot];
/*for (var k = 0; k < j; k++) {
if (this.pages[i].annotations[k].id === data.parent_annot) {
data.parent_annot_element = this.pages[i].annotations[k];
}
}*/
}
var newannot = this.create_annotation(this.tools[data.toolid].type, data.toolid, data, this.tools[data.toolid]);
var newannot = this.create_annotation(this.typetools[this.tools[data.toolid].type].label, data.toolid, data, this.tools[data.toolid]);
parentannot[data.id] = newannot;
this.pages[i].annotations[j] = newannot;
}
......@@ -5894,33 +5888,6 @@ EDITOR.prototype = {
},
context: this
});
/*stampfiles = this.get('stampfiles');
if (stampfiles.length <= 0) {
this.get_dialogue_element(TOOLSELECTOR.stamp).ancestor().hide();
} else {
filename = stampfiles[0].substr(stampfiles[0].lastIndexOf('/') + 1);
this.currentedit.stamp = filename;
currentstampbutton = this.get_dialogue_element(SELECTOR.STAMPSBUTTON);
picker = new M.assignfeedback_editpdfplus.stamppicker({
buttonNode: currentstampbutton,
stamps: stampfiles,
callback: function (e) {
var stamp = e.target.getAttribute('data-stamp'),
filename;
if (!stamp) {
stamp = e.target.ancestor().getAttribute('data-stamp');
}
filename = stamp.substr(stamp.lastIndexOf('/'));
this.currentedit.stamp = filename;
this.handle_tool_button(e, "stamp");
},
context: this
});
this.refresh_button_state();
}*/
},
update_custom_toolbars: function () {
Y.all(SELECTOR.CUSTOMTOOLBARS).each(function (toolbar) {
......@@ -6239,6 +6206,12 @@ EDITOR.prototype = {
* Factory method for creating annotations of the correct subclass.
* @public
* @method create_annotation
*
* @param {type} type label du type de tool
* @param {type} toolid id du tool en cours
* @param {type} data annotation complete si elle existe
* @param {type} toolobjet le tool
* @returns {M.assignfeedback_editpdfplus.annotationrectangle|M.assignfeedback_editpdfplus.annotationhighlight|M.assignfeedback_editpdfplus.annotationoval|Boolean|M.assignfeedback_editpdfplus.annotationstampplus|M.assignfeedback_editpdfplus.annotationframe|M.assignfeedback_editpdfplus.annotationline|M.assignfeedback_editpdfplus.annotationstampcomment|M.assignfeedback_editpdfplus.annotationhighlightplus|M.assignfeedback_editpdfplus.annotationverticalline|M.assignfeedback_editpdfplus.annotationpen}
*/
create_annotation: function (type, toolid, data, toolobjet) {
......@@ -6258,6 +6231,7 @@ EDITOR.prototype = {
} else if (toolid !== null && toolid[0] === 'c') {
data.toolid = toolid.substr(8);
}
data.tool = type;
data.editor = this;
if (data.tool === TOOLTYPE.LINE + '' || data.tool === TOOLTYPELIB.LINE) {
......
......@@ -112,6 +112,7 @@ Y.extend(ANNOTATION, Y.Base, {
*/
drawable: false,
tooltype: null,
tooltypefamille: null,
divcartridge: '',
textannot: '',
displaylock: 0,
......@@ -174,6 +175,7 @@ Y.extend(ANNOTATION, Y.Base, {
this.parent_annot = config.parent_annot;
this.id = config.id;
}
this.tooltypefamille = this.editor.typetools[this.tooltype.type];
},
/**
* Clean a comment record, returning an oject with only fields that are valid.
......
......@@ -312,10 +312,10 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......
......@@ -245,10 +245,10 @@ Y.extend(ANNOTATIONHIGHLIGHTPLUS, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......
......@@ -237,12 +237,13 @@ Y.extend(ANNOTATIONSTAMPCOMMENT, M.assignfeedback_editpdfplus.annotation, {
}
diveditiondisplay.append(divpropositiondisplay);
Y.log('draw_cartridge : ' + this.editor.typetools[this.toolid].label);
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......
......@@ -239,10 +239,10 @@ Y.extend(ANNOTATIONVERTICALLINE, M.assignfeedback_editpdfplus.annotation, {
//positionnement de la div par rapport a l'annotation
if (!this.cartridgex || this.cartridgex === 0) {
this.cartridgex = parseInt(this.tooltype.cartridge_positionx);
this.cartridgex = parseInt(this.tooltypefamille.cartridge_x);
}
if (!this.cartridgey || this.cartridgey === 0) {
this.cartridgey = parseInt(this.tooltype.cartridge_positiony);
this.cartridgey = parseInt(this.tooltypefamille.cartridge_y);
}
divdisplay.setX(offsetcanvas[0] + this.x + this.cartridgex);
divdisplay.setY(this.y + this.cartridgey);
......
......@@ -499,6 +499,12 @@ EDITOR.prototype = {
this.tools[tooltmp.id] = tooltmp;
}
this.typetools = [];
for (i = 0; i < data.typetools.length; i++) {
var typetooltmp = data.typetools[i];
this.typetools[typetooltmp.id] = typetooltmp;
}
for (i = 0; i < this.pages.length; i++) {
for (j = 0; j < this.pages[i].comments.length; j++) {
comment = this.pages[i].comments[j];
......@@ -516,13 +522,8 @@ EDITOR.prototype = {
data = this.pages[i].annotations[j