From b09c20f02fbd37bd76495cb970148eef62724534 Mon Sep 17 00:00:00 2001 From: asadiqbal Date: Wed, 30 Sep 2015 14:05:49 +0500 Subject: [PATCH] SOL-1225 --- .../js/certificates/views/signatory_editor.js | 35 +++++++++++++++++-- .../test_studio_settings_certificates.py | 8 ++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/cms/static/js/certificates/views/signatory_editor.js b/cms/static/js/certificates/views/signatory_editor.js index 750d5f9817..24bd47a498 100644 --- a/cms/static/js/certificates/views/signatory_editor.js +++ b/cms/static/js/certificates/views/signatory_editor.js @@ -85,8 +85,10 @@ function ($, _, Backbone, gettext, if (event && event.preventDefault) { event.preventDefault(); } this.model.set( 'name', - this.$('.signatory-name-input').val() + this.$('.signatory-name-input').val(), + { silent: true } ); + this.toggleValidationErrorMessage('name'); this.eventAgg.trigger("onSignatoryUpdated", this.model); }, @@ -95,8 +97,10 @@ function ($, _, Backbone, gettext, if (event && event.preventDefault) { event.preventDefault(); } this.model.set( 'title', - this.$('.signatory-title-input').val() + this.$('.signatory-title-input').val(), + { silent:true } ); + this.toggleValidationErrorMessage('title'); this.eventAgg.trigger("onSignatoryUpdated", this.model); }, @@ -105,7 +109,8 @@ function ($, _, Backbone, gettext, if (event && event.preventDefault) { event.preventDefault(); } this.model.set( 'organization', - this.$('.signatory-organization-input').val() + this.$('.signatory-organization-input').val(), + { silent: true } ); this.eventAgg.trigger("onSignatoryUpdated", this.model); }, @@ -178,7 +183,31 @@ function ($, _, Backbone, gettext, } }); modal.show(); + }, + + /** + * @desc Toggle the validation error messages. If given model attribute is not valid then show the error message + * else remove it. + * @param string modelAttribute - the attribute of the signatory model e.g. name, title. + */ + toggleValidationErrorMessage: function(modelAttribute) { + var selector = "div.add-signatory-" + modelAttribute; + if (!this.model.isValid() && _.has(this.model.validationError, modelAttribute)) { + + // Show the error message if it is not exist before. + if( !$(selector).hasClass('error')) { + var errorMessage = this.model.validationError[modelAttribute]; + $(selector).addClass("error"); + $(selector).append("" + errorMessage + ""); + } + } + else { + // Remove the error message. + $(selector).removeClass("error"); + $(selector + ">span.message-error").remove(); + } } + }); return SignatoryEditorView; }); diff --git a/common/test/acceptance/tests/studio/test_studio_settings_certificates.py b/common/test/acceptance/tests/studio/test_studio_settings_certificates.py index 95e08128ff..77d5857859 100644 --- a/common/test/acceptance/tests/studio/test_studio_settings_certificates.py +++ b/common/test/acceptance/tests/studio/test_studio_settings_certificates.py @@ -208,7 +208,13 @@ class CertificatesTest(StudioCourseTest): certificate = self.create_and_verify_certificate( "Course Title Override", 0, - [self.make_signatory_data('Signatory title with new line character \n')] + [ + { + 'name': 'Signatory Name', + 'title': 'Signatory title with new line character \n', + 'organization': 'Signatory Organization', + } + ] ) certificate.wait_for_certificate_delete_button()