themes_mapping.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * Provide methods for config-themes loading from server and saving them into models
  21. *
  22. * @type {Em.Mixin}
  23. */
  24. App.ThemesMappingMixin = Em.Mixin.create({
  25. /**
  26. * Load config themes from server and save them into models
  27. * @param {string} serviceName
  28. * @returns {$.ajax}
  29. * @method loadConfigTheme
  30. */
  31. loadConfigTheme: function(serviceName) {
  32. return App.ajax.send({
  33. name: 'configs.theme',
  34. sender: this,
  35. data: {
  36. serviceName: serviceName,
  37. stackVersionUrl: App.get('stackVersionURL')
  38. },
  39. success: '_saveThemeToModel'
  40. });
  41. },
  42. /**
  43. * Success-callback for <code>loadConfigTheme</code>
  44. * runs <code>themeMapper<code>
  45. * @param {object} data
  46. * @private
  47. * @method saveThemeToModel
  48. */
  49. _saveThemeToModel: function(data) {
  50. App.themesMapper.map(data);
  51. },
  52. /**
  53. * Load themes for specified services by one API call
  54. *
  55. * @method loadConfigThemeForServices
  56. * @param {String|String[]} serviceNames
  57. * @returns {$.ajax}
  58. */
  59. loadConfigThemeForServices: function (serviceNames) {
  60. return App.ajax.send({
  61. name: 'configs.theme.services',
  62. sender: this,
  63. data: {
  64. serviceNames: Em.makeArray(serviceNames).join(','),
  65. stackVersionUrl: App.get('stackVersionURL')
  66. },
  67. success: '_loadConfigThemeForServicesSuccess',
  68. error: '_loadConfigThemeForServicesError'
  69. });
  70. },
  71. /**
  72. * Success-callback for <code>loadConfigThemeForServices</code>
  73. * @param {object} data
  74. * @private
  75. * @method _loadConfigThemeForServicesSuccess
  76. */
  77. _loadConfigThemeForServicesSuccess: function(data) {
  78. if (!data.items.length) return;
  79. App.themesMapper.map({
  80. items: data.items.mapProperty('themes').reduce(function(p,c) {
  81. return p.concat(c);
  82. })
  83. });
  84. },
  85. /**
  86. * Error-callback for <code>loadConfigThemeForServices</code>
  87. * @param {object} request
  88. * @param {object} ajaxOptions
  89. * @param {string} error
  90. * @param {object} opt
  91. * @param {object} params
  92. * @private
  93. * @method _loadConfigThemeForServicesError
  94. */
  95. _loadConfigThemeForServicesError: function(request, ajaxOptions, error, opt, params) {
  96. }
  97. });