Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xblock-poll
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
xblock-poll
Commits
e7a6c95c
Commit
e7a6c95c
authored
Aug 19, 2015
by
Eugeny Kolpakov
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6 from open-craft/edx-release
Edx release
parents
66006d1f
4af6218b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
147 additions
and
116 deletions
+147
-116
poll/poll.py
+14
-0
poll/public/css/poll.css
+4
-0
poll/public/html/poll.html
+41
-42
poll/public/html/survey.html
+51
-52
poll/public/js/poll.js
+32
-18
poll/public/js/poll_edit.js
+5
-4
No files found.
poll/poll.py
View file @
e7a6c95c
...
...
@@ -519,6 +519,13 @@ class PollBlock(PollBase):
return
result
@XBlock.json_handler
def
student_voted
(
self
,
data
,
suffix
=
''
):
return
{
'voted'
:
self
.
get_choice
()
is
not
None
,
'private_results'
:
self
.
private_results
}
@staticmethod
def
workbench_scenarios
():
"""
...
...
@@ -876,6 +883,13 @@ class SurveyBlock(PollBase):
return
result
@XBlock.json_handler
def
student_voted
(
self
,
data
,
suffix
=
''
):
return
{
'voted'
:
self
.
get_choices
()
is
not
None
,
'private_results'
:
self
.
private_results
}
@staticmethod
def
workbench_scenarios
():
"""
...
...
poll/public/css/poll.css
View file @
e7a6c95c
...
...
@@ -216,3 +216,7 @@ th.survey-answer {
text-align
:
right
;
cursor
:
pointer
;
}
.poll-block-form-wrapper
{
display
:
none
;
}
poll/public/html/poll.html
View file @
e7a6c95c
{{ js_template|safe }}
<div
class=
"poll-block themed-xblock"
data-private=
"{% if private_results %}1{% endif %}"
data-can-vote=
"{% if can_vote %}1{% endif %}"
>
{# If no form is present, the Javascript will load the results instead. #}
{% if private_results or not choice %}
<h3
class=
"poll-header"
>
{{display_name}}
</h3>
<form>
<div
class=
"poll-question-container"
>
{{question|safe}}
</div>
<ul
class=
"poll-answers"
>
{% for key, value in answers %}
<li
class=
"poll-answer"
>
<input
type=
"radio"
name=
"choice"
id=
"{{url_name}}-answer-{{key}}"
value=
"{{key}}"
{%
if
choice =
=
key
%}
checked
{%
endif
%}
/>
{% if value.img %}
<div
class=
"poll-image"
>
<label
for=
"{{url_name}}-answer-{{key}}"
class=
"poll-image-label"
>
<img
src=
"{{value.img}}"
alt=
"{{value.img_alt|default_if_none:''}}"
/>
</label>
</div>
{% endif %}
<label
class=
"poll-answer"
for=
"{{url_name}}-answer-{{key}}"
>
{{value.label|safe}}
</label>
</li>
{% endfor %}
</ul>
<input
class=
"input-main"
type=
"button"
name=
"poll-submit"
value=
"{% if choice %}Resubmit{% else %}Submit{% endif %}"
disabled
/>
</form>
<div
class=
"poll-voting-thanks{% if not choice or can_vote %} poll-hidden{% endif %}"
><span>
Thank you for your submission!
</span></div>
<div
class=
"poll-submissions-count poll-hidden"
>
You have used
<span
class=
"poll-current-count"
>
{{ submissions_count }}
</span>
out of
<span
class=
"poll-max-submissions"
>
{{ max_submissions }}
</span>
submissions.
</div>
{% if feedback %}
<div
class=
"poll-feedback-container{% if not choice %} poll-hidden{% endif %}"
>
<hr
/>
<h3
class=
"poll-header"
>
Feedback
</h3>
<div
class=
"poll-feedback"
>
{{feedback|safe}}
</div>
</div>
{% endif %}
<div
class=
"poll-block-form-wrapper"
>
<h3
class=
"poll-header"
>
{{display_name}}
</h3>
<form>
<div
class=
"poll-question-container"
>
{{question|safe}}
</div>
<ul
class=
"poll-answers"
>
{% for key, value in answers %}
<li
class=
"poll-answer"
>
<input
type=
"radio"
name=
"choice"
id=
"{{url_name}}-answer-{{key}}"
value=
"{{key}}"
{%
if
choice =
=
key
%}
checked
{%
endif
%}
/>
{% if value.img %}
<div
class=
"poll-image"
>
<label
for=
"{{url_name}}-answer-{{key}}"
class=
"poll-image-label"
>
<img
src=
"{{value.img}}"
alt=
"{{value.img_alt|default_if_none:''}}"
/>
</label>
</div>
{% endif %}
<label
class=
"poll-answer"
for=
"{{url_name}}-answer-{{key}}"
>
{{value.label|safe}}
</label>
</li>
{% endfor %}
</ul>
<input
class=
"input-main"
type=
"button"
name=
"poll-submit"
value=
"{% if choice %}Resubmit{% else %}Submit{% endif %}"
disabled
/>
</form>
<div
class=
"poll-voting-thanks{% if not choice or can_vote %} poll-hidden{% endif %}"
><span>
Thank you for your submission!
</span></div>
<div
class=
"poll-submissions-count poll-hidden"
>
You have used
<span
class=
"poll-current-count"
>
{{ submissions_count }}
</span>
out of
<span
class=
"poll-max-submissions"
>
{{ max_submissions }}
</span>
submissions.
</div>
{% if feedback %}
<div
class=
"poll-feedback-container{% if not choice %} poll-hidden{% endif %}"
>
<hr
/>
<h3
class=
"poll-header"
>
Feedback
</h3>
<div
class=
"poll-feedback"
>
{{feedback|safe}}
</div>
</div>
{% endif %}
{% if can_view_private_results %}
<div
class=
"view-results-button-wrapper"
><button
class=
"view-results-button"
>
View results
</button></div>
{% endif %}
{% endif %}
{% if can_view_private_results %}
<div
class=
"view-results-button-wrapper"
><button
class=
"view-results-button"
>
View results
</button></div>
{% endif %}
</div>
</div>
poll/public/html/survey.html
View file @
e7a6c95c
{{ js_template|safe }}
<div
class=
"poll-block themed-xblock"
data-private=
"{% if private_results %}1{% endif %}"
data-can-vote=
"{% if can_vote %}1{% endif %}"
>
{# If no form is present, the Javascript will load the results instead. #}
{% if not choices or private_results %}
<h3
class=
"poll-header"
>
{{block_name}}
</h3>
<form>
<table
class=
"survey-table"
>
<thead>
<tr>
<th></th>
{% for answer, label in answers %}
<th
class=
"survey-answer"
>
{{label}}
</th>
{% endfor %}
</tr>
</thead>
{% for key, question in questions %}
<tr
class=
"survey-row"
>
<td
class=
"survey-question"
>
{% if question.img %}
<div
class=
"poll-image-td"
>
<img
src=
"{{question.img}}"
alt=
"{{question.img_alt|default_if_none:''}}"
/>
</div>
{% endif %}
{{question.label|safe}}
</td>
{% for answer, label in answers %}
<td
class=
"survey-option"
>
<label>
<input
type=
"radio"
name=
"{{key}}"
value=
"{{answer}}"
{%
if
question
.
choice =
=
answer
%}
checked
{%
endif
%}
/>
<span
class=
"sr"
>
{{label}}
</span>
</label>
</td>
<div
class=
"poll-block-form-wrapper"
>
<h3
class=
"poll-header"
>
{{block_name}}
</h3>
<form>
<table
class=
"survey-table"
>
<thead>
<tr>
<th></th>
{% for answer, label in answers %}
<th
class=
"survey-answer"
>
{{label}}
</th>
{% endfor %}
</tr>
</thead>
{% for key, question in questions %}
<tr
class=
"survey-row"
>
<td
class=
"survey-question"
>
{% if question.img %}
<div
class=
"poll-image-td"
>
<img
src=
"{{question.img}}"
alt=
"{{question.img_alt|default_if_none:''}}"
/>
</div>
{% endif %}
{{question.label|safe}}
</td>
{% for answer, label in answers %}
<td
class=
"survey-option"
>
<label>
<input
type=
"radio"
name=
"{{key}}"
value=
"{{answer}}"
{%
if
question
.
choice =
=
answer
%}
checked
{%
endif
%}
/>
<span
class=
"sr"
>
{{label}}
</span>
</label>
</td>
{% endfor %}
</tr>
{% endfor %}
</tr>
{% endfor %}
</table>
<input
class=
"input-main"
type=
"button"
name=
"poll-submit"
value=
"{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}"
disabled
/>
</form>
<div
class=
"poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"
><span>
Thank you for your submission!
</span></div>
<div
class=
"poll-submissions-count poll-hidden"
>
You have used
<span
class=
"poll-current-count"
>
{{ submissions_count }}
</span>
out of
<span
class=
"poll-max-submissions"
>
{{ max_submissions }}
</span>
submissions.
</div>
{% if feedback %}
<div
class=
"poll-feedback-container{% if not choices %} poll-hidden{% endif %}"
>
<hr
/>
<h3
class=
"poll-header"
>
Feedback
</h3>
<div
class=
"poll-feedback"
>
{{feedback|safe}}
</div>
</table>
<input
class=
"input-main"
type=
"button"
name=
"poll-submit"
value=
"{% if choices and can_vote %}Resubmit{% else %}Submit{% endif %}"
disabled
/>
</form>
<div
class=
"poll-voting-thanks{% if not choices or can_vote %} poll-hidden{% endif %}"
><span>
Thank you for your submission!
</span></div>
<div
class=
"poll-submissions-count poll-hidden"
>
You have used
<span
class=
"poll-current-count"
>
{{ submissions_count }}
</span>
out of
<span
class=
"poll-max-submissions"
>
{{ max_submissions }}
</span>
submissions.
</div>
{% endif %}
{% if feedback %}
<div
class=
"poll-feedback-container{% if not choices %} poll-hidden{% endif %}"
>
<hr
/>
<h3
class=
"poll-header"
>
Feedback
</h3>
<div
class=
"poll-feedback"
>
{{feedback|safe}}
</div>
</div>
{% endif %}
{% if can_view_private_results %}
<div
class=
"view-results-button-wrapper"
><button
class=
"view-results-button"
>
View results
</button></div>
{% endif %}
{% endif %}
{% if can_view_private_results %}
<div
class=
"view-results-button-wrapper"
><button
class=
"view-results-button"
>
View results
</button></div>
{% endif %}
</div>
</div>
poll/public/js/poll.js
View file @
e7a6c95c
...
...
@@ -7,23 +7,14 @@ function PollUtil (runtime, element, pollType) {
// Initialization function used for both Poll Types
this
.
voteUrl
=
runtime
.
handlerUrl
(
element
,
'vote'
);
this
.
tallyURL
=
runtime
.
handlerUrl
(
element
,
'get_results'
);
this
.
votedUrl
=
runtime
.
handlerUrl
(
element
,
'student_voted'
);
this
.
submit
=
$
(
'input[type=button]'
,
element
);
this
.
answers
=
$
(
'input[type=radio]'
,
element
);
this
.
resultsTemplate
=
Handlebars
.
compile
(
$
(
"#"
+
pollType
+
"-results-template"
,
element
).
html
());
this
.
viewResultsButton
=
$
(
'.view-results-button'
,
element
);
this
.
viewResultsButton
.
click
(
this
.
getResults
);
// If the submit button doesn't exist, the user has already
// selected a choice. Render results instead of initializing machinery.
if
(
!
self
.
submit
.
length
)
{
self
.
onSubmit
({
'success'
:
true
});
return
false
;
}
var
max_submissions
=
parseInt
(
$
(
'.poll-max-submissions'
,
element
).
text
());
var
current_count
=
parseInt
(
$
(
'.poll-current-count'
,
element
).
text
());
if
(
max_submissions
>
1
&&
current_count
>
0
)
{
$
(
'.poll-submissions-count'
,
element
).
show
();
}
return
true
;
return
this
.
shouldDisplayResults
();
};
this
.
pollInit
=
function
(){
...
...
@@ -83,6 +74,16 @@ function PollUtil (runtime, element, pollType) {
self
.
verifyAll
();
};
this
.
shouldDisplayResults
=
function
()
{
return
$
.
ajax
({
// Semantically, this would be better as GET, but we can use helper
// functions with POST.
type
:
"POST"
,
url
:
self
.
votedUrl
,
data
:
JSON
.
stringify
({})
});
};
this
.
surveyChoices
=
function
()
{
// Grabs all selections for survey answers, and returns a mapping for them.
var
choices
=
{};
...
...
@@ -186,12 +187,25 @@ function PollUtil (runtime, element, pollType) {
self
.
answers
.
unbind
(
"change.enableSubmit"
);
};
var
run_init
=
this
.
init
();
if
(
run_init
)
{
var
init_map
=
{
'poll'
:
self
.
pollInit
,
'survey'
:
self
.
surveyInit
};
init_map
[
pollType
]()
}
var
init_map
=
{
'poll'
:
self
.
pollInit
,
'survey'
:
self
.
surveyInit
};
this
.
init
().
done
(
function
(
data
)
{
// If the submit button doesn't exist, the user has already
// selected a choice. Render results instead of initializing machinery.
if
(
data
[
'voted'
]
&&
!
data
[
'private_results'
])
{
self
.
onSubmit
({
'success'
:
true
});
$
(
'.poll-block-form-wrapper'
,
element
).
hide
();
}
else
{
$
(
'.poll-block-form-wrapper'
,
element
).
show
();
var
max_submissions
=
parseInt
(
$
(
'.poll-max-submissions'
,
element
).
text
());
var
current_count
=
parseInt
(
$
(
'.poll-current-count'
,
element
).
text
());
if
(
max_submissions
>
1
&&
current_count
>
0
)
{
$
(
'.poll-submissions-count'
,
element
).
show
();
}
}
}).
always
(
function
(){
init_map
[
pollType
]();
});
}
function
PollBlock
(
runtime
,
element
)
{
...
...
poll/public/js/poll_edit.js
View file @
e7a6c95c
function
PollEditUtil
(
runtime
,
element
,
pollType
)
{
var
self
=
this
;
var
notify
;
...
...
@@ -105,14 +104,15 @@ function PollEditUtil(runtime, element, pollType) {
this
.
empowerArrows
=
function
(
scope
,
topMarker
,
bottomMarker
)
{
// Activates the arrows on rendered line items.
$
(
'.poll-move-up'
,
scope
).
click
(
function
()
{
$
(
'.poll-move-up'
,
scope
).
click
(
function
(
ev
)
{
var
tag
=
$
(
this
).
parents
(
'li'
);
if
(
tag
.
index
()
<=
(
$
(
topMarker
).
index
()
+
1
)){
return
;
}
tag
.
prev
().
before
(
tag
);
tag
.
fadeOut
(
0
).
fadeIn
(
'slow'
,
'swing'
);
self
.
scrollTo
(
tag
)
self
.
scrollTo
(
tag
);
ev
.
preventDefault
();
});
$
(
'.poll-move-down'
,
scope
).
click
(
function
()
{
var
tag
=
$
(
this
).
parents
(
'li'
);
...
...
@@ -121,7 +121,8 @@ function PollEditUtil(runtime, element, pollType) {
}
tag
.
next
().
after
(
tag
);
tag
.
fadeOut
(
0
).
fadeIn
(
'slow'
,
'swing'
);
self
.
scrollTo
(
tag
)
self
.
scrollTo
(
tag
);
ev
.
preventDefault
();
});
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment