jobsub.templates.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/filechooser.html',
  45. deletes: 'static/templates/widgets/filechooser.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. $.extend(module.prototype, {
  62. initialize: function(options) {
  63. var self = this;
  64. self.partials = {};
  65. $.each(options.partials, function(widget_id, url) {
  66. $.get(url, function(data) {
  67. self.partials[widget_id] = data;
  68. })
  69. });
  70. self.actions = {};
  71. $.each(options.actions, function(action_id, url) {
  72. $.get(url, function(data) {
  73. self.actions[action_id] = data;
  74. })
  75. });
  76. },
  77. getActionTemplate: function(id, context) {
  78. var self = this;
  79. var el = $('#' + id);
  80. if (el.length > 0 && el.html().length > 0) {
  81. return el;
  82. } else {
  83. var html = Mustache.to_html(self.actions[id], context, self.partials);
  84. if (el.length == 0) el = $('<script/>');
  85. el.attr('id', id);
  86. el.attr('type', 'text/html');
  87. el.html(html);
  88. $(document.body).append(el);
  89. return $('#' + id);
  90. }
  91. }
  92. });
  93. return module;
  94. })($, ko);
  95. var templates = new Templates();