Commit d3045d90 authored by Abdelmoujib Megzari's avatar Abdelmoujib Megzari
Browse files

reste 1 seul bug

parent 7dade4cc
......@@ -119,7 +119,8 @@ public class AssociateParagraphChoice extends HttpServlet {
}
System.out.println(paragraphFollowerID);
Paragraph oldParagraph = new ChoixDAO(ds).getChoiceParagraph(choiceID);
if(oldParagraph!=null && !oldParagraph.isValide() && oldParagraph.getAuteur() == session.getAttribute("username")){
System.out.println("associate_paragraph_info");
if(oldParagraph!=null && !oldParagraph.isValide() && oldParagraph.getAuteur().equals(session.getAttribute("username"))){
paragraphDAO.deleteParagraph(oldParagraph.getId());
}else if(oldParagraph!=null){
......
......@@ -88,16 +88,17 @@ public class ChoixDAO extends AbstractDAO {
}
}
public boolean publishChoice(int choiceId, Set<Integer> history) {
public boolean publishChoice(int choiceId, List<Integer> history) {
boolean publish = false;
Paragraph paragraph= getChoiceParagraph(choiceId);
if(paragraph==null){
return false;
}
history.add(choiceId);
history.add(paragraph.getId());
List<Integer> requires= new ParagraphDAO(dataSource).getReadBefore(paragraph.getId());
for (Integer req:requires){
if(!history.contains(req)){
history.remove(history.size()-1);
return false;
}
}
......@@ -115,6 +116,7 @@ public class ChoixDAO extends AbstractDAO {
}
}
history.remove(history.size()-1);
return publish;
}
......
......@@ -304,7 +304,7 @@ public class StoryDAO extends AbstractDAO {
boolean publish =false;
for (Choix choice :
choices) {
if(new ChoixDAO(dataSource).publishChoice(choice.getId(),new HashSet<Integer>())){
if(new ChoixDAO(dataSource).publishChoice(choice.getId(),new ArrayList<Integer>())){
publish = true;
}
}
......
......@@ -7,7 +7,7 @@
</span>
</c:if>
<c:if test="${choice['idParagrapheSuite']!=0}" var="new" scope="request">
<span class="choice ${choice['published']?'':'edit'}" id ="choice${choice['id']}" style ="${choice['published']?'':'display:none;'}" onclick="${'choose'}(${choice['idParagraphe']},${choice['idParagrapheSuite']},${storyid})">
<span class="choice ${choice['published']?'':'edit'}" id ="choice${choice['id']}" style ="${choice['published']?'':'display:none;'}" onclick="${'choose'}(${choice['idParagraphe']},${choice['idParagrapheSuite']},${storyid},${choice['id']})">
<c:out value="${choice['texte']}"/>
<div class="edit">
<c:forEach items="${choice['required']}" var="pid">
......
......@@ -28,8 +28,8 @@ function showLogin() {
y.style.display = "none";
}
}
function choose(sourceid, destinationid,story_id,mode,async){
function choose(sourceid, destinationid,story_id,choice_id,mode,async){
if (typeof(mode)=='undefined'){
mode = mod;
}
......@@ -53,7 +53,7 @@ function choose(sourceid, destinationid,story_id,mode,async){
switchMode(false);
switchMode(false);
}
editParagraphe(destinationid,false, true);
editParagraphe(destinationid,false, true,choice_id);
document.getElementById("subParagraph"+sourceid).scrollIntoView({behavior:"smooth", block:"start",inline:"nearest"});
}else {
$("#subParagraph" + sourceid).empty().append(data.responseText);
......@@ -78,7 +78,7 @@ function addChoice(paragraph_id,story_id) {
element.setAttribute("onclick","");
}
function editParagraphe(paragraph_id,isConclusion,notvalid) {
function editParagraphe(paragraph_id,isConclusion,notvalid,choice_id) {
var element = document.getElementById("paragrapheText"+paragraph_id);
var oldText = element.innerHTML;
$.post("ManageParagraph", {action: 4,paragraph_id: paragraph_id}).done(function(data) {
......@@ -87,7 +87,7 @@ function editParagraphe(paragraph_id,isConclusion,notvalid) {
if (notvalid){
additionalforms=`<button onclick="deleteParagraphe(${paragraph_id})" type="button">abandonner et dévrouiller</button>`+
`<br><input type="text" id="link${paragraph_id}">`+
`<button onclick="associate(${paragraph_id})" type="button">associer à ce paragraph existant</button>`+
`<button onclick="associate(${paragraph_id},${choice_id})" type="button">associer à ce paragraph existant</button>`+
`<br><input type="text" id="require${paragraph_id}">`+
`<button onclick="setReadBefore(${paragraph_id})" type="button">paragraphe requis</button>`;
}
......@@ -256,13 +256,16 @@ function deleteParagraphe(id){
}
function associate(id){
function associate(id,choice_id){
//TODO BUG LAST LOCK NOT WORKING AFTER UPDATING PAGE
//TODO bug detected after association the new paragraphe isn't deleted and is forever locked
let follower = parseInt(document.getElementById(`link${id}`).value);
console.log(follower);
if(typeof(choice_id)=='undefined'){
choice_id = last_lock;
}
let last_lock_first=document.getElementById(`paragraph_contents${id}`).parentElement.id;
$.post("AssociateParagraphChoice", {choice_id:last_lock , paragraphFollower: follower}).done(function (data) {
$.post("AssociateParagraphChoice", {choice_id:choice_id , paragraphFollower: follower}).done(function (data) {
console.log("done");
console.log(data);
choose(last_lock_first,follower,story_id);
......
Markdown is supported
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