fix context module item reordering error

test plan:
* add a module item
* confirm that the module is disabled (so you will
not be able to drag and drop the module items)
until the request has finished

fixes #CNVS-7761

Change-Id: Ica8d436bab66971c6b25a693c86effb7a9479974
Reviewed-on: https://gerrit.instructure.com/23747
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Product-Review: Matt Goodwin <mattg@instructure.com>
QA-Review: Hannah Bottalla <hannah@instructure.com>
This commit is contained in:
James Williams 2013-08-26 14:04:24 -06:00
parent 1949a8b9e2
commit 3693e171f1
2 changed files with 27 additions and 25 deletions

View File

@ -254,7 +254,7 @@ class ContextModulesController < ApplicationController
def reorder_items
@module = @context.context_modules.not_deleted.find(params[:context_module_id])
if authorized_action(@module, @current_user, :update)
order = params[:order].split(",")
order = params[:order].split(",").map{|id| id.to_i}
tags = @context.context_module_tags.active.find_all_by_id(order).compact
affected_module_ids = tags.map(&:context_module_id).uniq.compact
affected_items = []

View File

@ -80,25 +80,27 @@ define([
updateModuleItemPositions: function(event, ui) {
var $module = ui.item.parents(".context_module");
var url = $module.find(".reorder_items_url").attr('href');
$module.find(".content").loadingImage();
var items = [];
$module.find(".context_module_items .context_module_item").each(function() {
items.push($(this).getTemplateData({textValues: ['id']}).id);
});
$.ajaxJSON(url, 'POST', {order: items.join(",")}, function(data) {
$module.find(".content").loadingImage('remove');
if(data && data.context_module && data.context_module.content_tags) {
for(var idx in data.context_module.content_tags) {
var tag = data.context_module.content_tags[idx].content_tag;
$module.find("#context_module_item_" + tag.id).fillTemplateData({
data: {position: tag.position}
});
$module.find(".context_module_items.ui-sortable").sortable('disable');
$module.disableWhileLoading(
$.ajaxJSON(url, 'POST', {order: items.join(",")}, function(data) {
if(data && data.context_module && data.context_module.content_tags) {
for(var idx in data.context_module.content_tags) {
var tag = data.context_module.content_tags[idx].content_tag;
$module.find("#context_module_item_" + tag.id).fillTemplateData({
data: {position: tag.position}
});
}
}
}
}, function(data) {
$module.find(".content").loadingImage('remove');
$module.find(".content").errorBox(I18n.t('errors.reorder', 'Reorder failed, please try again.'));
});
$module.find(".context_module_items.ui-sortable").sortable('enable');
}, function(data) {
$module.find(".content").loadingImage('remove');
$module.find(".content").errorBox(I18n.t('errors.reorder', 'Reorder failed, please try again.'));
})
);
},
refreshProgressions: function(show_links) {
@ -804,17 +806,17 @@ define([
options.submit = function(item_data) {
var $module = $("#context_module_" + module.id);
var $item = modules.addItemToModule($module, item_data);
$module.find(".context_module_items.ui-sortable").sortable('refresh');
$module.find(".context_module_items.ui-sortable").sortable('refresh').sortable('disable');
var url = $module.find(".add_module_item_link").attr('rel');
$item.loadingImage({image_size: 'small'});
$.ajaxJSON(url, 'POST', item_data, function(data) {
$item.loadingImage('remove');
$item.remove();
data.content_tag.type = item_data['item[type]'];
modules.addItemToModule($module, data.content_tag);
$module.find(".context_module_items.ui-sortable").sortable('refresh');
modules.updateAssignmentData();
});
$module.disableWhileLoading(
$.ajaxJSON(url, 'POST', item_data, function(data) {
$item.remove();
data.content_tag.type = item_data['item[type]'];
modules.addItemToModule($module, data.content_tag);
$module.find(".context_module_items.ui-sortable").sortable('enable').sortable('refresh');
modules.updateAssignmentData();
})
);
};
INST.selectContentDialog(options);
}