Skip to content

Commit

Permalink
Javascript updated for instructor autocomplete
Browse files Browse the repository at this point in the history
ECOM-7186
  • Loading branch information
tasawernawaz committed Feb 27, 2017
1 parent b618823 commit 735a635
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions course_discovery/static/js/publisher/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ $(document).ready(function(){
$('#blog').val('');
clearModalError();
closeModal(e, $('#addInstructorModal'));
loadInstructor(response['uuid'])
},
error: function (response) {
addModalError(gettext("Something went wrong!"));
Expand Down Expand Up @@ -369,3 +370,32 @@ $(document).on('click', '.btn-edit-preview-url', function (e) {
$('.btn-preview-decline').click(function(e){
$('#decline-comment').toggle();
});

function loadInstructor(uuid) {
var url = $('#id_staff').attr('data-autocomplete-light-url') + '?q=' + uuid,
instructor,
id,
label,
image_source,
name;

$.getJSON({
url: url,
success: function (data) {
if (data['results'].length) {
// with uuid there will be only one instructor
instructor = data['results'][0];
id = instructor.id;
label = $.parseHTML(instructor.text);
image_source = $(label).find('img').attr('src');
name = $(label).find('b').text();
$('#id_staff').append($("<option/>", {
value: id,
text: name
}).attr('selected', 'selected'));
renderSelectedInstructor(id, name, image_source);
}

}
});
}

0 comments on commit 735a635

Please sign in to comment.