bundle-editor.ko.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 Bundle = function (vm, bundle) {
  17. var self = this;
  18. self.id = ko.observable(typeof bundle.id != "undefined" && bundle.id != null ? bundle.id : null);
  19. self.uuid = ko.observable(typeof bundle.uuid != "undefined" && bundle.uuid != null ? bundle.uuid : UUID());
  20. self.name = ko.observable(typeof bundle.name != "undefined" && bundle.name != null ? bundle.name : "");
  21. self.coordinators = ko.mapping.fromJS(typeof bundle.coordinators != "undefined" && bundle.coordinators != null ? bundle.coordinators : []);
  22. self.properties = ko.mapping.fromJS(typeof bundle.properties != "undefined" && bundle.properties != null ? bundle.properties : {});
  23. self.addCoordinator = function(coordinator_uuid) {
  24. var _var = {
  25. 'coordinator': coordinator_uuid,
  26. 'properties': []
  27. };
  28. self.coordinators.push(ko.mapping.fromJS(_var));
  29. };
  30. }
  31. var BundleEditorViewModel = function (bundle_json, coordinators_json) {
  32. var self = this;
  33. self.isEditing = ko.observable(true);
  34. self.isEditing.subscribe(function(newVal){
  35. $(document).trigger("editingToggled");
  36. });
  37. self.toggleEditing = function () {
  38. self.isEditing(! self.isEditing());
  39. };
  40. self.bundle = new Bundle(self, bundle_json);
  41. self.coordinators = ko.mapping.fromJS(coordinators_json);
  42. self.selectedCoordinator = ko.observable();
  43. self.addBundledCoordinator = function() {
  44. self.bundle.addCoordinator(self.selectedCoordinator());
  45. self.selectedCoordinator(null);
  46. };
  47. self.save = function () {
  48. $.post("/oozie/editor/bundle/save/", {
  49. "bundle": ko.mapping.toJSON(self.bundle)
  50. }, function (data) {
  51. if (data.status == 0) {
  52. self.bundle.id(data.id);
  53. $(document).trigger("info", data.message);
  54. if (window.location.search.indexOf("bundle") == -1) {
  55. window.location.hash = '#bundle=' + data.id;
  56. }
  57. }
  58. else {
  59. $(document).trigger("error", data.message);
  60. }
  61. }).fail(function (xhr, textStatus, errorThrown) {
  62. $(document).trigger("error", xhr.responseText);
  63. });
  64. };
  65. self.showSubmitPopup = function () {
  66. // If self.bundle.id() == null, need to save wf for now
  67. $(".jHueNotify").hide();
  68. logGA('submit');
  69. $.get("/oozie/editor/bundle/submit/" + self.bundle.id(), {
  70. }, function (data) {
  71. $(document).trigger("showSubmitPopup", data);
  72. }).fail(function (xhr, textStatus, errorThrown) {
  73. $(document).trigger("error", xhr.responseText);
  74. });
  75. };
  76. };
  77. function logGA(page) {
  78. if (typeof trackOnGA == 'function') {
  79. trackOnGA('oozie/editor/bundle/' + page);
  80. }
  81. }