clean up observer linking

observers can now be linked from either the course
details page or the user details page inside a course.
Fixed some bugs in this and made the code a bit
cleaner.

refs #3315

Change-Id: I004bc11d823fffcc76ab5b74ee235979248cae4d
Reviewed-on: https://gerrit.instructure.com/2263
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Brian Whitmer 2011-02-10 15:38:47 -07:00
parent 629805db3c
commit 7b840846bc
11 changed files with 151 additions and 77 deletions

View File

@ -52,6 +52,9 @@ ul.user_list li.user .short_name
margin-left: 10px
margin-top: 2px
ul.user_list li.user .associated_user_name:hover
text-decoration: underline
ul.user_list li.user .enrollment_type
font-size: 0.8em
margin: -2px 10px 0px

View File

@ -88,6 +88,9 @@
<b><a href="<%= context_url(@context, :context_section_url, enrollment.course_section_id) rescue "#" %>"><%= enrollment.try_rescue(:course_section).try_rescue(:display_name) || enrollment.short_name %></a></b>
<div style="font-size: 0.8em; padding-left: 20px;">Enrolled as a <%= enrollment.readable_type %></div>
<div style="font-size: 0.8em; padding-left: 20px;">created <%= datetime_string(enrollment.created_at) %></div>
<% if enrollment.associated_user && enrollment.is_a?(ObserverEnrollment) %>
<div style="font-size: 0.8em; padding-left: 20px;">linked to <%= enrollment.associated_user.name %></div>
<% end %>
<div style="font-size: 0.8em; padding-left: 20px; <%= hidden unless enrollment.completed? %>" class="completed_at_holder">completed <span class="completed_at"><%= datetime_string(enrollment.completed_at) %></div>
</td>
<% if !enrollment.admin? || (can_do(@context, @current_user, :manage_admin_users) && enrollment.user_id != @current_user.id) %>
@ -98,6 +101,12 @@
<div class="unconclude_enrollment_link_holder" style="margin-bottom: 5px; <%= hidden unless enrollment.completed? %>">
<a class="unconclude_enrollment_link" href="<%= context_url(@context, :controller => :courses, :action => :unconclude_user, :id => enrollment.id) %>">Restore this Enrollment</a>
</div>
<% if can_do(@context, @current_user, :manage_admin_users) && enrollment.is_a?(ObserverEnrollment) %>
<div class="link_enrollment_link_holder" style="margin-bottom: 5px;">
<a class="link_enrollment_link" href="#" data-id="<%= enrollment.id %>" data-associated-id="<%= enrollment.associated_user_id %>">Link this Enrollment</a>
</div>
<%= render :partial => 'courses/link_enrollment' %>
<% end %>
<div><% if enrollment.defined_by_sis? %>
<a href="#" title="This enrollment was defined by the university, and can't be deleted">Can't Delete</a>
<% else %>
@ -162,6 +171,16 @@ $(document).ready(function() {
}, function(data) {
});
});
$(".link_enrollment_link").click(function(event) {
event.preventDefault();
var $link = $(this);
var name = $("#name_and_email .name").text();
var id = $link.attr('data-id');
var associated_id = $link.attr('data-associated-id');
link_enrollment.choose(name, id, associated_id, function() {
location.reload();
});
});
$(".unconclude_enrollment_link").click(function(event) {
event.preventDefault();
var $enrollment = $(this).parents(".enrollment");

View File

@ -0,0 +1,29 @@
<% jammit_js :link_enrollment %>
<div id="link_student_dialog" style="display: none;">
<a href="<%= context_url(@context, :context_students_url) %>" class="student_url" style="display: none;">&nbsp;</a>
<% form_tag context_url(@context, :context_link_enrollment_url), {:id => "link_student_dialog_form"} do %>
<input type="hidden" name="enrollment_id" class="enrollment_id"/>
<p>
When an observer is linked to a student, they have access to that student's grades
and course interactions.
<span class="existing_user">
Right now this observer is linked to the student, <b class="existing_user_name">&nbsp;</b>.
</span>
</p>
<p>
To link the course observer <b class="short_name">&nbsp;</b> to a student, select
the student's name from the list below.
</p>
<p class="loading_message">Loading Students...</p>
<p class="students_link" style="display: none;">
<label for="student_enrollment_link_option">Student:</label>
<select name="student_id" class="student_options" id="student_enrollment_link_option">
<option value="none" class="blank">[ Select Student ]</option>
</select>
</p>
<div class="button-container">
<button type="submit" class="button save_button">Link to Student</button>
<button type="button" class="button button-secondary cancel_button">Cancel</button>
</div>
<% end %>
</div>

View File

@ -512,32 +512,7 @@
</div>
</div>
</div>
<div id="link_student_dialog" style="display: none;">
<% form_tag context_url(@context, :context_link_enrollment_url), {:id => "link_student_dialog_form"} do %>
<input type="hidden" name="enrollment_id" class="enrollment_id"/>
<p>
When an observer is linked to a student, they have access to that student's grades
and course interactions.
<span class="existing_user">
Right now this observer is linked to the student, <b class="existing_user_name">&nbsp;</b>.
</span>
</p>
<p>
To link the course observer <b class="short_name">&nbsp;</b> to a student, select
the student's name from the list below.
</p>
<p>
<label for="student_enrollment_link_option">Student:</label>
<select name="student_id" class="student_options" id="student_enrollment_link_option">
<option value="none" class="blank">[ Select Student ]</option>
</select>
</p>
<div class="button-container">
<button type="submit" class="button save_button">Link to Student</button>
<button type="button" class="button button-secondary">Cancel</button>
</div>
<% end %>
</div>
<%= render :partial => 'link_enrollment' %>
</div>
<div id="tab-navigation">
<% form_tag context_url(@context, :context_update_nav_url), {:id => "nav_form", :title => "Edit Course Navigation" } do %>

View File

@ -38,7 +38,7 @@
<% end %>
<% end %>
<span class="invitation_sent_at" style="display: none;"><%= datetime_string(enrollment.try_rescue(:updated_at)) || nbsp %></span>
<span class="associated_user_id" style="display: none;"><%= enrollment.try_rescue(:association_user_id) %></span>
<span class="associated_user_id" style="display: none;"><%= enrollment.try_rescue(:associated_user_id) %></span>
<span class="id" style="display: none;"><%= enrollment.try_rescue(:id) %></span>
<span class="user_id" style="display: none;"><%= enrollment.try_rescue(:user_id) %></span>
<span class="clear"></span>

View File

@ -1,5 +1,5 @@
<li class="<%= 'unpublished' if enrollment.course.created? || enrollment.course.claimed? %> <%= enrollment.workflow_state %>">
<a href="<%= course_path(enrollment.course_id) %>" style="float: left;">
<a href="<%= course_user_path(enrollment.course_id, enrollment.user_id) %>" style="float: left;">
<span class="name ellipsis" title="<%= enrollment.long_name %>">
<%= enrollment.long_name %>
<% if enrollment.course.created? || enrollment.course.claimed? %>
@ -9,6 +9,9 @@
<span class="subtitle ellipsis">
<%= enrollment.workflow_state.titleize %>,
Enrolled as <%= enrollment.readable_type %>
<% if enrollment.associated_user %>
linked to <%= enrollment.associated_user.name %>
<% end %>
</span>
</a>
<span style="float: right; margin-right: 5px; margin-top: 3px;">

View File

@ -166,6 +166,8 @@ javascripts:
- public/javascripts/json2.js
content_migration:
- public/javascripts/content_migration.js
link_enrollment:
- public/javascripts/link_enrollment.js
stylesheets:
common:

View File

@ -593,7 +593,7 @@ ActionController::Routing::Routes.draw do |map|
ApiRouteSet.new(map, "/api/v1") do |api|
api.resources :courses,
:only => %w(index) do |course|
course.students 'students.:format',
course.api_students 'students.:format',
:controller => 'courses', :action => 'students',
:conditions => { :method => :get }
course.resources :assignments,

View File

@ -261,47 +261,8 @@ $(document).ready(function() {
$(".associate_user_link").click(function(event) {
event.preventDefault();
var $user = $(this).parents(".user");
var $dialog = $("#link_student_dialog");
var data = $user.getTemplateData({textValues: ['name', 'id', 'associated_user_id', 'associated_user_name']});
data.existing_user_name = $(".user.user_" + data.associated_user_id + " .name").text() || data.associated_user_name || "User " + data.associated_user_id;
$dialog.find(".existing_user").hide();
if(data.associated_user_id) {
$dialog.find(".existing_user").show();
}
$dialog.find(".enrollment_id").val(data.id);
$dialog.find(".student_options option:not(.blank)").remove();
$(".student_enrollments .user").each(function() {
var user = $(this).getTemplateData({textValues: ['name', 'user_id']});
var $option = $("<option/>");
if(user.user_id && user.name) {
$option.val(user.user_id).text(user.name);
$dialog.find(".student_options").append($option);
}
});
$dialog.find(".student_options").val("none").val(data.associated_user_id);
$dialog
.fillTemplateData({data: data})
.dialog('close').dialog({
autoOpen: false,
title: "Link to Student",
width: 400
}).dialog('open');
});
$("#link_student_dialog .cancel_button").click(function() {
$("#link_student_dialog").dialog('close');
});
$("#link_student_dialog_form").formSubmit({
beforeSubmit: function(data) {
$(this)
.find("button").attr('disabled', true).end()
.find(".save_button").text("Linking to Student...");
},
success: function(data) {
$(this)
.find("button").attr('disabled', false).end()
.find(".save_button").text("Link to Student");
var enrollment = data.observer_enrollment;
var data = $user.getTemplateData({textValues: ['name', 'associated_user_id', 'id']});
link_enrollment.choose(data.name, data.id, data.associated_user_id, function(enrollment) {
if(enrollment) {
var user_name = enrollment.associated_user_name;
$("#enrollment_" + enrollment.id)
@ -309,13 +270,7 @@ $(document).ready(function() {
.find(".associated_user.unassociated").showIf(!enrollment.associated_user_id).end()
.fillTemplateData({data: enrollment});
}
$("#link_student_dialog").dialog('close');
},
error: function(data) {
$(this)
.find("button").attr('disabled', false)
.find(".save_button").text("Linking Failed, please try again");
}
});
});
$(".course_info").attr('title', 'Click to Edit').click(function() {
$(".edit_course_link:first").click();

View File

@ -75,6 +75,7 @@
message += ". The following addresses had problems:<br/><span style='font-size:0.8em;'>" + erroredEmails.join(',') + "</span>";
$.flashError(message, 20000);
}
$(document).triggerHandler('enrollment_added');
} else {
setTimeout(checkForFinish, 500);
}

View File

@ -0,0 +1,87 @@
var link_enrollment = (function() {
return {
choose: function(user_name, enrollment_id, current_user_id, callback) {
var $user = $(this).parents(".user");
var $dialog = $("#link_student_dialog");
var user_data = {};
user_data.short_name = user_name;
$dialog.fillTemplateData({data: user_data});
if(!$dialog.data('loaded')) {
$dialog.find(".loading_message").text("Loading Students...");
var url = $dialog.find(".student_url").attr('href');
$.ajaxJSON(url, 'GET', {}, function(data) {
for(var idx in data) {
var user = data[idx];
var $option = $("<option/>");
if(user.id && user.name) {
$option.val(user.id).text(user.name);
$dialog.find(".student_options").append($option);
}
}
var $option = $("<option/>");
$option.val("none").text("[ No Link ]");
$dialog.data('loaded', true);
$dialog.find(".student_options").append($option);
$dialog.find(".enrollment_id").val(enrollment_id);
$dialog.find(".student_options").val("none").val(current_user_id);
$dialog.find(".loading_message").hide().end()
.find(".students_link").show();
$dialog.find(".existing_user").showIf(current_user_id);
$dialog.data('callback', callback);
user_data.existing_user_name = $dialog.find(".student_options option[value='" + current_user_id + "']").text();
$dialog.fillTemplateData({data: user_data});
}, function() {
$dialog.find(".loading_message").text("Loading Students Failed, please try again");
$dialog.data('callback', callback);
});
} else {
$dialog.find(".enrollment_id").val(enrollment_id);
$dialog.find(".existing_user").showIf(current_user_id);
$dialog.find(".student_options").val("none").val(current_user_id);
user_data.existing_user_name = $dialog.find(".student_options option[value='" + current_user_id + "']").text();
$dialog.fillTemplateData({data: user_data});
}
$dialog.find(".existing_user").showIf(current_user_id);
$dialog.find(".student_options option:not(.blank)").remove();
$dialog
.dialog('close').dialog({
autoOpen: false,
title: "Link to Student",
width: 400
}).dialog('open');
}
};
})();
$(document).ready(function() {
$(document).bind('enrollment_added', function() {
$("#link_student_dialog").data('loaded', false);
});
$("#link_student_dialog .cancel_button").click(function() {
$("#link_student_dialog").dialog('close');
});
$("#link_student_dialog_form").formSubmit({
beforeSubmit: function(data) {
$(this)
.find("button").attr('disabled', true).end()
.find(".save_button").text("Linking to Student...");
},
success: function(data) {
$(this)
.find("button").attr('disabled', false).end()
.find(".save_button").text("Link to Student");
var enrollment = data.enrollment;
var callback = $("#link_student_dialog").data('callback');
$("#link_student_dialog").dialog('close');
if($.isFunction(callback) && enrollment) {
callback(enrollment);
}
},
error: function(data) {
$(this)
.find("button").attr('disabled', false)
.find(".save_button").text("Linking Failed, please try again");
}
});
});