jobsub.templates.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. archives: 'static/templates/widgets/filechooser.html',
  38. files: 'static/templates/widgets/filechooser.html',
  39. mkdirs: 'static/templates/widgets/filechooser.html',
  40. deletes: 'static/templates/widgets/filechooser.html',
  41. touchzs: 'static/templates/widgets/filechooser.html',
  42. chmods: 'static/templates/widgets/filechooser.html',
  43. moves: 'static/templates/widgets/filechooser.html',
  44. job_properties: 'static/templates/widgets/properties.html',
  45. prepares: 'static/templates/widgets/prepares.html',
  46. arguments: 'static/templates/widgets/params.html',
  47. args: 'static/templates/widgets/params.html',
  48. params: 'static/templates/widgets/params.html',
  49. arguments_envvars: 'static/templates/widgets/params.html',
  50. params_arguments: 'static/templates/widgets/params.html',
  51. }
  52. }, options);
  53. self.initialize(options);
  54. };
  55. $.extend(module.prototype, {
  56. initialize: function(options) {
  57. var self = this;
  58. self.partials = {};
  59. $.each(options.partials, function(widget_id, url) {
  60. $.get(url, function(data) {
  61. self.partials[widget_id] = data;
  62. })
  63. });
  64. self.actions = {};
  65. $.each(options.actions, function(action_id, url) {
  66. $.get(url, function(data) {
  67. self.actions[action_id] = data;
  68. })
  69. });
  70. },
  71. getActionTemplate: function(id, context) {
  72. var self = this;
  73. var el = $('#' + id);
  74. if (el.length > 0 && el.html().length > 0) {
  75. return el;
  76. } else {
  77. var html = Mustache.to_html(self.actions[id], context, self.partials);
  78. if (el.length == 0) el = $('<script/>');
  79. el.attr('id', id);
  80. el.attr('type', 'text/html');
  81. el.html(html);
  82. $(document.body).append(el);
  83. return $('#' + id);
  84. }
  85. }
  86. });
  87. return module;
  88. })($, ko);
  89. var templates = new Templates();