sqoop.connections.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 connections = (function($) {
  17. var ConnectionModel = koify.Model.extend({
  18. 'id': -1,
  19. 'updated': null,
  20. 'created': null,
  21. 'name': null,
  22. 'connector': [],
  23. 'connector_id': 0,
  24. 'framework': [],
  25. 'initialize': function(attrs) {
  26. var self = this;
  27. var attrs = $.extend(true, attrs, {});
  28. attrs = transform_keys(attrs, {
  29. 'connector-id': 'connector_id'
  30. });
  31. attrs = transform_values(attrs, {
  32. 'connector': to_forms,
  33. 'framework': to_forms
  34. });
  35. return attrs;
  36. }
  37. });
  38. var Connection = koify.Node.extend({
  39. 'identifier': 'connection',
  40. 'persists': true,
  41. 'modelClass': ConnectionModel,
  42. 'base_url': '/sqoop/api/connections/',
  43. 'initialize': function() {
  44. var self = this;
  45. self.parent.initialize.apply(self, arguments);
  46. self.selected = ko.observable();
  47. self.persisted = ko.computed(function() {
  48. return self.id() > -1;
  49. });
  50. }
  51. });
  52. function fetch_connections(options) {
  53. $(document).trigger('load.connections', [options]);
  54. var request = $.extend({
  55. url: '/sqoop/api/connections/',
  56. dataType: 'json',
  57. type: 'GET',
  58. success: fetcher_success('connections', Connection, options)
  59. }, options || {});
  60. $.ajax(request);
  61. }
  62. return {
  63. 'ConnectionModel': ConnectionModel,
  64. 'Connection': Connection,
  65. 'fetchConnections': fetch_connections
  66. }
  67. })($);