app.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584
  1. (() => {
  2. var __accessCheck = (obj, member, msg) => {
  3. if (!member.has(obj))
  4. throw TypeError("Cannot " + msg);
  5. };
  6. var __privateGet = (obj, member, getter) => {
  7. __accessCheck(obj, member, "read from private field");
  8. return getter ? getter.call(obj) : member.get(obj);
  9. };
  10. var __privateAdd = (obj, member, value) => {
  11. if (member.has(obj))
  12. throw TypeError("Cannot add the same private member more than once");
  13. member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
  14. };
  15. var __privateSet = (obj, member, value, setter) => {
  16. __accessCheck(obj, member, "write to private field");
  17. setter ? setter.call(obj, value) : member.set(obj, value);
  18. return value;
  19. };
  20. var __privateMethod = (obj, member, method) => {
  21. __accessCheck(obj, member, "access private method");
  22. return method;
  23. };
  24. // application/scripts/height_equaler.js
  25. var height_equaler = class {
  26. #to;
  27. #from;
  28. constructor(from, to) {
  29. this.#from = from;
  30. this.#to = to;
  31. this.#set_styles();
  32. new ResizeObserver(() => {
  33. this.#update();
  34. }).observe(from);
  35. setTimeout(() => {
  36. this.#update();
  37. }, 100);
  38. }
  39. get height() {
  40. return this.#from.offsetHeight;
  41. }
  42. #set_styles() {
  43. this.#to.style.height = "0px";
  44. this.#to.style.transition = "height 0.5s";
  45. }
  46. #update() {
  47. this.#to.style.height = this.height + "px";
  48. }
  49. };
  50. // application/scripts/product.js
  51. var product = class {
  52. name;
  53. description;
  54. author;
  55. image;
  56. stock_count;
  57. barcode;
  58. thumbnail;
  59. on_stock;
  60. constructor(target) {
  61. this.name = null;
  62. this.description = null;
  63. this.author = null;
  64. this.image = null;
  65. this.stock_count = null;
  66. this.barcode = null;
  67. this.thumbnail = null;
  68. this.on_stock = null;
  69. if ("name" in target)
  70. this.name = target["name"];
  71. if ("description" in target)
  72. this.description = target["description"];
  73. if ("author" in target)
  74. this.author = target["author"];
  75. if ("image" in target)
  76. this.image = target["image"];
  77. if ("stock_count" in target)
  78. this.stock_count = target["stock_count"];
  79. if ("barcode" in target)
  80. this.barcode = target["barcode"];
  81. if ("thumbnail" in target)
  82. this.thumbnail = target["thumbnail"];
  83. if ("on_stock" in target)
  84. this.on_stock = target["on_stock"];
  85. try {
  86. this.stock_count = Number(this.stock_count);
  87. } catch {
  88. this.stock_count = 0;
  89. }
  90. try {
  91. this.on_stock = Number(this.on_stock);
  92. } catch {
  93. this.on_stock = 0;
  94. }
  95. }
  96. get dump() {
  97. const dumped = {
  98. "name": new String(this.name),
  99. "description": new String(this.description),
  100. "author": new String(this.author),
  101. "image": new String(this.image),
  102. "barcode": new String(this.barcode),
  103. "thumbnail": new String(this.thumbnail),
  104. "stock_count": new String(this.stock_count)
  105. };
  106. if (this.on_stock !== null) {
  107. dumped["on_stock"] = new String(this.on_stock);
  108. }
  109. return dumped;
  110. }
  111. get ready() {
  112. if (this.name === null || this.description === null)
  113. return false;
  114. if (this.author === null || this.image === null)
  115. return false;
  116. if (this.stock_count === null || this.barcode === null)
  117. return false;
  118. if (this.thumbnail === null)
  119. return false;
  120. return true;
  121. }
  122. copy() {
  123. return new product(this.dump);
  124. }
  125. };
  126. // application/scripts/products_loader.js
  127. var _response_to_collection, response_to_collection_fn, _single_response_to_collection, single_response_to_collection_fn, _list_response_to_collection, list_response_to_collection_fn, _search, search_fn;
  128. var _products_loader = class {
  129. static async all() {
  130. var _a;
  131. const request2 = await fetch("/products/");
  132. const response = await request2.json();
  133. return __privateMethod(_a = _products_loader, _response_to_collection, response_to_collection_fn).call(_a, response);
  134. }
  135. static async search_name(name) {
  136. var _a;
  137. return await __privateMethod(_a = _products_loader, _search, search_fn).call(_a, "/product/search/name", name);
  138. }
  139. static async search_author(author) {
  140. var _a;
  141. return await __privateMethod(_a = _products_loader, _search, search_fn).call(_a, "/product/search/author", author);
  142. }
  143. static async search_barcode(barcode) {
  144. var _a;
  145. return await __privateMethod(_a = _products_loader, _search, search_fn).call(_a, "/product/get/barcode", barcode);
  146. }
  147. };
  148. var products_loader = _products_loader;
  149. _response_to_collection = new WeakSet();
  150. response_to_collection_fn = function(response) {
  151. if (response.result !== "success") {
  152. return new Array();
  153. }
  154. if ("collection" in response) {
  155. return __privateMethod(this, _list_response_to_collection, list_response_to_collection_fn).call(this, response);
  156. }
  157. return __privateMethod(this, _single_response_to_collection, single_response_to_collection_fn).call(this, response);
  158. };
  159. _single_response_to_collection = new WeakSet();
  160. single_response_to_collection_fn = function(response) {
  161. const result = new Array();
  162. result.push(new product(response.product));
  163. return result;
  164. };
  165. _list_response_to_collection = new WeakSet();
  166. list_response_to_collection_fn = function(response) {
  167. const result = new Array();
  168. response.collection.forEach((serialized) => {
  169. result.push(new product(serialized));
  170. });
  171. return result;
  172. };
  173. _search = new WeakSet();
  174. search_fn = async function(path, parameter) {
  175. var _a;
  176. const coded = encodeURI(parameter);
  177. const request2 = await fetch(path + "/" + coded);
  178. const response = await request2.json();
  179. return __privateMethod(_a = _products_loader, _response_to_collection, response_to_collection_fn).call(_a, response);
  180. };
  181. __privateAdd(products_loader, _response_to_collection);
  182. __privateAdd(products_loader, _single_response_to_collection);
  183. __privateAdd(products_loader, _list_response_to_collection);
  184. __privateAdd(products_loader, _search);
  185. // application/scripts/fullscreen.js
  186. var fullscreen = class {
  187. #node;
  188. constructor() {
  189. this.#node = null;
  190. }
  191. get visible() {
  192. return this.#node !== null;
  193. }
  194. _build_node() {
  195. throw new TypeError("This is virtual method!");
  196. }
  197. get #opacity() {
  198. if (!this.visible) {
  199. throw new TypeError("Can not change opacity of not existed.");
  200. }
  201. return Number(this.#node.style.opacity);
  202. }
  203. set #opacity(target) {
  204. if (!this.visible) {
  205. throw new TypeError("Can not change opacity of not existed.");
  206. }
  207. this.#node.style.opacity = String(target);
  208. }
  209. get_query(selector) {
  210. if (!this.visible) {
  211. throw new TypeError("Can not get item from not visible.");
  212. }
  213. return this.#node.querySelector(selector);
  214. }
  215. #prepare() {
  216. const container = document.createElement("div");
  217. container.classList.add("fullscreen-viewer");
  218. container.style.transition = "opacity 0.5s";
  219. container.appendChild(this._build_node());
  220. return container;
  221. }
  222. hide() {
  223. if (!this.visible) {
  224. return;
  225. }
  226. this.#opacity = 0;
  227. setTimeout(() => {
  228. if (!this.visible) {
  229. return;
  230. }
  231. this.#node.remove();
  232. this.#node = null;
  233. }, 500);
  234. }
  235. show() {
  236. if (this.visible) {
  237. return;
  238. }
  239. this.#node = this.#prepare();
  240. this.#opacity = 0;
  241. document.querySelector("body").appendChild(this.#node);
  242. setTimeout(() => {
  243. this.#opacity = 1;
  244. }, 100);
  245. }
  246. };
  247. // application/scripts/product_fullscreen.js
  248. var product_fullscreen = class extends fullscreen {
  249. #target;
  250. constructor(target) {
  251. super();
  252. this.#target = target;
  253. }
  254. get target() {
  255. return this.#target;
  256. }
  257. _build_node() {
  258. const container = document.createElement("div");
  259. container.classList.add("product-fullscreen-viewer");
  260. const image = document.createElement("div");
  261. image.style.backgroundImage = 'url("' + this.target.image + '")';
  262. image.classList.add("image");
  263. container.appendChild(image);
  264. const title = document.createElement("div");
  265. title.classList.add("title");
  266. container.appendChild(title);
  267. const title_content = document.createElement("h1");
  268. title_content.innerText = this.target.name;
  269. title.appendChild(title_content);
  270. const bottom = document.createElement("div");
  271. bottom.classList.add("bottom-side");
  272. container.appendChild(bottom);
  273. const bottom_header = document.createElement("div");
  274. bottom_header.classList.add("bottom-header");
  275. bottom.appendChild(bottom_header);
  276. const barcode_icon = document.createElement("span");
  277. barcode_icon.classList.add("material-icons");
  278. barcode_icon.innerText = "qr_code_scanner";
  279. const barcode_content = document.createElement("span");
  280. barcode_content.innerText = this.target.barcode;
  281. barcode_content.classList.add("numbers");
  282. const barcode = document.createElement("p");
  283. barcode.appendChild(barcode_icon);
  284. barcode.appendChild(barcode_content);
  285. bottom_header.appendChild(barcode);
  286. const author_icon = document.createElement("span");
  287. author_icon.classList.add("material-icons");
  288. author_icon.innerText = "attribution";
  289. const author_content = document.createElement("span");
  290. author_content.innerText = this.target.author;
  291. const author = document.createElement("p");
  292. author.appendChild(author_icon);
  293. author.appendChild(author_content);
  294. bottom_header.appendChild(author);
  295. const description = document.createElement("div");
  296. description.classList.add("description");
  297. bottom.appendChild(description);
  298. const description_content = document.createElement("p");
  299. description_content.innerText = this.target.description;
  300. description.appendChild(description_content);
  301. const close_button = document.createElement("button");
  302. close_button.classList.add("material-icons");
  303. close_button.classList.add("close");
  304. close_button.innerText = "close";
  305. container.appendChild(close_button);
  306. close_button.addEventListener("click", () => {
  307. this.hide();
  308. });
  309. return container;
  310. }
  311. };
  312. // application/scripts/user.js
  313. var user = class {
  314. #nick;
  315. #apikey;
  316. constructor(nick, apikey) {
  317. this.#nick = nick;
  318. this.#apikey = apikey;
  319. }
  320. get nick() {
  321. return this.#nick;
  322. }
  323. get apikey() {
  324. return this.#apikey;
  325. }
  326. };
  327. // application/scripts/login_manager.js
  328. var login_manager = class {
  329. get apikey() {
  330. return localStorage.getItem("apikey");
  331. }
  332. get logged_in() {
  333. return localStorage.getItem("apikey") !== null;
  334. }
  335. #create_request(data) {
  336. return {
  337. method: "POST",
  338. body: JSON.stringify(data),
  339. headers: {
  340. "Content-Type": "application/json"
  341. }
  342. };
  343. }
  344. async get_user() {
  345. if (!this.logged_in) {
  346. return null;
  347. }
  348. const request_data = this.#create_request({
  349. apikey: this.apikey
  350. });
  351. const request2 = await fetch("/user", request_data);
  352. const response = await request2.json();
  353. if (response.result !== "success") {
  354. return null;
  355. }
  356. return new user(
  357. response.nick,
  358. response.apikey
  359. );
  360. }
  361. async login(nick, password) {
  362. const request_data = this.#create_request({
  363. nick,
  364. password
  365. });
  366. const request2 = await fetch("/user/login", request_data);
  367. const response = await request2.json();
  368. if (response.result !== "success") {
  369. return false;
  370. }
  371. localStorage.setItem("apikey", response.apikey);
  372. return true;
  373. }
  374. logout() {
  375. localStorage.removeItem("apikey");
  376. }
  377. };
  378. // application/scripts/confirm_action.js
  379. var confirm_action = class {
  380. #node;
  381. #action;
  382. constructor() {
  383. this.#node = null;
  384. this.#action = true;
  385. }
  386. get _description() {
  387. throw new TypeError("It must be overwriten.");
  388. }
  389. get _title() {
  390. return _("you-must-confirm-it");
  391. }
  392. _action() {
  393. throw new TypeError("It must be overwriten.");
  394. }
  395. get _info() {
  396. return false;
  397. }
  398. show() {
  399. if (this.#node !== null) {
  400. return;
  401. }
  402. this.#action = true;
  403. this.#node = this.#create_window();
  404. document.querySelector("body").appendChild(this.#node);
  405. setTimeout(() => {
  406. this.#node.style.opacity = "1";
  407. }, 100);
  408. }
  409. hide() {
  410. if (this.#node === null) {
  411. return;
  412. }
  413. this.#action = false;
  414. this.#node.style.opacity = "0";
  415. setTimeout(() => {
  416. if (this.#node === null) {
  417. return;
  418. }
  419. this.#node.remove();
  420. this.#node = null;
  421. }, 500);
  422. }
  423. #create_window() {
  424. const container = document.createElement("div");
  425. container.classList.add("confirm-window");
  426. container.style.transition = "opacity 0.5s";
  427. container.style.opacity = "0";
  428. const center = document.createElement("div");
  429. center.classList.add("center");
  430. container.appendChild(center);
  431. const title = document.createElement("div");
  432. title.classList.add("title");
  433. center.appendChild(title);
  434. const title_text = document.createElement("h3");
  435. title_text.innerText = this._title;
  436. title.appendChild(title_text);
  437. const description = document.createElement("div");
  438. description.classList.add("description");
  439. center.appendChild(description);
  440. const description_text = document.createElement("p");
  441. description_text.innerText = this._description;
  442. description.appendChild(description_text);
  443. const buttons = document.createElement("div");
  444. buttons.classList.add("buttons");
  445. center.appendChild(buttons);
  446. const cancel_button = document.createElement("button");
  447. cancel_button.classList.add("cancel");
  448. cancel_button.classList.add("material-icons");
  449. cancel_button.innerText = "close";
  450. buttons.appendChild(cancel_button);
  451. cancel_button.addEventListener("click", () => {
  452. this.hide();
  453. });
  454. if (!this._info) {
  455. const confirm_button = document.createElement("button");
  456. confirm_button.classList.add("confirm");
  457. confirm_button.classList.add("material-icons");
  458. confirm_button.innerText = "send";
  459. buttons.appendChild(confirm_button);
  460. confirm_button.addEventListener("click", () => {
  461. if (this.#action === false) {
  462. return;
  463. }
  464. this._action();
  465. this.hide();
  466. });
  467. }
  468. return container;
  469. }
  470. };
  471. // application/scripts/request.js
  472. var request = class {
  473. get settings() {
  474. const settings = {
  475. "method": this.method,
  476. "headers": this.headers
  477. };
  478. if (this.method === "GET" || this.method === "HEAD") {
  479. return settings;
  480. }
  481. if (this.body === null) {
  482. return settings;
  483. }
  484. settings.body = this.body;
  485. return settings;
  486. }
  487. get _apikey() {
  488. const manager = new login_manager();
  489. if (manager.logged_in) {
  490. return manager.apikey;
  491. }
  492. throw new Error(_("user-must-be-logged-in"));
  493. }
  494. get method() {
  495. throw new TypeError("It must be overwrite.");
  496. }
  497. get url() {
  498. throw new TypeError("It must be overwrite.");
  499. }
  500. get headers() {
  501. if (this.method === "GET" || this.method === "HEAD") {
  502. return {};
  503. }
  504. if (typeof this.data === "string") {
  505. return {
  506. "Content-Type": "text/plain"
  507. };
  508. }
  509. return {
  510. "Content-Type": "application/json"
  511. };
  512. }
  513. get body() {
  514. if (this.data === null) {
  515. return null;
  516. }
  517. if (typeof this.data === "string") {
  518. return this.data;
  519. }
  520. return JSON.stringify(this.data);
  521. }
  522. get _response() {
  523. throw new TypeError("It must be overwrite.");
  524. }
  525. async connect() {
  526. const request2 = await fetch(this.url, this.settings);
  527. if (!request2.ok) {
  528. throw new Error(_("fail-when-request-__url__").format({
  529. url: this.url
  530. }));
  531. }
  532. const response = await request2.json();
  533. if (!("result" in response)) {
  534. throw new Error(_("bad-response-not-contain-result"));
  535. }
  536. return new this._response(response);
  537. }
  538. get data() {
  539. throw new TypeError("This must be overwrite.");
  540. }
  541. };
  542. // application/scripts/bool_response.js
  543. var bool_response = class {
  544. #result;
  545. #cause;
  546. constructor(target) {
  547. this.#result = target.result === "success";
  548. this.#cause = null;
  549. if (!this.result) {
  550. this.#cause = target.cause;
  551. }
  552. }
  553. get cause() {
  554. return this.#cause;
  555. }
  556. get result() {
  557. return this.#result;
  558. }
  559. };
  560. // application/scripts/delete_request.js
  561. var delete_request = class extends request {
  562. #product;
  563. constructor(product2) {
  564. super();
  565. this.#product = product2;
  566. }
  567. get _response() {
  568. return bool_response;
  569. }
  570. get data() {
  571. return {
  572. "apikey": this._apikey
  573. };
  574. }
  575. get url() {
  576. return "/product/barcode/" + this.#product.barcode;
  577. }
  578. get method() {
  579. return "DELETE";
  580. }
  581. };
  582. // application/scripts/product_containers.js
  583. var product_containers = class {
  584. #content;
  585. #where;
  586. #inserted;
  587. constructor(where) {
  588. this.#where = where;
  589. this.#content = new Array();
  590. this.#inserted = new Array();
  591. }
  592. add_list(target) {
  593. target.forEach((count) => {
  594. this.add(count);
  595. });
  596. return this;
  597. }
  598. add(target) {
  599. const current = new product_container(target);
  600. this.#content.push(current);
  601. return this;
  602. }
  603. clean() {
  604. this.#content = new Array();
  605. return this;
  606. }
  607. update() {
  608. this.#hide();
  609. setTimeout(() => {
  610. this.#content.forEach((count) => {
  611. this.#inserted.push(count);
  612. count.add(this.#where);
  613. });
  614. }, 500);
  615. return this;
  616. }
  617. #hide() {
  618. this.#inserted.forEach((count) => {
  619. if (!this.#content.includes(count)) {
  620. count.drop();
  621. }
  622. });
  623. this.#inserted = new Array();
  624. return this;
  625. }
  626. };
  627. // application/scripts/searcher.js
  628. var _input, _category, _manager, _result, _instances, _add, add_fn, _selector_complete, selector_complete_fn, _loader, loader_get, _result_title, result_title_get, result_title_set, _insert, insert_fn;
  629. var _searcher = class {
  630. constructor(search_form, manager, result) {
  631. __privateAdd(this, _selector_complete);
  632. __privateAdd(this, _loader);
  633. __privateAdd(this, _result_title);
  634. __privateAdd(this, _insert);
  635. __privateAdd(this, _input, void 0);
  636. __privateAdd(this, _category, void 0);
  637. __privateAdd(this, _manager, void 0);
  638. __privateAdd(this, _result, void 0);
  639. var _a;
  640. __privateSet(this, _input, search_form.querySelector('input[type="text"]'));
  641. __privateSet(this, _category, search_form.querySelector("select"));
  642. __privateSet(this, _manager, manager);
  643. __privateSet(this, _result, result);
  644. __privateMethod(this, _selector_complete, selector_complete_fn).call(this);
  645. search_form.addEventListener("submit", (target) => {
  646. target.preventDefault();
  647. this.update();
  648. });
  649. __privateMethod(_a = _searcher, _add, add_fn).call(_a, this);
  650. }
  651. static reload() {
  652. if (typeof __privateGet(_searcher, _instances) !== "object") {
  653. return;
  654. }
  655. __privateGet(_searcher, _instances).forEach((instance) => {
  656. instance.update();
  657. });
  658. }
  659. get categories() {
  660. return {
  661. "name": _("name-category"),
  662. "author": _("author-category"),
  663. "barcode": _("barcode-category")
  664. };
  665. }
  666. get category() {
  667. return __privateGet(this, _category).value;
  668. }
  669. get phrase() {
  670. return __privateGet(this, _input).value.trim();
  671. }
  672. async update() {
  673. if (this.phrase.length === 0) {
  674. this.show_all();
  675. return;
  676. }
  677. __privateMethod(this, _insert, insert_fn).call(this, await __privateGet(this, _loader, loader_get).call(this, this.phrase));
  678. }
  679. async show_all() {
  680. __privateMethod(this, _insert, insert_fn).call(this, await products_loader.all());
  681. }
  682. };
  683. var searcher = _searcher;
  684. _input = new WeakMap();
  685. _category = new WeakMap();
  686. _manager = new WeakMap();
  687. _result = new WeakMap();
  688. _instances = new WeakMap();
  689. _add = new WeakSet();
  690. add_fn = function(instance) {
  691. if (typeof __privateGet(_searcher, _instances) !== "object") {
  692. __privateSet(_searcher, _instances, new Array());
  693. }
  694. __privateGet(_searcher, _instances).push(instance);
  695. };
  696. _selector_complete = new WeakSet();
  697. selector_complete_fn = function() {
  698. const category = __privateGet(this, _category);
  699. const categories = this.categories;
  700. Object.keys(categories).forEach((name) => {
  701. const option = document.createElement("option");
  702. option.value = name;
  703. option.innerText = categories[name];
  704. category.appendChild(option);
  705. });
  706. };
  707. _loader = new WeakSet();
  708. loader_get = function() {
  709. return {
  710. "name": products_loader.search_name,
  711. "author": products_loader.search_author,
  712. "barcode": products_loader.search_barcode
  713. }[this.category];
  714. };
  715. _result_title = new WeakSet();
  716. result_title_get = function() {
  717. return __privateGet(this, _result).innerText;
  718. };
  719. result_title_set = function(target) {
  720. __privateGet(this, _result).innerText = target;
  721. };
  722. _insert = new WeakSet();
  723. insert_fn = function(list) {
  724. if (list.length === 0) {
  725. __privateSet(this, _result_title, _("not-found-anything"), result_title_set);
  726. } else {
  727. __privateSet(this, _result_title, _("browse-our-products"), result_title_set);
  728. }
  729. __privateGet(this, _manager).clean().add_list(list).update();
  730. };
  731. __privateAdd(searcher, _add);
  732. __privateAdd(searcher, _instances, void 0);
  733. // application/scripts/delete_product_window.js
  734. var delete_product_window = class extends confirm_action {
  735. #target;
  736. constructor(target) {
  737. super();
  738. this.#target = target;
  739. }
  740. get _title() {
  741. return _("do-you-want-to-remove-it");
  742. }
  743. get _description() {
  744. let content = _("you-try-to-remove-__name__").format({
  745. name: this.#target.name
  746. });
  747. return content;
  748. }
  749. async _action() {
  750. new delete_request(this.#target).connect();
  751. searcher.reload();
  752. }
  753. };
  754. // application/scripts/formscreen.js
  755. var formscreen = class extends fullscreen {
  756. #form;
  757. #result;
  758. constructor() {
  759. super();
  760. this.#form = null;
  761. this.#result = null;
  762. }
  763. get _name() {
  764. throw new TypeError("This is virtual getter!");
  765. }
  766. _process() {
  767. this._error = "This is abstract, and must be overwriten.";
  768. }
  769. _build_form() {
  770. throw new TypeError("This is virtual method!");
  771. }
  772. _get_input(name) {
  773. return this.get_query('input[name="' + name + '"]');
  774. }
  775. get _has_submit() {
  776. return true;
  777. }
  778. _build_node() {
  779. const center = document.createElement("div");
  780. center.classList.add("center");
  781. const title = document.createElement("div");
  782. title.classList.add("title");
  783. center.appendChild(title);
  784. const title_content = document.createElement("h3");
  785. title_content.innerText = this._name;
  786. title.appendChild(title_content);
  787. const form = document.createElement("form");
  788. center.appendChild(form);
  789. form.addEventListener("change", () => {
  790. this._clear_results();
  791. });
  792. this.#form = document.createElement("div");
  793. this.#form.classList.add("content");
  794. form.appendChild(this.#form);
  795. this.#result = document.createElement("div");
  796. this.#result.classList.add("result");
  797. form.appendChild(this.#result);
  798. const bottom = document.createElement("div");
  799. bottom.classList.add("bottom");
  800. form.appendChild(bottom);
  801. const close_button = document.createElement("button");
  802. close_button.classList.add("close");
  803. close_button.classList.add("material-icons");
  804. close_button.innerText = "close";
  805. close_button.type = "button";
  806. bottom.appendChild(close_button);
  807. if (this._has_submit) {
  808. const send_button = document.createElement("button");
  809. send_button.classList.add("send");
  810. send_button.classList.add("material-icons");
  811. send_button.innerText = "send";
  812. send_button.type = "submit";
  813. bottom.appendChild(send_button);
  814. }
  815. close_button.addEventListener("click", () => {
  816. this.hide();
  817. });
  818. form.addEventListener("submit", (target) => {
  819. target.preventDefault();
  820. this._process();
  821. });
  822. this._refresh();
  823. return center;
  824. }
  825. _refresh() {
  826. while (this.#form.lastChild) {
  827. this.#form.lastChild.remove();
  828. }
  829. this._build_form();
  830. }
  831. _create_input(name, label_text, placeholder, worker = null) {
  832. const container = document.createElement("div");
  833. container.classList.add("input-container");
  834. container.classList.add("input-" + name);
  835. const label = document.createElement("label");
  836. label.htmlFor = name;
  837. label.innerText = label_text;
  838. container.appendChild(label);
  839. const input = document.createElement("input");
  840. input.type = "text";
  841. input.placeholder = placeholder;
  842. input.name = name;
  843. input.id = name;
  844. container.appendChild(input);
  845. if (worker !== null) {
  846. worker(input);
  847. }
  848. if (!this.#form) {
  849. throw new Error("Screen is not visible yet!");
  850. }
  851. this._append_child(container);
  852. return (target = null) => {
  853. if (target !== null) {
  854. input.value = target;
  855. }
  856. return input.value;
  857. };
  858. }
  859. _append_child(target) {
  860. this.#form.appendChild(target);
  861. }
  862. _clear_results() {
  863. if (!this.#result) {
  864. return;
  865. }
  866. while (this.#result.lastChild) {
  867. this.#result.lastChild.remove();
  868. }
  869. }
  870. set _info(target) {
  871. this._clear_results();
  872. const info = document.createElement("p");
  873. info.classList.add("info");
  874. info.innerText = target;
  875. if (this.#result) {
  876. this.#result.appendChild(info);
  877. }
  878. }
  879. set _error(target) {
  880. this._clear_results();
  881. const info = document.createElement("p");
  882. info.classList.add("error");
  883. info.innerText = target;
  884. if (this.#result) {
  885. this.#result.appendChild(info);
  886. }
  887. }
  888. set _success(target) {
  889. this._clear_results();
  890. const info = document.createElement("p");
  891. info.classList.add("success");
  892. info.innerText = target;
  893. if (this.#result) {
  894. this.#result.appendChild(info);
  895. }
  896. }
  897. };
  898. // application/scripts/product_base.js
  899. var product_base = class {
  900. name;
  901. description;
  902. author;
  903. barcode;
  904. stock_count;
  905. constructor(target = null) {
  906. this.name = this._extract(target, "name");
  907. this.description = this._extract(target, "description");
  908. this.author = this._extract(target, "author");
  909. this.barcode = this._extract(target, "barcode");
  910. this.stock_count = this._extract(target, "stock_count");
  911. if (this.stock_count !== null) {
  912. try {
  913. this.stock_count = Number(this.stock_count);
  914. } catch {
  915. this.stock_count = 0;
  916. }
  917. }
  918. }
  919. get dump() {
  920. return {
  921. "name": new String(this.name),
  922. "description": new String(this.description),
  923. "author": new String(this.author),
  924. "barcode": new String(this.barcode),
  925. "stock_count": new String(this.stock_count)
  926. };
  927. }
  928. _extract(dict, name) {
  929. if (dict === null) {
  930. return null;
  931. }
  932. if (name in dict) {
  933. return dict[name];
  934. }
  935. return null;
  936. }
  937. get avairable() {
  938. return this.stock_count > 0;
  939. }
  940. };
  941. // application/scripts/edit_request.js
  942. var edit_request = class extends request {
  943. #target;
  944. #updated;
  945. constructor(target, updated) {
  946. super();
  947. this.#target = target;
  948. this.#updated = updated;
  949. }
  950. get _response() {
  951. return bool_response;
  952. }
  953. get data() {
  954. return Object.assign(this.#updated.dump, {
  955. "apikey": this._apikey
  956. });
  957. }
  958. get method() {
  959. return "POST";
  960. }
  961. get url() {
  962. return "/product/update/barcode/" + this.#target.barcode;
  963. }
  964. };
  965. // application/scripts/edit_image_request.js
  966. var edit_image_request = class extends request {
  967. #image;
  968. #target;
  969. constructor(target, image) {
  970. super();
  971. this.#target = target;
  972. this.#image = image;
  973. }
  974. get _response() {
  975. return bool_response;
  976. }
  977. get data() {
  978. return {
  979. "image": this.#image,
  980. "apikey": this._apikey
  981. };
  982. }
  983. get method() {
  984. return "POST";
  985. }
  986. get url() {
  987. return "/product/update/image/barcode/" + this.#target.barcode;
  988. }
  989. };
  990. // application/scripts/product_editor.js
  991. var product_editor = class extends formscreen {
  992. #target;
  993. #name;
  994. #description;
  995. #author;
  996. #barcode;
  997. #stock_count;
  998. #image;
  999. #loaded_image_type;
  1000. #loaded_image;
  1001. #image_preview;
  1002. constructor(target) {
  1003. super();
  1004. this.#target = target;
  1005. }
  1006. get target() {
  1007. return this.#target;
  1008. }
  1009. get _name() {
  1010. return _("product-editor");
  1011. }
  1012. _build_form() {
  1013. this.#loaded_image = null;
  1014. this.#loaded_image_type = null;
  1015. this.#name = this._create_input(
  1016. "name",
  1017. _("name-prompt"),
  1018. _("name-sample"),
  1019. (input) => {
  1020. input.value = this.#target.name;
  1021. }
  1022. );
  1023. this.#description = this._create_input(
  1024. "description",
  1025. _("description-prompt"),
  1026. _("description-sample"),
  1027. (input) => {
  1028. input.value = this.#target.description;
  1029. }
  1030. );
  1031. this.#author = this._create_input(
  1032. "author",
  1033. _("author-prompt"),
  1034. _("author-sample"),
  1035. (input) => {
  1036. input.value = this.#target.author;
  1037. }
  1038. );
  1039. this.#barcode = this._create_input(
  1040. "barcode",
  1041. _("barcode-prompt"),
  1042. _("barcode-sample"),
  1043. (input) => {
  1044. input.type = "number";
  1045. input.value = this.#target.barcode;
  1046. }
  1047. );
  1048. this.#stock_count = this._create_input(
  1049. "stock_count",
  1050. _("stock-count-prompt"),
  1051. _("stock-count-sample"),
  1052. (input) => {
  1053. input.type = "number";
  1054. input.value = this.#target.stock_count;
  1055. }
  1056. );
  1057. this._create_input(
  1058. "image",
  1059. _("change-product-image"),
  1060. "",
  1061. (input) => {
  1062. this.#image = input;
  1063. input.type = "file";
  1064. input.accept = "image/*";
  1065. input.addEventListener("change", () => {
  1066. this.#load_image_from_file();
  1067. });
  1068. }
  1069. );
  1070. this.#image_preview = document.createElement("img");
  1071. this.#image_preview.style.opacity = "1";
  1072. this.#image_preview.src = this.#target.image;
  1073. this._append_child(this.#image_preview);
  1074. }
  1075. get #ready_image() {
  1076. return this.#loaded_image;
  1077. }
  1078. #update_image_preview() {
  1079. this.#image_preview.src = "data:" + this.#loaded_image_type + ";base64," + this.#loaded_image;
  1080. this.#image_preview.style.opacity = "1";
  1081. }
  1082. #reset_image() {
  1083. this.#loaded_image = null;
  1084. this.#loaded_image_type = null;
  1085. this.#image_preview.style.opacity = "0";
  1086. this.#image_preview.src = "";
  1087. }
  1088. async #load_image_from_file() {
  1089. if (this.#image.files.length === 0) {
  1090. this.#reset_image();
  1091. }
  1092. const file = this.#image.files.item(0);
  1093. const buffer = await file.arrayBuffer();
  1094. let as_string = new String();
  1095. new Uint8Array(buffer).forEach((letter) => {
  1096. as_string += String.fromCharCode(letter);
  1097. });
  1098. this.#loaded_image = btoa(as_string);
  1099. this.#loaded_image_type = file.type;
  1100. this.#update_image_preview();
  1101. }
  1102. async #submit() {
  1103. const copy = this.#target.copy();
  1104. copy.name = this.#name();
  1105. copy.description = this.#description();
  1106. copy.author = this.#author();
  1107. copy.barcode = this.#barcode();
  1108. copy.stock_count = this.#stock_count();
  1109. const request2 = new edit_request(this.#target, copy);
  1110. const response = await request2.connect();
  1111. if (!response.result) {
  1112. throw new Error(response.cause);
  1113. }
  1114. this.#target = copy;
  1115. }
  1116. async #image_submit() {
  1117. const image = await this.#ready_image;
  1118. if (image === null) {
  1119. return;
  1120. }
  1121. const request2 = new edit_image_request(this.#target, image);
  1122. const response = await request2.connect();
  1123. if (!response.result) {
  1124. throw new Error(response.cause);
  1125. }
  1126. }
  1127. async _process() {
  1128. try {
  1129. this._info = _("updating-product-data");
  1130. await this.#submit();
  1131. this._info = _("processing-image");
  1132. await this.#image_submit();
  1133. this._success = _("uploaded-successfull");
  1134. searcher.reload();
  1135. setTimeout(() => {
  1136. this.hide();
  1137. }, 500);
  1138. } catch (error) {
  1139. this._error = new String(error);
  1140. }
  1141. }
  1142. };
  1143. // application/scripts/rents_screen.js
  1144. var rents_screen = class extends formscreen {
  1145. #target;
  1146. #email;
  1147. #phone;
  1148. get _email() {
  1149. return this.#email();
  1150. }
  1151. get _phone() {
  1152. return this.#phone();
  1153. }
  1154. constructor(target) {
  1155. super();
  1156. this.#target = target;
  1157. }
  1158. get _target() {
  1159. return this.#target;
  1160. }
  1161. _build_form() {
  1162. this.#email = this._create_input(
  1163. "email",
  1164. _("email-prompt"),
  1165. _("email-sample"),
  1166. (input) => {
  1167. input.type = "email";
  1168. }
  1169. );
  1170. this.#phone = this._create_input(
  1171. "phone",
  1172. _("phone-number-prompt"),
  1173. _("phone-number-sample"),
  1174. (input) => {
  1175. input.type = "tel";
  1176. const add_prefix = () => {
  1177. if (input.value.length === 0) {
  1178. input.value = "+48 ";
  1179. }
  1180. };
  1181. input.addEventListener("click", add_prefix);
  1182. input.addEventListener("focus", add_prefix);
  1183. }
  1184. );
  1185. }
  1186. };
  1187. // application/scripts/reservation.js
  1188. var reservation = class {
  1189. email;
  1190. phone_number;
  1191. product_barcode;
  1192. constructor(target = null) {
  1193. this.email = null;
  1194. this.phone_number = null;
  1195. this.product_barcode = null;
  1196. if (target === null) {
  1197. return;
  1198. }
  1199. if ("email" in target) {
  1200. this.email = target["email"];
  1201. }
  1202. if ("target_barcode" in target) {
  1203. this.product_barcode = target["target_barcode"];
  1204. }
  1205. if ("phone_number" in target) {
  1206. this.phone_number = target["phone_number"];
  1207. }
  1208. }
  1209. get dump() {
  1210. const dumped = {
  1211. "target_barcode": this.product_barcode
  1212. };
  1213. if (this.email !== null) {
  1214. dumped["email"] = this.email;
  1215. }
  1216. if (this.phone_number !== null) {
  1217. dumped["phone_number"] = this.phone_number;
  1218. }
  1219. return dumped;
  1220. }
  1221. get ready() {
  1222. if (this.product_barcode === null)
  1223. return false;
  1224. if (this.email === null && this.phone_number === null)
  1225. return false;
  1226. return true;
  1227. }
  1228. copy() {
  1229. return new reservation(this.dump);
  1230. }
  1231. };
  1232. // application/scripts/product_rent_request.js
  1233. var product_rent_request = class extends request {
  1234. #reservation;
  1235. constructor(reservation2) {
  1236. super();
  1237. this.#reservation = reservation2;
  1238. }
  1239. get data() {
  1240. return Object.assign(this.#reservation.dump, {
  1241. "apikey": this._apikey
  1242. });
  1243. }
  1244. get _response() {
  1245. return bool_response;
  1246. }
  1247. get method() {
  1248. return "POST";
  1249. }
  1250. get url() {
  1251. return "/rent/product/barcode/" + this.#reservation.product_barcode;
  1252. }
  1253. };
  1254. // application/scripts/reservation_factory.js
  1255. var reservation_factory = class {
  1256. #target;
  1257. constructor() {
  1258. this.#target = new reservation();
  1259. }
  1260. phone_number(target) {
  1261. target = target.trim().replaceAll("-", "");
  1262. if (target.length === 0) {
  1263. target = null;
  1264. }
  1265. this.#target.phone_number = target;
  1266. return this;
  1267. }
  1268. email(target) {
  1269. target = target.trim();
  1270. if (target.length === 0) {
  1271. target = null;
  1272. }
  1273. this.#target.email = target;
  1274. return this;
  1275. }
  1276. product(target) {
  1277. this.#target.product_barcode = target.barcode;
  1278. return this;
  1279. }
  1280. result() {
  1281. if (this.#target.ready) {
  1282. return this.#target;
  1283. }
  1284. throw new Error("Target reservation is not ready yet.");
  1285. }
  1286. };
  1287. // application/scripts/product_rent.js
  1288. var product_rent = class extends rents_screen {
  1289. get _name() {
  1290. return _("product-rent");
  1291. }
  1292. async _process() {
  1293. try {
  1294. this._info = _("processing");
  1295. const target = new reservation_factory().email(this._email).phone_number(this._phone).product(this._target).result();
  1296. const request2 = new product_rent_request(target);
  1297. const response = await request2.connect();
  1298. if (!response.result) {
  1299. throw new Error(response.cause);
  1300. }
  1301. this._success = _("new-rent-added");
  1302. searcher.reload();
  1303. setTimeout(() => {
  1304. this.hide();
  1305. }, 500);
  1306. } catch (error) {
  1307. this._error = String(error);
  1308. }
  1309. }
  1310. };
  1311. // application/scripts/product_give_back_request.js
  1312. var product_give_back_request = class extends request {
  1313. #reservation;
  1314. constructor(reservation2) {
  1315. super();
  1316. this.#reservation = reservation2;
  1317. }
  1318. get data() {
  1319. return Object.assign(this.#reservation.dump, {
  1320. "apikey": this._apikey
  1321. });
  1322. }
  1323. get _response() {
  1324. return bool_response;
  1325. }
  1326. get method() {
  1327. return "POST";
  1328. }
  1329. get url() {
  1330. return "/give_back/product/barcode/" + this.#reservation.product_barcode;
  1331. }
  1332. };
  1333. // application/scripts/product_give_back.js
  1334. var product_give_back = class extends rents_screen {
  1335. get _name() {
  1336. return _("product-give-back");
  1337. }
  1338. async _process() {
  1339. try {
  1340. this._info = _("processing");
  1341. const target = new reservation_factory().email(this._email).phone_number(this._phone).product(this._target).result();
  1342. const request2 = new product_give_back_request(target);
  1343. const response = await request2.connect();
  1344. if (!response.result) {
  1345. throw new Error(response.cause);
  1346. }
  1347. this._success = _("give-back-successfull");
  1348. searcher.reload();
  1349. setTimeout(() => {
  1350. this.hide();
  1351. }, 500);
  1352. } catch (error) {
  1353. this._error = String(error);
  1354. }
  1355. }
  1356. };
  1357. // application/scripts/reservations_response.js
  1358. var reservations_response = class extends bool_response {
  1359. #collection;
  1360. constructor(target) {
  1361. super(target);
  1362. if (!this.result) {
  1363. return;
  1364. }
  1365. this.#collection = new Array();
  1366. target["reservations"].forEach((count) => {
  1367. this.#collection.push(new reservation(count));
  1368. });
  1369. }
  1370. get collection() {
  1371. if (!this.result) {
  1372. throw new Error(this.cause);
  1373. }
  1374. return this.#collection;
  1375. }
  1376. };
  1377. // application/scripts/product_reservations_request.js
  1378. var product_reservations_request = class extends request {
  1379. #target;
  1380. constructor(target) {
  1381. super();
  1382. this.#target = target;
  1383. }
  1384. get _response() {
  1385. return reservations_response;
  1386. }
  1387. get data() {
  1388. return {
  1389. "apikey": this._apikey
  1390. };
  1391. }
  1392. get method() {
  1393. return "POST";
  1394. }
  1395. get url() {
  1396. return "/reservations/product/barcode/" + this.#target.barcode;
  1397. }
  1398. };
  1399. // application/scripts/product_all_rents.js
  1400. var product_all_rents = class extends formscreen {
  1401. #target;
  1402. constructor(target) {
  1403. super();
  1404. this.#target = target;
  1405. }
  1406. get _name() {
  1407. return _("all-rents");
  1408. }
  1409. get _has_submit() {
  1410. return false;
  1411. }
  1412. #create_single(target) {
  1413. const container = document.createElement("div");
  1414. container.classList.add("reservation-info");
  1415. if (target.phone_number !== null) {
  1416. const phone_icon = document.createElement("span");
  1417. phone_icon.classList.add("material-icons");
  1418. phone_icon.innerText = "phone";
  1419. const phone_number = document.createElement("span");
  1420. phone_number.classList.add("numbers");
  1421. phone_number.innerText = target.phone_number;
  1422. const phone_number_container = document.createElement("p");
  1423. phone_number_container.appendChild(phone_icon);
  1424. phone_number_container.appendChild(phone_number);
  1425. container.appendChild(phone_number_container);
  1426. }
  1427. if (target.email !== null) {
  1428. const email_icon = document.createElement("span");
  1429. email_icon.classList.add("material-icons");
  1430. email_icon.innerText = "mail";
  1431. const email = document.createElement("span");
  1432. email.innerText = target.email;
  1433. const email_container = document.createElement("p");
  1434. email_container.appendChild(email_icon);
  1435. email_container.appendChild(email);
  1436. container.appendChild(email_container);
  1437. }
  1438. return container;
  1439. }
  1440. #create_single_button(target) {
  1441. const button = document.createElement("button");
  1442. button.classList.add("material-icons");
  1443. button.classList.add("give-back-button");
  1444. button.innerText = "save_alt";
  1445. button.addEventListener("click", async () => {
  1446. try {
  1447. this._info = _("processing");
  1448. const request2 = new product_give_back_request(target);
  1449. const response = await request2.connect();
  1450. if (!response.result) {
  1451. throw new Error(_(response.cause));
  1452. }
  1453. this._refresh();
  1454. searcher.reload();
  1455. } catch (error) {
  1456. this._error = String(error);
  1457. }
  1458. });
  1459. return button;
  1460. }
  1461. _process() {
  1462. return;
  1463. }
  1464. async _build_form() {
  1465. try {
  1466. this._info = _("loading");
  1467. const request2 = new product_reservations_request(this.#target);
  1468. const response = await request2.connect();
  1469. const list = document.createElement("div");
  1470. list.classList.add("reservations-list");
  1471. let empty = true;
  1472. response.collection.forEach((count) => {
  1473. const item = document.createElement("div");
  1474. item.classList.add("reservation");
  1475. const left = this.#create_single(count);
  1476. const right = this.#create_single_button(count);
  1477. empty = false;
  1478. item.appendChild(left);
  1479. item.appendChild(right);
  1480. list.appendChild(item);
  1481. });
  1482. this._append_child(list);
  1483. if (empty) {
  1484. this._success = "not-found-any-reservations";
  1485. } else {
  1486. this._clear_results();
  1487. }
  1488. } catch (error) {
  1489. this._error = String(error);
  1490. }
  1491. }
  1492. };
  1493. // application/scripts/product_not_avairable.js
  1494. var product_not_avairable = class extends confirm_action {
  1495. get _title() {
  1496. return _("product-not-avairable");
  1497. }
  1498. get _description() {
  1499. return _("this-product-is-not-avairable-yet");
  1500. }
  1501. get _info() {
  1502. return true;
  1503. }
  1504. };
  1505. // application/scripts/product_container.js
  1506. var product_container = class {
  1507. #target;
  1508. #node;
  1509. #login;
  1510. constructor(target) {
  1511. this.#target = new product(target.dump);
  1512. this.#node = null;
  1513. this.#login = new login_manager().logged_in;
  1514. }
  1515. get #header() {
  1516. const header = document.createElement("div");
  1517. header.classList.add("header");
  1518. const title = document.createElement("h3");
  1519. title.innerText = this.#target.name;
  1520. header.appendChild(title);
  1521. if (this.#login) {
  1522. header.appendChild(this.#manage);
  1523. }
  1524. return header;
  1525. }
  1526. get #manage() {
  1527. const manage = document.createElement("div");
  1528. manage.classList.add("manage");
  1529. const all_rents_button = document.createElement("button");
  1530. all_rents_button.classList.add("material-icons");
  1531. all_rents_button.classList.add("all-rents-button");
  1532. all_rents_button.innerText = "list";
  1533. manage.appendChild(all_rents_button);
  1534. const rent_button = document.createElement("button");
  1535. rent_button.classList.add("material-icons");
  1536. rent_button.classList.add("rent-button");
  1537. rent_button.innerText = "backpack";
  1538. manage.appendChild(rent_button);
  1539. const give_back_button = document.createElement("button");
  1540. give_back_button.classList.add("material-icons");
  1541. give_back_button.classList.add("give-back-button");
  1542. give_back_button.innerText = "save_alt";
  1543. manage.appendChild(give_back_button);
  1544. const edit_button = document.createElement("button");
  1545. edit_button.classList.add("material-icons");
  1546. edit_button.classList.add("edit-button");
  1547. edit_button.innerText = "edit";
  1548. manage.appendChild(edit_button);
  1549. const delete_button = document.createElement("button");
  1550. delete_button.classList.add("material-icons");
  1551. delete_button.classList.add("delete-button");
  1552. delete_button.innerText = "remove_circle_outline";
  1553. manage.appendChild(delete_button);
  1554. all_rents_button.addEventListener("click", () => {
  1555. new product_all_rents(this.#target).show();
  1556. });
  1557. rent_button.addEventListener("click", () => {
  1558. if (this.#target.on_stock > 0) {
  1559. new product_rent(this.#target).show();
  1560. } else {
  1561. new product_not_avairable().show();
  1562. }
  1563. });
  1564. give_back_button.addEventListener("click", () => {
  1565. new product_give_back(this.#target).show();
  1566. });
  1567. edit_button.addEventListener("click", () => {
  1568. new product_editor(this.#target).show();
  1569. });
  1570. delete_button.addEventListener("click", () => {
  1571. new delete_product_window(this.#target).show();
  1572. });
  1573. return manage;
  1574. }
  1575. get #description() {
  1576. const container = document.createElement("div");
  1577. container.classList.add("description");
  1578. const description = document.createElement("p");
  1579. description.innerText = this.#target.description;
  1580. description.classList.add("content");
  1581. const author_container = document.createElement("div");
  1582. author_container.classList.add("author");
  1583. const author = document.createElement("span");
  1584. author.innerText = this.#target.author;
  1585. const author_icon = document.createElement("span");
  1586. author_icon.classList.add("material-icons");
  1587. author_icon.innerText = "attribution";
  1588. author_container.appendChild(author_icon);
  1589. author_container.appendChild(author);
  1590. const stock_count = document.createElement("p");
  1591. stock_count.classList.add("stock-count");
  1592. stock_count.classList.add("material-icons");
  1593. if (this.#target.on_stock > 0) {
  1594. stock_count.innerText = "check_circle";
  1595. stock_count.classList.add("avairable");
  1596. } else {
  1597. stock_count.innerText = "cancel";
  1598. stock_count.classList.add("unavairable");
  1599. }
  1600. const barcode_container = document.createElement("p");
  1601. barcode_container.classList.add("barcode");
  1602. const barcode = document.createElement("span");
  1603. barcode.innerText = this.#target.barcode;
  1604. barcode.classList.add("numbers");
  1605. const barcode_icon = document.createElement("span");
  1606. barcode_icon.classList.add("material-icons");
  1607. barcode_icon.innerText = "qr_code_scanner";
  1608. barcode_container.appendChild(barcode_icon);
  1609. barcode_container.appendChild(barcode);
  1610. container.appendChild(description);
  1611. container.appendChild(author_container);
  1612. container.appendChild(barcode_container);
  1613. container.appendChild(stock_count);
  1614. return container;
  1615. }
  1616. get #cache_bypass() {
  1617. if (!this.#login) {
  1618. return "?cache=1";
  1619. }
  1620. return "?cache=" + new String(Math.floor(Math.random() * 100));
  1621. }
  1622. get #image() {
  1623. const image = document.createElement("img");
  1624. image.classList.add("image");
  1625. image.src = this.#target.thumbnail + this.#cache_bypass;
  1626. image.alt = this.#target.name;
  1627. image.loading = "lazy";
  1628. image.addEventListener("click", () => {
  1629. new product_fullscreen(this.#target).show();
  1630. });
  1631. return image;
  1632. }
  1633. get node() {
  1634. if (this.#node !== null) {
  1635. return this.#node;
  1636. }
  1637. const bottom_container = document.createElement("div");
  1638. bottom_container.classList.add("bottom-container");
  1639. bottom_container.appendChild(this.#description);
  1640. bottom_container.appendChild(this.#image);
  1641. const container = document.createElement("div");
  1642. container.classList.add("product");
  1643. container.appendChild(this.#header);
  1644. container.appendChild(bottom_container);
  1645. return this.#node = container;
  1646. }
  1647. add(target) {
  1648. const node = this.node;
  1649. node.style.opacity = "0";
  1650. node.style.transition = "opacity 0.5s";
  1651. target.appendChild(node);
  1652. setTimeout(() => {
  1653. node.style.opacity = "1";
  1654. }, 50);
  1655. }
  1656. drop() {
  1657. const container = this.#node;
  1658. if (container === null) {
  1659. throw new TypeError("It is not showed yet.");
  1660. }
  1661. container.style.opacity = "1";
  1662. container.style.transition = "opacity 0.5s";
  1663. setTimeout(() => {
  1664. container.style.opacity = "0";
  1665. }, 50);
  1666. setTimeout(() => {
  1667. this.#node = null;
  1668. container.remove();
  1669. }, 550);
  1670. }
  1671. };
  1672. // application/scripts/login_prompt.js
  1673. var login_prompt = class extends formscreen {
  1674. #nick;
  1675. #password;
  1676. constructor(target) {
  1677. super();
  1678. target.addEventListener("click", () => {
  1679. this.show();
  1680. });
  1681. }
  1682. get _name() {
  1683. return _("login-window");
  1684. }
  1685. async _process() {
  1686. try {
  1687. this._info = _("processing");
  1688. await this.#login();
  1689. this._success = _("logged-in");
  1690. setTimeout(() => {
  1691. location.reload();
  1692. }, 250);
  1693. } catch (error) {
  1694. this._error = new String(error);
  1695. }
  1696. }
  1697. async #login() {
  1698. const manager = new login_manager();
  1699. const result = await manager.login(
  1700. this.#nick(),
  1701. this.#password()
  1702. );
  1703. if (result) {
  1704. return;
  1705. }
  1706. throw new Error(_("can-not-login-check-nick-and-password"));
  1707. }
  1708. _build_form() {
  1709. this.#nick = this._create_input(
  1710. "nick",
  1711. _("nick-prompt"),
  1712. _("nick-sample")
  1713. );
  1714. this.#password = this._create_input(
  1715. "password",
  1716. _("password-prompt"),
  1717. _("password-sample"),
  1718. (input) => {
  1719. input.type = "password";
  1720. }
  1721. );
  1722. }
  1723. };
  1724. // application/scripts/create_request.js
  1725. var create_request = class extends request {
  1726. #image;
  1727. #product;
  1728. constructor(product2, image) {
  1729. super();
  1730. this.#image = image;
  1731. this.#product = product2;
  1732. }
  1733. get _response() {
  1734. return bool_response;
  1735. }
  1736. get data() {
  1737. return Object.assign(this.#product.dump, {
  1738. "image": this.#image,
  1739. "apikey": this._apikey
  1740. });
  1741. }
  1742. get method() {
  1743. return "POST";
  1744. }
  1745. get url() {
  1746. return "/product/create";
  1747. }
  1748. };
  1749. // application/scripts/autocomplete_response.js
  1750. var autocomplete_response = class extends bool_response {
  1751. #found;
  1752. constructor(target) {
  1753. super(target);
  1754. this.#found = null;
  1755. if (this.result) {
  1756. this.#found = target["found"];
  1757. }
  1758. }
  1759. get found() {
  1760. if (this.#found === null) {
  1761. throw new Error("Server response is not complete.");
  1762. }
  1763. return this.#found;
  1764. }
  1765. };
  1766. // application/scripts/autocomplete_request.js
  1767. var autocomplete_request = class extends request {
  1768. #barcode;
  1769. constructor(barcode) {
  1770. super();
  1771. this.#barcode = barcode;
  1772. }
  1773. get _response() {
  1774. return autocomplete_response;
  1775. }
  1776. get data() {
  1777. return {
  1778. "apikey": this._apikey
  1779. };
  1780. }
  1781. get method() {
  1782. return "POST";
  1783. }
  1784. get url() {
  1785. return "/complete/barcode/" + this.#barcode;
  1786. }
  1787. };
  1788. // application/scripts/product_adder.js
  1789. var product_adder = class extends formscreen {
  1790. #name;
  1791. #description;
  1792. #author;
  1793. #barcode;
  1794. #stock_count;
  1795. #image;
  1796. #loaded_image_type;
  1797. #loaded_image;
  1798. #image_preview;
  1799. get _name() {
  1800. return _("add-product");
  1801. }
  1802. async #autocomplete() {
  1803. const barcode = this.#barcode();
  1804. if (barcode.length === 0) {
  1805. this._info = _("fill-barcode-first");
  1806. return;
  1807. }
  1808. this._info = _("searching-in-the-web");
  1809. try {
  1810. const request2 = new autocomplete_request(barcode);
  1811. const response = await request2.connect();
  1812. if (!response.result) {
  1813. throw new Error(response.cause);
  1814. }
  1815. const product2 = response.found;
  1816. this.#name(product2.title);
  1817. this.#description(product2.description);
  1818. this.#author(product2.author);
  1819. this.#barcode(product2.barcode);
  1820. this.#loaded_image = product2.image;
  1821. this.#loaded_image_type = product2.image_type;
  1822. this.#update_image_preview();
  1823. this._info = _("autocomplete-ready-check-results");
  1824. } catch (error) {
  1825. this._error = new String(error);
  1826. }
  1827. }
  1828. #update_image_preview() {
  1829. this.#image_preview.src = "data:" + this.#loaded_image_type + ";base64," + this.#loaded_image;
  1830. this.#image_preview.style.opacity = "1";
  1831. }
  1832. get #autocomplete_button() {
  1833. const button = document.createElement("div");
  1834. button.classList.add("autocomplete-button");
  1835. button.classList.add("button");
  1836. const icon = document.createElement("span");
  1837. icon.classList.add("material-icons");
  1838. icon.innerText = "auto_fix_normal";
  1839. button.appendChild(icon);
  1840. const text = document.createElement("span");
  1841. text.classList.add("text");
  1842. text.innerText = _("autocomplete");
  1843. button.appendChild(text);
  1844. return button;
  1845. }
  1846. _build_form() {
  1847. this.#loaded_image = null;
  1848. this.#loaded_image_type = null;
  1849. this.#name = this._create_input(
  1850. "name",
  1851. _("name-prompt"),
  1852. _("name-sample")
  1853. );
  1854. this.#description = this._create_input(
  1855. "description",
  1856. _("description-prompt"),
  1857. _("description-sample")
  1858. );
  1859. this.#author = this._create_input(
  1860. "author",
  1861. _("author-prompt"),
  1862. _("author-sample")
  1863. );
  1864. this.#barcode = this._create_input(
  1865. "barcode",
  1866. _("barcode-prompt"),
  1867. _("barcode-sample"),
  1868. (input) => {
  1869. input.type = "number";
  1870. }
  1871. );
  1872. this.#stock_count = this._create_input(
  1873. "stock_count",
  1874. _("stock-count-prompt"),
  1875. _("stock-count-sample"),
  1876. (input) => {
  1877. input.type = "number";
  1878. }
  1879. );
  1880. this._create_input(
  1881. "image",
  1882. _("image-prompt"),
  1883. "",
  1884. (input) => {
  1885. this.#image = input;
  1886. input.type = "file";
  1887. input.accept = "image/*";
  1888. input.addEventListener("change", () => {
  1889. this.#load_image_from_file();
  1890. });
  1891. }
  1892. );
  1893. this.#image_preview = document.createElement("img");
  1894. this.#image_preview.style.opacity = "0";
  1895. this._append_child(this.#image_preview);
  1896. const autocomplete = this.#autocomplete_button;
  1897. this._append_child(autocomplete);
  1898. autocomplete.addEventListener("click", () => {
  1899. this.#autocomplete();
  1900. });
  1901. }
  1902. #reset_image() {
  1903. this.#loaded_image = null;
  1904. this.#loaded_image_type = null;
  1905. this.#image_preview.style.opacity = "0";
  1906. this.#image_preview.src = "";
  1907. }
  1908. async #load_image_from_file() {
  1909. if (this.#image.files.length === 0) {
  1910. this.#reset_image();
  1911. }
  1912. const file = this.#image.files.item(0);
  1913. const buffer = await file.arrayBuffer();
  1914. let as_string = new String();
  1915. new Uint8Array(buffer).forEach((letter) => {
  1916. as_string += String.fromCharCode(letter);
  1917. });
  1918. this.#loaded_image = btoa(as_string);
  1919. this.#loaded_image_type = file.type;
  1920. this.#update_image_preview();
  1921. }
  1922. get #ready_image() {
  1923. if (this.#loaded_image === null) {
  1924. throw new Error(_("load-any-image-first"));
  1925. }
  1926. return this.#loaded_image;
  1927. }
  1928. async #submit() {
  1929. const product2 = new product_base();
  1930. product2.name = this.#name();
  1931. product2.description = this.#description();
  1932. product2.author = this.#author();
  1933. product2.stock_count = this.#stock_count();
  1934. product2.barcode = this.#barcode();
  1935. const request2 = new create_request(product2, this.#ready_image);
  1936. const response = await request2.connect();
  1937. if (!response.result) {
  1938. throw new Error(response.cause);
  1939. }
  1940. }
  1941. async _process() {
  1942. try {
  1943. this._info = _("creating-new-product");
  1944. await this.#submit();
  1945. this._success = _("created-new-product-success");
  1946. searcher.reload();
  1947. setTimeout(() => {
  1948. this.hide();
  1949. }, 500);
  1950. } catch (error) {
  1951. this._error = new String(error);
  1952. }
  1953. }
  1954. };
  1955. // application/scripts/import_process_fail.js
  1956. var import_process_fail = class {
  1957. #product;
  1958. #error;
  1959. constructor(product2, error) {
  1960. this.#product = product2;
  1961. this.#error = error;
  1962. }
  1963. get error() {
  1964. return this.#error;
  1965. }
  1966. get product() {
  1967. return this.#product;
  1968. }
  1969. };
  1970. // application/scripts/database.js
  1971. var database = class {
  1972. #content;
  1973. #processed;
  1974. #on_skip;
  1975. constructor(content) {
  1976. this.#content = content;
  1977. this.#processed = /* @__PURE__ */ new Map();
  1978. this.#on_skip = null;
  1979. }
  1980. #append(target) {
  1981. if (this.#processed.has(target.barcode)) {
  1982. this.#processed.get(target.barcode).stock_count += 1;
  1983. return;
  1984. }
  1985. this.#processed.set(target.barcode, target);
  1986. }
  1987. #validate(target) {
  1988. if (!("id" in target)) {
  1989. throw new Error("One of item has no ID.");
  1990. }
  1991. if (!("title" in target)) {
  1992. throw new Error("Product " + target.barcode + " has no title.");
  1993. }
  1994. if (!("author" in target)) {
  1995. throw new Error("Product " + target.barcode + " has no author.");
  1996. }
  1997. }
  1998. #convert(target) {
  1999. this.#validate(target);
  2000. const product2 = new product_base();
  2001. product2.name = target.title;
  2002. product2.description = "";
  2003. product2.author = target.author;
  2004. product2.stock_count = 1;
  2005. product2.barcode = target.id;
  2006. return product2;
  2007. }
  2008. on_skip(target) {
  2009. this.#on_skip = target;
  2010. return this;
  2011. }
  2012. process() {
  2013. this.#processed.clear();
  2014. if (!(this.#content instanceof Array)) {
  2015. throw new Error("Database woud be array of objects.");
  2016. }
  2017. this.#content.forEach((count) => {
  2018. try {
  2019. const product2 = this.#convert(count);
  2020. this.#append(product2);
  2021. } catch (error) {
  2022. if (this.#on_skip === null) {
  2023. return;
  2024. }
  2025. try {
  2026. this.#on_skip(new import_process_fail(count, error));
  2027. } catch (fail) {
  2028. console.log(fail);
  2029. }
  2030. }
  2031. });
  2032. return this;
  2033. }
  2034. results() {
  2035. return Array.from(this.#processed.values());
  2036. }
  2037. };
  2038. // application/scripts/product_response.js
  2039. var product_response = class extends bool_response {
  2040. #product;
  2041. constructor(target) {
  2042. super(target);
  2043. this.#product = null;
  2044. if (this.result) {
  2045. if (!("product" in target)) {
  2046. throw new Error(_("incomplete-request-with-good-status"));
  2047. }
  2048. this.#product = new product(target.product);
  2049. }
  2050. }
  2051. get product() {
  2052. return this.#product;
  2053. }
  2054. };
  2055. // application/scripts/product_get_request.js
  2056. var product_get_request = class extends request {
  2057. #barcode;
  2058. constructor(barcode) {
  2059. super();
  2060. this.#barcode = barcode;
  2061. }
  2062. get _response() {
  2063. return product_response;
  2064. }
  2065. get data() {
  2066. return null;
  2067. }
  2068. get method() {
  2069. return "GET";
  2070. }
  2071. get url() {
  2072. return "/product/get/barcode/" + new String(this.#barcode);
  2073. }
  2074. };
  2075. // application/scripts/import_loop.js
  2076. var import_loop = class {
  2077. #content;
  2078. #on_autocomplete;
  2079. #on_create;
  2080. #on_single_fail;
  2081. #on_skip;
  2082. #on_single_success;
  2083. #finally;
  2084. on_autocomplete(target) {
  2085. this.#on_autocomplete = target;
  2086. return this;
  2087. }
  2088. on_create(target) {
  2089. this.#on_create = target;
  2090. return this;
  2091. }
  2092. on_single_fail(target) {
  2093. this.#on_single_fail = target;
  2094. return this;
  2095. }
  2096. on_skip(target) {
  2097. this.#on_skip = target;
  2098. return this;
  2099. }
  2100. on_single_success(target) {
  2101. this.#on_single_success = target;
  2102. return this;
  2103. }
  2104. finally(target) {
  2105. this.#finally = target;
  2106. return this;
  2107. }
  2108. constructor(dataset) {
  2109. this.#content = dataset;
  2110. this.#on_autocomplete = null;
  2111. this.#on_create = null;
  2112. this.#on_single_fail = null;
  2113. this.#on_skip = null;
  2114. this.#on_single_success = null;
  2115. this.#finally = null;
  2116. }
  2117. async #autocomplete(target) {
  2118. if (this.#on_autocomplete !== null) {
  2119. try {
  2120. this.#on_autocomplete(target);
  2121. } catch (error) {
  2122. console.log(error);
  2123. }
  2124. }
  2125. const request2 = new autocomplete_request(target.barcode);
  2126. const response = await request2.connect();
  2127. if (!response.result) {
  2128. throw new Error(response.cause);
  2129. }
  2130. const found = response.found;
  2131. target.description = found.description;
  2132. if (found.image.length === 0) {
  2133. throw new Error("Image for " + target.barcode + " not found.");
  2134. }
  2135. return new create_request(target, found.image);
  2136. }
  2137. async process() {
  2138. for (const count of this.#content) {
  2139. try {
  2140. await this.#create(count);
  2141. } catch (error) {
  2142. if (this.#on_single_fail !== null) {
  2143. try {
  2144. const fail = new import_process_fail(count, error);
  2145. this.#on_single_fail(fail);
  2146. } catch (error2) {
  2147. console.log(error2);
  2148. }
  2149. }
  2150. }
  2151. }
  2152. if (this.#finally !== null) {
  2153. try {
  2154. this.#finally();
  2155. } catch (error) {
  2156. console.log(error);
  2157. }
  2158. }
  2159. return this;
  2160. }
  2161. async #exists(target) {
  2162. const request2 = new product_get_request(target.barcode);
  2163. const response = await request2.connect();
  2164. return response.product !== null;
  2165. }
  2166. async #create(target) {
  2167. if (await this.#exists(target)) {
  2168. try {
  2169. const result = new import_process_fail(target, null);
  2170. this.#on_skip(result);
  2171. } catch (error) {
  2172. console.log(error);
  2173. }
  2174. return;
  2175. }
  2176. const request2 = await this.#autocomplete(target);
  2177. if (this.on_create !== null) {
  2178. try {
  2179. this.#on_create(target);
  2180. } catch (error) {
  2181. console.log(error);
  2182. }
  2183. }
  2184. const response = await request2.connect();
  2185. if (!response.result) {
  2186. throw new Error(response.cause);
  2187. }
  2188. if (this.#on_single_success !== null) {
  2189. try {
  2190. this.#on_single_success(target);
  2191. } catch (error) {
  2192. console.log(error);
  2193. }
  2194. }
  2195. }
  2196. };
  2197. // application/scripts/import_log.js
  2198. var import_log = class {
  2199. #log;
  2200. constructor() {
  2201. this.#log = new Array();
  2202. }
  2203. #append(target) {
  2204. this.#log.push(target);
  2205. }
  2206. #error_dump(error) {
  2207. return "Error: " + new String(error) + ".";
  2208. }
  2209. #product_dump(product2) {
  2210. return 'Product: barcode: "' + product2.barcode + '", title: "' + product2.title + '".';
  2211. }
  2212. fail(target) {
  2213. this.#append(
  2214. "Fail when processing item. " + this.#product_dump(target.product) + " " + this.#error_dump(target.error)
  2215. );
  2216. }
  2217. skip(target) {
  2218. this.#append(
  2219. "Skipping not ready item. " + this.#product_dump(target.product) + " " + this.#error_dump(target.error)
  2220. );
  2221. }
  2222. get length() {
  2223. return this.#log.length;
  2224. }
  2225. content() {
  2226. return this.#log.join("\n");
  2227. }
  2228. };
  2229. // application/scripts/downloader.js
  2230. var downloader = class {
  2231. #name;
  2232. #content;
  2233. #type;
  2234. #encode;
  2235. constructor() {
  2236. this.#name = "download.json";
  2237. this.#content = "";
  2238. this.#type = "text/plain";
  2239. this.#encode = "utf-8";
  2240. }
  2241. name(target) {
  2242. this.#name = target;
  2243. return this;
  2244. }
  2245. content(target) {
  2246. this.#content = target;
  2247. return this;
  2248. }
  2249. type(target) {
  2250. this.#type = target;
  2251. return this;
  2252. }
  2253. encode(target) {
  2254. this.#encode = target;
  2255. return this;
  2256. }
  2257. get #href() {
  2258. return "data:" + this.#type + ";charset=" + this.#encode + "," + encodeURIComponent(this.#content);
  2259. }
  2260. get #link() {
  2261. const link = document.createElement("a");
  2262. link.style.display = "none";
  2263. link.href = this.#href;
  2264. link.download = this.#name;
  2265. return link;
  2266. }
  2267. process() {
  2268. const link = this.#link;
  2269. const body = document.querySelector("body");
  2270. body.appendChild(link);
  2271. link.click();
  2272. body.removeChild(link);
  2273. return this;
  2274. }
  2275. };
  2276. // application/scripts/import_products.js
  2277. var import_products = class extends formscreen {
  2278. #file;
  2279. #content;
  2280. get _name() {
  2281. return _("import-products-json");
  2282. }
  2283. _build_form() {
  2284. this._create_input("file", "Database:", "", (input) => {
  2285. this.#file = input;
  2286. input.type = "file";
  2287. input.accept = "application/json";
  2288. });
  2289. }
  2290. async #load_file() {
  2291. if (this.#file.files.length === 0) {
  2292. throw new Error("select-products-json-database-first");
  2293. }
  2294. const file = this.#file.files.item(0);
  2295. const text = await file.text();
  2296. return JSON.parse(text);
  2297. }
  2298. async _process() {
  2299. try {
  2300. this._info = _("loading-file");
  2301. this.#content = await this.#load_file();
  2302. this._info = _("parsing-file-to-dataset");
  2303. const result = new import_log();
  2304. const dataset = new database(this.#content).on_skip((fail) => {
  2305. this._info = _("skipping-import-product-__barcode__").format({
  2306. barcode: fail.product.barcode
  2307. });
  2308. result.skip(fail);
  2309. }).process().results();
  2310. const loop = new import_loop(dataset).on_autocomplete((target) => {
  2311. this._info = _("searching-for-product-__barcode__").format({
  2312. barcode: target.barcode
  2313. });
  2314. }).on_create((target) => {
  2315. this._info = _("creating-product-__barcode__").format({
  2316. barcode: target.barcode
  2317. });
  2318. }).on_single_fail((target) => {
  2319. this._info = _("can-not-add-product-__barcode__").format({
  2320. barcode: target.product.barcode
  2321. });
  2322. result.fail(target);
  2323. }).on_skip((target) => {
  2324. this._info = _("skipping-product-__barcode").format({
  2325. barcode: target.product.barcode
  2326. });
  2327. result.skip(target);
  2328. }).on_single_success((target) => {
  2329. this._info = _("created-product-__barcode__").format({
  2330. barcode: target.barcode
  2331. });
  2332. }).finally(() => {
  2333. searcher.reload();
  2334. const log = new downloader().content(result.content()).type("text/plain").encode("utf-8").name("import-json.log").process();
  2335. if (result.length === 0) {
  2336. this._success = _("all-items-imported");
  2337. setTimeout(() => {
  2338. this.hide();
  2339. });
  2340. } else {
  2341. this._success = _("not-all-items-imported");
  2342. }
  2343. }).process();
  2344. } catch (error) {
  2345. this._error = new String(error);
  2346. }
  2347. }
  2348. };
  2349. // application/scripts/login_bar.js
  2350. var login_bar = class {
  2351. #manager;
  2352. constructor(target) {
  2353. this.#manager = new login_manager();
  2354. if (!this.#manager.logged_in) {
  2355. this.#not_logged(target);
  2356. return;
  2357. }
  2358. this.#logged(target);
  2359. }
  2360. #not_login_propertly() {
  2361. this.#manager.logout();
  2362. location.reload();
  2363. }
  2364. async #logged(target) {
  2365. const user2 = await this.#manager.get_user();
  2366. if (user2 === null) {
  2367. this.#not_login_propertly();
  2368. }
  2369. const info_icon = document.createElement("span");
  2370. info_icon.classList.add("icon");
  2371. info_icon.classList.add("material-icons");
  2372. info_icon.innerText = "account_circle";
  2373. const info_content = document.createElement("span");
  2374. info_content.innerText = user2.nick;
  2375. const info = document.createElement("p");
  2376. info.classList.add("login-info");
  2377. info.appendChild(info_icon);
  2378. info.appendChild(info_content);
  2379. target.appendChild(info);
  2380. const logout_button = document.createElement("button");
  2381. logout_button.innerText = "logout";
  2382. logout_button.classList.add("logout-button");
  2383. logout_button.classList.add("material-icons");
  2384. target.appendChild(logout_button);
  2385. const add_product_button = document.createElement("button");
  2386. add_product_button.innerText = "add";
  2387. add_product_button.classList.add("add-product-button");
  2388. add_product_button.classList.add("material-icons");
  2389. target.appendChild(add_product_button);
  2390. const import_products_button = document.createElement("button");
  2391. import_products_button.innerText = "dataset_linked";
  2392. import_products_button.classList.add("material-icons");
  2393. import_products_button.classList.add("import-products-button");
  2394. target.appendChild(import_products_button);
  2395. add_product_button.addEventListener("click", () => {
  2396. new product_adder().show();
  2397. });
  2398. import_products_button.addEventListener("click", () => {
  2399. new import_products().show();
  2400. });
  2401. logout_button.addEventListener("click", () => {
  2402. this.#manager.logout();
  2403. location.reload();
  2404. });
  2405. }
  2406. #not_logged(target) {
  2407. const login_button = document.createElement("button");
  2408. login_button.innerText = "account_circle";
  2409. login_button.classList.add("login-button");
  2410. login_button.classList.add("material-icons");
  2411. target.appendChild(login_button);
  2412. new login_prompt(login_button);
  2413. }
  2414. };
  2415. // application/scripts/scroll_up.js
  2416. var scroll_up = class {
  2417. #button;
  2418. constructor(button) {
  2419. this.#button = button;
  2420. this.#update();
  2421. document.addEventListener("scroll", () => {
  2422. this.#update();
  2423. });
  2424. this.#button.addEventListener("click", () => {
  2425. this.scroll();
  2426. });
  2427. }
  2428. scroll() {
  2429. this.#position = 0;
  2430. }
  2431. get #position() {
  2432. return document.scrollingElement.scrollTop;
  2433. }
  2434. set #position(target) {
  2435. document.scrollingElement.scrollTop = target;
  2436. }
  2437. get #visible() {
  2438. return Number(this.#button.style.opacity) === 1;
  2439. }
  2440. set #visible(target) {
  2441. this.#button.style.opacity = target ? "1" : "0";
  2442. }
  2443. get #margin() {
  2444. return 20;
  2445. }
  2446. #update() {
  2447. this.#visible = this.#position > this.#margin;
  2448. }
  2449. };
  2450. // application/scripts/color_theme.js
  2451. var color_theme = class {
  2452. #button;
  2453. #themes;
  2454. get themes() {
  2455. return Object.keys(this.#themes);
  2456. }
  2457. theme_name(target) {
  2458. return this.#themes[target];
  2459. }
  2460. constructor(button, themes = null) {
  2461. this.#button = button;
  2462. this.#themes = themes;
  2463. if (this.#themes === null) {
  2464. this.#themes = {
  2465. "dark-theme": "Dark",
  2466. "white-theme": "White"
  2467. };
  2468. }
  2469. this.#load();
  2470. this.#button.addEventListener("click", () => {
  2471. this.change();
  2472. });
  2473. }
  2474. get current() {
  2475. if (localStorage.hasOwnProperty("theme")) {
  2476. return localStorage.getItem("theme");
  2477. }
  2478. return this.themes[this.themes.length - 1];
  2479. }
  2480. #load() {
  2481. this.#show(this.current);
  2482. }
  2483. #save(target) {
  2484. localStorage.setItem("theme", target);
  2485. }
  2486. #show(target) {
  2487. const themes = this.themes;
  2488. const body = document.querySelector("body");
  2489. body.classList.forEach((count) => {
  2490. if (themes.indexOf(count) !== -1) {
  2491. body.classList.remove(count);
  2492. }
  2493. });
  2494. body.classList.add(target);
  2495. }
  2496. change() {
  2497. const themes = this.themes;
  2498. const current = this.current;
  2499. let position = themes.indexOf(current) + 1;
  2500. if (position === themes.length) {
  2501. position = 0;
  2502. }
  2503. const updated = themes[position];
  2504. this.#save(updated);
  2505. this.#show(updated);
  2506. }
  2507. };
  2508. // application/scripts/core.js
  2509. document.addEventListener("DOMContentLoaded", async () => {
  2510. const languages = new cx_libtranslate.languages("app/assets/languages");
  2511. await languages.load("index.json");
  2512. const preferences = new cx_libtranslate.preferences(languages);
  2513. preferences.selector.insert().add_listener(() => {
  2514. location.reload();
  2515. });
  2516. const phrasebook = await preferences.load_choosen_phrasebook();
  2517. phrasebook.set_as_default();
  2518. const autotranslate = await preferences.get_autotranslate();
  2519. autotranslate.connect();
  2520. const top_bar_spacing = new height_equaler(
  2521. document.querySelector(".top-bar"),
  2522. document.querySelector(".top-bar-spacing")
  2523. );
  2524. const container = document.querySelector(".products");
  2525. const search_bar = document.querySelector("form.search");
  2526. const search_title = document.querySelector(".search-title");
  2527. const login_space = document.querySelector(".top-bar .right");
  2528. const scroll_up_button = document.querySelector(".scroll-up-button");
  2529. const reverse_colors = document.querySelector(".reverse-colors");
  2530. const manager = new product_containers(container);
  2531. new login_bar(login_space);
  2532. new scroll_up(scroll_up_button);
  2533. new color_theme(reverse_colors);
  2534. new searcher(search_bar, manager, search_title).show_all();
  2535. });
  2536. })();