jobsub.ko.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 Design = function (design) {
  17. return {
  18. id:design.id,
  19. owner:design.owner,
  20. name:design.name,
  21. description:design.description,
  22. type:design.type,
  23. lastModifiedMillis:design.last_modified,
  24. lastModified:moment.unix(design.last_modified).format("MMMM DD, YYYY hh:mm a"),
  25. paramsUrl:design.url_params,
  26. submitUrl:design.url_submit,
  27. editUrl:design.url_edit,
  28. deleteUrl:design.url_delete,
  29. cloneUrl:design.url_clone,
  30. canSubmit:design.can_submit,
  31. canDelete:design.can_delete,
  32. selected:ko.observable(false),
  33. handleSelect:function (row, e) {
  34. this.selected(!this.selected());
  35. }
  36. }
  37. }
  38. var JobSubModel = function (designs) {
  39. var self = this;
  40. self.designs = ko.observableArray(ko.utils.arrayMap(designs, function (design) {
  41. return new Design(design);
  42. }));
  43. self.isLoading = ko.observable(true);
  44. self.allSelected = ko.observable(false);
  45. self.selectedDesigns = ko.computed(function () {
  46. return ko.utils.arrayFilter(self.designs(), function (design) {
  47. return design.selected();
  48. });
  49. }, self);
  50. self.selectedDesign = ko.computed(function () {
  51. return self.selectedDesigns()[0];
  52. }, self);
  53. self.selectAll = function () {
  54. self.allSelected(!self.allSelected());
  55. ko.utils.arrayForEach(self.designs(), function (design) {
  56. design.selected(self.allSelected());
  57. });
  58. return true;
  59. };
  60. self.cloneDesign = function () {
  61. location.href = self.selectedDesign().cloneUrl;
  62. };
  63. self.editDesign = function (design) {
  64. if (design.editUrl == null) {
  65. design = self.selectedDesign();
  66. }
  67. if (design != null && design.canSubmit) {
  68. location.href = design.editUrl;
  69. }
  70. };
  71. self.deleteDesign = function () {
  72. $("#deleteWfForm").attr("action", self.selectedDesign().deleteUrl);
  73. $("#deleteWfMessage").text(deleteMessage.replace("##PLACEHOLDER##", self.selectedDesign().name));
  74. $("#deleteWf").modal("show");
  75. };
  76. self.submitDesign = function () {
  77. $("#submitWfForm").attr("action", self.selectedDesign().submitUrl);
  78. $("#submitWfMessage").text(submitMessage.replace("##PLACEHOLDER##", self.selectedDesign().name));
  79. // We will show the model form, but disable the submit button
  80. // until we've finish loading the parameters via ajax.
  81. $("#submitBtn").attr("disabled", "disabled");
  82. $("#submitWf").modal("show");
  83. $.get(self.selectedDesign().paramsUrl, function (data) {
  84. var params = data["params"]
  85. var container = $("#param-container");
  86. container.empty();
  87. for (key in params) {
  88. if (!params.hasOwnProperty(key)) {
  89. continue;
  90. }
  91. container.append(
  92. $("<div/>").addClass("clearfix")
  93. .append($("<label/>").text(params[key]))
  94. .append(
  95. $("<div/>").addClass("input")
  96. .append($("<input/>").attr("name", key).attr("type", "text"))
  97. )
  98. )
  99. }
  100. // Good. We can submit now.
  101. $("#submitBtn").removeAttr("disabled");
  102. }, "json");
  103. };
  104. };