Commit e5f69ce6 by swdanielli

Merge pull request #23 from pmitros/danielli/studio_view

studio view
parents 1ee30f35 e162844d
......@@ -185,7 +185,7 @@ class RecommenderXBlock(XBlock):
'ENTRIES_PER_PAGE': 5,
'PAGE_SPAN': 2
},
scope=Scope.user_state_summary
scope=Scope.content
)
# A dict of parameters for client side initial setting
......@@ -254,8 +254,8 @@ class RecommenderXBlock(XBlock):
DISABLE_DEV_UX: whether to disable the UX under development
CURRENT_PAGE: the default page of resources showed to students
ENTRIES_PER_PAGE: the number of resources in each page
PAGE_SPAN: the number of previous and following pages showed in the pagination item
INTRO: whether to show intro.js
PAGE_SPAN: page range in pagination control
INTRO: whether to take users on a little tour when they see the RecommenderXBlock first time
IS_USER_STAFF: whether the user is staff
"""
result = {}
......@@ -267,6 +267,34 @@ class RecommenderXBlock(XBlock):
return result
@XBlock.json_handler
def set_client_side_settings(self, data, _suffix=''):
"""
Set the parameters for student-view, client side configurations.
Args:
data: dict in JSON format
data['DISABLE_DEV_UX']: whether to disable the UX under development
data['ENTRIES_PER_PAGE']: the number of resources in each page
data['PAGE_SPAN']: page range in pagination control
data['INTRO']: whether to take users on a little tour when they see the RecommenderXBlock first time
"""
if data['DISABLE_DEV_UX'].lower() == 'false':
self.client_side_settings['DISABLE_DEV_UX'] = False
else:
self.client_side_settings['DISABLE_DEV_UX'] = True
if data['INTRO'].lower() == 'false':
self.intro_enabled = False
else:
self.intro_enabled = True
for key in ['PAGE_SPAN', 'ENTRIES_PER_PAGE']:
self.client_side_settings[key] = int(data[key])
tracker.emit('set_client_side_settings', data)
return {'Success': True}
@XBlock.json_handler
def handle_vote(self, data, _suffix=''):
"""
Add/Subtract one vote to an entry of resource.
......@@ -850,6 +878,10 @@ class RecommenderXBlock(XBlock):
"recommenderstudio.html",
self.resource_string("static/html/recommenderstudio.html"))
frag = Fragment(self.template_lookup.get_template("recommenderstudio.html").render())
frag.add_css(pkg_resources.resource_string(__name__, "static/css/recommenderstudio.css"))
frag.add_javascript_url("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js")
frag.add_javascript(pkg_resources.resource_string(__name__, "static/js/src/recommenderstudio.js"))
frag.initialize_js('RecommenderXBlock')
return frag
@staticmethod
......
/* CSS for studio view of RecommenderXBlock */
.clearFix {clear: both; height: 0.5em;}
.recommenderModifyTitleContainer {
font-size: 14px;
padding-top: 0.5em;
padding-left: 0.5em;
background-color: rgba(0,0,0,0.05);
height: 28px;
color: #948f8f;
}
.recommenderModify {
width: 700px;
}
.recommenderModifyTitle { float: right; padding-right: 2em; overflow: auto; }
.setRecommenderConfig, .setRecommenderConfigTitle {
padding-left: 1em;
}
.configSubmit { margin-top: 0.5em; }
<div class="recommenderBlock">
<div class='recommenderModify'>
<div class='recommenderModifyTitleContainer'>
<div class='recommenderModifyTitle'>Configuration setting</div>
</div>
<div class="setRecommenderConfig">
<div class="setRecommenderConfigTitle">Set the student-view, client side configurations for RecommenderXblock.</div>
<div class="config">
<select name='introEnable' class='introEnable'><option value='true'>Yes</option><option value='false'>No</option></select>
<span>Do you want to take users on a little tour when they see the RecommenderXBlock first time?</span>
</div>
<div class="config">
<select name='developedUXDisable' class='developedUXDisable'><option value='true'>Yes</option><option value='false'>No</option></select>
<span>Do you want to disable the UX functions which are under development?</span>
</div>
<div class="config">
<select name='entriesPerPage' class='entriesPerPage'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option selected='selected' value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
</select>
<span>How many resources you want to show in each page of the resource list?</span>
</div>
<div class="config">
<select name='pageSpan' class='pageSpan'>
<option value='1'>1</option>
<option selected='selected' value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>
<span>How many page icons in pagination control (i.e., page range)? The icons for pages from (current page - page range) to (current page + page range) will be shown.</span>
</div>
<input type="button" value="Set configurations" class="configSubmit"/>
</div>
</div>
</div>
</div>
function RecommenderXBlock(runtime, element) {
/* Grab URLs from server */
var setConfigUrl = runtime.handlerUrl(element, 'set_client_side_settings');
/**
* Bind the event for setting the student-view, client side configurations.
*/
function bindConfigSettingEvent() {
$('.configSubmit').click(function() {
var data = {};
data['DISABLE_DEV_UX'] = $('.developedUXDisable').val();
data['ENTRIES_PER_PAGE'] = $('.entriesPerPage').val();
data['PAGE_SPAN'] = $('.pageSpan').val();
data['INTRO'] = $('.introEnable').val();
$.ajax({
type: "POST",
url: setConfigUrl,
data: JSON.stringify(data),
success: function(result) {
if (result['Success'] == true) { alert('The configurations have been updated'); }
}
});
});
}
bindConfigSettingEvent();
}
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