Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
5ef584a3
Commit
5ef584a3
authored
Feb 08, 2013
by
Valera Rozuvan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added client side check for current state on Poll initialization.
parent
d95052e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
40 deletions
+70
-40
common/lib/xmodule/xmodule/js/src/poll/poll_main.js
+70
-40
No files found.
common/lib/xmodule/xmodule/js/src/poll/poll_main.js
View file @
5ef584a3
...
@@ -125,6 +125,17 @@ PollMain.prototype = {
...
@@ -125,6 +125,17 @@ PollMain.prototype = {
_this
.
showAnswerGraph
(
response
.
poll_answers
,
response
.
total
);
_this
.
showAnswerGraph
(
response
.
poll_answers
,
response
.
total
);
_this
.
jsonConfig
.
poll_answer
=
answer
;
_this
.
jsonConfig
.
total
=
response
.
total
;
$
.
each
(
response
.
poll_answers
,
function
(
index
,
value
)
{
_this
.
jsonConfig
.
poll_answers
[
index
]
=
value
;
});
logme
(
'Current "jsonConfig": '
);
logme
(
_this
.
jsonConfig
);
_this
.
questionEl
.
children
(
'.poll_question_div'
).
html
(
JSON
.
stringify
(
_this
.
jsonConfig
));
/*
/*
_this.vertModEl.find('.xmodule_ConditionalModule').each(
_this.vertModEl.find('.xmodule_ConditionalModule').each(
function (index, value) {
function (index, value) {
...
@@ -135,7 +146,56 @@ PollMain.prototype = {
...
@@ -135,7 +146,56 @@ PollMain.prototype = {
}
}
);
);
}
}
}
// End-of: 'submitAnswer': function (answer, answerEl) {
},
// End-of: 'submitAnswer': function (answer, answerEl) {
'postInit'
:
function
()
{
var
_this
;
// Access this object inside inner functions.
_this
=
this
;
// Get the DOM id of the question.
this
.
id
=
this
.
questionEl
.
attr
(
'id'
);
// Get the URL to which we will post the users answer to the question.
this
.
ajax_url
=
this
.
questionEl
.
data
(
'ajax-url'
);
this
.
questionHtmlMarkup
=
$
(
'<div />'
).
html
(
this
.
jsonConfig
.
question
).
text
();
this
.
questionEl
.
append
(
this
.
questionHtmlMarkup
);
// When the user selects and answer, we will set this flag to true.
this
.
questionAnswered
=
false
;
logme
(
'this.jsonConfig.answers: '
,
this
.
jsonConfig
.
answers
);
logme
(
'this.jsonConfig.poll_answer: '
,
this
.
jsonConfig
.
poll_answer
);
$
.
each
(
this
.
jsonConfig
.
answers
,
function
(
index
,
value
)
{
var
answerEl
;
answerEl
=
$
(
'<div class="poll_answer">'
+
value
+
'</li>'
);
answerEl
.
on
(
'click'
,
function
()
{
_this
.
submitAnswer
(
index
,
answerEl
);
});
if
(
index
===
_this
.
jsonConfig
.
poll_answer
)
{
answerEl
.
addClass
(
'answered'
);
_this
.
questionAnswered
=
true
;
}
answerEl
.
appendTo
(
_this
.
questionEl
);
});
this
.
graphAnswerEl
=
$
(
'<div class="graph_answer"></div>'
);
this
.
graphAnswerEl
.
hide
();
this
.
graphAnswerEl
.
appendTo
(
this
.
questionEl
);
logme
(
'PollMain object: '
,
this
);
// If it turns out that the user already answered the question, show the answers graph.
if
(
this
.
questionAnswered
===
true
)
{
this
.
showAnswerGraph
(
this
.
jsonConfig
.
poll_answers
,
this
.
jsonConfig
.
total
);
}
}
// End-of: 'postInit': function () {
};
// End-of: PollMain.prototype = {
};
// End-of: PollMain.prototype = {
return
PollMain
;
return
PollMain
;
...
@@ -227,6 +287,8 @@ function PollMain(el) {
...
@@ -227,6 +287,8 @@ function PollMain(el) {
"three of them to kill and eat the cabin boy, in order to save their own lives?</p>"
"three of them to kill and eat the cabin boy, in order to save their own lives?</p>"
};
};
}
}
_this
.
postInit
();
}());
}());
}
else
{
}
else
{
try
{
try
{
...
@@ -253,47 +315,15 @@ function PollMain(el) {
...
@@ -253,47 +315,15 @@ function PollMain(el) {
return
;
return
;
}
}
// Get the DOM id of the question.
$
.
postWithPrefix
(
this
.
id
=
this
.
questionEl
.
attr
(
'id'
);
_this
.
ajax_url
+
'/'
+
'get_state'
,
{},
function
(
response
)
{
// Get the URL to which we will post the users answer to the question.
logme
(
'Get pre init state.'
);
this
.
ajax_url
=
this
.
questionEl
.
data
(
'ajax-url'
);
logme
(
'response:'
,
response
);
this
.
questionHtmlMarkup
=
$
(
'<div />'
).
html
(
this
.
jsonConfig
.
question
).
text
();
_this
.
postInit
();
this
.
questionEl
.
append
(
this
.
questionHtmlMarkup
);
// When the user selects and answer, we will set this flag to true.
this
.
questionAnswered
=
false
;
logme
(
'this.jsonConfig.answers: '
,
this
.
jsonConfig
.
answers
);
logme
(
'this.jsonConfig.poll_answer: '
,
this
.
jsonConfig
.
poll_answer
);
$
.
each
(
this
.
jsonConfig
.
answers
,
function
(
index
,
value
)
{
var
answerEl
;
answerEl
=
$
(
'<div class="poll_answer">'
+
value
+
'</li>'
);
answerEl
.
on
(
'click'
,
function
()
{
_this
.
submitAnswer
(
index
,
answerEl
);
});
if
(
index
===
_this
.
jsonConfig
.
poll_answer
)
{
answerEl
.
addClass
(
'answered'
);
_this
.
questionAnswered
=
true
;
}
}
);
answerEl
.
appendTo
(
_this
.
questionEl
);
});
this
.
graphAnswerEl
=
$
(
'<div class="graph_answer"></div>'
);
this
.
graphAnswerEl
.
hide
();
this
.
graphAnswerEl
.
appendTo
(
this
.
questionEl
);
logme
(
'PollMain object: '
,
this
);
// If it turns out that the user already answered the question, show the answers graph.
if
(
this
.
questionAnswered
===
true
)
{
this
.
showAnswerGraph
(
this
.
jsonConfig
.
poll_answers
,
this
.
jsonConfig
.
total
);
}
}
// End-of: function PollMain(el) {
}
// End-of: function PollMain(el) {
});
// End-of: define('PollMain', ['logme'], function (logme) {
});
// End-of: define('PollMain', ['logme'], function (logme) {
...
...
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