sqoop.utils.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 url = ko.utils.unwrapObservable(valueAccessor());
  43. routie(url);
  44. return false;
  45. });
  46. }
  47. };
  48. ko.bindingHandlers.editableText = {
  49. init: function(element, valueAccessor) {
  50. $(element).on('blur', function() {
  51. var observable = valueAccessor();
  52. observable( $(this).text() );
  53. });
  54. },
  55. update: function(element, valueAccessor) {
  56. var value = ko.utils.unwrapObservable(valueAccessor());
  57. $(element).text(value);
  58. }
  59. };
  60. ko.bindingHandlers.clickValue = {
  61. init: function(element, valueAccessor) {
  62. var value = ko.utils.unwrapObservable(valueAccessor());
  63. if ($(element).val() == value) {
  64. $(element).click();
  65. }
  66. $(element).on('click', function() {
  67. var observable = valueAccessor();
  68. observable( $(this).val() );
  69. });
  70. },
  71. update: function(element, valueAccessor) {
  72. var value = ko.utils.unwrapObservable(valueAccessor());
  73. if ($(element).val() == value) {
  74. $(element).click();
  75. }
  76. }
  77. };
  78. //// JQuery Utils
  79. if (jQuery) {
  80. jQuery.extend({
  81. setdefault: function(obj, accessor, default_value) {
  82. if (!(accessor in obj)) {
  83. obj[accessor] = default_value;
  84. }
  85. return obj[accessor];
  86. }
  87. });
  88. }