Преглед изворни кода

AMBARI-4136. Unsaved Config Changes prompt should say Save, Discard, Cancel. (akovalenko)

Aleksandr Kovalenko пре 11 година
родитељ
комит
21d0830929

+ 21 - 9
ambari-web/app/controllers/main/service/info/configs.js

@@ -22,6 +22,7 @@ require('controllers/wizard/slave_component_groups_controller');
 App.MainServiceInfoConfigsController = Em.Controller.extend({
   name: 'mainServiceInfoConfigsController',
   isHostsConfigsPage: false,
+  forceTransition: false,
   dataIsLoaded: false,
   stepConfigs: [], //contains all field properties that are viewed in this service
   selectedService: null,
@@ -147,6 +148,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
   clearStep: function () {
     this.set('isInit', true);
     this.set('hash', null);
+    this.set('forceTransition', false);
     this.set('dataIsLoaded', false);
     this.set('filter', '');
     this.get('filterColumns').setEach('selected', false);
@@ -2014,7 +2016,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
   selectConfigGroup: function (event) {
     if (!this.get('isInit')) {
       if (this.hasUnsavedChanges()) {
-        this.showSavePopup(event);
+        this.showSavePopup(null, event);
         return;
       }
     }
@@ -2033,26 +2035,36 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
    * If some configs are changed and user navigates away or select another config-group, show this popup with propose to save changes
    * @param {object} event - triggered event for seleting another config-group
    */
-  showSavePopup: function(event) {
-    if (!event) event = null;
+  showSavePopup: function (path, event) {
     var _this = this;
     App.ModalPopup.show({
       header: Em.I18n.t('common.warning'),
       body: Em.I18n.t('services.service.config.exitPopup.body'),
+      footerClass: Ember.View.extend({
+        templateName: require('templates/main/service/info/save_popup_footer'),
+        isSaveDisabled: function() {
+          return _this.get('isSubmitDisabled');
+        }.property()
+      }),
       primary: Em.I18n.t('common.save'),
       secondary: Em.I18n.t('common.cancel'),
-      onPrimary: function() {
+      onSave: function () {
         _this.restartServicePopup();
-        this._super();
+        this.hide();
       },
-      onSecondary: function() {
-        if (event) {
+      onDiscard: function () {
+        if (path) {
+          _this.set('forceTransition', true);
+          App.router.route(path);
+        } else if (event) {
           // Prevent multiple popups
           _this.set('hash', _this.getHash());
-
           _this.selectConfigGroup(event);
         }
-        this._super();
+        this.hide();
+      },
+      onCancel: function () {
+        this.hide();
       }
     });
   }

+ 1 - 0
ambari-web/app/messages.js

@@ -162,6 +162,7 @@ Em.I18n.translations = {
   'common.conf.group': 'Configuration Group',
   'common.ignore': 'Ignore',
   'common.restart': 'Restart',
+  'common.discard': 'Discard',
 
   'requestInfo.installComponents':'Install Components',
   'requestInfo.installServices':'Install Services',

+ 10 - 3
ambari-web/app/routes/main.js

@@ -869,10 +869,12 @@ module.exports = Em.Route.extend({
           var item = router.get('mainServiceItemController.content');
           router.get('mainServiceItemController').connectOutlet('mainServiceInfoConfigs', item);
         },
-        exit: function(router, context) {
+        unroutePath: function (router, context) {
           var controller = router.get('mainServiceInfoConfigsController');
-          if (controller.hasUnsavedChanges()) {
-            controller.showSavePopup();
+          if (!controller.get('forceTransition') && controller.hasUnsavedChanges()) {
+            controller.showSavePopup(context);
+          } else {
+            this._super(router, context);
           }
         }
       }),
@@ -884,6 +886,11 @@ module.exports = Em.Route.extend({
         }
       }),
       showInfo: function (router, event) {
+        var mainServiceInfoConfigsController = App.router.get('mainServiceInfoConfigsController');
+        if (event.context === 'summary' && mainServiceInfoConfigsController.hasUnsavedChanges()) {
+          mainServiceInfoConfigsController.showSavePopup(router.get('location.lastSetURL').replace('configs', 'summary'));
+          return false;
+        }
         var parent = event.view._parentView;
         parent.deactivateChildViews();
         event.view.set('active', "active");

+ 23 - 0
ambari-web/app/templates/main/service/info/save_popup_footer.hbs

@@ -0,0 +1,23 @@
+{{!
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+}}
+
+<div class="modal-footer">
+  <button type="button" class="btn btn" {{action onCancel target="view.parentView"}}>{{t common.cancel}}</button>
+  <button type="button" class="btn btn" {{action onDiscard target="view.parentView"}}>{{t common.discard}}</button>
+  <button type="button" class="btn btn-success" {{bindAttr disabled="view.isSaveDisabled"}} {{action onSave target="view.parentView"}}>{{t common.save}}</button>
+</div>