Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
67eec948
Commit
67eec948
authored
Oct 12, 2016
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sortable organizations in admin program form
ECOM-5680
parent
d0565ea7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
15 deletions
+25
-15
course_discovery/apps/course_metadata/admin.py
+2
-0
course_discovery/apps/course_metadata/forms.py
+3
-0
course_discovery/static/js/sortable_select.js
+20
-15
No files found.
course_discovery/apps/course_metadata/admin.py
View file @
67eec948
...
...
@@ -111,6 +111,8 @@ class ProgramAdmin(admin.ModelAdmin):
try
:
# courses are ordered by django id, but form.cleaned_data is ordered correctly
obj
.
courses
=
form
.
cleaned_data
.
get
(
'courses'
)
obj
.
authoring_organizations
=
form
.
cleaned_data
.
get
(
'authoring_organizations'
)
obj
.
credit_backing_organizations
=
form
.
cleaned_data
.
get
(
'credit_backing_organizations'
)
obj
.
save
()
self
.
save_error
=
False
except
ProgramPublisherException
as
ex
:
...
...
course_discovery/apps/course_metadata/forms.py
View file @
67eec948
...
...
@@ -39,18 +39,21 @@ class ProgramAdminForm(HackDjangoAutocompleteMixin, forms.ModelForm):
url
=
'admin_metadata:course-autocomplete'
,
attrs
=
{
'data-minimum-input-length'
:
3
,
'class'
:
'sortable-select'
,
},
),
'authoring_organizations'
:
autocomplete
.
ModelSelect2Multiple
(
url
=
'admin_metadata:organisation-autocomplete'
,
attrs
=
{
'data-minimum-input-length'
:
3
,
'class'
:
'sortable-select'
,
}
),
'credit_backing_organizations'
:
autocomplete
.
ModelSelect2Multiple
(
url
=
'admin_metadata:organisation-autocomplete'
,
attrs
=
{
'data-minimum-input-length'
:
3
,
'class'
:
'sortable-select'
,
}
),
'video'
:
autocomplete
.
ModelSelect2
(
...
...
course_discovery/static/js/sortable_select.js
View file @
67eec948
function
updateSelect2Data
(
visibleCourseTitles
){
function
updateSelect2Data
(
el
){
var
i
,
j
,
visible
Course
TitlesLength
,
visibleTitlesLength
,
selectOptionsLength
,
visible
Course
Titles
=
[],
visibleTitles
=
[],
selectOptions
=
[],
items
=
[],
selectOptionsSelector
=
'.field-courses .select2-hidden-accessible'
;
selectOptionsElement
=
$
(
el
).
find
(
'.select2-hidden-accessible'
),
selectChoicesElement
=
$
(
el
).
find
(
'.select2-selection__choice'
),
selectOptionElement
=
$
(
selectOptionsElement
).
find
(
'option'
);
$
(
'.field-courses .select2-selection__choice'
)
.
each
(
function
(
index
,
value
){
selectChoicesElement
.
each
(
function
(
index
,
value
){
if
(
value
.
title
){
visible
Course
Titles
.
push
(
value
.
title
);
visibleTitles
.
push
(
value
.
title
);
}
});
$
(
'.field-courses .select2-hidden-accessible option'
)
.
each
(
function
(
index
,
value
){
selectOptionElement
.
each
(
function
(
index
,
value
){
selectOptions
.
push
({
id
:
value
.
value
,
text
:
value
.
text
});
});
// Update select2 options with new data
visible
CourseTitlesLength
=
visibleCours
eTitles
.
length
;
visible
TitlesLength
=
visibl
eTitles
.
length
;
selectOptionsLength
=
selectOptions
.
length
;
for
(
i
=
0
;
i
<
visible
Course
TitlesLength
;
i
++
)
{
for
(
i
=
0
;
i
<
visibleTitlesLength
;
i
++
)
{
for
(
j
=
0
;
j
<
selectOptionsLength
;
j
++
)
{
if
(
selectOptions
[
j
].
text
===
visible
Course
Titles
[
i
]){
if
(
selectOptions
[
j
].
text
===
visibleTitles
[
i
]){
items
.
push
(
'<option selected="selected" value="'
+
selectOptions
[
j
].
id
+
'">'
+
selectOptions
[
j
].
text
+
'</option>'
);
}
}
}
if
(
items
){
$
(
selectOptionsSelector
)
.
html
(
items
.
join
(
'
\
n'
));
selectOptionsElement
.
html
(
items
.
join
(
'
\
n'
));
}
}
$
(
window
).
load
(
function
(){
$
(
function
()
{
var
domSelector
=
'.field-courses .select2-selection--multiple'
;
$
(
'.field-courses ul.select2-selection__rendered'
).
sortable
({
containment
:
'parent'
,
update
:
updateSelect2Data
$
(
'.sortable-select'
).
parents
(
'.form-row'
).
each
(
function
(
index
,
el
){
$
(
el
).
find
(
'ul.select2-selection__rendered'
).
sortable
({
containment
:
'parent'
,
update
:
function
(){
updateSelect2Data
(
el
);}
})
})
})
});
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