Commit 0e5c1ed0 by attiyaishaque Committed by Attiya Ishaque

Course team would be able to edit existing instructor of same org.

parent 3029daf8
......@@ -71,7 +71,9 @@ class PersonAutocomplete(LoginRequiredMixin, autocomplete.Select2QuerySetView):
'uuid': result.uuid,
'profile_image': result.get_profile_image_url,
'full_name': result.full_name,
'position': result.position if hasattr(result, 'position') else None
'position': result.position if hasattr(result, 'position') else None,
'organization_id': result.position.organization_id if hasattr(result, 'position') else None
}
return render_to_string('publisher/_personLookup.html', context=context)
......@@ -29,7 +29,8 @@ class PersonModelMultipleChoice(forms.ModelMultipleChoiceField):
context = {
'profile_image': obj.get_profile_image_url,
'full_name': obj.full_name,
'uuid': obj.uuid if not obj.profile_image_url else None
'uuid': obj.uuid,
'organization_id': obj.position.organization_id if hasattr(obj, 'position') else None
}
return str(render_to_string('publisher/_personFieldLabel.html', context=context))
......
<img src="{{ profile_image }}"/><span{% if uuid %} data-uuid="{{ uuid }}" {% endif %}>{{ full_name }}</span>
<img src="{{ profile_image }}"/><span{% if uuid %} data-uuid="{{ uuid }}" {% endif %}>{{ full_name }}</span>{% if organization_id %}<span>{{ organization_id }}</span>{% endif %}
......@@ -5,6 +5,7 @@
<b>{{ full_name }}</b>
{% if position %}
<p>{{ position }}</p>
<span class="hidden">{{ organization_id }}</span>
{% endif %}
</td>
</tr>
......
......@@ -208,6 +208,8 @@
<div class="col col-6 help-text">
{% trans "The primary instructor or instructors for the course." %}
</div>
<div id="user_organizations_ids" class="hidden">{{ organizations_ids|safe }}</div>
<div id="course_user_role" class="hidden">{{ course_user_role }}</div>
<div class="col col-6 instructor-select">
<label class="field-label ">{{ run_form.staff.label_tag }} <span class="required">*</span></label>
{{ run_form.staff }}
......
......@@ -58,8 +58,9 @@ class PersonModelMultipleChoiceTests(TestCase):
# we need to loop through choices because it is a ModelChoiceIterator
for __, choice_label in course_form.fields['staff'].choices:
expected = '<img src="{url}"/><span>{full_name}</span>'.format(
expected = '<img src="{url}"/><span data-uuid="{uuid}" >{full_name}</span>'.format(
full_name=person.full_name,
uuid=person.uuid,
url=person.get_profile_image_url
)
self.assertEqual(choice_label.strip(), expected)
......
......@@ -702,7 +702,12 @@ class CourseRunEditView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMix
context = self.get_context_data()
course_run = context.get('course_run')
course = course_run.course
course_user_role = course.get_user_role(user=self.request.user)
if course_user_role == PublisherUserRole.CourseTeam:
context['organizations_ids'] = list(mixins.get_user_organizations(self.request.user).
values_list('id', flat=True))
context['course_user_role'] = course_user_role
context['run_form'] = self.run_form(
instance=course_run, is_project_coordinator=context.get('is_project_coordinator')
)
......
......@@ -4,9 +4,10 @@ $(document).ready(function(){
var id = this.value,
label = $.parseHTML(this.label),
image_source = $(label[0]).attr('src'),
name = $(label[1]).text();
uuid = $(label[1]).data('uuid');
renderSelectedInstructor(id, name, image_source, uuid);
name = $(label[1]).text(),
uuid = $(label[1]).data('uuid'),
organization_id = $(label[2]).text();
renderSelectedInstructor(id, name, image_source, uuid, organization_id);
});
$("#id_staff").on("select2:select", function(e) {
......@@ -14,8 +15,10 @@ $(document).ready(function(){
id = $instructorSelector.id,
selectedInstructorData = $.parseHTML($instructorSelector.text)[0],
image_source = $(selectedInstructorData).find('img').attr('src'),
name = $(selectedInstructorData).find('b').text();
renderSelectedInstructor(id, name, image_source);
name = $(selectedInstructorData).find('b').text(),
uuid = $(selectedInstructorData)[0].id,
organization_id = $(selectedInstructorData).find('span').text();
renderSelectedInstructor(id, name, image_source, uuid, organization_id);
});
......@@ -136,15 +139,19 @@ $(document).on('click', '.selected-instructor a.delete', function (e) {
$('.instructor-select').find('.select2-selection__choice').remove();
});
function renderSelectedInstructor(id, name, image, uuid) {
var instructorHtmlStart = '<div class="instructor" id= "instructor_'+ id +'"><div><img src="' + image + '"></div><div>',
function renderSelectedInstructor(id, name, image, uuid, organization_id) {
var user_organizations_ids = $('#user_organizations_ids').text(),
course_user_role = $('#course_user_role').text(),
instructorHtmlStart = '<div class="instructor" id= "instructor_'+ id +'"><div><img src="' + image + '"></div><div>',
instructorHtmlEnd = '<b>' + name + '</b></div></div>',
controlOptions = '<a class="delete" id="' + id + '"href="#"><i class="fa fa-trash-o fa-fw"></i></a>';
if (uuid) {
controlOptions += '<a class="edit" id="' + uuid + '"href="#"><i class="fa fa-pencil-square-o fa-fw"></i></a>';
}
if (course_user_role == "course_team") {
if ($.inArray(parseInt(organization_id), JSON.parse(user_organizations_ids)) > -1 && uuid) {
controlOptions += '<a class="edit" id="' + uuid + '"href="#"><i class="fa fa-pencil-square-o fa-fw"></i></a>';
}
}
$('.selected-instructor').append(instructorHtmlStart + controlOptions + instructorHtmlEnd);
}
......@@ -191,6 +198,7 @@ function loadInstructor(uuid, editMode) {
value: id,
text: name
}).attr('selected', 'selected'));
organization_id = $(label).find('span').text()
if (editMode) {
// Updating the existing instructor
......@@ -199,7 +207,7 @@ function loadInstructor(uuid, editMode) {
instructor_id.find('b').text(name);
}
else {
renderSelectedInstructor(id, name, image_source, uuid);
renderSelectedInstructor(id, name, image_source, uuid, organization_id);
}
}
......@@ -223,7 +231,12 @@ $(document).on('click', '.selected-instructor a.edit', function (e) {
$.getJSON({
url: btnInstructor.data('url') + uuid,
success: function (data) {
$('.select-image').attr('src', data['profile_image']['medium']['url']);
if ($.isEmptyObject(data['profile_image'])) {
$('.select-image').attr('src', data['profile_image_url']);
}
else {
$('.select-image').attr('src', data['profile_image']['medium']['url']);
}
$('#given-name').val(data['given_name']);
$('#family-name').val(data['family_name']);
$('#title').val(data['position']['title']);
......
......@@ -216,6 +216,9 @@
.field-value {
margin-bottom: 20px;
}
.hidden {
display : none;
}
.help-text {
p {
margin-bottom: 0;
......
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