An unfinished system to manage all your paper documentation in an easy way.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

autodoc.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /* AutoDoc Javascript */
  2. var conf = {
  3. default_hash: "home",
  4. openapi: "/v1",
  5. pageinit: {
  6. home: "page_load_home",
  7. document: "page_load_document",
  8. upload: "page_load_upload",
  9. tags: "page_load_tags"
  10. },
  11. home: {
  12. width: 4,
  13. curpage: 0,
  14. end: 0
  15. },
  16. run: {
  17. "upload_handler": 0,
  18. "upload_status": 0
  19. },
  20. busy: 0
  21. };
  22. var temp = {
  23. upload: [],
  24. documentid: null
  25. };
  26. $(document).ready(function () {
  27. // loader icon thread
  28. loader_icon_update();
  29. // load the current page based on anchor
  30. change_page();
  31. // initialise drop zone
  32. upload_zone_init();
  33. // main page scroll event
  34. $(document).scroll(function () {
  35. page_home_scroll();
  36. });
  37. // modal left paging
  38. $('#autodoc_home_modal_left').mouseenter(function (e) {
  39. $(e.target).fadeTo("slow", 0.8);
  40. })
  41. .mouseleave(function (e) {
  42. $(e.target).fadeTo("slow", 0.15);
  43. })
  44. .click(function (e) {
  45. home_modal_page_prev();
  46. });
  47. // modal right paging
  48. $('#autodoc_home_modal_right')
  49. .mouseenter(function (e) {
  50. $(e.target).fadeTo("slow", 0.8);
  51. })
  52. .mouseleave(function (e) {
  53. $(e.target).fadeTo("slow", 0.15);
  54. })
  55. .click(function (e) {
  56. home_modal_page_next();
  57. });
  58. // modal resize buttons events
  59. $('.autodoc_home_modal_size').click(function (e) {
  60. $('.autodoc_home_modal_size').removeClass("active");
  61. $(e.target).addClass("active");
  62. home_modal_resize($(e.target).html());
  63. });
  64. // click to rename page in modal
  65. $('span.autodoc_home_modal_name').click(function (e) {
  66. $(e.target).addClass('d-none');
  67. $('input.autodoc_home_modal_name').removeClass('d-none');
  68. });
  69. // [enter] event of modal name edit
  70. $('input.autodoc_home_modal_name').change(function (e) {
  71. var docid = $('#autodoc_home_modal').data('documentid');
  72. document_update_name(docid, $(e.target).val(), docid);
  73. });
  74. // modal show typeahead
  75. $('.autodoc_home_modal_tags_show').click(function (e) {
  76. $('.autodoc_home_modal_tags_show').addClass('d-none');
  77. $('.autodoc_home_modal_tags_add').removeClass('d-none');
  78. });
  79. // document page
  80. // make primary button
  81. $('.autodoc_document_btn_primary').click(function(e) {
  82. $(e.target).addClass('disabled');
  83. var docid = $('#autodoc_tab_document').data('docid');
  84. var pageid = $('.autodoc_document_image').data('pageid');
  85. loader_icon_on();
  86. $.ajax({
  87. type: "PATCH",
  88. url: conf.openapi + "/documents/" + docid + "?primarypage=" + pageid,
  89. success: function () {
  90. loader_icon_off();
  91. $('.autodoc_document_btn_primary').removeClass('disabled');
  92. }
  93. });
  94. });
  95. // tag menu select
  96. $('.autodoc_tag_list').change(function (e) {
  97. console.log(e);
  98. var tagId = $('.autodoc_tag_list').val();
  99. var tagName = $('.autodoc_tag_list').children("option:selected").html();
  100. var tagColor = $('.autodoc_tag_list').children("option:selected").attr('data');
  101. if (tagId == "") {
  102. $(".autodoc_tag_list").addClass('d-none');
  103. $(".autodoc_tag_text").removeClass('d-none');
  104. $('.autodoc_tag_text').val('');
  105. $('.autodoc_tag_color.btn-primary').click();
  106. $('.autodoc_tag_id').val('');
  107. }
  108. else {
  109. $(".autodoc_tag_list").addClass('d-none');
  110. $(".autodoc_tag_text").removeClass('d-none');
  111. $('.autodoc_tag_text').val(tagName);
  112. $('.autodoc_tag_color.btn-' + tagColor).click();
  113. $('.autodoc_tag_id').val(tagId);
  114. $('.autodoc_tag_text').keyup();
  115. }
  116. });
  117. // tags add button
  118. $('.autodoc_tag_add').click(function (e) {
  119. var tagId = $('.autodoc_tag_id').val();
  120. var tagName = $('.autodoc_tag_text').val();
  121. var tagColor = $('.autodoc_tag_color.active').attr('data').split('_').pop();
  122. var url = conf.openapi + "/tags/";
  123. var urlparam = "tagName=" + encodeURIComponent(tagName) + "&tagColor=" + encodeURIComponent(tagColor);
  124. var method = "POST";
  125. if (tagId != "") {
  126. method = "PATCH";
  127. url += tagId;
  128. }
  129. loader_icon_on();
  130. $.ajax({
  131. type: method,
  132. url: url + '?' + urlparam,
  133. success: function () {
  134. loader_icon_off();
  135. location.reload();
  136. }
  137. });
  138. });
  139. // tags delete event
  140. $('.autodoc_tag_delete').click(function (e) {
  141. var tagId = $('.autodoc_tag_id').val();
  142. if (tagId != "") {
  143. loader_icon_on();
  144. $.ajax({
  145. type: "DELETE",
  146. url: conf.openapi + "/tags/" + tagId,
  147. success: function () {
  148. loader_icon_off();
  149. location.reload();
  150. }
  151. });
  152. }
  153. else {
  154. location.reload();
  155. }
  156. });
  157. // tags add color events
  158. $('.autodoc_tag_color').click(function (e) {
  159. var btn = e.target;
  160. while ($(btn).prop("tagName") != "BUTTON") {
  161. btn = $(btn).parent();
  162. }
  163. $(btn).parent().children().removeClass('active');
  164. $(btn).addClass('active');
  165. $('.autodoc_tag_btn_on').addClass('d-none');
  166. $('.autodoc_tag_btn_off').removeClass('d-none');
  167. $(btn).children('.autodoc_tag_btn_on').removeClass('d-none');
  168. $(btn).children('.autodoc_tag_btn_off').addClass('d-none');
  169. $(btn).parent().children().each(function (id, x) {
  170. var myclass = 'badge-' + $(x).attr('data').split('_').pop();
  171. $('#autodoc_tag_result').removeClass(myclass);
  172. });
  173. var myclass = 'badge-' + $(btn).attr('data').split('_').pop();
  174. $('#autodoc_tag_result').addClass(myclass);
  175. });
  176. // tag add text events
  177. $('.autodoc_tag_text').keyup(function (e) {
  178. $('#autodoc_tag_result').html($(e.target).val());
  179. });
  180. });
  181. // anchor change event
  182. $(window).bind("hashchange", function () {
  183. change_page();
  184. });
  185. function change_page() {
  186. var args = document.location.hash.substr(1).split('_') || conf.default_hash.split('_');
  187. var hash = args.shift();
  188. if (!$("#autodoc_tab_" + hash).length) {
  189. hash = conf.default_hash;
  190. }
  191. /* change menu highlights and content visibility */
  192. $("#autodoc_navbar")
  193. .find("a")
  194. .each(function (id, obj) {
  195. var curhash = $(obj)
  196. .attr("href")
  197. .substr(1);
  198. if (curhash == hash) {
  199. $(obj)
  200. .parent()
  201. .addClass("active");
  202. $("#autodoc_tab_" + curhash).removeClass("d-none");
  203. } else {
  204. $(obj)
  205. .parent()
  206. .removeClass("active");
  207. $("#autodoc_tab_" + curhash).addClass("d-none");
  208. }
  209. });
  210. if (conf.pageinit[hash]) {
  211. var func = conf.pageinit[hash];
  212. console.log(func);
  213. if (window[func]) {
  214. window[func](args);
  215. }
  216. }
  217. }
  218. function isvisible(obj) {
  219. var top_of_fileent = $(obj).offset().top;
  220. var bottom_of_fileent = $(obj).offset().top + $(obj).outerHeight();
  221. var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
  222. var top_of_screen = $(window).scrollTop();
  223. if (bottom_of_screen > top_of_fileent && top_of_screen < bottom_of_fileent) {
  224. return true;
  225. }
  226. return false;
  227. }
  228. function page_load_home() {
  229. document_load();
  230. }
  231. function page_load_document(args) {
  232. var [docid] = args;
  233. if (!docid) { return false; }
  234. $('#autodoc_tab_document').data('docid', docid);
  235. $('.autodoc_document_empty').addClass('d-none');
  236. $('.autodoc_document_body').removeClass('d-none');
  237. $('.autodoc_document_image').attr('src','');
  238. loader_icon_on();
  239. $.getJSON(
  240. conf.openapi + "/documents/" + docid,
  241. function (doc) {
  242. loader_icon_off();
  243. $('span.autodoc_document_name').html(doc.name);
  244. $('input.autodoc_document_name').val(doc.name);
  245. $('.autodoc_document_created').html(doc.created);
  246. $('.autodoc_document_languages').html(doc.languages.join(','));
  247. $('.autodoc_document_owner').html(doc.owner);
  248. $('.autodoc_document_pages').html(doc.pageId.length);
  249. for(var i=0; i<doc.tags.length; i++) {
  250. var tag = $('.autodoc_document_tags_template').clone().removeClass('d-none');
  251. $(tag).html(doc.tags[i].name);
  252. $(tag).addClass('badge-' + doc.tags[i].color);
  253. $('.autodoc_document_tags').append(tag);
  254. }
  255. if ($('.slick-slide').length > 0) {
  256. $('.autodoc_document_carousel').slick('unslick');
  257. }
  258. $('.autodoc_document_carousel').children().remove();
  259. for (var i = 0; i < doc.pageId.length; i++) {
  260. var item = $('.autodoc_document_template_carousel').children().clone();
  261. $(item).children('img').attr('data-lazy',
  262. conf.openapi + "/pages/" + doc.pageId[i] + "/image?maxWidth=300");
  263. $(item).data('pageid', doc.pageId[i]);
  264. $(item).click(function(e) {
  265. var pageid = $(e.target).parent().data('pageid');
  266. $('.autodoc_document_image').attr('src',
  267. conf.openapi + "/pages/" + pageid + "/image"
  268. );
  269. $('.autodoc_document_image').data('pageid', pageid);
  270. });
  271. $('.autodoc_document_carousel').append(item);
  272. }
  273. $('.autodoc_document_image').attr('src', conf.openapi + "/pages/" + doc.primaryPage + "/image");
  274. $('.autodoc_document_image').data('pageid', doc.primaryPage);
  275. $('.autodoc_document_carousel').slick({
  276. lazyLoad: 'ondemand',
  277. slidesToShow: 3,
  278. slidesToScroll: 3,
  279. dots: true,
  280. infinite: true
  281. });
  282. }
  283. );
  284. }
  285. function page_load_upload() {
  286. upload_status();
  287. }
  288. function page_load_tags() {
  289. // update tag list
  290. loader_icon_on();
  291. $.getJSON(conf.openapi + "/tags", function (tags) {
  292. loader_icon_off();
  293. $.each(tags, function (n, tag) {
  294. $('.autodoc_tag_list').append(
  295. '<option data="' + tag.color + '" value="' + tag.id + '">' +
  296. tag.name +
  297. '</option>'
  298. );
  299. });
  300. });
  301. }
  302. function document_load() {
  303. if (conf.home.curpage == 0) {
  304. $("#autodoc_home_body").html("");
  305. }
  306. var tmpl = $("#autodoc_template_home");
  307. var row = $(tmpl)
  308. .find(".autodoc_template_home_row")
  309. .clone();
  310. loader_icon_on();
  311. $.getJSON(
  312. conf.openapi +
  313. "/documents?pageSize=" +
  314. conf.home.width +
  315. "&pageIndex=" +
  316. conf.home.curpage,
  317. null,
  318. function (data, textStatus, jqXHR) {
  319. // last document was loaded, stop scrolling
  320. loader_icon_off();
  321. if (data.length < conf.home.width) {
  322. conf.home.end = 1;
  323. }
  324. $.each(data, function (id, doc) {
  325. var col = $(tmpl)
  326. .find(".autodoc_template_home_col")
  327. .clone();
  328. $(col)
  329. .find(".autodoc_template_home_img")
  330. .attr(
  331. "src",
  332. conf.openapi +
  333. "/documents/" +
  334. doc.id +
  335. "/image?maxWidth=" +
  336. Math.floor(1000 / conf.home.width)
  337. );
  338. $(col).find(".autodoc_template_home_img").data("documentId", doc.id);
  339. $(col).find(".autodoc_template_home_img").on('click', function (e) {
  340. window.location.hash = 'document_' + $(e.target).data("documentId");
  341. e.preventDefault();
  342. // home_modal_open($(e.target).data("documentId"));
  343. });
  344. $(col)
  345. .find(".autodoc_template_home_owner")
  346. .html(doc.owner);
  347. $(col)
  348. .find(".autodoc_template_home_created")
  349. .html(doc.created);
  350. $(col)
  351. .find(".autodoc_template_home_name")
  352. .html(doc.name);
  353. $(col)
  354. .find(".autodoc_template_home_pages")
  355. .html(doc.pageId.length);
  356. $.each(doc.tags, function (id, tag) {
  357. $(col)
  358. .find(".autodoc_template_home_tag")
  359. .after(
  360. $(col)
  361. .find(".autodoc_template_home_tag")
  362. .clone()
  363. .html(tag)
  364. );
  365. });
  366. $(row).append(col);
  367. });
  368. $("#autodoc_home_body").append(row);
  369. // continue to load until out of browser.
  370. page_home_scroll();
  371. }
  372. );
  373. }
  374. function page_home_scroll() {
  375. // don't scroll if we've loaded the last document
  376. if (conf.home.end) {
  377. return;
  378. }
  379. if (isvisible($(".autodoc_template_home_col").last())) {
  380. console.log("scroll to page " + conf.home.curpage);
  381. conf.home.curpage++;
  382. document_load();
  383. }
  384. }
  385. function upload_zone_init() {
  386. $(window).on("dragover dragleave drop", function (e) { e.preventDefault() });
  387. $('.autodoc_upload_zone').on({
  388. dragenter: upload_zone_highlight,
  389. dragleave: upload_zone_normal,
  390. dragover: upload_zone_over,
  391. drop: upload_zone_drop
  392. });
  393. }
  394. function upload_zone_highlight(e) {
  395. $(e.target).addClass('autodoc_upload_zone_hover');
  396. }
  397. function upload_zone_over(e) {
  398. return true;
  399. }
  400. function upload_zone_normal(e) {
  401. $(e.target).removeClass('autodoc_upload_zone_hover');
  402. }
  403. function upload_zone_drop(e) {
  404. var ev = e.originalEvent;
  405. $.each(ev.dataTransfer.files, function (id, file) {
  406. console.log(file);
  407. var fileid = temp.upload.length;
  408. temp.upload.push({
  409. progress: 0,
  410. error: null,
  411. obj: file
  412. });
  413. upload_zone_normal(e);
  414. });
  415. if (conf.run.upload_handler == 0) {
  416. upload_handler();
  417. }
  418. if (conf.run.upload_status == 0) {
  419. upload_status();
  420. }
  421. }
  422. function upload_handler() {
  423. var stop = 1;
  424. conf.run.upload_handler = 1;
  425. console.log("upload_handler");
  426. if (temp.documentid == null) {
  427. console.log("creating documentId");
  428. loader_icon_on();
  429. $.post(conf.openapi + "/documents", {}, function (data) {
  430. loader_icon_off();
  431. temp.documentid = data.id;
  432. });
  433. stop = 0;
  434. }
  435. else {
  436. for (var id = 0; id < temp.upload.length; id++) {
  437. var file = temp.upload[id];
  438. if (file.progress != 100) {
  439. if (file.progress == 0) {
  440. if (file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg') {
  441. file['progress'] = 100;
  442. file['error'] = 'invalid file type';
  443. }
  444. else {
  445. var reader = new FileReader();
  446. file['progress'] = 1;
  447. $(reader).on('load', id, upload_read_event);
  448. $(reader).on('loadstart', id, upload_read_event);
  449. $(reader).on('loadend', id, upload_read_event);
  450. $(reader).on('progress', id, upload_read_event);
  451. $(reader).on('error', id, upload_read_event);
  452. $(reader).on('abort', id, upload_read_event);
  453. reader.readAsArrayBuffer(file.obj);
  454. }
  455. }
  456. stop = 0;
  457. break;
  458. }
  459. }
  460. }
  461. if (stop) {
  462. conf.run.upload_handler = 0;
  463. }
  464. else {
  465. setTimeout(function () { upload_handler(); }, 500);
  466. }
  467. }
  468. function upload_read_event(e) {
  469. if (e.type == 'progress') {
  470. if (e.lengthComputable) {
  471. var progress = Math.floor(e.originalEvent.loaded / e.originalEvent.total * 50);
  472. if (progress < 1) { progress = 1; }
  473. if (progress > 49) { progress = 49; }
  474. temp.upload[e.data]['progress'] = progress;
  475. }
  476. }
  477. else if (e.type == 'load') {
  478. temp.upload[e.data]['progress'] = 50;
  479. loader_icon_on();
  480. $.ajax({
  481. type: 'POST',
  482. url: conf.openapi + "/documents/" + temp.documentid + "/data",
  483. data: e.target.result,
  484. contentType: temp.upload[e.data].obj.type,
  485. context: { id: e.data },
  486. processData: false,
  487. xhr: function () {
  488. var xhr = $.ajaxSettings.xhr();
  489. xhr.upload.addEventListener("progress", (function () {
  490. var id = e.data;
  491. return function (evt) {
  492. if (evt.lengthComputable) {
  493. var progress = Math.floor(evt.loaded / evt.total * 50);
  494. if (progress < 1) { progress = 1; }
  495. if (progress > 49) { progress = 49; }
  496. temp.upload[id].progress = 50 + progress;
  497. // console.log("upload_progress_event", evt);
  498. }
  499. }
  500. })(), false);
  501. return xhr;
  502. },
  503. success: function (data, status, xhr) {
  504. loader_icon_off();
  505. temp.upload[this.id].progress = 100;
  506. }
  507. });
  508. }
  509. }
  510. function upload_status() {
  511. var stop = 1;
  512. conf.run.upload_status = 1;
  513. $.each(temp.upload, function (id, file) {
  514. if (!$('.autodoc_upload_status_' + id).length) {
  515. var obj = $(".autodoc_template_progress").children().clone();
  516. $(obj).addClass('autodoc_upload_status_' + id);
  517. $('.autodoc_upload_status').append(obj);
  518. stop = 0;
  519. }
  520. var obj = $('.autodoc_upload_status_' + id).children();
  521. if (file.error != null) {
  522. $(obj).html(file.obj.name + ': ' + file.error);
  523. $(obj).css('width', '100%');
  524. $(obj).addClass('bg-danger');
  525. $(obj).removeClass("progress-bar-animated");
  526. $(obj).removeClass("progress-bar-striped");
  527. }
  528. else if (file.progress == 100) {
  529. $(obj).html(file.obj.name);
  530. $(obj).css('width', '100%');
  531. $(obj).addClass('bg-success');
  532. $(obj).removeClass('progress-bar-animated');
  533. $(obj).removeClass("progress-bar-striped");
  534. }
  535. else if (file.progress < 50) {
  536. $(obj).html(file.obj.name + ': ' + 'reading file');
  537. $(obj).css('width', file.progress + '%');
  538. stop = 0;
  539. }
  540. else {
  541. $(obj).html(file.obj.name + ': ' + 'sending file');
  542. $(obj).css('width', file.progress + '%');
  543. stop = 0;
  544. }
  545. });
  546. if (stop) {
  547. conf.run.upload_status = 0;
  548. }
  549. else {
  550. setTimeout(function () { upload_status(); }, 100);
  551. }
  552. }
  553. function home_modal_page(pageNum) {
  554. var doc = $('#autodoc_home_modal').data('document');
  555. var pageTotal = doc.pageId.length;
  556. if (pageNum < 0) {
  557. pageNum = pageTotal - 1;
  558. }
  559. if (pageNum > pageTotal - 1) {
  560. pageNum = 0;
  561. }
  562. $('.autodoc_home_modal_page').html(pageNum + 1);
  563. $('#autodoc_home_modal').data('pageNum', pageNum);
  564. $('#autodoc_home_modal_img').attr('src',
  565. conf.openapi +
  566. "/pages/" +
  567. doc.pageId[pageNum] +
  568. "/image");
  569. }
  570. function home_modal_resize(size) {
  571. var newclass;
  572. $('#autodoc_home_modal').children().removeClass('modal-sm modal-lg modal-xl');
  573. switch (size) {
  574. case "S": newclass = "modal-sm"; break;
  575. case "M": break;
  576. case "L": newclass = "modal-lg"; break;
  577. case "XL": newclass = "modal-xl"; break;
  578. }
  579. if (newclass) {
  580. $('#autodoc_home_modal').children().addClass(newclass);
  581. }
  582. }
  583. function home_modal_page_prev() {
  584. home_modal_page(
  585. $('#autodoc_home_modal').data('pageNum') - 1);
  586. }
  587. function home_modal_page_next() {
  588. home_modal_page(
  589. $('#autodoc_home_modal').data('pageNum') + 1);
  590. }
  591. function home_modal_open(docid) {
  592. loader_icon_on();
  593. $.getJSON(conf.openapi + "/documents/" + docid, function (data) {
  594. loader_icon_off();
  595. $('#autodoc_home_modal').data('document', data);
  596. $('#autodoc_home_modal').data('documentid', docid);
  597. var pageNum;
  598. for (var i = 0; i < data.pageId.length; i++) {
  599. if (data.pageId[i] == data.primaryPage) {
  600. pageNum = i;
  601. break;
  602. }
  603. }
  604. $('span.autodoc_home_modal_name').html(data.name ? data.name : 'n/a');
  605. $('input.autodoc_home_modal_name').val(data.name ? data.name : '');
  606. $('.autodoc_home_modal_created').html(data.created);
  607. $('.autodoc_home_modal_languages').html(data.languages.join(' '));
  608. $('.autodoc_home_modal_pages').html(data.pageId.length);
  609. $('.autodoc_home_modal_owner').html(data.owner);
  610. home_modal_page(pageNum);
  611. $('#autodoc_home_modal').modal('show');
  612. });
  613. }
  614. function home_modal_close(docid) {
  615. $('#autodoc_home_modal').modal('hide');
  616. }
  617. function document_update_name(docid, name) {
  618. loader_icon_on();
  619. $.ajax({
  620. type: "PATCH",
  621. url: conf.openapi + "/documents/" + docid + "?name=" + encodeURIComponent(name),
  622. success: function (data) {
  623. loader_icon_off();
  624. $('span.autodoc_home_modal_name').removeClass('d-none');
  625. $('input.autodoc_home_modal_name').addClass('d-none');
  626. home_modal_open(docid);
  627. }
  628. });
  629. }
  630. // handle ajax busy icon
  631. function loader_icon_on() {
  632. conf.busy++;
  633. }
  634. function loader_icon_off() {
  635. setTimeout(function() { conf.busy--; }, 1000);
  636. }
  637. function loader_icon_update() {
  638. if ( conf.busy > 0 ) {
  639. $('.autodoc_ajax_on').removeClass('d-none');
  640. $('.autodoc_ajax_off').addClass('d-none');
  641. }
  642. else {
  643. $('.autodoc_ajax_off').removeClass('d-none');
  644. $('.autodoc_ajax_on').addClass('d-none');
  645. }
  646. setTimeout(loader_icon_update, 100);
  647. }