Fixes issue with setting "or" condition

for "OR" module feature flag

Test Plan:
* Enable "OR" Condition Feature Flag
* Create a module and specify completion
  requirements with the default setting
  that ALL requirements must be met to be
  marked as completed
* Log in as a student that has access
  to the modules; it should not be marked
  as completed if the student hasn't compeleted
  the requirement

Change-Id: I0c45d13c8dd21a0d5c80c4deb49a6c2c68030342
Reviewed-on: https://gerrit.instructure.com/57506
Reviewed-by: Brock Cooper <bcooper@instructure.com>
Tested-by: Jenkins
QA-Review: Clare Strong <clare@instructure.com>
Product-Review: Brock Cooper <bcooper@instructure.com>
This commit is contained in:
Dan Minkevitch 2015-06-30 15:45:39 -06:00 committed by Brock Cooper
parent ac95f2d672
commit cf3d13fb53
3 changed files with 46 additions and 40 deletions

View File

@ -56,12 +56,12 @@
<% if @context.feature_enabled?(:nc_or) %>
<div class="ic-Form-control ic-Form-control--radio requirement-count-radio">
<div class="ic-Radio">
<%= f.radio_button :requirement_count, 0 %>
<%= f.label :requirement_count_0, t("Student must complete all of these requirements"), class: "ic-Label" %>
<%= f.radio_button :requirement_count, "" %>
<%= f.label :requirement_count, t("Student must complete all of these requirements"), class: "ic-Label", value: "" %>
</div>
<div class="ic-Radio">
<%= f.radio_button :requirement_count, 1 %>
<%= f.label :requirement_count_1, t("Student must complete one of these requirements"), class: "ic-Label" %>
<%= f.label :requirement_count, t("Student must complete one of these requirements"), class: "ic-Label", value: 1 %>
</div>
</div>
<% end %>

View File

