Commit 42b3ed3c by attiyaishaque Committed by Attiya Ishaque

Fix instructor bio editing capability for all internal users.

parent 295fa22d
...@@ -72,7 +72,8 @@ class PersonAutocomplete(LoginRequiredMixin, autocomplete.Select2QuerySetView): ...@@ -72,7 +72,8 @@ class PersonAutocomplete(LoginRequiredMixin, autocomplete.Select2QuerySetView):
'profile_image': result.get_profile_image_url, 'profile_image': result.get_profile_image_url,
'full_name': result.full_name, '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 'organization_id': result.position.organization_id if hasattr(result, 'position') else None,
'can_edit_instructor': not result.profile_image_url,
} }
......
...@@ -29,6 +29,7 @@ class PersonModelMultipleChoice(forms.ModelMultipleChoiceField): ...@@ -29,6 +29,7 @@ class PersonModelMultipleChoice(forms.ModelMultipleChoiceField):
context = { context = {
'profile_image': obj.get_profile_image_url, 'profile_image': obj.get_profile_image_url,
'full_name': obj.full_name, 'full_name': obj.full_name,
'can_edit_instructor': not obj.profile_image_url,
'uuid': obj.uuid, 'uuid': obj.uuid,
'organization_id': obj.position.organization_id if hasattr(obj, 'position') else None 'organization_id': obj.position.organization_id if hasattr(obj, 'position') else None
} }
......
<img src="{{ profile_image }}"/><span{% if uuid %} data-uuid="{{ uuid }}" {% endif %}>{{ full_name }}</span>{% if organization_id %}<span>{{ organization_id }}</span>{% endif %} <img src="{{ profile_image }}"/><span{% if can_edit_instructor %} data-can-edit="{{ can_edit_instructor }}" {% endif %} data-uuid="{{ uuid }}" >{{ full_name }}</span>{% if organization_id %}<span>{{ organization_id }}</span>{% endif %}
<table class="instructor-option" id="{{ uuid }}"> <table class="instructor-option" id="{{ uuid }}" {% if can_edit_instructor %} data-can-edit="{{ can_edit_instructor }}" {% endif %}>
<tr> <tr>
<td><img src="{{ profile_image }}" alt="profile image"/></td> <td><img src="{{ profile_image }}" alt="profile image"/></td>
<td> <td>
......
...@@ -6,8 +6,9 @@ $(document).ready(function(){ ...@@ -6,8 +6,9 @@ $(document).ready(function(){
image_source = $(label[0]).attr('src'), image_source = $(label[0]).attr('src'),
name = $(label[1]).text(), name = $(label[1]).text(),
uuid = $(label[1]).data('uuid'), uuid = $(label[1]).data('uuid'),
organization_id = $(label[2]).text(); organization_id = $(label[2]).text(),
renderSelectedInstructor(id, name, image_source, uuid, organization_id); edit_instructor = $(label[1]).data('can-edit');
renderSelectedInstructor(id, name, image_source, uuid, organization_id, edit_instructor);
}); });
$("#id_staff").on("select2:select", function(e) { $("#id_staff").on("select2:select", function(e) {
...@@ -17,8 +18,9 @@ $(document).ready(function(){ ...@@ -17,8 +18,9 @@ $(document).ready(function(){
image_source = $(selectedInstructorData).find('img').attr('src'), image_source = $(selectedInstructorData).find('img').attr('src'),
name = $(selectedInstructorData).find('b').text(), name = $(selectedInstructorData).find('b').text(),
uuid = $(selectedInstructorData)[0].id, uuid = $(selectedInstructorData)[0].id,
organization_id = $(selectedInstructorData).find('span').text(); organization_id = $(selectedInstructorData).find('span').text(),
renderSelectedInstructor(id, name, image_source, uuid, organization_id); edit_instructor = $(selectedInstructorData).data('can-edit');
renderSelectedInstructor(id, name, image_source, uuid, organization_id, edit_instructor);
}); });
...@@ -139,7 +141,7 @@ $(document).on('click', '.selected-instructor a.delete', function (e) { ...@@ -139,7 +141,7 @@ $(document).on('click', '.selected-instructor a.delete', function (e) {
$('.instructor-select').find('.select2-selection__choice').remove(); $('.instructor-select').find('.select2-selection__choice').remove();
}); });
function renderSelectedInstructor(id, name, image, uuid, organization_id) { function renderSelectedInstructor(id, name, image, uuid, organization_id, edit_instructor) {
var user_organizations_ids = $('#user_organizations_ids').text(), var user_organizations_ids = $('#user_organizations_ids').text(),
course_user_role = $('#course_user_role').text(), course_user_role = $('#course_user_role').text(),
instructorHtmlStart = '<div class="instructor" id= "instructor_'+ id +'"><div><img src="' + image + '"></div><div>', instructorHtmlStart = '<div class="instructor" id= "instructor_'+ id +'"><div><img src="' + image + '"></div><div>',
...@@ -152,6 +154,11 @@ function renderSelectedInstructor(id, name, image, uuid, organization_id) { ...@@ -152,6 +154,11 @@ function renderSelectedInstructor(id, name, image, uuid, organization_id) {
controlOptions += '<a class="edit" id="' + uuid + '"href="#"><i class="fa fa-pencil-square-o fa-fw"></i></a>'; controlOptions += '<a class="edit" id="' + uuid + '"href="#"><i class="fa fa-pencil-square-o fa-fw"></i></a>';
} }
} }
else {
if (edit_instructor){
controlOptions += '<a class="edit" id="' + uuid + '"href="#"><i class="fa fa-pencil-square-o fa-fw"></i></a>';
}
}
$('.selected-instructor').append(instructorHtmlStart + controlOptions + instructorHtmlEnd); $('.selected-instructor').append(instructorHtmlStart + controlOptions + instructorHtmlEnd);
} }
...@@ -182,7 +189,9 @@ function loadInstructor(uuid, editMode) { ...@@ -182,7 +189,9 @@ function loadInstructor(uuid, editMode) {
label, label,
image_source, image_source,
name, name,
instructor_id; instructor_id,
organization_id,
edit_instructor;
$.getJSON({ $.getJSON({
url: url, url: url,
...@@ -198,7 +207,8 @@ function loadInstructor(uuid, editMode) { ...@@ -198,7 +207,8 @@ function loadInstructor(uuid, editMode) {
value: id, value: id,
text: name text: name
}).attr('selected', 'selected')); }).attr('selected', 'selected'));
organization_id = $(label).find('span').text() organization_id = $(label).find('span').text();
edit_instructor = $(label).data('can-edit');
if (editMode) { if (editMode) {
// Updating the existing instructor // Updating the existing instructor
...@@ -207,7 +217,7 @@ function loadInstructor(uuid, editMode) { ...@@ -207,7 +217,7 @@ function loadInstructor(uuid, editMode) {
instructor_id.find('b').text(name); instructor_id.find('b').text(name);
} }
else { else {
renderSelectedInstructor(id, name, image_source, uuid, organization_id); renderSelectedInstructor(id, name, image_source, uuid, organization_id, edit_instructor);
} }
} }
......
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