Skip to content

Commit 87f68ff

Browse files
author
Mark Ericksen
committed
improve error handling for ePortfolio section editing
fixes CNVS-5727 testing steps: - on an ePortfolio page, click "Organize Sections" to add a new section. - blank out the name and hit enter (nothing happens) you should now be able to set some valid text and save it. (previously it would not save valid text until refreshing the page) - set a name that is too long (> 255 chars) and verify a popup/alert message reports that the name is too long and the invalid entry is removed from the page - editing an existing section - clearing the name and trying to save (nothing happens) then setting to something should now save - set a name that is too long (> 255 chars) and verify that an error message is displayed on the section name input with a meaningful error message Change-Id: I04dfab3cd741c4b04c5f8b2990aee8216aa34d7f Reviewed-on: https://gerrit.instructure.com/24164 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jon Jensen <jon@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com>
1 parent 22ca033 commit 87f68ff

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

app/controllers/eportfolio_categories_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def update
4949
format.html { redirect_to eportfolio_category_url(@portfolio, @category) }
5050
format.json { render :json => @category.to_json }
5151
else
52+
format.json { render :json => @category.errors.to_json }
5253
end
5354
end
5455
end

app/models/eportfolio_category.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class EportfolioCategory < ActiveRecord::Base
2424
belongs_to :eportfolio
2525
before_save :infer_unique_slug
2626
validates_presence_of :eportfolio_id
27-
27+
validates_length_of :name, :maximum => maximum_string_length, :allow_blank => true
28+
2829
acts_as_list :scope => :eportfolio
2930

3031
def infer_unique_slug

public/javascripts/eportfolio.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ define([
542542
function saveObject($obj, type) {
543543
var isSaving = $obj.data('event_pending');
544544
if(isSaving || $obj.length === 0) { return; }
545-
$obj.data('event_pending', true);
546545
var method = "PUT";
547546
var url = $obj.find(".rename_" + type + "_url").attr('href');
548547
if($obj.attr('id') == type + '_new') {
@@ -567,6 +566,7 @@ define([
567566
if(method == "POST") {
568567
$obj.attr('id', type + '_saving');
569568
}
569+
$obj.data('event_pending', true);
570570
$obj.addClass('event_pending');
571571
$.ajaxJSON(url, method, data, function(data) {
572572
$obj.removeClass('event_pending');
@@ -585,7 +585,27 @@ define([
585585
});
586586
$obj.data('event_pending', false);
587587
countObjects(type);
588-
});
588+
},
589+
// error callback
590+
function(data, xhr, textStatus, errorThrown){
591+
$obj.removeClass('event_pending');
592+
$obj.data('event_pending', false);
593+
var name_message = I18n.t("errors.section_name_invalid", "Section name is not valid")
594+
if (xhr['name'] && xhr['name'].length > 0 && xhr['name'][0]['message'] == 'too_long') {
595+
name_message = I18n.t("errors.section_name_too_long", "Section name is too long");
596+
}
597+
if ($obj.hasClass('unsaved')) {
598+
alert(name_message);
599+
$obj.remove();
600+
}
601+
else {
602+
// put back in "edit" mode
603+
$obj.find('.edit_section_link').click();
604+
$obj.find('#section_name').errorBox(name_message).css('z-index', 20)
605+
}
606+
},
607+
// options
608+
{skipDefaultError: true});
589609
return true;
590610
}
591611
function editObject($obj, type) {

0 commit comments

Comments
 (0)