@ -348,7 +348,7 @@ define([
$module.find(".prerequisites .prerequisite_criterion").each(function() {
prerequisites.push($(this).getTemplateData({textValues: ['id', 'name', 'type']}));
});
$form.find(".prerequisites_list .criteria_list").empty();
for(var idx in prerequisites) {
var pre = prerequisites[idx];
@ -372,21 +372,21 @@ define([
.find(".prerequisites_list .criteria_list").showIf(prerequisites.length != 0).end()
.find(".add_prerequisite_link").showIf(!no_prereqs).end()
.find(".completion_entry .criteria_list").showIf(!no_items).end()
.find(".completion_entry .no_items_message").hide().end()
.find(".add_completion_criterion_link").showIf(!no_items);
// Set no items or criteria message plus diasable elements if there are no items or no requirements
if (no_items) {
$form.find(".completion_entry .no_items_message").show();
} else if ($module.find(".content .context_module_item .criterion.defined").length !== 0) {
$(".require-sequential").children().show();
$(".requirement-count-radio .ic-Radio").children().show();
}
}
var $requirmentCount = $module.find('.pill li').data("requirement-count");
$requirmentCount == 1 ? $('#context_module_requirement_count_1').prop('checked', true) : $('#context_module_requirement_count_0').prop('checked', true);
var $requirementCount = $module.find('.pill li').data("requirement-count");
$requirementCount == 1 ? $('#context_module_requirement_count_1').prop('checked', true) : $('#context_module_requirement_count').prop('checked', true);
$module.fadeIn('fast', function() {
});
@ -653,7 +653,7 @@ define([
// Update requirement message pill
var $pillMessage = $module.find('.pill li');
var newPillMessage = data.context_module.requirement_count && data.context_module.requirement_count !== 0 ? I18n.t("Complete One Item") : I18n.t("Complete All Items");
var newPillMessage = data.context_module.requirement_count ? I18n.t("Complete One Item") : I18n.t("Complete All Items");
$pillMessage.text(newPillMessage);
$pillMessage.data("requirement-count", data.context_module.requirement_count);
@ -695,8 +695,14 @@ define([
prereqs.push("module_" + id);
}
});
data['context_module[requirement_count]'] = $('input[name="context_module[requirement_count]"]:checked').val();
"0";
var requirementCount = $('input[name="context_module[requirement_count]"]:checked').val();
if (requirementCount) {
data['context_module[requirement_count]'] = requirementCount;
} else {
delete data['context_module[requirement_count]'];
}
data['context_module[prerequisites]'] = prereqs.join(",");
data['context_module[completion_requirements][none]'] = "none";
$(this).find(".criteria_list .criterion").each(function() {
@ -771,7 +777,7 @@ define([
var $pre = $form.find("#criterion_blank_prereq").clone(true).removeAttr('id');
$select.find("." + $module.attr('id')).remove();
var afters = [];
$("#context_modules .context_module").each(function() {
if($(this)[0] == $module[0] || afters.length > 0) {
afters.push($(this).attr('id'));
@ -850,7 +856,7 @@ define([
var $option = $(this).parents(".completion_criterion_option");
// Show score text box and do some resizing of drop down to get it to stay on one line
$option.find(".min_score_box").showIf($(this).val() == 'min_score');
$option.find(".min_score_box").showIf($(this).val() == 'min_score');
var id = $option.find(".id").val();
var points_possible = $.trim($("#context_module_item_" + id + " .points_possible_display").text().split(' ')[0]);
@ -913,7 +919,7 @@ define([
modules.addItemToModule($module, data.content_tag);
$module.find(".context_module_items.ui-sortable").sortable('refresh');
modules.updateAssignmentData();
}, function(data) {
}).done (function() {
if (elemID) {
@ -921,12 +927,12 @@ define([
var $activeElemClass = "." + $(activeElem).attr('class').split(' ').join(".");
$(elemID).find($activeElemClass).focus();
}, 0);
} else {
$cogLink.focus();
}
})
});
$(".edit_item_link").live('click', function(event) {
event.preventDefault();
@ -1460,14 +1466,14 @@ define([
$elem.find(":tabbable:first").focus();
};
// This method will select the items passed in with the options object
// This method will select the items passed in with the options object
// and can be used to advance the focus or return to the previous module or module_item
// This will also return the element that is now in focus
// This will also return the element that is now in focus
var selectItem = function (options) {
options = options || {};
if (!$currentElem) {
$elem = $('.context_module:first');
$elem = $('.context_module:first');
} else if($currentElem && $currentElem.hasClass('context_module')) {
$elem = options.selectWhenModuleFocused && options.selectWhenModuleFocused.item;
$elem = $elem.length ? $elem : (options.selectWhenModuleFocused && options.selectWhenModuleFocused.fallbackModule);
@ -1493,14 +1499,14 @@ define([
selectWhenModuleFocused: {
item: $currentElem && $currentElem.prev(".context_module").find(".context_module_item:visible:last"),
fallbackModule: $currentElem && $currentElem.prev(".context_module")
},
},
selectWhenModuleItemFocused: {
item: $currentElem && $currentElem.prev(".context_module_item:visible"),
fallbackModule: $currentElem && $currentElem.parents(".context_module")
}
};
var $elem = selectItem(params);
if ($elem.length) $currentElem = $elem;
if ($elem.length) $currentElem = $elem;
});
@ -1510,22 +1516,22 @@ define([
selectWhenModuleFocused: {
item: $currentElem && $currentElem.find(".context_module_item:visible:first"),
fallbackModule: $currentElem && $currentElem.next(".context_module")
},
},
selectWhenModuleItemFocused: {
item: $currentElem && $currentElem.next(".context_module_item:visible"),
fallbackModule: $currentElem && $currentElem.parents(".context_module").next(".context_module")
}
};
var $elem = selectItem(params);
if ($elem.length) $currentElem = $elem;
if ($elem.length) $currentElem = $elem;
});
});
// "e" opens up Edit Module Settings form if focus is on Module or Edit Item Details form if focused on Module Item
// "d" deletes module or module item
// "space" opens up Move Item or Move Module form depending on which item is focused
$document.keycodes('e d space', function(event) {
$elem = getClosestModuleOrItem($currentElem);
$elem = getClosestModuleOrItem($currentElem);
$hasClassItemHover = $elem.hasClass('context_module_item_hover');
if(event.keyString == 'e') {
@ -1544,14 +1550,14 @@ define([
event.preventDefault();
});
});
// "n" opens up the Add Module form
$document.keycodes('n', function(event) {
$(".add_module_link:visible:first").click();
event.preventDefault();
});
});
// "i" indents module item
// "o" outdents module item
$document.keycodes('i o', function(event) {

View File

@ -113,7 +113,7 @@ describe "context modules" do
it "should add and remove completion criteria" do
get "/courses/#{@course.id}/modules"
add_existing_module_item('#assignments_select', 'Assignment', @assignment.title)
@course.reload
smodule = @course.context_modules.first
smodule.publish!
@ -394,7 +394,7 @@ describe "context modules" do
third_module_name = 'Third Module'
add_module(first_module_name)
add_module(second_module_name)
#adding second module - can't use add_module method because a prerequisite needs to be added to this module
add_form = new_module_form
replace_content(add_form.find_element(:id, 'context_module_name'), third_module_name)
@ -436,7 +436,7 @@ describe "context modules" do
@course.enable_feature!(:nc_or)
get "/courses/#{@course.id}/modules"
add_existing_module_item('#assignments_select', 'Assignment', @assignment.title)
@course.reload
# add completion criterion
@ -456,7 +456,7 @@ describe "context modules" do
# Test that pill now says Complete One Item right after change and one reload
expect(fj('.pill li').text).to eq "Complete One Item"
@course.reload
get "/courses/#{@course.id}/modules"
expect(fj('.pill li').text).to eq "Complete One Item"
end
@ -480,7 +480,7 @@ describe "context modules" do
it "should validate locking a module item display functionality" do
get "/courses/#{@course.id}/modules"
add_form = new_module_form
lock_check = add_form.find_element(:id, 'unlock_module_at')
lock_check.click
@ -661,13 +661,13 @@ describe "context modules" do
# i : Increase Indent
# o : Decrease Indent
# n : New Module
modules = create_modules(2, true)
modules[0].add_item({:id => @assignment.id, :type => 'assignment'})
modules[0].add_item({:id => @assignment2.id, :type => 'assignment'})
modules[1].add_item({:id => @assignment3.id, :type => 'assignment'})
get "/courses/#{@course.id}/modules"
context_modules = ff('.context_module .icon-drag-handle')
context_module_items = ff('.context_module_item a.title')
@ -677,7 +677,7 @@ describe "context modules" do
context_modules[0].send_keys(:arrow_down)
check_element_has_focus(context_module_items[0])
context_module_items[0].send_keys("j")
check_element_has_focus(context_module_items[1])
@ -686,7 +686,7 @@ describe "context modules" do
context_module_items[0].send_keys(:arrow_up)
check_element_has_focus(context_modules[0])
# Test Edit key
wait_for_ajaximations(1000) # Has to wait one second before sending keys for it to work
context_modules[0].send_keys("e")
@ -705,12 +705,12 @@ describe "context modules" do
# Test Indent / Outdent
expect(ff('.context_module_item')[0]).to have_class('indent_0')
wait_for_ajaximations(1000)
wait_for_ajaximations(1000)
context_module_items[0].send_keys("i")
keep_trying_until do
expect(ff('.context_module_item')[0]).to have_class('indent_1')
end
wait_for_ajaximations(1000)
ff('.context_module_item a.title')[0].send_keys("o")
keep_trying_until do