sqoop.models.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. function transform_keys(model, keys_dict) {
  17. $.each(keys_dict, function(key, new_key) {
  18. if (key in model) {
  19. model[new_key] = model[key];
  20. delete model[key];
  21. }
  22. });
  23. return model;
  24. }
  25. function transform_values(model, func_dict) {
  26. $.each(func_dict, function(key, f) {
  27. if (key in model) {
  28. model[key] = f(key, model[key]);
  29. }
  30. });
  31. return model;
  32. }
  33. function to_form(value) {
  34. return new FormModel(value);
  35. }
  36. function to_forms(key, value) {
  37. $.each(value, function(index, form_dict) {
  38. value[index] = to_form(form_dict);
  39. });
  40. return value;
  41. }
  42. function to_input(value) {
  43. return new InputModel(value);
  44. }
  45. function to_inputs(key, value) {
  46. $.each(value, function(index, input_dict) {
  47. value[index] = to_input(input_dict);
  48. });
  49. return value;
  50. }
  51. var FormModel = koify.Model.extend({
  52. 'id': -1,
  53. 'inputs': [],
  54. 'name': null,
  55. 'type': null,
  56. 'initialize': function(attrs) {
  57. var self = this;
  58. var attrs = $.extend(true, attrs, {});
  59. attrs = transform_values(attrs, {
  60. 'inputs': to_inputs
  61. });
  62. return attrs;
  63. }
  64. });
  65. var InputModel = koify.Model.extend({
  66. 'id': -1,
  67. 'name': null,
  68. 'type': null,
  69. 'size': -1,
  70. 'sensitive': false,
  71. 'values': null,
  72. 'value': null,
  73. 'initialize': function(attrs) {
  74. var self = this;
  75. var attrs = $.extend(true, attrs, {});
  76. if ('values' in attrs) {
  77. attrs['values'] = attrs['values'].split(',');
  78. }
  79. if ('value' in attrs) {
  80. attrs.value = decodeURIComponent(attrs.value);
  81. }
  82. return attrs;
  83. }
  84. });