jobsub.templates.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. //// Load templates
  17. // Load partial templates (for widgets)
  18. // Load action templates
  19. var Templates = (function($, ko) {
  20. var module = function(options) {
  21. var self = this;
  22. var options = $.extend({
  23. actions: {
  24. mapreduce: 'static/templates/actions/mapreduce.html',
  25. java: 'static/templates/actions/java.html',
  26. streaming: 'static/templates/actions/streaming.html',
  27. hive: 'static/templates/actions/hive.html',
  28. pig: 'static/templates/actions/pig.html',
  29. sqoop: 'static/templates/actions/sqoop.html',
  30. fs: 'static/templates/actions/fs.html',
  31. ssh: 'static/templates/actions/ssh.html',
  32. shell: 'static/templates/actions/shell.html',
  33. email: 'static/templates/actions/email.html',
  34. distcp: 'static/templates/actions/distcp.html'
  35. },
  36. partials: {
  37. name: 'static/templates/widgets/text.html',
  38. description: 'static/templates/widgets/text.html',
  39. is_shared: 'static/templates/widgets/checkbox.html',
  40. // Oozie parameters
  41. parameters: 'static/templates/widgets/parameters.html',
  42. archives: 'static/templates/widgets/filechooser.html',
  43. files: 'static/templates/widgets/filechooser.html',
  44. mkdirs: 'static/templates/widgets/folderchooser.html',
  45. deletes: 'static/templates/widgets/folderchooser.html',
  46. touchzs: 'static/templates/widgets/filechooser.html',
  47. chmods: 'static/templates/widgets/filechooser.html',
  48. moves: 'static/templates/widgets/filechooser.html',
  49. job_properties: 'static/templates/widgets/properties.html',
  50. prepares: 'static/templates/widgets/prepares.html',
  51. arguments: 'static/templates/widgets/params.html',
  52. args: 'static/templates/widgets/params.html',
  53. params: 'static/templates/widgets/params.html',
  54. arguments_envvars: 'static/templates/widgets/params.html',
  55. params_arguments: 'static/templates/widgets/params.html',
  56. capture_output: 'static/templates/widgets/checkbox.html'
  57. }
  58. }, options);
  59. self.initialize(options);
  60. };
  61. function invertDictionary(dict) {
  62. var inverse = {};
  63. $.each(dict, function(key, value) {
  64. if (value in inverse) {
  65. inverse[value].push(key);
  66. } else {
  67. inverse[value] = [key];
  68. }
  69. });
  70. return inverse;
  71. }
  72. $.extend(module.prototype, {
  73. initialize: function(options) {
  74. var self = this;
  75. var reverse_partials = invertDictionary(options.partials);
  76. var reverse_actions = invertDictionary(options.actions);
  77. self.partials = {};
  78. $.each(reverse_partials, function(url, widget_ids) {
  79. $.get(url, function(data) {
  80. $.each(widget_ids, function(index, widget_id) {
  81. self.partials[widget_id] = data;
  82. });
  83. });
  84. });
  85. self.actions = {};
  86. $.each(reverse_actions, function(url, widget_ids) {
  87. $.get(url, function(data) {
  88. $.each(widget_ids, function(index, widget_id) {
  89. self.actions[widget_id] = data;
  90. });
  91. });
  92. });
  93. },
  94. getActionTemplate: function(id, context) {
  95. var self = this;
  96. var el = $('#' + id);
  97. if (el.length > 0 && el.html().length > 0) {
  98. return el;
  99. } else {
  100. var html = Mustache.to_html(self.actions[id], context, self.partials);
  101. // no jQuery here, IE8 doesn't like it.
  102. var scriptTag = document.createElement('script');
  103. scriptTag.setAttribute('id', id);
  104. scriptTag.setAttribute('type', 'text/html');
  105. scriptTag.text = html;
  106. document.body.appendChild(scriptTag);
  107. return $('#' + id);
  108. }
  109. }
  110. });
  111. return module;
  112. })($, ko);
  113. var templates = new Templates();