Commit e3f81830 by Sola

crowdxblock with basic functionality. can rate hints, make new hints, has default hints.

parent 5091590c
from .crowdxblock import CrowdXBlock
\ No newline at end of file
import pkg_resources
import logging
import operator
import random
from xblock.core import XBlock
from xblock.fields import Scope, Integer, Boolean, String, Dict, List
from xblock.fragment import Fragment
log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
hints = Dict(default={}, scope=Scope.content) #All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating}
HintsToUse = Dict(default={}, scope=Scope.user_state) #Dict of hints to provide user
WrongAnswers = List(default=[], scope=Scope.user_state) #List of mistakes made by user
DefaultHints = Dict(default={"hint": 100, "hinttwo": 10, "hintthree": 0, "hintasdf": 50, "aas;dklfj?": 1000, "SuperDuperBestHint": 10000}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake
Used = List(default=[], scope=Scope.user_state)#List of used hints from HintsToUse
def student_view(self, context=None):
html = self.resource_string("static/html/crowdxblock.html")
frag = Fragment(html.format(self=self))
frag.add_css(self.resource_string("static/css/crowdxblock.css"))
frag.add_javascript(self.resource_string("static/js/src/crowdxblock.js"))
frag.initialize_js('CrowdXBlock')
return frag
def resource_string(self, path):
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
@XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = data["submittedanswer"]
if data["submittedanswer"] not in self.WrongAnswers:
self.WrongAnswers.append(data["submittedanswer"]) #add user's incorrect answer to WrongAnswers
if data["submittedanswer"] not in self.hints:
self.hints[data["submittedanswer"]] = {} #add user's incorrect answer to WrongAnswers
for key in self.hints:
if key == data["submittedanswer"]:
for y in self.hints[key]:
self.HintsToUse[y] += self.hints[key[y]] #If the user's incorrect answre has precedence in hints, add hints listed under
if len(self.HintsToUse) < 2: #incorrect answer to HintsToUse
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
else:
self.HintsToUse = self.DefaultHints.copy()
if len(self.WrongAnswers) == 1:
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]}
else:
NotUsed = random.choice(self.HintsToUse.keys())
if len(NotUsed) != len(self.Used):
while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
self.Used.append(NotUsed)
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
@XBlock.json_handler
def get_feedback(self, data, suffix=''): #feedback, either rating or making a hint, starts here
if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback
return {'lenused': int(len(self.Used))}
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
for key in self.hints: #rating for hints in hints dictionary
if key == self.WrongAnswers[data['ansnum']]:
for y in self.hints[self.WrongAnswers[data['ansnum']]]: #ansnum represents which hint/
if y == self.Used[data['ansnum']]: #answer pair is being rated
self.hints[self.WrongAnswers[data['ansnum']][y]] += int(data["rating"])#0 is first hint/answer
for key in self.DefaultHints:
if key == self.Used[data['ansnum']]: #rating for hints in DefaultHints
self.DefaultHints[key] += int(data["rating"])
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}#
@XBlock.json_handler
def get_data(self, data, suffix=''): #pass hint/answer text to js to see in html
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
@XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints
for key in self.hints:
if key == self.WrongAnswers[data['ansnum']]:
for y in self.hints[self.WrongAnswers[data['ansnum']]]:
if y == data['submission']: #if the exact hint already exists, +1 rate
self.hints[self.WrongAnswers[data['ansnum']][y]] += int(data["rating"])
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
else:
self.hints[key[data['submission']]] = 0 #add with default rating of 0
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
@staticmethod
def workbench_scenarios():
"""A canned scenario for display in the workbench."""
return [
("CrowdXBlock",
"""<vertical_demo>
<crowdxblock/>
</vertical_demo>
"""),
]
import pkg_resources
import logging
import operator
import random
from xblock.core import XBlock
from xblock.fields import Scope, Integer, Boolean, String, Dict, List
from xblock.fragment import Fragment
log = logging.getLogger(__name__)
#get_hint and get_feedback are in
class CrowdXBlock(XBlock):
hints = Dict(default={}, scope=Scope.content) #All hints. sorted by type of mistake. type_of_incorrect_answer{"hint":rating, "hint":rating}
HintsToUse = Dict(default={}, scope=Scope.user_state) #Dict of hints to provide user
WrongAnswers = List(default=[], scope=Scope.user_state) #List of mistakes made by user
DefaultHints = Dict(default={"hint": 100, "hinttwo": 10, "hintthree": 0, "hintasdf": 50, "aas;dklfj?": 1000, "SuperDuperBestHint": 10000}, scope=Scope.content) #Default hints in case no incorrect answers in hints match the user's mistake
Used = List(default=[], scope=Scope.user_state)#List of used hints from HintsToUse
def student_view(self, context=None):
html = self.resource_string("static/html/crowdxblock.html")
frag = Fragment(html.format(self=self))
frag.add_css(self.resource_string("static/css/crowdxblock.css"))
frag.add_javascript(self.resource_string("static/js/src/crowdxblock.js"))
frag.initialize_js('CrowdXBlock')
return frag
def resource_string(self, path):
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
@XBlock.json_handler
def get_hint(self, data, suffix=''): #get hints into HintsToUse dict, pass on to user
answer = data["submittedanswer"]
if data["submittedanswer"] not in self.WrongAnswers:
self.WrongAnswers.append(data["submittedanswer"]) #add user's incorrect answer to WrongAnswers
if data["submittedanswer"] not in self.hints:
self.hints[data["submittedanswer"]] = Dict{} #add user's incorrect answer to WrongAnswers
for key in self.hints:
if key == data["submittedanswer"]:
for y in self.hints[key]:
self.HintsToUse[y] += self.hints[key[y]] #If the user's incorrect answre has precedence in hints, add hints listed under
if len(self.HintsToUse) < 2: #incorrect answer to HintsToUse
self.HintsToUse.update(self.DefaultHints) #Use DefaultHints if there aren't enough other hints
else:
self.HintsToUse = self.DefaultHints.copy()
if len(self.WrongAnswers) == 1:
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]}
else:
NotUsed = random.choice(self.HintsToUse.keys())
if len(NotUsed) != len(self.Used):
while NotUsed in self.Used:
NotUsed = random.choice(self.HintsToUse.keys()) #Choose random hint that hasn't already been Used
self.Used.append(NotUsed)
return {'HintsToUse': NotUsed} #note to self dont let python get into endless notused loop
@XBlock.json_handler
def get_feedback(self, data, suffix=''): #feedback, either rating or making a hint, starts here
if len(self.WrongAnswers) == 0:
return #Do nothing if no mistakes were made
else: #lenth of Used will be used to dictate flow of feedback
return {'lenused': int(len(self.Used))}
@XBlock.json_handler #add 1 or -1 to rating of a hint
def rate_hint(self, data, suffix=''):
for key in self.hints: #rating for hints in hints dictionary
if key == self.WrongAnswers[data['ansnum']]:
for y in self.hints[self.WrongAnswers[data['ansnum']]]: #ansnum represents which hint/
if y == self.Used[data['ansnum']]: #answer pair is being rated
self.hints[self.WrongAnswers[data['ansnum']][y]] += int(data["rating"])#0 is first hint/answer
for key in self.DefaultHints:
if key == self.Used[data['ansnum']]: #rating for hints in DefaultHints
self.DefaultHints[key] += int(data["rating"])
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}#
@XBlock.json_handler
def get_data(self, data, suffix=''): #pass hint/answer text to js to see in html
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
@XBlock.json_handler
def give_hint(self, data, suffix=''): #add student-made hint into hints
for key in self.hints:
if key == self.WrongAnswers[data['ansnum']]:
for y in self.hints[self.WrongAnswers[data['ansnum']]]:
if y == data['submission']: #if the exact hint already exists, +1 rate
self.hints[self.WrongAnswers[data['ansnum']][y]] += int(data["rating"])
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
else:
self.hints[key[data['submission']]] = 0 #add with default rating of 0
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
return {'wngans': self.WrongAnswers[data["ansnum"]], 'hntusd': self.Used[data["ansnum"]]}
@staticmethod
def workbench_scenarios():
"""A canned scenario for display in the workbench."""
return [
("CrowdXBlock",
"""<vertical_demo>
<crowdxblock/>
</vertical_demo>
"""),
]
This static directory is for files that should be included in your kit as plain
static files.
You can ask the runtime for a URL that will retrieve these files with:
url = self.runtime.local_resource_url(self, "static/js/lib.js")
The default implementation is very strict though, and will not serve files from
the static directory. It will serve files from a directory named "public".
Create a directory alongside this one named "public", and put files there.
Then you can get a url with code like this:
url = self.runtime.local_resource_url(self, "public/js/lib.js")
The sample code includes a function you can use to read the content of files
in the static directory, like this:
frag.add_javascript(self.resource_string("static/js/my_block.js"))
/* CSS for CrowdXBlock */
.crowdxblock_block .count {
font-weight: bold;
}
.crowdxblock_block p {
cursor: pointer;
}
.crowdxblock_block .crowdsource-wrapper {
box-shadow: inset 0 1px 2px 1px rgba(0,0,0,0.1);
border-radius: 2px;
display: none;
margin-top: 20px;
padding: (15px);
background: rgb(253, 248, 235);
}
.crowdxblock_block .hint-inner-container {
padding-left: 15px;
padding-right: 15px;
font-size: 16px;
}
.crowdxblock_block .vote {
padding-top: 0px !important;
padding-bottom: 0px !important;
}
/* CSS for CrowdXBlock */
/*
.crowdxblock_block .count {
font-weight: bold;
}
.crowdxblock_block p {
cursor: pointer;
}
.crowdxblock_block .crowdsource-wrapper {
box-shadow: inset 0 1px 2px 1px rgba(0,0,0,0.1);
border-radius: 2px;
display: none;
margin-top: 20px;
padding: (15px);
background: rgb(253, 248, 235);
}
.crowdxblock_block .hint-inner-container {
padding-left: 15px;
padding-right: 15px;
font-size: 16px;
}
.crowdxblock_block .vote {
padding-top: 0px !important;
padding-bottom: 0px !important;
}
<div class="crowdxblock_block"> <!--most stuff just for testing purposes-->
<p>CrowdXBlock: hints here? <span class='HintsToUse'>{self.HintsToUse}</span>
</p>
</div>
<div class="crowdxblock_block">
<p>CrowdXBlock: Your last answer:
</p>
<h2 class="problem-header">
Numerical Input
</h2>
<section class="correct"></section>
<p>
<span class='Thankyou'></span>
</p>
<p>
<span class='WrongAnswer'></span>
</p>
<p>
<span class='HintUsed'></span>
</p>
<section class="solution-span"><span id="solution_i4x-Me-19_002-problem-Numerical_Input_solution_1"></span></section></div>
<section class="action">
<input type="hidden" name="problem_id" value="Numerical Input">
<input id="upvote" type="button" value="Upvote">
<input id="downvote" type="button" value="Downvote">
<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" value="Submit Hint">
</div></section></span>
</section>
</section>
</section>
</section>
<div class="crowdxblock_block"> <!--most stuff just for testing purposes-->
<p>CrowdXBlock: hints here? <span class='HintsToUse'>{self.HintsToUse}</span>
</p>
</div>
<div class="crowdxblock_block">
<p>CrowdXBlock: Your last answer:
</p>
<h2 class="problem-header">
Numerical Input
</h2>
<section class="correct"></section>
<p>
<span class='Thankyou'></span>
</p>
<p>
<span class='WrongAnswer'></span>
</p>
<p>
<span class='HintUsed'></span>
</p>
<section class="solution-span"><span id="solution_i4x-Me-19_002-problem-Numerical_Input_solution_1"></span></section></div>
<section class="action">
<input type="hidden" name="problem_id" value="Numerical Input">
<input id="upvote" type="button" value="Upvote">
<input id="downvote" type="button" value="Downvote">
<section class="problem">
<span><br><span> I'm sure something will go here.</span></span>
<section id="studentinput" class="textinput">
<input type="text" name="studentinput" id="answer" class="math" size="40">
<input id="submit" type="button" value="Submit Hint">
</div></section></span>
</section>
</section>
</section>
</section>
/*
function updateCount(result) {
$('.count', element).text(result.count);
}
function checktheanswer(result) {
// capture the information from server and render your screen to show the submission result
$('.studentanswer', element).text(result.studentanswer);
}
var handlerUrl = runtime.handlerUrl(element, 'increment_count');
var handlerUrlcheck = runtime.handlerUrl(element, 'checkanswer');
$('#check').click(function(eventObject) {
capture what the user types
$.ajax({
type: "POST",
url: handlerUrlcheck,
data: JSON.stringify({"submittedanswer": $('#answer').val()}),
success: checktheanswer
});
$.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({"hello": "world"}), // pass what user types to server
success: updateCount
});
});
*/
//my coding attemps start here i guess
/*this.url = this.el.data('url');
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();*/
/*function capture_problem(event_type, data, element) {
var answers, response,
_this = this;
answers = data[0];
response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){
var a = 0 //test
var howmany = 0.0;
var whichanswer = 0.0;
var WrongAnswer = [];
var HintUsed = [];
function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
}
function getfeedback(result){
howmany = result;
console.log(howmany);
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_data'),
data: JSON.stringify({"ansnum": whichanswer}),
success: morefeedback
});
}
function morefeedback(result){
if(whichanswer != (howmany - 1)){
whichanswer += 1;
}
console.log(howmany);
console.log(whichanswer);
$('.WrongAnswer', element).text("For your incorrect answer of: " + result.wngans);
$('.HintUsed', element).text("You recieved the hint: " + result.hntusd);
$('.Thankyou', element).text("Thankyou for your help!");
}
$('#upvote', element).click(function(eventObject) {
if(whichanswer != howmany){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": whichanswer}), //return answer data to py /*answers*/
success: morefeedback
});} else{
$('.WrongAnswer', element).text();
$('.HintUsed', element).text();
$('.Thankyou', element).text("You're all done.");}
})
$('#downvote', element).click(function(eventObject) {
if(whichanswer != howmany){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": -1, "ansnum": whichanswer}), //return answer data to py /*answers*/
success: morefeedback
});} else{
$('.WrongAnswer', element).text();
$('.HintUsed', element).text();
$('.Thankyou', element).text("You're all done.");}
})
$('#submit', element).click(function(eventObject) {
if(whichanswer != howmany){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('#answer').val(), "ansnum": whichanswer}), //return answer data to py /*answers*/
success: morefeedback
});} else{
$('.WrongAnswer', element).text();
$('.HintUsed', element).text();
$('.Thankyou', element).text("You're all done.");}
})
$('p', element).click(function(eventObject) { //for test
a += 1
if (a != 5) { //when answer is incorrect /*response.search(/class="correct/) === -1*/
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": a}), //return student's incorrect answer here
success: seehint
});
} else { //answer is correct
$('.correct', element).text("You're correct.");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
};
}
)}
/*
function updateCount(result) {
$('.count', element).text(result.count);
}
function checktheanswer(result) {
// capture the information from server and render your screen to show the submission result
$('.studentanswer', element).text(result.studentanswer);
}
var handlerUrl = runtime.handlerUrl(element, 'increment_count');
var handlerUrlcheck = runtime.handlerUrl(element, 'checkanswer');
$('#check').click(function(eventObject) {
capture what the user types
$.ajax({
type: "POST",
url: handlerUrlcheck,
data: JSON.stringify({"submittedanswer": $('#answer').val()}),
success: checktheanswer
});
$.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({"hello": "world"}), // pass what user types to server
success: updateCount
});
});
*/
//my coding attemps start here i guess
/*this.url = this.el.data('url');
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();*/
/*function capture_problem(event_type, data, element) {
var answers, response,
_this = this;
answers = data[0];
response = data[1];*/ //use this snippet for actual code? maybe?
function CrowdXBlock(runtime, element){
var a = 0 //test
var howmany = 0.0;
var whichanswer = 0.0;
var WrongAnswer = [];
var HintUsed = [];
function seehint(result){//use html to show these results somewhere i guess
$('.HintsToUse', element).text(result.HintsToUse); //text(result.self.hints?)
}
function getfeedback(result){
howmany = result;
console.log(howmany);
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_data'),
data: JSON.stringify({"ansnum": whichanswer}),
success: morefeedback
});
}
function morefeedback(result){
if(whichanswer != (howmany - 1){
whichanswer += 1;
}
console.log(howmany);
console.log(whichanswer);
$('.WrongAnswer', element).text("For your incorrect answer of: " + result.wngans);
$('.HintUsed', element).text("You recieved the hint: " + result.hntusd);
$('.Thankyou', element).text("Thankyou for your help!");
}
$('#upvote', element).click(function(eventObject) {
if(whichanswer != howmany){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": 1, "ansnum": whichanswer}), //return answer data to py /*answers*/
success: morefeedback
});} else{
$('.WrongAnswer', element).text();
$('.HintUsed', element).text();
$('.Thankyou', element).text("You're all done.");}
})
$('#downvote', element).click(function(eventObject) {
if(whichanswer != howmany){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'rate_hint'),
data: JSON.stringify({"rating": -1, "ansnum": whichanswer}), //return answer data to py /*answers*/
success: morefeedback
});} else{
$('.WrongAnswer', element).text();
$('.HintUsed', element).text();
$('.Thankyou', element).text("You're all done.");}
})
$('#submit', element).click(function(eventObject) {
if(whichanswer != howmany){
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'give_hint'),
data: JSON.stringify({"submission": $('#answer').val(), "ansnum": whichanswer}), //return answer data to py /*answers*/
success: morefeedback
});} else{
$('.WrongAnswer', element).text();
$('.HintUsed', element).text();
$('.Thankyou', element).text("You're all done.");}
})
$('p', element).click(function(eventObject) { //for test
a += 1
if (a != 5) { //when answer is incorrect /*response.search(/class="correct/) === -1*/
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_hint'),
data: JSON.stringify({"submittedanswer": a}), //return student's incorrect answer here
success: seehint
});
} else { //answer is correct
$('.correct', element).text("You're correct.");
$.ajax({
type: "POST",
url: runtime.handlerUrl(element, 'get_feedback'),
data: JSON.stringify({"hello": "world"}),
success: getfeedback
});
};
}
)}
/* Javascript for CrowdXBlock. */
function CrowdXBlock(runtime, element) {
function Hinter(element) {
var _this = this;
this.set_bottom_links = function() {
return Hinter.prototype.set_bottom_links.apply(_this, arguments);
};
this.answer_choice_handle = function(eventObj) {
return Hinter.prototype.answer_choice_handle.apply(_this, arguments);
};
this.wizard_link_handle = function(eventObj) {
return Hinter.prototype.wizard_link_handle.apply(_this, arguments);
};
this.clear_default_text = function(eventObj) {
return Hinter.prototype.clear_default_text.apply(_this, arguments);
};
this.submit_hint = function(eventObj) {
return Hinter.prototype.submit_hint.apply(_this, arguments);
};
this.vote = function(eventObj) {
return Hinter.prototype.vote.apply(_this, arguments);
};
this.expand = function(eventObj) {
return Hinter.prototype.expand.apply(_this, arguments);
};
this.bind = function() {
return Hinter.prototype.bind.apply(_this, arguments);
};
this.capture_problem = function(event_type, data, element) {
return Hinter.prototype.capture_problem.apply(_this, arguments);
};
this.el = $(element).find('.crowdsource-wrapper');
this.url = this.el.data('url');
Logger.listen('problem_graded', this.el.data('child-id'), this.capture_problem);
this.render();
}
Hinter.prototype.capture_problem = function(event_type, data, element) {
var answers, response,
_this = this;
answers = data[0];
response = data[1];
if (response.search(/class="correct/) === -1) {
return $.postWithPrefix("" + this.url + "/get_hint", answers, function(response) {
return _this.render(response.contents);
});
} else {
return $.postWithPrefix("" + this.url + "/get_feedback", answers, function(response) {
return _this.render(response.contents);
});
}
};
Hinter.prototype.$ = function(selector) {
return $(selector, this.el);
};
Hinter.prototype.bind = function() {
this.$('input.vote').click(this.vote);
this.$('input.submit-hint').click(this.submit_hint);
this.$('.custom-hint').click(this.clear_default_text);
this.$('.expand').click(this.expand);
this.$('.wizard-link').click(this.wizard_link_handle);
return this.$('.answer-choice').click(this.answer_choice_handle);
};
Hinter.prototype.expand = function(eventObj) {
var target;
target = this.$('#' + this.$(eventObj.currentTarget).data('target'));
if (this.$(target).css('crowdxblock') === 'none') {
this.$(target).css('crowdxblock', 'block');
} else {
this.$(target).css('crowdxblock', 'none');
}
return this.set_bottom_links();
};
Hinter.prototype.submit_hint = function(eventObj) {
var post_json, textarea,
_this = this;
textarea = $('.custom-hint');f
if (this.answer === '') {
return;
}
post_json = {
'answer': this.answer,
'hint': textarea.val()
};
var post_json = {}
post_json['answer'] = this.answer;
post_json[]
JSON.stringify(post_json)
return $.postWithPrefix("" + this.url + "/submit_hint", post_json, function(response) {
return _this.render(response.contents);
});
};
/* $.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({"hello": "world"}),
success: updateCount
});*/
Hinter.prototype.clear_default_text = function(eventObj) {
var target;
target = this.$(eventObj.currentTarget);
if (target.data('cleared') === void 0) {
target.val('');
return target.data('cleared', true);
}
};
Hinter.prototype.wizard_link_handle = function(eventObj) {
var target;
target = this.$(eventObj.currentTarget);
return this.go_to(target.attr('dest'));
};
Hinter.prototype.answer_choice_handle = function(eventObj) {
this.answer = this.$(eventObj.target).attr('value');
this.$('#blank-answer').html(this.answer);
return this.go_to('p3');
};
Hinter.prototype.set_bottom_links = function() {
var viewbox_height;
this.$('.bottom').css('margin-top', '0px');
viewbox_height = parseInt(this.$('.wizard-viewbox').css('height'), 10);
return this.$('.bottom').each(function(index, obj) {
var view_height;
view_height = parseInt($(obj).parent().css('height'), 10);
return $(obj).css('margin-top', (viewbox_height - view_height) + 'px');
});
};
Hinter.prototype.render = function(content) {
var hints_exist, styles,
_this = this;
if (content) {
content = content.trim();
}
if (content) {
this.el.html(content);
this.el.show();
JavascriptLoader.executeModuleScripts(this.el, function() {
return _this.bind();
});
this.$('#previous-answer-0').css('crowdxblock', 'inline');
} else {
this.el.hide();
}
this.answer = '';
styles = document.body.style;
if (styles.WebkitTransform === '' || styles.transform === '') {
this.go_to = this.transform_go_to;
} else {
this.go_to = this.legacy_go_to;
}
hints_exist = this.$('#hints-exist').html() === 'True';
if (hints_exist) {
return this.go_to('p1');
} else {
return this.go_to('p2');
}
};
Hinter.prototype.transform_go_to = function(view_id) {
var id_to_index, translate_string;
id_to_index = {
'p1': 0,
'p2': 1,
'p3': 2
};
translate_string = 'translateX(' + id_to_index[view_id] * -1 * parseInt($('#' + view_id).css('width'), 10) + 'px)';
this.$('.wizard-container').css('transform', translate_string);
this.$('.wizard-container').css('-webkit-transform', translate_string);
return this.set_bottom_links();
};
Hinter.prototype.legacy_go_to = function(view_id) {
this.$('.wizard-view').css('display', 'none');
this.$('#' + view_id).css('display', 'block');
return this.set_bottom_links();
};
return Hinter;
})();
}).call(this);
/*
function updateCount(result) {
$('.count', element).text(result.count);
}
function checktheanswer(result) {
// capture the information from server and render your screen to show the submission result
$('.studentanswer', element).text(result.studentanswer);
}
var handlerUrl = runtime.handlerUrl(element, 'increment_count');
var handlerUrlcheck = runtime.handlerUrl(element, 'checkanswer');
$('#check').click(function(eventObject) {
capture what the user types
$.ajax({
type: "POST",
url: handlerUrlcheck,
data: JSON.stringify({"submittedanswer": $('#answer').val()}),
success: checktheanswer
});
$.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({"hello": "world"}), // pass what user types to server
success: updateCount
});
});
*/
Metadata-Version: 1.0
Name: crowdxblock-xblock
Version: 0.1
Summary: crowdxblock XBlock
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
crowdxblock/__init__.py
crowdxblock/crowdxblock.py
crowdxblock/static/README.txt
crowdxblock/static/css/crowdxblock.css
crowdxblock/static/html/crowdxblock.html
crowdxblock/static/js/src/crowdxblock.js
crowdxblock_xblock.egg-info/PKG-INFO
crowdxblock_xblock.egg-info/SOURCES.txt
crowdxblock_xblock.egg-info/dependency_links.txt
crowdxblock_xblock.egg-info/entry_points.txt
crowdxblock_xblock.egg-info/requires.txt
crowdxblock_xblock.egg-info/top_level.txt
\ No newline at end of file
[xblock.v1]
crowdxblock = crowdxblock:CrowdXBlock
XBlock
\ No newline at end of file
"""Setup for crowdxblock XBlock."""
import os
from setuptools import setup
def package_data(pkg, roots):
"""Generic function to find package_data.
All of the files under each of the `roots` will be declared as package
data for package `pkg`.
"""
data = []
for root in roots:
for dirname, _, files in os.walk(os.path.join(pkg, root)):
for fname in files:
data.append(os.path.relpath(os.path.join(dirname, fname), pkg))
return {pkg: data}
setup(
name='crowdxblock-xblock',
version='0.1',
description='crowdxblock XBlock', # TODO: write a better description.
packages=[
'crowdxblock',
],
install_requires=[
'XBlock',
],
entry_points={
'xblock.v1': [
'crowdxblock = crowdxblock:CrowdXBlock',
]
},
package_data=package_data("crowdxblock", ["static", "public"]),
)
\ No newline at end of file
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