sqoop.connectors.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. var connectors = (function($) {
  17. var ConnectorModel = koify.Model.extend({
  18. 'id': -1,
  19. 'name': null,
  20. 'class': null,
  21. 'job_forms': {
  22. 'IMPORT': [],
  23. 'EXPORT': []
  24. },
  25. 'con_forms': [],
  26. 'version': null,
  27. 'resources': {},
  28. 'initialize': function(attrs) {
  29. var self = this;
  30. var _attrs = $.extend(true, {}, attrs);
  31. _attrs = transform_keys(_attrs, {
  32. 'job-forms': 'job_forms',
  33. 'con-forms': 'con_forms'
  34. });
  35. _attrs = transform_values(_attrs, {
  36. 'con_forms': to_forms,
  37. 'job_forms': function(key, value) {
  38. transform_values(value, {
  39. 'IMPORT': to_forms,
  40. 'EXPORT': to_forms
  41. });
  42. return value;
  43. }
  44. });
  45. return _attrs;
  46. }
  47. });
  48. var Connector = koify.Node.extend({
  49. 'identifier': 'connector',
  50. 'persist': false,
  51. 'model_class': ConnectorModel,
  52. 'base_url': '/sqoop/api/connectors/',
  53. 'initialize': function() {
  54. var self = this;
  55. self.parent.initialize.apply(self, arguments);
  56. self.selected = ko.observable();
  57. },
  58. map: function() {
  59. var self = this;
  60. var mapping_options = $.extend(true, {
  61. 'ignore': ['parent', 'initialize']
  62. }, forms.MapProperties);
  63. if ('__ko_mapping__' in self) {
  64. ko.mapping.fromJS(self.model, mapping_options, self);
  65. } else {
  66. var mapped = ko.mapping.fromJS(self.model, mapping_options);
  67. $.extend(self, mapped);
  68. }
  69. }
  70. });
  71. function fetch_connectors(options) {
  72. $(document).trigger('load.connectors', [options]);
  73. var request = $.extend({
  74. url: '/sqoop/api/connectors/',
  75. dataType: 'json',
  76. type: 'GET',
  77. success: fetcher_success('connectors', Connector, options)
  78. }, options || {});
  79. $.ajax(request);
  80. }
  81. return {
  82. 'ConnectorModel': ConnectorModel,
  83. 'Connector': Connector,
  84. 'fetchConnectors': fetch_connectors
  85. };
  86. })($);