sqoop.wizard.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 wizard = (function($) {
  17. var Wizard = koify.KOClass(function(options) {
  18. var self = this;
  19. var options = options || {};
  20. self.page_lookup = {};
  21. self.pages = ko.observableArray();
  22. self.index = ko.observable(0);
  23. self.page = ko.computed(function() {
  24. if (self.pages().length > 0 && self.index() < self.pages().length && self.index() >= 0) {
  25. return self.pages()[self.index()];
  26. } else {
  27. return null;
  28. }
  29. });
  30. self.hasNext = ko.computed(function() {
  31. var next_index = self.index() + 1;
  32. return self.pages().length > 0 && next_index < self.pages().length;
  33. });
  34. self.hasPrevious = ko.computed(function() {
  35. var previous_index = self.index() - 1;
  36. return self.pages().length > 0 && previous_index >= 0;
  37. });
  38. self.nextIndex = ko.computed(function() {
  39. if (self.hasNext()) {
  40. return self.index() + 1;
  41. } else {
  42. return -1;
  43. }
  44. });
  45. self.previousIndex = ko.computed(function() {
  46. if (self.hasPrevious()) {
  47. return self.index() - 1;
  48. } else {
  49. return -1;
  50. }
  51. });
  52. self.initialize(options);
  53. }, {
  54. initialize: function(options) {
  55. var self = this;
  56. self.options = options || {};
  57. if (self.options.pages) {
  58. self.pages(options.pages);
  59. }
  60. if (self.options.index) {
  61. self.index(self.options.index);
  62. }
  63. },
  64. addPage: function(page) {
  65. var self = this;
  66. self.page_lookup[page.identifier()] = self.pages().length;
  67. self.pages.push(page);
  68. },
  69. getIndex: function(identifier) {
  70. var self = this;
  71. return self.page_lookup[identifier];
  72. },
  73. clearPages: function() {
  74. var self = this;
  75. self.pages([]);
  76. self.index(0);
  77. }
  78. });
  79. var Page = koify.KOClass(function(options) {
  80. var self = this;
  81. var options = options || {};
  82. self.identifier = ko.observable();
  83. self.caption = ko.observable();
  84. self.description= ko.observable();
  85. self.template = ko.observable();
  86. self.node = ko.observable();
  87. self.initialize(options);
  88. }, {
  89. initialize: function(options) {
  90. var self = this;
  91. self.options = options || {};
  92. self.identifier(self.options.identifier);
  93. self.caption(self.options.caption);
  94. self.description(self.options.description);
  95. self.node(self.options.node);
  96. self.template(self.options.template);
  97. }
  98. });
  99. return {
  100. 'Wizard': Wizard,
  101. 'Page': Page
  102. };
  103. })($);