Commit a0ab195e by Sola

now have submission buttons that are specific to the incorrect answer to which…

now have submission buttons that are specific to the incorrect answer to which the student wants to submit a hint. i believe all is functional.
parent bd777f90
...@@ -34,110 +34,113 @@ class CrowdXBlock(XBlock): ...@@ -34,110 +34,113 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = str(data["submittedanswer"]) answer = str(data["submittedanswer"])
if str(data["submittedanswer"]) == self.correctanswer: if str(data["submittedanswer"]) == self.correctanswer:
return{"correct": 1} return{"correct": 1}
hintsarehere = 0 hintsarehere = 0
self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers
for key in self.hints: for key in self.hints:
temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works
if str(key) == str(data["submittedanswer"]): if str(key) == str(data["submittedanswer"]):
print("HI HEllO") print("HI HEllO")
self.HintsToUse = {} self.HintsToUse = {}
self.HintsToUse.update(ast.literal_eval(temphints)) self.HintsToUse.update(ast.literal_eval(temphints))
for key in self.HintsToUse: for key in self.HintsToUse:
if key not in self.Used: if key not in self.Used:
hintsarehere = 1 hintsarehere = 1
if hintsarehere == 0: print("hints are here doe")
print("PLSDONTHAPPENDOE") if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
if str(data["submittedanswer"]) not in self.hints: if str(data["submittedanswer"]) not in self.hints:
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used: if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]} return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
else: else:
NotUsed = random.choice(self.HintsToUse.keys()) NotUsed = random.choice(self.HintsToUse.keys())
if len(NotUsed) != len(self.Used): if len(NotUsed) != len(self.Used):
while NotUsed in self.Used: while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
self.Used.append(NotUsed) self.Used.append(NotUsed)
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
@XBlock.json_handler @XBlock.json_handler
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
feedbackdict = {} feedbackdict = {}
if len(self.WrongAnswers) == 0: if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback else: #lenth of Used will be used to dictate flow of feedback
for i in range(0, len(self.Used)): for i in range(0, len(self.Used)):
ans = str('wngans' + str(i)) ans = str('wngans' + str(i))
hnt = str('hntusd' + str(i)) hnt = str('hntusd' + str(i))
feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i]) feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i])
print str(feedbackdict) print str(feedbackdict)
return feedbackdict return feedbackdict
@XBlock.json_handler #add 1 or -1 to rating of a hint @XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''): def rate_hint(self, data, suffix=''):
ansnum = self.Used.index(str(data['ansnum'])) ansnum = self.Used.index(str(data['ansnum']))
print("ansnum is" + ansnum) print("ansnum is" + str(ansnum))
if self.Voted == 0: if self.Voted == 0:
for key in self.DefaultHints: for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"]) self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints) print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict)) tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(data["rating"]) tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict self.hints[str(key)] = tempdict
print("TESTING AGAIN HI") print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)])) print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints)) print("otherstuff " + str(self.hints))
self.Voted = 1 self.Voted = 1
@XBlock.json_handler @XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints def give_hint(self, data, suffix=''): #add student-made hint into hints
if self.Voted == 0: if self.Voted == 0:
for key in self.hints: for key in self.hints:
if str(key) == str(self.WrongAnswers[0]): print(str(key))
if str(data['submission']) not in self.hints[str(key)]: print("still working here")
tempdict = str(self.hints[str(key)]) #rate hint that is in hints if str(key) == self.WrongAnswers[self.Used.index(str(data['id']))]:
tempdict = (ast.literal_eval(tempdict)) if str(data['submission']) not in self.hints[str(key)]:
tempdict.update({data['submission']: 0}) tempdict = str(self.hints[str(key)]) #rate hint that is in hints
self.hints[str(key)] = tempdict tempdict = (ast.literal_eval(tempdict))
self.Voted = 1 tempdict.update({data['submission']: 0})
print("TESTING AGAIN HI") self.hints[str(key)] = tempdict
print("hints are " + str(self.hints[str(key)])) self.Voted = 1
print("otherstuff " + str(self.hints)) print("TESTING AGAIN HI")
else: print("hints are " + str(self.hints[str(key)]))
ansnum = self.Used.index(data['submission']) print("otherstuff " + str(self.hints))
for key in self.DefaultHints: else:
ansnum = self.Used.index(data['submission'])
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(1) self.DefaultHints[str(key)] += int(1)
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints) print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict)) tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(1) tempdict[self.Used[int(ansnum)]] += int(1)
self.hints[str(key)] = tempdict self.hints[str(key)] = tempdict
print("TESTING AGAIN HI") print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)])) print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints)) print("otherstuff " + str(self.hints))
self.Voted = 1 self.Voted = 1
@XBlock.json_handler @XBlock.json_handler
def clear_states(self, data, suffix=''): def clear_states(self, data, suffix=''):
self.Used = [] self.Used = []
self.HintsToUse = {} self.HintsToUse = {}
self.Voted = 0 self.Voted = 0
self.WrongAnswers = [] self.WrongAnswers = []
@staticmethod @staticmethod
def workbench_scenarios(): def workbench_scenarios():
......
...@@ -34,110 +34,113 @@ class CrowdXBlock(XBlock): ...@@ -34,110 +34,113 @@ class CrowdXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = str(data["submittedanswer"]) answer = str(data["submittedanswer"])
if str(data["submittedanswer"]) == self.correctanswer: if str(data["submittedanswer"]) == self.correctanswer:
return{"correct": 1} return{"correct": 1}
hintsarehere = 0 hintsarehere = 0
self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers self.WrongAnswers.append(str(data["submittedanswer"])) #add user's incorrect answer to WrongAnswers
for key in self.hints: for key in self.hints:
temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works temphints = str(self.hints[str(key)]) #perhaps a better way to do this exists, but for now this works
if str(key) == str(data["submittedanswer"]): if str(key) == str(data["submittedanswer"]):
print("HI HEllO") print("HI HEllO")
self.HintsToUse = {} self.HintsToUse = {}
self.HintsToUse.update(ast.literal_eval(temphints)) self.HintsToUse.update(ast.literal_eval(temphints))
for key in self.HintsToUse: for key in self.HintsToUse:
if key not in self.Used: if key not in self.Used:
hintsarehere = 1 hintsarehere = 1
if hintsarehere == 0: print("hints are here doe")
print("PLSDONTHAPPENDOE") if hintsarehere == 0:
print("PLSDONTHAPPENDOE")
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
if str(data["submittedanswer"]) not in self.hints: if str(data["submittedanswer"]) not in self.hints:
self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers self.hints[str(data["submittedanswer"])] = {} #add user's incorrect answer to WrongAnswers
if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used: if max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0] not in self.Used:
self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first self.Used.append(max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]) #Highest rated hint is shown first
return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]} return {'HintsToUse': max(self.HintsToUse.iteritems(), key=operator.itemgetter(1))[0]}
else: else:
NotUsed = random.choice(self.HintsToUse.keys()) NotUsed = random.choice(self.HintsToUse.keys())
if len(NotUsed) != len(self.Used): if len(NotUsed) != len(self.Used):
while NotUsed in self.Used: while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
self.Used.append(NotUsed) self.Used.append(NotUsed)
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
@XBlock.json_handler @XBlock.json_handler
def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data def get_feedback(self, data, suffix=''): #start feedback, sent hint/answer data
feedbackdict = {} feedbackdict = {}
if len(self.WrongAnswers) == 0: if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback else: #lenth of Used will be used to dictate flow of feedback
for i in range(0, len(self.Used)): for i in range(0, len(self.Used)):
ans = str('wngans' + str(i)) ans = str('wngans' + str(i))
hnt = str('hntusd' + str(i)) hnt = str('hntusd' + str(i))
feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i]) feedbackdict[str(self.Used[i])] = str(self.WrongAnswers[i])
print str(feedbackdict) print str(feedbackdict)
return feedbackdict return feedbackdict
@XBlock.json_handler #add 1 or -1 to rating of a hint @XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''): def rate_hint(self, data, suffix=''):
ansnum = self.Used.index(str(data['ansnum'])) ansnum = self.Used.index(str(data['ansnum']))
print ansnum print("ansnum is" + str(ansnum))
if self.Voted == 0: if self.Voted == 0:
for key in self.DefaultHints: for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(data["rating"]) self.DefaultHints[str(key)] += int(data["rating"])
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints) print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict)) tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected if str(key) == str(self.WrongAnswers[ansnum]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(data["rating"]) tempdict[self.Used[int(ansnum)]] += int(data["rating"])
self.hints[str(key)] = tempdict self.hints[str(key)] = tempdict
print("TESTING AGAIN HI") print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)])) print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints)) print("otherstuff " + str(self.hints))
self.Voted = 1 self.Voted = 1
@XBlock.json_handler @XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints def give_hint(self, data, suffix=''): #add student-made hint into hints
if self.Voted == 0: if self.Voted == 0:
for key in self.hints: for key in self.hints:
if str(key) == str(self.WrongAnswers[0]): print(str(key))
if str(data['submission']) not in self.hints[str(key)]: print("still working here")
tempdict = str(self.hints[str(key)]) #rate hint that is in hints if str(key) == self.WrongAnswer[self.Used.index(str(data['id']))]:
tempdict = (ast.literal_eval(tempdict)) if str(data['submission']) not in self.hints[str(key)]:
tempdict.update({data['submission']: 0}) tempdict = str(self.hints[str(key)]) #rate hint that is in hints
self.hints[str(key)] = tempdict tempdict = (ast.literal_eval(tempdict))
self.Voted = 1 tempdict.update({data['submission']: 0})
print("TESTING AGAIN HI") self.hints[str(key)] = tempdict
print("hints are " + str(self.hints[str(key)])) self.Voted = 1
print("otherstuff " + str(self.hints)) print("TESTING AGAIN HI")
else: print("hints are " + str(self.hints[str(key)]))
ansnum = self.Used.index(data['submission']) print("otherstuff " + str(self.hints))
for key in self.DefaultHints: else:
ansnum = self.Used.index(data['submission'])
for key in self.DefaultHints:
if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints if key == self.Used[int(ansnum)]: #rating for hints in DefaultHints
self.DefaultHints[str(key)] += int(1) self.DefaultHints[str(key)] += int(1)
self.Voted = 1 self.Voted = 1
print str(self.DefaultHints) print str(self.DefaultHints)
return return
for key in self.hints: for key in self.hints:
tempdict = str(self.hints[str(key)]) #rate hint that is in hints tempdict = str(self.hints[str(key)]) #rate hint that is in hints
tempdict = (ast.literal_eval(tempdict)) tempdict = (ast.literal_eval(tempdict))
if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected if str(key) == str(self.WrongAnswers[int(ansnum)]): #ansnum will the the answer/hint pair that is selected
tempdict[self.Used[int(ansnum)]] += int(1) tempdict[self.Used[int(ansnum)]] += int(1)
self.hints[str(key)] = tempdict self.hints[str(key)] = tempdict
print("TESTING AGAIN HI") print("TESTING AGAIN HI")
print("hints are " + str(self.hints[str(key)])) print("hints are " + str(self.hints[str(key)]))
print("otherstuff " + str(self.hints)) print("otherstuff " + str(self.hints))
self.Voted = 1 self.Voted = 1
@XBlock.json_handler @XBlock.json_handler
def clear_states(self, data, suffix=''): def clear_states(self, data, suffix=''):
self.Used = [] self.Used = []
self.HintsToUse = {} self.HintsToUse = {}
self.Voted = 0 self.Voted = 0
self.WrongAnswers = [] self.WrongAnswers = []
@staticmethod @staticmethod
def workbench_scenarios(): def workbench_scenarios():
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
</p> </p>
<span><br><span> Dummy Answer Input Here</span></span> <span><br><span> Dummy Answer Input Here</span></span>
<section id="studentinput" class="textinput"> <section id="studentinput" class="textinput">
<input type="text" name="studentanswer" id="studentsubmit" class="math" size="40"> <input type="text" name="studentanswer" id="studentsubmit" class="notmath" size="40">
<input id="studentanswer" type="button" class="button" value="Submit Answer"> <input id="studentanswer" type="button" class="button" value="Submit Answer">
</div> </div>
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
<input type="hidden" name="problem_id" value="Numerical Input"> <input type="hidden" name="problem_id" value="Numerical Input">
<section class="problem"> <section class="problem">
<span><br><span> Enter and submit your own hint!</span></span>
<section id="studentinput" class="textinput">
<input type="text" name="studentinput" id="answer" class="math" size="40">
<input id="submit" type="button" class="button" value="Submit Hint">
</div></section></span> </div></section></span>
</section> </section>
......
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
<span class='Thankyou'></span> <span class='Thankyou'></span>
</p> </p>
<script id="feedback"> <div class="hintansarea">
var hintused = []
var wronganswer = [] </div>
</script>
<p> <p>
<input id="caus" type="button" class="button" value="clearAllUserState"> <input id="caus" type="button" class="button" value="clearAllUserState">
...@@ -31,10 +30,6 @@ var wronganswer = [] ...@@ -31,10 +30,6 @@ var wronganswer = []
<input type="hidden" name="problem_id" value="Numerical Input"> <input type="hidden" name="problem_id" value="Numerical Input">
<section class="problem"> <section class="problem">
<span><br><span> Enter and submit your own hint!</span></span>
<section id="studentinput" class="textinput">
<input type="text" name="studentinput" id="answer" class="math" size="40">
<input id="submit" type="button" class="button" value="Submit Hint">
</div></section></span> </div></section></span>
</section> </section>
......
...@@ -30,25 +30,32 @@ function CrowdXBlock(runtime, element){ ...@@ -30,25 +30,32 @@ function CrowdXBlock(runtime, element){
$("#feedback").show(); $("#feedback").show();
$.each(result, function(index, value) { $.each(result, function(index, value) {
console.log( index + ": " + value ); console.log( index + ": " + value );
$('.hintansarea').append("<p> For your incorrect answer of:" + " " + value + "</p> <p> You received the hint:" + " " + index + " <input id\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"> </p>"); $('.hintansarea').append("<p id=\"submit" + index + "\"> For your incorrect answer of:" + " " + value + "</p> <p> You received the hint:" + " " + index + " <input id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"> </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">");
}); });
}; };
$(document).on('click', '.hintbutton', function(){ //upvote $(document).on('click', '.hintbutton', function(){ //upvote
console.log("please show me something"); console.log("the first id" + this.id);
id = this.id; id = this.id;
console.log($(this).id()); console.log($(this).attr('id'));
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'), url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}), data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}),
success: finish success: finish
});}) });})
$('#submit', element).click(function(eventObject) { $(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
console.log("this id " + $(this).attr('id'));
$('#submit' + id).append("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><<input id=\"submit\" type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");})
$(document).on('click', '#submit', function(){
console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id'));
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'give_hint'), url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('#answer').val()}), //give hin for first incorrect answer data: JSON.stringify({"submission": $('.math').val(), "id": $(".math").attr('id')}), //give hin for first incorrect answer
success: finish success: finish
}); });
$("#answer").val('');}) $("#answer").val('');})
...@@ -64,28 +71,16 @@ function CrowdXBlock(runtime, element){ ...@@ -64,28 +71,16 @@ function CrowdXBlock(runtime, element){
$("#studentsubmit").val(''); $("#studentsubmit").val('');
$("#answer").val('');}) $("#answer").val('');})
function finish(){ function finish(){
$("#pair0").hide(); $(".hintbutton").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$('.Thankyou', element).text("Thankyou for your help!"); $('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide(); $('.correct', element).hide();
$(".hintansarea").hide();
} }
function clearstates(){ function clearstates(){
$("#pair0").hide(); $(".hintansarea").hide();
$("#pair3").hide(); $(".hintbutton").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide(); $("#answer").hide();
$(".problem").hide(); $(".problem").hide();
$('.WrongAnswer0', element).text();
$('.HintUsed0', element).text();
$('.WrongAnswer1', element).text();
$('.HintUsed1', element).text();
$('.WrongAnswer2', element).text();
$('.HintUsed2', element).text();
$('.WrongAnswer3', element).text();
$('.HintUsed3', element).text();
} }
function checkreply(result){ function checkreply(result){
......
...@@ -30,25 +30,32 @@ function CrowdXBlock(runtime, element){ ...@@ -30,25 +30,32 @@ function CrowdXBlock(runtime, element){
$("#feedback").show(); $("#feedback").show();
$.each(result, function(index, value) { $.each(result, function(index, value) {
console.log( index + ": " + value ); console.log( index + ": " + value );
$('.hintansarea').append("<p> For your incorrect answer of:" + " " + value + "</p> <p> You received the hint:" + " " + index + " <input id\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"> </p>"); $('.hintansarea').append("<p id=\"submit" + index + "\"> For your incorrect answer of:" + " " + value + "</p> <p> You received the hint:" + " " + index + " <input id=\"" + index + "\" type=\"button\" class=\"hintbutton\" value=\"Upvote this Hint\"> </p><p> <input id=\"" + index + "\" type=\"button\" class=\"submitbutton\" value=\"Submit a hint for this problem\">");
}); });
}; };
$(document).on('click', '.hintbutton', function(){ //upvote $(document).on('click', '.hintbutton', function(){ //upvote
console.log("please show me something"); console.log("the first id" + this.id);
id = this.id; id = this.id;
console.log($(this).attr('value')); console.log($(this).attr('id'));
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'), url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}), data: JSON.stringify({"rating": 1, "ansnum": $(this).attr('id')}),
success: finish success: finish
});}) });})
$('#submit', element).click(function(eventObject) { $(document).on('click', '.submitbutton', function(){ //upvote
console.log("submitbutton hit");
id = this.id;
console.log("this id " + $(this).attr('id'));
$('#submit' + id).append("<p><input type=\"text\" name=\"studentinput\" id=\"" + id + "\" class=\"math\" size=\"40\"><<input id=\"submit\" type=\"button\" class=\"button\" value=\"Submit Hint\"> </p>");})
$(document).on('click', '#submit', function(){
console.log("the other id thing" + this.id);
console.log("thisthing" + $(".math").attr('id'));
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: runtime.handlerUrl(element, 'give_hint'), url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('#answer').val()}), //give hin for first incorrect answer data: JSON.stringify({"submission": $('#answer').val(), "id": $(".math").attr('id')}), //give hin for first incorrect answer
success: finish success: finish
}); });
$("#answer").val('');}) $("#answer").val('');})
...@@ -64,28 +71,16 @@ function CrowdXBlock(runtime, element){ ...@@ -64,28 +71,16 @@ function CrowdXBlock(runtime, element){
$("#studentsubmit").val(''); $("#studentsubmit").val('');
$("#answer").val('');}) $("#answer").val('');})
function finish(){ function finish(){
$("#pair0").hide(); $(".hintbutton").hide();
$("#pair3").hide();
$("#pair2").hide();
$("#pair1").hide();
$('.Thankyou', element).text("Thankyou for your help!"); $('.Thankyou', element).text("Thankyou for your help!");
$('.correct', element).hide(); $('.correct', element).hide();
$(".hintansarea").hide();
} }
function clearstates(){ function clearstates(){
$("#pair0").hide(); $(".hintansarea").hide();
$("#pair3").hide(); $(".hintbutton").hide();
$("#pair2").hide();
$("#pair1").hide();
$("#answer").hide(); $("#answer").hide();
$(".problem").hide(); $(".problem").hide();
$('.WrongAnswer0', element).text();
$('.HintUsed0', element).text();
$('.WrongAnswer1', element).text();
$('.HintUsed1', element).text();
$('.WrongAnswer2', element).text();
$('.HintUsed2', element).text();
$('.WrongAnswer3', element).text();
$('.HintUsed3', element).text();
} }
function checkreply(result){ function checkreply(result){
......
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