jobsub.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. //// Helper methods
  17. var format = (function(){
  18. // Date.format follows python datetime formatting.
  19. // @see http://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
  20. var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
  21. 'Thursday', 'Friday', 'Saturday'];
  22. var MONTH = ['January', 'February', 'March', 'April',
  23. 'May', 'June', 'July', 'August',
  24. 'September', 'October', 'November', 'December'];
  25. return function(format) {
  26. var self = this;
  27. // 'esc' declares whether or not we found an escape character.
  28. var esc = false;
  29. var str = '';
  30. for (var i = 0; i < format.length; ++i) {
  31. if (esc) {
  32. // Escape character followed by these characters
  33. // is a formatting option.
  34. switch(format[i]) {
  35. case 'a':
  36. str += WEEKDAYS[self.getDay()].substring(0,3);
  37. break;
  38. case 'A':
  39. str += WEEKDAYS[self.getDay()];
  40. break;
  41. case 'b':
  42. str += MONTH[self.getMonth()].substring(0,3);
  43. break;
  44. case 'B':
  45. str += MONTH[self.getMonth()];
  46. break;
  47. case 'c':
  48. str += self.toLocaleString();
  49. break;
  50. case 'd':
  51. var tmp = '00' + self.getDate();
  52. str += tmp.substring(tmp.length - 2, tmp.length);
  53. break;
  54. case 'f':
  55. // TODO: Microsecond as a decimal number [0,999999], zero-padded on the left
  56. break;
  57. case 'H':
  58. var tmp = '00' + self.getHours();
  59. str += tmp.substring(tmp.length - 2, tmp.length);
  60. break;
  61. case 'I':
  62. var hour = self.getHours() % 12;
  63. var tmp = '00' + ((hour == 0) ? '12' : hour);
  64. str += tmp.substring(tmp.length - 2, tmp.length);
  65. break;
  66. case 'j':
  67. // TODO: Day of the year as a decimal number [001,366].
  68. break;
  69. case 'm':
  70. var tmp = '00' + (self.getMonth() + 1);
  71. str += tmp.substring(tmp.length - 2, tmp.length);
  72. case 'M':
  73. var tmp = '00' + self.getMinutes();
  74. str += tmp.substring(tmp.length - 2, tmp.length);
  75. break;
  76. case 'p':
  77. str += (self.getHours() > 11) ? 'PM' : 'AM';
  78. break;
  79. case 'S':
  80. var tmp = '00' + self.getSeconds();
  81. str += tmp.substring(tmp.length - 2, tmp.length);
  82. break;
  83. case 'U':
  84. // TODO: Week number of the year [0,53]. Sunday starts.
  85. break;
  86. case 'w':
  87. str += self.getDay();
  88. break;
  89. case 'W':
  90. // TODO: Week number of the year [0,53]. Monday starts.
  91. break;
  92. case 'x':
  93. str += self.toLocaleDateString();
  94. break;
  95. case 'X':
  96. str += self.toLocaleTimeString();
  97. break;
  98. case 'y':
  99. str += self.getFullYear() % 100;
  100. break;
  101. case 'Y':
  102. str += self.getFullYear();
  103. break;
  104. case 'z':
  105. // TODO: UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive)
  106. break;
  107. case 'Z':
  108. // Time zone name (empty string if the object is naive).
  109. break;
  110. case '%':
  111. str += '%'
  112. break
  113. default:
  114. // Bad escape.
  115. str += '%' + format[i];
  116. break;
  117. }
  118. esc = false;
  119. } else {
  120. switch(format[i]) {
  121. case '%':
  122. esc = true;
  123. break;
  124. default:
  125. str += format[i];
  126. break;
  127. }
  128. }
  129. }
  130. return str;
  131. };
  132. })();
  133. Date.prototype.format = format;
  134. function showSection(section) {
  135. $('.section').hide();
  136. $('#' + section).show();
  137. $(window).scrollTop(0);
  138. // Filechooser.
  139. $(".pathChooserKo").each(function(){
  140. var self = $(this);
  141. self.after(getFileBrowseButton(self));
  142. });
  143. }
  144. function getFileBrowseButton(inputElement) {
  145. return $("<button>").addClass("btn").addClass("fileChooserBtn").text("..").click(function(e){
  146. e.preventDefault();
  147. $("#fileChooserModal").jHueFileChooser({
  148. initialPath: inputElement.val(),
  149. onFileChoose: function(filePath) {
  150. inputElement.val(filePath);
  151. inputElement.change();
  152. addFileBrowseButton();
  153. $("#chooseFile").modal("hide");
  154. },
  155. createFolder: false
  156. });
  157. $("#chooseFile").modal("show");
  158. })
  159. }
  160. function addFileBrowseButton() {
  161. // Filechooser.
  162. $(".pathChooserKo").each(function(){
  163. var self = $(this);
  164. if (!self.siblings().hasClass('fileChooserBtn')) {
  165. self.after(getFileBrowseButton(self));
  166. }
  167. });
  168. }
  169. //// Event handling.
  170. var events = [
  171. 'add.file.workflow',
  172. 'add.property.workflow',
  173. 'add.archive.workflow',
  174. 'add.arg.workflow',
  175. 'add.argument.workflow',
  176. 'add.envvar.workflow',
  177. 'add.param.workflow',
  178. 'add.prepare_delete.workflow',
  179. 'add.prepare_mkdir.workflow',
  180. 'add.delete.workflow',
  181. 'add.mkdir.workflow',
  182. 'add.chmod.workflow',
  183. 'add.move.workflow',
  184. 'add.touchz.workflow',
  185. 'add.parameter.workflow',
  186. 'remove.file.workflow',
  187. 'remove.property.workflow',
  188. 'remove.archive.workflow',
  189. 'remove.arg.workflow',
  190. 'remove.argument.workflow',
  191. 'remove.envvar.workflow',
  192. 'remove.param.workflow',
  193. 'remove.prepare_delete.workflow',
  194. 'remove.prepare_mkdir.workflow',
  195. 'remove.delete.workflow',
  196. 'remove.mkdir.workflow',
  197. 'remove.chmod.workflow',
  198. 'remove.move.workflow',
  199. 'remove.touchz.workflow',
  200. 'remove.parameter.workflow',
  201. 'error.design'
  202. ];
  203. $.each(events, function(index, event) {
  204. $(document).bind(event, addFileBrowseButton);
  205. $(document).bind(event, function() {
  206. $(".propKey").typeahead({
  207. source:(typeof AUTOCOMPLETE_PROPERTIES != 'undefined') ? AUTOCOMPLETE_PROPERTIES : []
  208. });
  209. });
  210. });
  211. $(document).bind('error.design', addFileBrowseButton);
  212. $(document).bind('save.design', function() {designs.load();});
  213. $(document).bind('delete.design', function() {designs.load();});
  214. $(document).bind('clone.design', function() {designs.load();});
  215. $(document).bind('load.designs', function() { routie('list-designs'); });