groups_mapping.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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-groups loading from server and saving them into models
  21. *
  22. * @type {Em.Mixin}
  23. */
  24. App.GroupsMappingMixin = Em.Mixin.create({
  25. /**
  26. * Load config groups
  27. * @param {String[]} serviceNames
  28. * @returns {$.Deferred()}
  29. * @method loadConfigGroups
  30. */
  31. loadConfigGroups: function (serviceNames) {
  32. var dfd = $.Deferred();
  33. if (!serviceNames || serviceNames.length === 0) {
  34. dfd.resolve();
  35. } else {
  36. App.ajax.send({
  37. name: 'configs.config_groups.load.services',
  38. sender: this,
  39. data: {
  40. serviceList: serviceNames.join(','),
  41. dfd: dfd
  42. },
  43. success: 'saveConfigGroupsToModel'
  44. });
  45. }
  46. return dfd.promise();
  47. },
  48. /**
  49. * Runs <code>configGroupsMapper<code>
  50. * @param {object} data
  51. * @param {object} opt
  52. * @param {object} params
  53. * @method saveConfigGroupsToModel
  54. */
  55. saveConfigGroupsToModel: function (data, opt, params) {
  56. App.configGroupsMapper.map(data, params.serviceList.split(','));
  57. params.dfd.resolve();
  58. }
  59. });