config_widget_view.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /**
  20. * Common view for config widgets
  21. * @type {Em.View}
  22. */
  23. App.ConfigWidgetView = Em.View.extend({
  24. /**
  25. * @type {App.ConfigProperty}
  26. */
  27. config: null,
  28. /**
  29. * Config name to display.
  30. * @type {String}
  31. */
  32. configLabel: function() {
  33. return this.get('config.displayName') || this.get('config.name');
  34. }.property('config.name', 'config.displayName'),
  35. /**
  36. * Error message computed in config property model
  37. * @type {String|Boolean}
  38. */
  39. configErrorMessage: function() {
  40. return this.get('config.errorMessage') || false;
  41. }.property('config.errorMessage'),
  42. /**
  43. * Determines if config-value was changed
  44. * @type {boolean}
  45. */
  46. valueIsChanged: function () {
  47. return this.get('config.value') != this.get('config.defaultValue');
  48. }.property('config.value'),
  49. /**
  50. * @type {boolean}
  51. */
  52. isComparison: false,
  53. /**
  54. * Reset config-value to its default
  55. * @method restoreValue
  56. */
  57. restoreValue: function () {
  58. this.set('config.value', this.get('config.defaultValue'));
  59. },
  60. /**
  61. * Determines if override is allowed for <code>config</code>
  62. * @type {boolean}
  63. */
  64. overrideAllowed: function () {
  65. var config = this.get('config');
  66. if (!config) return false;
  67. return config.get('isOriginalSCP') && config.get('isPropertyOverridable') && !this.get('isComparison');
  68. }.property('config.isOriginalSCP', 'config.isPropertyOverridable', 'isComparison'),
  69. /**
  70. * Determines if undo is allowed for <code>config</code>
  71. * @type {boolean}
  72. */
  73. undoAllowed: function () {
  74. var config = this.get('config');
  75. if (!config) return false;
  76. return !config.get('cantBeUndone') && config.get('isNotDefaultValue');
  77. }.property('config.cantBeUndone', 'config.isNotDefaultValue')
  78. });