An unfinished system to manage all your paper documentation in an easy way.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autodoc.js 9.2KB

5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /* AutoDoc Javascript */
  2. var conf = {
  3. default_hash: "home",
  4. openapi: "/v1",
  5. pageinit: {
  6. home: "page_load_home()",
  7. upload: "page_load_upload()"
  8. },
  9. home: {
  10. width: 4,
  11. curpage: 0,
  12. end: 0
  13. },
  14. run: {
  15. "upload_handler": 0,
  16. "upload_status": 0
  17. }
  18. };
  19. var temp = {
  20. upload: [],
  21. documentid: null
  22. };
  23. $(document).ready(function () {
  24. change_page();
  25. upload_zone_init();
  26. $(document).scroll(function () {
  27. page_home_scroll();
  28. });
  29. });
  30. $(window).bind("hashchange", function () {
  31. change_page();
  32. });
  33. function change_page() {
  34. var hash = document.location.hash.substr(1) || conf.default_hash;
  35. if (!$("#autodoc_tab_" + hash).length) {
  36. hash = conf.default_hash;
  37. }
  38. /* change menu highlights and content visibility */
  39. $("#autodoc_navbar")
  40. .find("a")
  41. .each(function (id, obj) {
  42. var curhash = $(obj)
  43. .attr("href")
  44. .substr(1);
  45. if (curhash == hash) {
  46. $(obj)
  47. .parent()
  48. .addClass("active");
  49. $("#autodoc_tab_" + curhash).removeClass("d-none");
  50. } else {
  51. $(obj)
  52. .parent()
  53. .removeClass("active");
  54. $("#autodoc_tab_" + curhash).addClass("d-none");
  55. }
  56. });
  57. if (conf.pageinit[hash]) {
  58. eval(conf.pageinit[hash]);
  59. }
  60. }
  61. function isvisible(obj) {
  62. var top_of_fileent = $(obj).offset().top;
  63. var bottom_of_fileent = $(obj).offset().top + $(obj).outerHeight();
  64. var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
  65. var top_of_screen = $(window).scrollTop();
  66. if (bottom_of_screen > top_of_fileent && top_of_screen < bottom_of_fileent) {
  67. return true;
  68. }
  69. return false;
  70. }
  71. function page_load_home() {
  72. document_load();
  73. }
  74. function page_load_upload() {
  75. upload_status();
  76. }
  77. function document_load() {
  78. if (conf.home.curpage == 0) {
  79. $("#autodoc_home_body").html("");
  80. }
  81. var tmpl = $("#autodoc_template_home");
  82. var row = $(tmpl)
  83. .find(".autodoc_template_home_row")
  84. .clone();
  85. $.getJSON(
  86. conf.openapi +
  87. "/documents?pageSize=" +
  88. conf.home.width +
  89. "&pageIndex=" +
  90. conf.home.curpage,
  91. null,
  92. function (data, textStatus, jqXHR) {
  93. // last document was loaded, stop scrolling
  94. if (data.length < conf.home.width) {
  95. conf.home.end = 1;
  96. }
  97. $.each(data, function (id, doc) {
  98. var col = $(tmpl)
  99. .find(".autodoc_template_home_col")
  100. .clone();
  101. $(col)
  102. .find(".autodoc_template_home_img")
  103. .attr(
  104. "src",
  105. conf.openapi +
  106. "/documents/" +
  107. doc.id +
  108. "/image?maxWidth=" +
  109. Math.floor(1000 / conf.home.width)
  110. );
  111. $(col).find(".autodoc_template_home_img").data("documentId", doc.id);
  112. $(col).find(".autodoc_template_home_img").on('click', function (e) {
  113. home_modal_open($(e.target).data("documentId"));
  114. });
  115. $(col)
  116. .find(".autodoc_template_home_owner")
  117. .html(doc.owner);
  118. $(col)
  119. .find(".autodoc_template_home_created")
  120. .html(doc.created);
  121. $(col)
  122. .find(".autodoc_template_home_name")
  123. .html(doc.name);
  124. $(col)
  125. .find(".autodoc_template_home_pages")
  126. .html(doc.pageId.length);
  127. $.each(doc.tags, function (id, tag) {
  128. $(col)
  129. .find(".autodoc_template_home_tag")
  130. .after(
  131. $(col)
  132. .find(".autodoc_template_home_tag")
  133. .clone()
  134. .html(tag)
  135. );
  136. });
  137. $(row).append(col);
  138. });
  139. $("#autodoc_home_body").append(row);
  140. // continue to load until out of browser.
  141. page_home_scroll();
  142. }
  143. );
  144. }
  145. function page_home_scroll() {
  146. // don't scroll if we've loaded the last document
  147. if (conf.home.end) {
  148. return;
  149. }
  150. if (isvisible($(".autodoc_template_home_col").last())) {
  151. console.log("scroll to page " + conf.home.curpage);
  152. conf.home.curpage++;
  153. document_load();
  154. }
  155. }
  156. function upload_zone_init() {
  157. $(window).on("dragover dragleave drop", function (e) { e.preventDefault() });
  158. $('.autodoc_upload_zone').on({
  159. dragenter: upload_zone_highlight,
  160. dragleave: upload_zone_normal,
  161. dragover: upload_zone_over,
  162. drop: upload_zone_drop
  163. });
  164. }
  165. function upload_zone_highlight(e) {
  166. $(e.target).addClass('autodoc_upload_zone_hover');
  167. }
  168. function upload_zone_over(e) {
  169. return true;
  170. }
  171. function upload_zone_normal(e) {
  172. $(e.target).removeClass('autodoc_upload_zone_hover');
  173. }
  174. function upload_zone_drop(e) {
  175. var ev = e.originalEvent;
  176. $.each(ev.dataTransfer.files, function (id, file) {
  177. console.log(file);
  178. var fileid = temp.upload.length;
  179. temp.upload.push({
  180. progress: 0,
  181. error: null,
  182. obj: file
  183. });
  184. upload_zone_normal(e);
  185. });
  186. if (conf.run.upload_handler == 0) {
  187. upload_handler();
  188. }
  189. if (conf.run.upload_status == 0) {
  190. upload_status();
  191. }
  192. }
  193. function upload_handler() {
  194. var stop = 1;
  195. conf.run.upload_handler = 1;
  196. console.log("upload_handler");
  197. if (temp.documentid == null) {
  198. console.log("creating documentId");
  199. $.post(conf.openapi + "/documents", {}, function (data) {
  200. temp.documentid = data.id;
  201. });
  202. stop = 0;
  203. }
  204. else {
  205. for (var id = 0; id < temp.upload.length; id++) {
  206. var file = temp.upload[id];
  207. if (file.progress != 100) {
  208. if (file.progress == 0) {
  209. if (file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg') {
  210. file['progress'] = 100;
  211. file['error'] = 'invalid file type';
  212. }
  213. else {
  214. var reader = new FileReader();
  215. file['progress'] = 1;
  216. $(reader).on('load', id, upload_read_event);
  217. $(reader).on('loadstart', id, upload_read_event);
  218. $(reader).on('loadend', id, upload_read_event);
  219. $(reader).on('progress', id, upload_read_event);
  220. $(reader).on('error', id, upload_read_event);
  221. $(reader).on('abort', id, upload_read_event);
  222. reader.readAsArrayBuffer(file.obj);
  223. }
  224. }
  225. stop = 0;
  226. break;
  227. }
  228. }
  229. }
  230. if (stop) {
  231. conf.run.upload_handler = 0;
  232. }
  233. else {
  234. setTimeout(function () { upload_handler(); }, 500);
  235. }
  236. }
  237. function upload_read_event(e) {
  238. if (e.type == 'progress') {
  239. if (e.lengthComputable) {
  240. var progress = Math.floor(e.originalEvent.loaded / e.originalEvent.total * 50);
  241. if (progress < 1) { progress = 1; }
  242. if (progress > 49) { progress = 49; }
  243. temp.upload[e.data]['progress'] = progress;
  244. }
  245. }
  246. else if (e.type == 'load') {
  247. temp.upload[e.data]['progress'] = 50;
  248. console.log(e.target.result);
  249. console.log("upload_id", e.data);
  250. $.ajax({
  251. type: 'POST',
  252. url: conf.openapi + "/documents/" + temp.documentid + "/data",
  253. data: e.target.result,
  254. contentType: temp.upload[e.data].obj.type,
  255. context: { id: e.data },
  256. processData: false,
  257. xhr: function () {
  258. var xhr = $.ajaxSettings.xhr();
  259. xhr.upload.addEventListener("progress", (function () {
  260. var id = e.data;
  261. return function (evt) {
  262. if (evt.lengthComputable) {
  263. var progress = Math.floor(evt.loaded / evt.total * 50);
  264. if (progress < 1) { progress = 1; }
  265. if (progress > 49) { progress = 49; }
  266. temp.upload[id].progress = 50 + progress;
  267. // console.log("upload_progress_event", evt);
  268. }
  269. }
  270. })(), false);
  271. return xhr;
  272. },
  273. success: function (data, status, xhr) {
  274. console.log("upload_success_this", this);
  275. temp.upload[this.id].progress = 100;
  276. }
  277. });
  278. }
  279. }
  280. function upload_status() {
  281. var stop = 1;
  282. conf.run.upload_status = 1;
  283. $.each(temp.upload, function (id, file) {
  284. if (!$('.autodoc_upload_status_' + id).length) {
  285. var obj = $(".autodoc_template_progress").children().clone();
  286. $(obj).addClass('autodoc_upload_status_' + id);
  287. $('.autodoc_upload_status').append(obj);
  288. stop = 0;
  289. }
  290. var obj = $('.autodoc_upload_status_' + id).children();
  291. if (file.error != null) {
  292. $(obj).html(file.obj.name + ': ' + file.error);
  293. $(obj).css('width', '100%');
  294. $(obj).addClass('bg-danger');
  295. $(obj).removeClass("progress-bar-animated");
  296. $(obj).removeClass("progress-bar-striped");
  297. }
  298. else if (file.progress == 100) {
  299. $(obj).html(file.obj.name);
  300. $(obj).css('width', '100%');
  301. $(obj).addClass('bg-success');
  302. $(obj).removeClass('progress-bar-animated');
  303. $(obj).removeClass("progress-bar-striped");
  304. }
  305. else if (file.progress < 50) {
  306. $(obj).html(file.obj.name + ': ' + 'reading file');
  307. $(obj).css('width', file.progress + '%');
  308. stop = 0;
  309. }
  310. else {
  311. $(obj).html(file.obj.name + ': ' + 'sending file');
  312. $(obj).css('width', file.progress + '%');
  313. stop = 0;
  314. }
  315. });
  316. if (stop) {
  317. conf.run.upload_status = 0;
  318. }
  319. else {
  320. setTimeout(function () { upload_status(); }, 100);
  321. }
  322. }
  323. function home_modal_open(docid) {
  324. $('#autodoc_home_modal_img').attr('src',
  325. conf.openapi +
  326. "/documents/" +
  327. docid +
  328. "/image");
  329. $('#autodoc_home_modal').modal('show');
  330. }
  331. function home_modal_close(docid) {
  332. $('#autodoc_home_modal').modal('hide');
  333. }