sqoop.utils.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. //// JQuery Utils
  61. if (jQuery) {
  62. jQuery.extend({
  63. setdefault: function(obj, accessor, default_value) {
  64. if (!(accessor in obj)) {
  65. obj[accessor] = default_value;
  66. }
  67. return obj[accessor];
  68. }
  69. });
  70. }