jobsub.js 7.5 KB

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