sqoop.utils.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. //// Get collections utils
  17. function fetcher_success(name, Node, options) {
  18. return function(data) {
  19. switch(data.status) {
  20. case -1:
  21. $(document).trigger('connection_error.' + name, [options, data])
  22. break;
  23. case 0:
  24. var nodes = [];
  25. $.each(data[name], function(index, model_dict) {
  26. var node = new Node({modelDict: model_dict});
  27. nodes.push(node);
  28. });
  29. $(document).trigger('loaded.' + name, [nodes, options]);
  30. break;
  31. default:
  32. case 1:
  33. $(document).trigger('load_error.' + name, [options, data]);
  34. break;
  35. }
  36. };
  37. }
  38. //// KO utils
  39. ko.bindingHandlers.routie = {
  40. init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
  41. $(element).click(function() {
  42. var obj = ko.utils.unwrapObservable(valueAccessor());
  43. var url = null;
  44. var bubble = false;
  45. if ($.isPlainObject(obj)) {
  46. url = obj.url;
  47. bubble = !!obj.bubble;
  48. } else {
  49. url = obj;
  50. }
  51. routie(url);
  52. return bubble;
  53. });
  54. }
  55. };
  56. ko.bindingHandlers.editableText = {
  57. init: function(element, valueAccessor) {
  58. $(element).on('blur', function() {
  59. var observable = valueAccessor();
  60. observable( $(this).text() );
  61. });
  62. },
  63. update: function(element, valueAccessor) {
  64. var value = ko.utils.unwrapObservable(valueAccessor());
  65. $(element).text(value);
  66. }
  67. };
  68. ko.bindingHandlers.clickValue = {
  69. init: function(element, valueAccessor) {
  70. var value = ko.utils.unwrapObservable(valueAccessor());
  71. if ($(element).val() == value) {
  72. $(element).click();
  73. }
  74. $(element).on('click', function() {
  75. var observable = valueAccessor();
  76. observable( $(this).val() );
  77. });
  78. },
  79. update: function(element, valueAccessor) {
  80. var value = ko.utils.unwrapObservable(valueAccessor());
  81. if ($(element).val() == value) {
  82. $(element).click();
  83. }
  84. }
  85. };
  86. //// JQuery Utils
  87. if (jQuery) {
  88. jQuery.extend({
  89. setdefault: function(obj, accessor, default_value) {
  90. if (!(accessor in obj)) {
  91. obj[accessor] = default_value;
  92. }
  93. return obj[accessor];
  94. }
  95. });
  96. }