define([
- 'common/modals',
+ 'common/modal-form',
'templates/coding-rules'
-], function (Modal, Templates) {
+], function (ModalFormView, Templates) {
var $ = jQuery;
- return Modal.extend({
+ return ModalFormView.extend({
template: Templates['coding-rules-custom-rule-creation'],
- ui: {
- customRuleCreationKey: '#coding-rules-custom-rule-creation-key',
- customRuleCreationName: '#coding-rules-custom-rule-creation-name',
- customRuleCreationHtmlDescription: '#coding-rules-custom-rule-creation-html-description',
- customRuleCreationSeverity: '#coding-rules-custom-rule-creation-severity',
- customRuleCreationStatus: '#coding-rules-custom-rule-creation-status',
- customRuleCreationParameters: '[name]',
- customRuleCreationCreate: '#coding-rules-custom-rule-creation-create',
- customRuleCreationReactivate: '#coding-rules-custom-rule-creation-reactivate',
- modalFoot: '.modal-foot'
+ ui: function () {
+ return _.extend(ModalFormView.prototype.ui.apply(this, arguments), {
+ customRuleCreationKey: '#coding-rules-custom-rule-creation-key',
+ customRuleCreationName: '#coding-rules-custom-rule-creation-name',
+ customRuleCreationHtmlDescription: '#coding-rules-custom-rule-creation-html-description',
+ customRuleCreationSeverity: '#coding-rules-custom-rule-creation-severity',
+ customRuleCreationStatus: '#coding-rules-custom-rule-creation-status',
+ customRuleCreationParameters: '[name]',
+ customRuleCreationCreate: '#coding-rules-custom-rule-creation-create',
+ customRuleCreationReactivate: '#coding-rules-custom-rule-creation-reactivate',
+ modalFoot: '.modal-foot'
+ });
},
events: function () {
- return _.extend(Modal.prototype.events.apply(this, arguments), {
+ return _.extend(ModalFormView.prototype.events.apply(this, arguments), {
'input @ui.customRuleCreationName': 'generateKey',
'keydown @ui.customRuleCreationName': 'generateKey',
'keyup @ui.customRuleCreationName': 'generateKey',
},
onRender: function () {
- Modal.prototype.onRender.apply(this, arguments);
+ ModalFormView.prototype.onRender.apply(this, arguments);
this.keyModifiedByUser = false;
that.$('.modal-warning').show();
that.ui.modalFoot.html(Templates['coding-rules-custom-rule-reactivation']());
} else {
- jQuery.ajaxSettings.error(jqXHR, textStatus, errorThrown);
- that.ui.modalFoot.html(origFooter);
+ that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings);
}
});
},
};
});
- return _.extend(Modal.prototype.serializeData.apply(this, arguments), {
+ return _.extend(ModalFormView.prototype.serializeData.apply(this, arguments), {
change: this.model && this.model.has('key'),
params: params,
severities: ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'],
--- /dev/null
+define(['common/modals'], function (ModalView) {
+
+ return ModalView.extend({
+
+ ui: function () {
+ return {
+ messagesContainer: '.js-modal-messages'
+ };
+ },
+
+ events: function () {
+ return _.extend(ModalView.prototype.events.apply(this, arguments), {
+ 'submit form': 'onFormSubmit'
+ });
+ },
+
+ onFormSubmit: function (e) {
+ e.preventDefault();
+ },
+
+ showErrors: function (errors, warnings) {
+ var container = this.ui.messagesContainer.empty();
+ if (_.isArray(errors)) {
+ errors.forEach(function (error) {
+ var html = '<div class="message-error">' + error.msg + '</div>';
+ container.append(html);
+ });
+ }
+ if (_.isArray(warnings)) {
+ warnings.forEach(function (warn) {
+ var html = '<div class="message-alert">' + warn.msg + '</div>';
+ container.append(html);
+ });
+ }
+ }
+ });
+
+});
--- /dev/null
+define(['backbone.marionette'], function (Marionette) {
+
+ var $ = jQuery,
+ EVENT_SCOPE = 'modal';
+
+ return Marionette.ItemView.extend({
+ className: 'modal',
+ overlayClassName: 'modal-overlay',
+
+ events: function () {
+ return {
+ 'click .js-modal-close': 'close'
+ };
+ },
+
+ onRender: function () {
+ var that = this;
+ this.$el.detach().appendTo($('body'));
+ this.renderOverlay();
+ this.keyScope = key.getScope();
+ key.setScope('modal');
+ key('escape', 'modal', function () {
+ that.close();
+ return false;
+ });
+ },
+
+ onClose: function () {
+ this.removeOverlay();
+ key.deleteScope('modal');
+ key.setScope(this.keyScope);
+ },
+
+ renderOverlay: function () {
+ var overlay = $('.' + this.overlayClassName);
+ if (overlay.length === 0) {
+ $('<div class="' + this.overlayClassName + '"></div>').appendTo($('body'));
+ }
+ },
+
+ removeOverlay: function () {
+ $('.' + this.overlayClassName).remove();
+ },
+
+ attachCloseEvents: function () {
+ var that = this;
+ $('body').on('click.' + EVENT_SCOPE, function () {
+ $('body').off('click.' + EVENT_SCOPE);
+ that.close();
+ });
+ }
+ });
+
+});