From bcd2ad2b3ac7ee3194e8c391858d07c2f9d02621 Mon Sep 17 00:00:00 2001 From: Vitaly Kramskikh Date: Thu, 31 Oct 2013 16:36:58 +0400 Subject: [PATCH] Unbreak and refactor error messages Change-Id: I76b1c209390345961fe09f9ccd57749231893acf --- nailgun/static/js/utils.js | 3 ++- nailgun/static/js/views/dialogs.js | 32 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/nailgun/static/js/utils.js b/nailgun/static/js/utils.js index 5a8874c623..720b95e74f 100644 --- a/nailgun/static/js/utils.js +++ b/nailgun/static/js/utils.js @@ -51,7 +51,8 @@ define(['require'], function(require) { var dialogViews = require('views/dialogs'); // avoid circular dependencies var dialog = new dialogViews.Dialog(); parentView.registerSubView(dialog); - dialog.displayInfoMessage(_.extend({error: true, message: ''}, options)); + dialog.render(_.extend({title: '', message: ''}, options)); + dialog.displayErrorMessage(options); }, showBandwidth: function(bandwidth) { bandwidth = parseInt(bandwidth, 10); diff --git a/nailgun/static/js/views/dialogs.js b/nailgun/static/js/views/dialogs.js index f22381fa20..41a6fd9510 100644 --- a/nailgun/static/js/views/dialogs.js +++ b/nailgun/static/js/views/dialogs.js @@ -49,7 +49,7 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl beforeTearDown: function() { this.$el.modal('hide'); }, - displayErrorMessage: function () { + displayError: function() { var logsLink; try { if (app.page.model.constructor == models.Cluster) { @@ -57,12 +57,13 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl logsLink = '#cluster/' + app.page.model.id + '/logs/' + utils.serializeTabOptions(options); } } catch(e) {} - this.$('.modal-body').html(this.errorMessageTemplate({logsLink: logsLink})); + this.$('.modal-body').removeClass().addClass('modal-body'); + this.$('.modal-body').html(views.Dialog.prototype.errorMessageTemplate({logsLink: logsLink})); }, - displayInfoMessage: function(options) { - this.$el.html(views.Dialog.prototype.template(options)); - if (options.error) { - this.displayErrorMessage(); + displayErrorMessage: function(options) { + this.displayError(); + if (options.message) { + this.$('.text-error').text(options.message); } }, initialize: function(options) { @@ -166,10 +167,7 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl this.$el.modal('hide'); }, this)) .fail(_.bind(function() { - this.displayInfoMessage({ - title: 'Environment Configuration Error', - message: 'Your OpenStack environment has been created, but confiugration failed. You can configure it manually.' - }); + this.displayErrorMessage({message: 'Your OpenStack environment has been created, but configuration failed. You can configure it manually.'}); }, this)); }, this)) .fail(_.bind(function(response) { @@ -178,9 +176,9 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl this.goToPane(0); cluster.trigger('invalid', cluster, {name: response.responseText}); } else if (response.status == 400) { - this.displayInfoMessage({error: false, title: 'Create a new OpenStack environment error', message: response.responseText}); + this.displayErrorMessage({message: response.responseText}); } else { - this.displayErrorMessage(); + this.displayError(); } }, this)); } @@ -508,7 +506,7 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl app.page.update(); this.$el.modal('hide'); }, this)) - .fail(_.bind(this.displayErrorMessage, this)); + .fail(_.bind(this.displayError, this)); } else { this.$el.modal('hide'); } @@ -568,7 +566,7 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl this.model.get('nodes').trigger('resize'); app.navbar.refresh(); }, this)) - .fail(_.bind(this.displayErrorMessage, this)); + .fail(_.bind(this.displayError, this)); }, render: function() { this.constructor.__super__.render.call(this, {cluster: this.model}); @@ -589,7 +587,7 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl this.$el.modal('hide'); app.page.deploymentStarted(); }, this)) - .fail(_.bind(this.displayErrorMessage, this)); + .fail(_.bind(this.displayError, this)); }, render: function() { this.constructor.__super__.render.call(this, { @@ -613,7 +611,7 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl app.navbar.refresh(); app.navigate('#clusters', {trigger: true}); }, this)) - .fail(_.bind(this.displayErrorMessage, this)); + .fail(_.bind(this.displayError, this)); }, render: function() { this.constructor.__super__.render.call(this, {cluster: this.model}); @@ -780,7 +778,7 @@ function(require, utils, models, simpleMessageTemplate, createClusterWizardTempl app.navbar.refresh(); app.page.removeFinishedTasks(); }, this)) - .fail(_.bind(this.displayErrorMessage, this)); + .fail(_.bind(this.displayError, this)); } }, render: function() {