config_widget_view.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. require('views/common/controls_view');
  20. /**
  21. * Common view for config widgets
  22. * @type {Em.View}
  23. */
  24. App.ConfigWidgetView = Em.View.extend(App.SupportsDependentConfigs, App.WidgetPopoverSupport, {
  25. /**
  26. * @type {App.ConfigProperty}
  27. */
  28. config: null,
  29. /**
  30. * Alias to <code>config.isOriginalSCP</code>
  31. * Should be used in the templates
  32. * Don't use original <code>config.isOriginalSCP</code> in the widget-templates!!!
  33. * @type {boolean}
  34. */
  35. isOriginalSCPBinding: 'config.isOriginalSCP',
  36. /**
  37. * Alias to <code>config.isComparison</code>
  38. * Should be used in the templates
  39. * Don't use original <code>config.isComparison</code> in the widget-templates!!!
  40. * @type {boolean}
  41. */
  42. isComparisonBinding: 'config.isComparison',
  43. /**
  44. * Config name to display.
  45. * @type {String}
  46. */
  47. configLabel: function() {
  48. return this.get('config.displayName') || this.get('config.name');
  49. }.property('config.name', 'config.displayName'),
  50. /**
  51. * Error message computed in config property model
  52. * @type {String|Boolean}
  53. */
  54. configErrorMessage: function() {
  55. return this.get('config.errorMessage') || false;
  56. }.property('config.errorMessage'),
  57. /**
  58. * Determines if config-value was changed
  59. * @type {boolean}
  60. */
  61. valueIsChanged: function () {
  62. return this.get('config.value') != this.get('config.defaultValue');
  63. }.property('config.value'),
  64. /**
  65. * Reset config-value to its default
  66. * @method restoreValue
  67. */
  68. restoreValue: function () {
  69. this.set('config.value', this.get('config.defaultValue'));
  70. },
  71. /**
  72. * Determines if override is allowed for <code>config</code>
  73. * @type {boolean}
  74. */
  75. overrideAllowed: function () {
  76. var config = this.get('config');
  77. if (!config) return false;
  78. return config.get('isOriginalSCP') && config.get('isPropertyOverridable') && !this.get('config.isComparison');
  79. }.property('config.isOriginalSCP', 'config.isPropertyOverridable', 'config.isComparison'),
  80. /**
  81. * Determines if undo is allowed for <code>config</code>
  82. * @type {boolean}
  83. */
  84. undoAllowed: function () {
  85. var config = this.get('config');
  86. if (!config) return false;
  87. return !config.get('cantBeUndone') && config.get('isNotDefaultValue');
  88. }.property('config.cantBeUndone', 'config.isNotDefaultValue'),
  89. /**
  90. * sync widget value with config value when dependent properties
  91. * have been loaded or changed
  92. */
  93. syncValueWithConfig: function() {
  94. this.setValue(this.get('config.value'));
  95. }.observes('controller.recommendationTimeStamp'),
  96. /**
  97. * set widget value same as config value
  98. * useful for widgets that work with intermediate config value, not original
  99. * for now used in slider widget
  100. * @abstract
  101. */
  102. setValue: Em.K
  103. });