Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
RecommenderXBlock
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
RecommenderXBlock
Commits
71a1acd3
Commit
71a1acd3
authored
Jun 19, 2014
by
swdanielli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixing, comment
parent
ff642c83
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
18 deletions
+66
-18
recommender/recommender.py
+4
-4
recommender/static/html/recommender.html
+31
-0
recommender/static/js/src/recommender.js
+31
-14
No files found.
recommender/recommender.py
View file @
71a1acd3
...
@@ -166,10 +166,11 @@ class RecommenderXBlock(XBlock):
...
@@ -166,10 +166,11 @@ class RecommenderXBlock(XBlock):
print
"Edit failed!"
print
"Edit failed!"
return
{
"Success"
:
False
}
return
{
"Success"
:
False
}
# check url for redundancy
# check url for redundancy
recoms
=
self
.
recommendations
for
recom
in
self
.
recommendations
:
for
recom
in
recoms
:
if
self
.
recommendations
[
idx
][
'url'
]
==
data
[
'url'
]:
continue
if
recom
[
'url'
]
==
data
[
'url'
]:
if
recom
[
'url'
]
==
data
[
'url'
]:
print
"
edit to esisting resource
"
print
"
provided url is existing
"
return
{
"Success"
:
False
}
return
{
"Success"
:
False
}
for
key
in
data
:
for
key
in
data
:
...
@@ -216,7 +217,6 @@ class RecommenderXBlock(XBlock):
...
@@ -216,7 +217,6 @@ class RecommenderXBlock(XBlock):
frag
=
Fragment
(
self
.
template_lookup
.
get_template
(
"recommender.html"
)
.
render
(
resources
=
resources
,
upvotes
=
self
.
upvotes
,
downvotes
=
self
.
downvotes
))
frag
=
Fragment
(
self
.
template_lookup
.
get_template
(
"recommender.html"
)
.
render
(
resources
=
resources
,
upvotes
=
self
.
upvotes
,
downvotes
=
self
.
downvotes
))
frag
.
add_css_url
(
"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css"
)
frag
.
add_css_url
(
"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css"
)
frag
.
add_css_url
(
"//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"
)
frag
.
add_javascript_url
(
"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"
)
frag
.
add_javascript_url
(
"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"
)
frag
.
add_css
(
self
.
resource_string
(
"static/css/recommender.css"
))
frag
.
add_css
(
self
.
resource_string
(
"static/css/recommender.css"
))
frag
.
add_javascript
(
self
.
resource_string
(
"static/js/src/recommender.js"
))
frag
.
add_javascript
(
self
.
resource_string
(
"static/js/src/recommender.js"
))
...
...
recommender/static/html/recommender.html
View file @
71a1acd3
...
@@ -176,6 +176,37 @@
...
@@ -176,6 +176,37 @@
.recommender_vote_score.downvoting
,
.recommender_vote_arrow_down.downvoting
{
color
:
red
;
}
.recommender_vote_score.downvoting
,
.recommender_vote_arrow_down.downvoting
{
color
:
red
;
}
.recommender_vote_arrow_up.downvoting
,
.recommender_vote_arrow_down.upvoting
{
color
:
rgb
(
204
,
198
,
198
);
}
.recommender_vote_arrow_up.downvoting
,
.recommender_vote_arrow_down.upvoting
{
color
:
rgb
(
204
,
198
,
198
);
}
/*.tooltip {
display:none;
background-color:#ffa;
border:1px solid #cc9;
padding:3px;
font-size:13px;
-moz-box-shadow: 2px 2px 11px #666;
-webkit-box-shadow: 2px 2px 11px #666;
} */
/*
[title]{
position:relative;
}
[title]:after{
content:attr(title);
color:#fff;
background:#333;
background:rgba(51,51,51,0.75);
padding:5px;
position:absolute;
left:-9999px;
opacity:0;
bottom:100%;
white-space:nowrap;
-webkit-transition:0.25s linear opacity;
}
[title]:hover:after{
left:5px;
opacity:1;
}*/
a
:link
{
color
:
black
;
}
a
:link
{
color
:
black
;
}
form
{
margin
:
0em
;
}
form
{
margin
:
0em
;
}
</style>
</style>
...
...
recommender/static/js/src/recommender.js
View file @
71a1acd3
...
@@ -25,18 +25,19 @@ function RecommenderXBlock(runtime, element) {
...
@@ -25,18 +25,19 @@ function RecommenderXBlock(runtime, element) {
if
(
$
(
this
).
find
(
'.hide-show-icon'
).
text
()
==
'▲'
)
{
if
(
$
(
this
).
find
(
'.hide-show-icon'
).
text
()
==
'▲'
)
{
$
(
this
).
find
(
'.hide-show-icon'
).
text
(
'▼'
);
$
(
this
).
find
(
'.hide-show-icon'
).
text
(
'▼'
);
//$(this).parent().find('.more').show();
//$(this).parent().find('.more').show();
$
(
this
).
parent
().
find
(
'.recommender_row_inner'
).
slideUp
(
'fast'
);
$
(
".recommender_row_inner"
,
element
).
slideUp
(
'fast'
);
$
(
'.resource_add_button'
).
css
(
'visibility'
,
'hidden'
);
$
(
'.resource_add_button'
).
css
(
'visibility'
,
'hidden'
);
$
(
this
).
css
(
'cursor'
,
's-resize'
);
$
(
this
).
css
(
'cursor'
,
's-resize'
);
}
}
else
{
else
{
$
(
this
).
find
(
'.hide-show-icon'
).
text
(
'▲'
);
$
(
this
).
find
(
'.hide-show-icon'
).
text
(
'▲'
);
//$(this).parent().find('.less').show();
//$(this).parent().find('.less').show();
$
(
this
).
parent
().
find
(
'.recommender_row_inner'
).
slideDown
(
'fast'
);
$
(
".recommender_row_inner"
,
element
).
slideDown
(
'fast'
);
$
(
'.resource_add_button'
).
css
(
'visibility'
,
'visible'
);
$
(
'.resource_add_button'
).
css
(
'visibility'
,
'visible'
);
$
(
this
).
css
(
'cursor'
,
'n-resize'
);
$
(
this
).
css
(
'cursor'
,
'n-resize'
);
}
}
//$(this).hide();
//$(this).hide();
addTooltip
();
});
});
function
pagination
()
{
function
pagination
()
{
...
@@ -52,13 +53,15 @@ function RecommenderXBlock(runtime, element) {
...
@@ -52,13 +53,15 @@ function RecommenderXBlock(runtime, element) {
}
}
function
paginationRow
()
{
function
paginationRow
()
{
var
totalPage
=
parseInt
(
$
(
'.recommender_resource'
).
length
/
entriesPerPage
+
0.999
);
var
totalPage
=
Math
.
ceil
(
$
(
'.recommender_resource'
).
length
/
entriesPerPage
);
if
(
totalPage
==
1
)
{
return
;
}
if
(
totalPage
==
1
)
{
return
;
}
$
(
'.pagination'
).
empty
();
$
(
'.pagination'
).
empty
();
$
(
'.paginationCell'
).
unbind
();
$
(
'.paginationCell'
).
unbind
();
/* creating pagination for each page of resource list */
for
(
var
pageIdx
=
1
;
pageIdx
<=
totalPage
;
pageIdx
++
)
{
for
(
var
pageIdx
=
1
;
pageIdx
<=
totalPage
;
pageIdx
++
)
{
var
content
=
'<div class="paginationRow">'
;
var
content
=
'<div class="paginationRow">'
;
/* no previous page if current page = 1 */
if
(
pageIdx
==
1
)
{
content
+=
'<div class="paginationCell" style="visibility: hidden;">◄</div>'
;
}
if
(
pageIdx
==
1
)
{
content
+=
'<div class="paginationCell" style="visibility: hidden;">◄</div>'
;
}
else
{
content
+=
'<div class="paginationCell">◄</div>'
;
}
else
{
content
+=
'<div class="paginationCell">◄</div>'
;
}
...
@@ -69,6 +72,7 @@ function RecommenderXBlock(runtime, element) {
...
@@ -69,6 +72,7 @@ function RecommenderXBlock(runtime, element) {
}
}
if
(
pageIdx
+
pageSpan
<
totalPage
)
{
content
+=
'<div class="paginationCell" style="cursor: default;">...</div>'
;
}
if
(
pageIdx
+
pageSpan
<
totalPage
)
{
content
+=
'<div class="paginationCell" style="cursor: default;">...</div>'
;
}
/* no next page if current page is last page */
if
(
pageIdx
==
totalPage
)
{
content
+=
'<div class="paginationCell" style="visibility: hidden;">►</div>'
;
}
if
(
pageIdx
==
totalPage
)
{
content
+=
'<div class="paginationCell" style="visibility: hidden;">►</div>'
;
}
else
{
content
+=
'<div class="paginationCell">►</div>'
;
}
else
{
content
+=
'<div class="paginationCell">►</div>'
;
}
...
@@ -110,6 +114,7 @@ function RecommenderXBlock(runtime, element) {
...
@@ -110,6 +114,7 @@ function RecommenderXBlock(runtime, element) {
$
(
'.editSourceBlock'
).
hide
();
$
(
'.editSourceBlock'
).
hide
();
$
(
'.recommender_modify'
).
hide
();
$
(
'.recommender_modify'
).
hide
();
$
(
'.recommender_content'
).
show
();
$
(
'.recommender_content'
).
show
();
if
(
$
(
'.recommender_row_top'
).
css
(
'cursor'
)
==
's-resize'
)
{
$
(
".hide-show"
).
click
();
}
}
}
$
(
'.backToViewButton'
).
click
(
function
(){
$
(
'.backToViewButton'
).
click
(
function
(){
...
@@ -121,7 +126,7 @@ function RecommenderXBlock(runtime, element) {
...
@@ -121,7 +126,7 @@ function RecommenderXBlock(runtime, element) {
$
(
'#addResourceForm'
).
append
(
'<input type="hidden" name="Policy" value="'
+
policyBase64
+
'">'
$
(
'#addResourceForm'
).
append
(
'<input type="hidden" name="Policy" value="'
+
policyBase64
+
'">'
+
'<input type="hidden" name="Signature" value="'
+
signature
+
'">'
+
'<input type="hidden" name="Signature" value="'
+
signature
+
'">'
+
'Previewing screenshot: <input type="file" name="file"><br>'
+
'Previewing screenshot: <input type="file" name="file"><br>'
+
'<input type="submit" class="submitAddResourceForm" name="submit" value="Upload File" style="margin-top: 0.5em">'
//
+ '<input type="submit" class="submitAddResourceForm" name="submit" value="Upload File" style="margin-top: 0.5em">'
+
'<input type="button" value="Add resource" class="add_submit" style="margin-top: 0.5em" disabled >'
);
+
'<input type="button" value="Add resource" class="add_submit" style="margin-top: 0.5em" disabled >'
);
function
addResourceReset
()
{
function
addResourceReset
()
{
...
@@ -132,7 +137,7 @@ function RecommenderXBlock(runtime, element) {
...
@@ -132,7 +137,7 @@ function RecommenderXBlock(runtime, element) {
var
key
=
"uploads/"
+
(
new
Date
).
getTime
();
var
key
=
"uploads/"
+
(
new
Date
).
getTime
();
$
(
'#addResourceForm'
).
find
(
"input[name='key']"
).
val
(
key
);
$
(
'#addResourceForm'
).
find
(
"input[name='key']"
).
val
(
key
);
$
(
'.add_submit'
).
attr
(
'disabled'
,
true
);
$
(
'.add_submit'
).
attr
(
'disabled'
,
true
);
$
(
'.submitAddResourceForm'
).
attr
(
'disabled'
,
false
);
//
$('.submitAddResourceForm').attr('disabled', false);
}
}
addResourceReset
();
addResourceReset
();
...
@@ -144,14 +149,19 @@ function RecommenderXBlock(runtime, element) {
...
@@ -144,14 +149,19 @@ function RecommenderXBlock(runtime, element) {
$
(
'.add_submit'
).
attr
(
'disabled'
,
false
);
$
(
'.add_submit'
).
attr
(
'disabled'
,
false
);
}
}
$
(
'.in_title'
).
change
(
function
()
{
enableAddSubmit
();
});
$
(
'.in_title'
).
bind
(
'input propertychange'
,
function
()
{
enableAddSubmit
();
});
$
(
'.in_url'
).
change
(
function
()
{
enableAddSubmit
();
});
$
(
'.in_url'
).
bind
(
'input propertychange'
,
function
()
{
enableAddSubmit
();
});
$
(
'#addResourceForm'
).
find
(
"input[name='file']"
).
change
(
function
(){
if
(
$
(
this
).
val
()
==
''
)
{
return
false
;
}
$
(
"#addResourceForm"
).
submit
();
});
$
(
"#addResourceForm"
).
submit
(
function
(
e
)
{
$
(
"#addResourceForm"
).
submit
(
function
(
e
)
{
if
(
$
(
'#addResourceForm'
).
find
(
"input[name='file']"
).
val
()
==
''
)
{
return
false
;
}
if
(
$
(
'#addResourceForm'
).
find
(
"input[name='file']"
).
val
()
==
''
)
{
return
false
;
}
enableAddSubmit
();
enableAddSubmit
();
$
(
'.submitAddResourceForm'
).
attr
(
'disabled'
,
true
);
//
$('.submitAddResourceForm').attr('disabled', true);
return
true
;
return
true
;
});
});
...
@@ -315,7 +325,7 @@ function RecommenderXBlock(runtime, element) {
...
@@ -315,7 +325,7 @@ function RecommenderXBlock(runtime, element) {
+
'<input type="hidden" name="Policy" value="'
+
policyBase64
+
'">'
+
'<input type="hidden" name="Policy" value="'
+
policyBase64
+
'">'
+
'<input type="hidden" name="Signature" value="'
+
signature
+
'">'
+
'<input type="hidden" name="Signature" value="'
+
signature
+
'">'
+
'Previewing screenshot: <input type="file" name="file"><br>'
+
'Previewing screenshot: <input type="file" name="file"><br>'
+
'<input type="submit" class="submitEditResourceForm" name="submit" value="Upload File" style="margin-top: 0.5em">'
//
+ '<input type="submit" class="submitEditResourceForm" name="submit" value="Upload File" style="margin-top: 0.5em">'
+
'<input type="button" value="Edit resource" class="edit_submit" style="margin-top: 0.5em" disabled></form>'
;
+
'<input type="button" value="Edit resource" class="edit_submit" style="margin-top: 0.5em" disabled></form>'
;
$
(
'.editSourceBlock'
).
append
(
$
(
'.editSourceBlock'
).
append
(
...
@@ -339,14 +349,19 @@ function RecommenderXBlock(runtime, element) {
...
@@ -339,14 +349,19 @@ function RecommenderXBlock(runtime, element) {
$
(
'.edit_submit'
).
attr
(
'disabled'
,
false
);
$
(
'.edit_submit'
).
attr
(
'disabled'
,
false
);
}
}
$
(
'.edit_title'
).
change
(
function
()
{
enableEditSubmit
();
});
$
(
'.edit_title'
).
bind
(
'input propertychange'
,
function
()
{
enableEditSubmit
();
});
$
(
'.edit_url'
).
change
(
function
()
{
enableEditSubmit
();
});
$
(
'.edit_url'
).
bind
(
'input propertychange'
,
function
()
{
enableEditSubmit
();
});
$
(
'#editResourceForm'
).
find
(
"input[name='file']"
).
change
(
function
(){
if
(
$
(
this
).
val
()
==
''
)
{
return
false
;
}
$
(
"#editResourceForm"
).
submit
();
});
$
(
"#editResourceForm"
).
submit
(
function
(
e
)
{
$
(
"#editResourceForm"
).
submit
(
function
(
e
)
{
if
(
$
(
'#editResourceForm'
).
find
(
"input[name='file']"
).
val
()
==
''
)
{
return
false
;
}
if
(
$
(
'#editResourceForm'
).
find
(
"input[name='file']"
).
val
()
==
''
)
{
return
false
;
}
enableEditSubmit
();
enableEditSubmit
();
$
(
'.submitEditResourceForm'
).
attr
(
'disabled'
,
'disabled'
);
//
$('.submitEditResourceForm').attr('disabled', 'disabled');
return
true
;
return
true
;
});
});
...
@@ -358,7 +373,7 @@ function RecommenderXBlock(runtime, element) {
...
@@ -358,7 +373,7 @@ function RecommenderXBlock(runtime, element) {
data
[
'title'
]
=
$
(
'.edit_title'
).
val
();
data
[
'title'
]
=
$
(
'.edit_title'
).
val
();
if
(
data
[
'url'
]
==
''
||
data
[
'title'
]
==
''
)
{
return
;
}
if
(
data
[
'url'
]
==
''
||
data
[
'title'
]
==
''
)
{
return
;
}
data
[
'description'
]
=
baseUrl
+
key
;
if
(
$
(
'#editResourceForm'
).
find
(
"input[name='file']"
).
val
()
!=
''
)
{
data
[
'description'
]
=
baseUrl
+
key
;
}
$
.
ajax
({
$
.
ajax
({
type
:
"POST"
,
type
:
"POST"
,
url
:
editResourceUrl
,
url
:
editResourceUrl
,
...
@@ -367,7 +382,7 @@ function RecommenderXBlock(runtime, element) {
...
@@ -367,7 +382,7 @@ function RecommenderXBlock(runtime, element) {
if
(
result
[
'Success'
]
==
true
)
{
if
(
result
[
'Success'
]
==
true
)
{
$
(
divEdit
).
parent
().
parent
().
find
(
'.recommender_title'
).
find
(
'a'
).
text
(
data
[
'title'
]);
$
(
divEdit
).
parent
().
parent
().
find
(
'.recommender_title'
).
find
(
'a'
).
text
(
data
[
'title'
]);
$
(
divEdit
).
parent
().
parent
().
find
(
'.recommender_title'
).
find
(
'a'
).
attr
(
'href'
,
data
[
'url'
]);
$
(
divEdit
).
parent
().
parent
().
find
(
'.recommender_title'
).
find
(
'a'
).
attr
(
'href'
,
data
[
'url'
]);
$
(
divEdit
).
parent
().
parent
().
find
(
'.recommender_descriptionSlot'
).
text
(
data
[
'description'
]);
if
(
"description"
in
data
)
{
$
(
divEdit
).
parent
().
parent
().
find
(
'.recommender_descriptionSlot'
).
text
(
data
[
'description'
]);
}
$
(
'.editSourceBlock'
).
empty
();
$
(
'.editSourceBlock'
).
empty
();
backToView
();
backToView
();
}
}
...
@@ -427,6 +442,8 @@ function RecommenderXBlock(runtime, element) {
...
@@ -427,6 +442,8 @@ function RecommenderXBlock(runtime, element) {
$
(
'.edit_title'
).
attr
(
'title'
,
'Type in the description of the resource'
);
$
(
'.edit_title'
).
attr
(
'title'
,
'Type in the description of the resource'
);
$
(
'.edit_url'
).
attr
(
'title'
,
'Type in the hyperlink to the resource'
);
$
(
'.edit_url'
).
attr
(
'title'
,
'Type in the hyperlink to the resource'
);
$
(
'.backToViewButton'
).
attr
(
'title'
,
'Back to list of related resources'
);
$
(
'.backToViewButton'
).
attr
(
'title'
,
'Back to list of related resources'
);
if
(
$
(
'.recommender_row_top'
).
find
(
'.hide-show-icon'
).
text
()
==
'▲'
)
{
$
(
'.recommender_row_top'
).
attr
(
'title'
,
'Select to hide the list'
);
}
else
{
$
(
'.recommender_row_top'
).
attr
(
'title'
,
'Select for expanding resource list'
);
}
}
}
}
}
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