Gitlab CSE Unil

Commit 3e200ca3 authored by M. Chardon's avatar M. Chardon
Browse files

outil type 4 : ajout cadre supplémentaire + enregistrement

parent fa5ac608
......@@ -194,7 +194,15 @@ class page_editor {
$DB->delete_records('assignfeedback_editpp_annot', array('gradeid' => $gradeid, 'pageno' => $pageno, 'draft' => 1));
$added = 0;
$annotationdiv = array();
foreach ($annotations as $record) {
//debugging($record->divcartridge . ' - ' . $record->parent_annot_div);
$currentdiv = $record->divcartridge;
if ($record->parent_annot_div != '') {
//on est dans le cas d'une annotation liee
$idparent = $annotationdiv[$record->parent_annot_div];
$record->parent_annot = intval($idparent);
}
// Force these.
if (!($record instanceof annotation)) {
$annotation = new annotation($record);
......@@ -204,7 +212,12 @@ class page_editor {
$annotation->gradeid = $gradeid;
$annotation->pageno = $pageno;
$annotation->draft = 1;
if (self::add_annotation($annotation)) {
$newid = self::add_annotation($annotation);
if ($newid) {
if ($currentdiv != '') {
$annotationdiv[$currentdiv] = $newid;
debugging($currentdiv . ' -> ' . $newid);
}
$added++;
}
}
......@@ -328,6 +341,10 @@ class page_editor {
global $DB;
$annotation->id = null;
debugging('idparent : ' . $annotation->parent_annot);
if ($annotation->parent_annot == 0) {
$annotation->parent_annot = null;
}
return $DB->insert_record('assignfeedback_editpp_annot', $annotation);
}
......
......@@ -680,6 +680,8 @@ Y.extend(ANNOTATION, Y.Base, {
displaylock: 0,
borderstyle: '',
parent_annot: 0,
parent_annot_element: null,
id: 0,
/**
* Initialise the annotation.
*
......@@ -687,24 +689,25 @@ Y.extend(ANNOTATION, Y.Base, {
* @return void
*/
initializer: function (config) {
if (config.parent_annot) {
this.editor = config.parent_annot.editor || null;
this.gradeid = parseInt(config.parent_annot.gradeid, 10) || 0;
this.pageno = parseInt(config.parent_annot.pageno, 10) || 0;
if (config.parent_annot_element) {
this.editor = config.parent_annot_element.editor || null;
this.gradeid = parseInt(config.parent_annot_element.gradeid, 10) || 0;
this.pageno = parseInt(config.parent_annot_element.pageno, 10) || 0;
this.x = parseInt(config.x, 10) || 0;
this.y = parseInt(config.y, 10) || 0;
this.endx = parseInt(config.endx, 10) || 0;
this.endy = parseInt(config.endy, 10) || 0;
this.path = config.path || '';
this.toolid = config.toolid || this.editor.get_dialogue_element(TOOLTYPEID.RECTANGLE);
this.colour = config.parent_annot.colour || 'red';
this.colour = config.parent_annot_element.colour || 'red';
this.drawable = false;
this.tooltype = config.tooltype;
this.textannot = config.parent_annot.textannot;
this.displaylock = config.parent_annot.displaylock;
this.borderstyle = config.parent_annot.borderstyle || 'solid';
this.parent_annot = -1;
config.parent_annot.children.push(this);
this.textannot = config.parent_annot_element.textannot;
this.displaylock = config.parent_annot_element.displaylock;
this.borderstyle = config.parent_annot_element.borderstyle || 'solid';
this.parent_annot = config.parent_annot_element.id;
this.parent_annot_element = config.parent_annot_element;
config.parent_annot_element.children.push(this);
} else {
this.editor = config.editor || null;
this.gradeid = parseInt(config.gradeid, 10) || 0;
......@@ -722,27 +725,9 @@ Y.extend(ANNOTATION, Y.Base, {
this.displaylock = config.displaylock;
this.borderstyle = config.borderstyle || 'solid';
this.parent_annot = config.parent_annot;
this.id = config.id;
}
},
clone: function () {
return {
editor: this.editor,
gradeid: this.gradeid,
pageno: this.pageno,
x: this.x,
y: this.y,
endx: this.endx,
endy: this.endy,
path: this.path,
toolid: this.toolid,
colour: this.colour,
tooltype: this.tooltype,
textannot: this.textannot,
displaylock: this.displaylock,
borderstyle: this.borderstyle,
parent_annot: this
};
},
/**
* Clean a comment record, returning an oject with only fields that are valid.
* @public
......@@ -750,6 +735,25 @@ Y.extend(ANNOTATION, Y.Base, {
* @return {}
*/
clean: function () {
if (this.parent_annot_element) {
return {
gradeid: this.gradeid,
x: parseInt(this.x, 10),
y: parseInt(this.y, 10),
endx: parseInt(this.endx, 10),
endy: parseInt(this.endy, 10),
toolid: this.toolid,
path: this.path,
pageno: this.pageno,
colour: this.colour,
textannot: this.textannot,
displaylock: parseInt(this.displaylock, 10),
borderstyle: this.borderstyle,
parent_annot: this.parent_annot,
divcartridge: this.divcartridge,
parent_annot_div: this.parent_annot_element.divcartridge
};
}
return {
gradeid: this.gradeid,
x: parseInt(this.x, 10),
......@@ -763,7 +767,9 @@ Y.extend(ANNOTATION, Y.Base, {
textannot: this.textannot,
displaylock: parseInt(this.displaylock, 10),
borderstyle: this.borderstyle,
parent_annot: this.parent_annot
parent_annot: this.parent_annot,
divcartridge: this.divcartridge,
parent_annot_div: ''
};
},
/**
......@@ -859,6 +865,20 @@ Y.extend(ANNOTATION, Y.Base, {
if (this.drawable) {
this.drawable.erase();
}
if (this.children.length > 0) {
for (i = 0; i < this.children.length; i++) {
if (this.children[i] && (this.children[i].parent_annot === this.id || this.children[i].parent_annot_element.divcartridge === this.divcartridge)) {
for (var j = 0; j < annotations.length; j++) {
if (annotations[j] === this.children[i]) {
annotations.splice(j, 1);
if (this.children[i].drawable) {
this.children[i].drawable.erase();
}
}
}
}
}
}
this.editor.currentannotation = false;
this.editor.save_current_page();
return;
......@@ -2501,7 +2521,7 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
shape,
bounds,
highlightcolour;
bounds = new M.assignfeedback_editpdfplus.rect();
bounds.bound([new M.assignfeedback_editpdfplus.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdfplus.point(edit.end.x, edit.end.y)]);
......@@ -2602,7 +2622,7 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
return highlightcolour;
},
draw_catridge: function (edit) {
if (this.parent_annot !== -1) {
if (this.parent_annot_element === null && this.parent_annot === 0) {
var offsetcanvas = this.editor.get_dialogue_element(SELECTOR.DRAWINGCANVAS).getXY();
if (this.divcartridge === '') {
var date = (new Date().toJSON()).replace(/:/g, '').replace(/\./g, '');
......@@ -2749,7 +2769,7 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
},
add_annot: function (e) {
//var new_frame = this.clone();
this.editor.currentedit.parent_annot = this;
this.editor.currentedit.parent_annot_element = this;
this.editor.handle_tool_button(e, TOOLTYPELIB.FRAME, 'ctbutton' + this.toolid);
/*var annotation = new M.assignfeedback_editpdfplus.annotationframe(new_frame);
if (annotation) {
......@@ -2774,6 +2794,15 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
shape.set("stroke", {
color: this.colour
});
for (var i = 0; i < this.children.length; i++) {
if (this.children[i] && (this.children[i].parent_annot === this.id || this.children[i].parent_annot_element.divcartridge === this.divcartridge)) {
this.children[i].colour = colour;
var shapechd = this.editor.graphic.getShapeById(this.children[i].shape_id);
shapechd.set("stroke", {
color: this.colour
});
}
}
var divprincipale = this.editor.get_dialogue_element('#' + this.divcartridge);
divprincipale.setStyles({
'border-color': this.colour,
......@@ -2808,6 +2837,25 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
dashstyle: [2, 2]
});
}
for (i = 0; i < this.children.length; i++) {
if (this.children[i] && (this.children[i].parent_annot === this.id || this.children[i].parent_annot_element.divcartridge === this.divcartridge)) {
this.children[i].borderstyle = border;
var shapechd = this.editor.graphic.getShapeById(this.children[i].shape_id);
if (this.borderstyle === 'solid') {
shapechd.set("stroke", {
dashstyle: 'none'
});
} else if (this.borderstyle === 'dashed') {
shapechd.set("stroke", {
dashstyle: [5, 3]
});
} else {
shapechd.set("stroke", {
dashstyle: [2, 2]
});
}
}
}
var divprincipale = this.editor.get_dialogue_element('#' + this.divcartridge);
divprincipale.setStyles({
'border-style': this.borderstyle
......@@ -4785,9 +4833,20 @@ EDITOR.prototype = {
comment.colour,
comment.rawtext);
}
var parentannot = [];
for (j = 0; j < this.pages[i].annotations.length; j++) {
data = this.pages[i].annotations[j];
this.pages[i].annotations[j] = this.create_annotation(this.tools[data.toolid].type, data.toolid, data, this.tools[data.toolid]); //@TODO
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]);
parentannot[data.id] = newannot;
this.pages[i].annotations[j] = newannot;
}
}
......@@ -5257,7 +5316,7 @@ EDITOR.prototype = {
}
data.tool = type;
data.editor = this;
Y.log('create_annotation post analyse : ' + data.tool + ' - ' + data.toolid);
Y.log('create_annotation post analyse : ' + data.tool + ' - ' + data.toolid + ' - ' + data.parent_annot);
if (data.tool === TOOLTYPE.LINE + '' || data.tool === TOOLTYPELIB.LINE) {
return new M.assignfeedback_editpdfplus.annotationline(data);
} else if (data.tool === TOOLTYPE.RECTANGLE + '' || data.tool === TOOLTYPELIB.RECTANGLE) {
......@@ -5305,7 +5364,15 @@ EDITOR.prototype = {
if (data.colour === "") {
data.colour = TOOLTYPEDEFAULTCOLOR.FRAME;
}
data.parent_annot = this.currentedit.parent_annot;
if (!data.parent_annot && !data.parent_annot_element) {
if (this.currentedit.parent_annot_element) {
data.parent_annot_element = this.currentedit.parent_annot_element;
//this.currentedit.parent_annot_element = null;
} else {
data.parent_annot_element = null;
data.parent_annot = 0;
}
}
return new M.assignfeedback_editpdfplus.annotationframe(data);
}
}
......
......@@ -680,6 +680,8 @@ Y.extend(ANNOTATION, Y.Base, {
displaylock: 0,
borderstyle: '',
parent_annot: 0,
parent_annot_element: null,
id: 0,
/**
* Initialise the annotation.
*
......@@ -687,24 +689,25 @@ Y.extend(ANNOTATION, Y.Base, {
* @return void
*/
initializer: function (config) {
if (config.parent_annot) {
this.editor = config.parent_annot.editor || null;
this.gradeid = parseInt(config.parent_annot.gradeid, 10) || 0;
this.pageno = parseInt(config.parent_annot.pageno, 10) || 0;
if (config.parent_annot_element) {
this.editor = config.parent_annot_element.editor || null;
this.gradeid = parseInt(config.parent_annot_element.gradeid, 10) || 0;
this.pageno = parseInt(config.parent_annot_element.pageno, 10) || 0;
this.x = parseInt(config.x, 10) || 0;
this.y = parseInt(config.y, 10) || 0;
this.endx = parseInt(config.endx, 10) || 0;
this.endy = parseInt(config.endy, 10) || 0;
this.path = config.path || '';
this.toolid = config.toolid || this.editor.get_dialogue_element(TOOLTYPEID.RECTANGLE);
this.colour = config.parent_annot.colour || 'red';
this.colour = config.parent_annot_element.colour || 'red';
this.drawable = false;
this.tooltype = config.tooltype;
this.textannot = config.parent_annot.textannot;
this.displaylock = config.parent_annot.displaylock;
this.borderstyle = config.parent_annot.borderstyle || 'solid';
this.parent_annot = -1;
config.parent_annot.children.push(this);
this.textannot = config.parent_annot_element.textannot;
this.displaylock = config.parent_annot_element.displaylock;
this.borderstyle = config.parent_annot_element.borderstyle || 'solid';
this.parent_annot = config.parent_annot_element.id;
this.parent_annot_element = config.parent_annot_element;
config.parent_annot_element.children.push(this);
} else {
this.editor = config.editor || null;
this.gradeid = parseInt(config.gradeid, 10) || 0;
......@@ -722,27 +725,9 @@ Y.extend(ANNOTATION, Y.Base, {
this.displaylock = config.displaylock;
this.borderstyle = config.borderstyle || 'solid';
this.parent_annot = config.parent_annot;
this.id = config.id;
}
},
clone: function () {
return {
editor: this.editor,
gradeid: this.gradeid,
pageno: this.pageno,
x: this.x,
y: this.y,
endx: this.endx,
endy: this.endy,
path: this.path,
toolid: this.toolid,
colour: this.colour,
tooltype: this.tooltype,
textannot: this.textannot,
displaylock: this.displaylock,
borderstyle: this.borderstyle,
parent_annot: this
};
},
/**
* Clean a comment record, returning an oject with only fields that are valid.
* @public
......@@ -750,6 +735,25 @@ Y.extend(ANNOTATION, Y.Base, {
* @return {}
*/
clean: function () {
if (this.parent_annot_element) {
return {
gradeid: this.gradeid,
x: parseInt(this.x, 10),
y: parseInt(this.y, 10),
endx: parseInt(this.endx, 10),
endy: parseInt(this.endy, 10),
toolid: this.toolid,
path: this.path,
pageno: this.pageno,
colour: this.colour,
textannot: this.textannot,
displaylock: parseInt(this.displaylock, 10),
borderstyle: this.borderstyle,
parent_annot: this.parent_annot,
divcartridge: this.divcartridge,
parent_annot_div: this.parent_annot_element.divcartridge
};
}
return {
gradeid: this.gradeid,
x: parseInt(this.x, 10),
......@@ -763,7 +767,9 @@ Y.extend(ANNOTATION, Y.Base, {
textannot: this.textannot,
displaylock: parseInt(this.displaylock, 10),
borderstyle: this.borderstyle,
parent_annot: this.parent_annot
parent_annot: this.parent_annot,
divcartridge: this.divcartridge,
parent_annot_div: ''
};
},
/**
......@@ -859,6 +865,20 @@ Y.extend(ANNOTATION, Y.Base, {
if (this.drawable) {
this.drawable.erase();
}
if (this.children.length > 0) {
for (i = 0; i < this.children.length; i++) {
if (this.children[i] && (this.children[i].parent_annot === this.id || this.children[i].parent_annot_element.divcartridge === this.divcartridge)) {
for (var j = 0; j < annotations.length; j++) {
if (annotations[j] === this.children[i]) {
annotations.splice(j, 1);
if (this.children[i].drawable) {
this.children[i].drawable.erase();
}
}
}
}
}
}
this.editor.currentannotation = false;
this.editor.save_current_page();
return;
......@@ -2490,7 +2510,7 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
shape,
bounds,
highlightcolour;
bounds = new M.assignfeedback_editpdfplus.rect();
bounds.bound([new M.assignfeedback_editpdfplus.point(edit.start.x, edit.start.y),
new M.assignfeedback_editpdfplus.point(edit.end.x, edit.end.y)]);
......@@ -2590,7 +2610,7 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
return highlightcolour;
},
draw_catridge: function (edit) {
if (this.parent_annot !== -1) {
if (this.parent_annot_element === null && this.parent_annot === 0) {
var offsetcanvas = this.editor.get_dialogue_element(SELECTOR.DRAWINGCANVAS).getXY();
if (this.divcartridge === '') {
var date = (new Date().toJSON()).replace(/:/g, '').replace(/\./g, '');
......@@ -2734,7 +2754,7 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
},
add_annot: function (e) {
//var new_frame = this.clone();
this.editor.currentedit.parent_annot = this;
this.editor.currentedit.parent_annot_element = this;
this.editor.handle_tool_button(e, TOOLTYPELIB.FRAME, 'ctbutton' + this.toolid);
/*var annotation = new M.assignfeedback_editpdfplus.annotationframe(new_frame);
if (annotation) {
......@@ -2758,6 +2778,15 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
shape.set("stroke", {
color: this.colour
});
for (var i = 0; i < this.children.length; i++) {
if (this.children[i] && (this.children[i].parent_annot === this.id || this.children[i].parent_annot_element.divcartridge === this.divcartridge)) {
this.children[i].colour = colour;
var shapechd = this.editor.graphic.getShapeById(this.children[i].shape_id);
shapechd.set("stroke", {
color: this.colour
});
}
}
var divprincipale = this.editor.get_dialogue_element('#' + this.divcartridge);
divprincipale.setStyles({
'border-color': this.colour,
......@@ -2792,6 +2821,25 @@ Y.extend(ANNOTATIONFRAME, M.assignfeedback_editpdfplus.annotation, {
dashstyle: [2, 2]
});
}
for (i = 0; i < this.children.length; i++) {
if (this.children[i] && (this.children[i].parent_annot === this.id || this.children[i].parent_annot_element.divcartridge === this.divcartridge)) {
this.children[i].borderstyle = border;
var shapechd = this.editor.graphic.getShapeById(this.children[i].shape_id);
if (this.borderstyle === 'solid') {
shapechd.set("stroke", {
dashstyle: 'none'
});
} else if (this.borderstyle === 'dashed') {
shapechd.set("stroke", {
dashstyle: [5, 3]
});
} else {
shapechd.set("stroke", {
dashstyle: [2, 2]
});
}
}
}
var divprincipale = this.editor.get_dialogue_element('#' + this.divcartridge);
divprincipale.setStyles({
'border-style': this.borderstyle
......@@ -4766,9 +4814,20 @@ EDITOR.prototype = {
comment.colour,
comment.rawtext);
}
var parentannot = [];
for (j = 0; j < this.pages[i].annotations.length; j++) {
data = this.pages[i].annotations[j];
this.pages[i].annotations[j] = this.create_annotation(this.tools[data.toolid].type, data.toolid, data, this.tools[data.toolid]); //@TODO
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]);
parentannot[data.id] = newannot;
this.pages[i].annotations[j] = newannot;
}
}
......@@ -5283,7 +5342,15 @@ EDITOR.prototype = {
if (data.colour === "") {
data.colour = TOOLTYPEDEFAULTCOLOR.FRAME;
}
data.parent_annot = this.currentedit.parent_annot;
if (!data.parent_annot && !data.parent_annot_element) {
if (this.currentedit.parent_annot_element) {
data.parent_annot_element = this.currentedit.parent_annot_element;
//this.currentedit.parent_annot_element = null;
} else {
data.parent_annot_element = null;
data.parent_annot = 0;
}
}
return new M.assignfeedback_editpdfplus.annotationframe(data);
}
}
......
......@@ -117,6 +117,8 @@ Y.extend(ANNOTATION, Y.Base, {
displaylock: 0,
borderstyle: '',
parent_annot: 0,
parent_annot_element: null,
id: 0,
/**
* Initialise the annotation.
*
......@@ -124,24 +126,25 @@ Y.extend(ANNOTATION, Y.Base, {
* @return void
*/
initializer: function (config) {
if (config.parent_annot) {
this.editor = config.parent_annot.editor || null;
this.gradeid = parseInt(config.parent_annot.gradeid, 10) || 0;
this.pageno = parseInt(config.parent_annot.pageno, 10) || 0;
if (config.parent_annot_element) {
this.editor = config.parent_annot_element.editor || null;
this.gradeid = parseInt(config.parent_annot_element.gradeid, 10) || 0;
this.pageno = parseInt(config.parent_annot_element.pageno, 10) || 0;
this.x = parseInt(config.x, 10) || 0;
this.y = parseInt(config.y, 10) || 0;
this.endx = parseInt(config.endx, 10) || 0;
this.endy = parseInt(config.endy, 10) || 0;