application.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.ApplicationController = Em.Controller.extend(App.UserPref, {
  20. name: 'applicationController',
  21. clusterName: function () {
  22. return (App.router.get('clusterController.clusterName') || 'My Cluster');
  23. }.property('App.router.clusterController.clusterName'),
  24. /**
  25. * set ambari server version from installerController or mainController, making sure version shown up all the time
  26. */
  27. ambariVersion: function () {
  28. return (App.router.get('installerController.ambariServerVersion') || App.router.get('mainController.ambariServerVersion') || Em.I18n.t('common.notAvailable'));
  29. }.property('App.router.installerController.ambariServerVersion', 'App.router.mainController.ambariServerVersion'),
  30. clusterDisplayName: function () {
  31. var name = this.get('clusterName');
  32. return name.length > 13 ? name.substr(0, 10) + "..." : name;
  33. }.property('clusterName'),
  34. isClusterDataLoaded: function() {
  35. return App.router.get('clusterController.isLoaded') && App.router.get('loggedIn');
  36. }.property('App.router.clusterController.isLoaded','App.router.loggedIn'),
  37. init: function(){
  38. this._super();
  39. },
  40. dataLoading: function () {
  41. var dfd = $.Deferred();
  42. var self = this;
  43. this.getUserPref(this.persistKey()).done(function () {
  44. var curPref = self.get('currentPrefObject');
  45. self.set('currentPrefObject', null);
  46. dfd.resolve(curPref);
  47. });
  48. return dfd.promise();
  49. },
  50. persistKey: function (loginName) {
  51. if (App.get('testMode')) {
  52. return 'admin_settings_show_bg';
  53. }
  54. if (!loginName)
  55. loginName = App.router.get('loginName');
  56. return 'admin-settings-show-bg-' + loginName;
  57. },
  58. currentPrefObject: null,
  59. getUserPrefSuccessCallback: function (response, request, data) {
  60. if (response != null) {
  61. console.log('Got persist value from server with key ' + data.key + '. Value is: ' + response);
  62. this.set('currentPrefObject', response);
  63. return response;
  64. }
  65. },
  66. getUserPrefErrorCallback: function (request, ajaxOptions, error) {
  67. // this user is first time login
  68. if (request.status == 404) {
  69. console.log('Persist did NOT find the key');
  70. this.set('currentPrefObject', true);
  71. this.postUserPref(this.persistKey(), true);
  72. return true;
  73. }
  74. },
  75. showSettingsPopup: function() {
  76. // Settings only for admins
  77. if (!App.get('isAdmin')) return;
  78. var self = this;
  79. var curValue = null;
  80. this.dataLoading().done(function (initValue) {
  81. App.ModalPopup.show({
  82. header: Em.I18n.t('common.userSettings'),
  83. bodyClass: Em.View.extend({
  84. templateName: require('templates/common/settings'),
  85. isNotShowBgChecked: !initValue,
  86. updateValue: function () {
  87. curValue = !this.get('isNotShowBgChecked');
  88. }.observes('isNotShowBgChecked')
  89. }),
  90. primary: Em.I18n.t('common.save'),
  91. onPrimary: function() {
  92. if (curValue == null) {
  93. curValue = initValue;
  94. }
  95. var key = self.persistKey();
  96. if (!App.testMode) {
  97. self.postUserPref(key, curValue);
  98. }
  99. this.hide();
  100. }
  101. })
  102. });
  103. },
  104. showAboutPopup: function() {
  105. var self = this;
  106. App.ModalPopup.show({
  107. header: Em.I18n.t('common.aboutAmbari'),
  108. secondary: false,
  109. bodyClass: Em.View.extend({
  110. templateName: require('templates/common/about'),
  111. ambariVersion: this.get('ambariVersion')
  112. })
  113. });
  114. }
  115. });