jobsub.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. addFileBrowseButton();
  139. }
  140. function getFileBrowseButton(inputElement, folderSelectable, fileSelectable, uploadFile, createFolder) {
  141. var modal = null;
  142. if (fileSelectable && folderSelectable) {
  143. modal = "#choosePath";
  144. } else if (folderSelectable) {
  145. modal = "#chooseDirectory";
  146. } else {
  147. modal = "#chooseFile";
  148. }
  149. var chooser = modal + " .chooser";
  150. return $("<button>").addClass("btn").addClass("chooserBtn").text("..").click(function(e){
  151. e.preventDefault();
  152. $(chooser).jHueFileChooser({
  153. initialPath: inputElement.val(),
  154. onFileChoose: function(filePath) {
  155. if (fileSelectable){
  156. inputElement.val(filePath);
  157. inputElement.change();
  158. addFileBrowseButton();
  159. $(modal).modal("hide");
  160. }
  161. },
  162. onFolderChange: function(filePath) {
  163. inputElement.val(filePath);
  164. inputElement.change();
  165. },
  166. onFolderChoose: function(filePath) {
  167. if (folderSelectable){
  168. inputElement.val(filePath);
  169. inputElement.change();
  170. addFileBrowseButton();
  171. $(modal).modal("hide");
  172. }
  173. },
  174. createFolder: createFolder,
  175. selectFolder: folderSelectable,
  176. uploadFile: uploadFile,
  177. forceRefresh: true
  178. });
  179. $(modal).modal("show");
  180. })
  181. }
  182. function addFileBrowseButton() {
  183. // Filechooser.
  184. $(".pathChooserKo").each(function(){
  185. var self = $(this);
  186. if (!self.siblings().hasClass('chooserBtn')) {
  187. self.after(getFileBrowseButton(self, true, true, false, true));
  188. }
  189. });
  190. $(".pathFileChooserKo").each(function(){
  191. var self = $(this);
  192. if (!self.siblings().hasClass('chooserBtn')) {
  193. self.after(getFileBrowseButton(self, false, true, true, false));
  194. }
  195. });
  196. $(".pathFolderChooserKo").each(function(){
  197. var self = $(this);
  198. if (!self.siblings().hasClass('chooserBtn')) {
  199. self.after(getFileBrowseButton(self, true, false, false, true));
  200. }
  201. });
  202. }
  203. //// Event handling.
  204. var events = [
  205. 'add.file.workflow',
  206. 'add.property.workflow',
  207. 'add.archive.workflow',
  208. 'add.arg.workflow',
  209. 'add.argument.workflow',
  210. 'add.envvar.workflow',
  211. 'add.param.workflow',
  212. 'add.prepare_delete.workflow',
  213. 'add.prepare_mkdir.workflow',
  214. 'add.delete.workflow',
  215. 'add.mkdir.workflow',
  216. 'add.chmod.workflow',
  217. 'add.move.workflow',
  218. 'add.touchz.workflow',
  219. 'add.parameter.workflow',
  220. 'remove.file.workflow',
  221. 'remove.property.workflow',
  222. 'remove.archive.workflow',
  223. 'remove.arg.workflow',
  224. 'remove.argument.workflow',
  225. 'remove.envvar.workflow',
  226. 'remove.param.workflow',
  227. 'remove.prepare_delete.workflow',
  228. 'remove.prepare_mkdir.workflow',
  229. 'remove.delete.workflow',
  230. 'remove.mkdir.workflow',
  231. 'remove.chmod.workflow',
  232. 'remove.move.workflow',
  233. 'remove.touchz.workflow',
  234. 'remove.parameter.workflow',
  235. 'error.design'
  236. ];
  237. $.each(events, function(index, event) {
  238. $(document).bind(event, addFileBrowseButton);
  239. $(document).bind(event, function() {
  240. $(".propKey").typeahead({
  241. source:(typeof AUTOCOMPLETE_PROPERTIES != 'undefined') ? AUTOCOMPLETE_PROPERTIES : []
  242. });
  243. });
  244. });
  245. $(document).bind('error.design', addFileBrowseButton);
  246. $(document).bind('loaded.designs', function() { routie('list-designs'); });