index.js 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620
  1. htmlElemAttr.forEach((prop) => {
  2. $('#set-icube-' + prop).on("click", function () {
  3. clickOn(prop, this);
  4. });
  5. });
  6. /**
  7. *
  8. * @param { PropertyKey } prop
  9. */
  10. function finishToSet (prop) {
  11. if ($('#set-icube-' + prop).hasClass("active-icube-setting")) {
  12. if (selectedIcube)
  13. selectedIcube.finishToSetProperty(prop);
  14. if (prop === 'connection') {
  15. updateConnectorsPrice();
  16. }
  17. }
  18. g_sceneMode = sceneMode.normal;
  19. }
  20. /**
  21. *
  22. * @param { PropertyKey } prop
  23. * @param { htmlDomElement } htmlElem
  24. */
  25. function clickOn (prop, htmlElem) {
  26. updateDrawButtonState();
  27. if (['passthrough', 'charger'].includes(prop)) {
  28. if (currentView !== ViewType.free)
  29. switch_to_free_camera();
  30. else
  31. switchCamera(ViewType.free);
  32. scene.activeCamera.alpha = g_rackingOrientation === OrientationRacking.horizontal ? Math.PI / 4 : 3 * Math.PI / 4;
  33. scene.activeCamera.beta = 1;
  34. }
  35. else {
  36. if (currentView !== ViewType.top)
  37. switch_to_top_camera();
  38. }
  39. if ($(htmlElem).hasClass("active-icube-setting")) {
  40. finishToSet(prop);
  41. }
  42. else {
  43. if (prop === 'connection') {
  44. // check if exist icube to connect
  45. const validIcube = getValidIcubeToConect();
  46. if (validIcube.length === 0) {
  47. Utils.logg('Can\'t connect the icubes!', 'error');
  48. return;
  49. }
  50. }
  51. htmlElemAttr.forEach((localProp) => {
  52. if (localProp !== prop)
  53. finishToSet(localProp);
  54. });
  55. if (selectedIcube)
  56. selectedIcube.previewProperty(prop);
  57. tracking(65 + parseInt(htmlElemAttr.indexOf(prop)));
  58. }
  59. renderScene(1000);
  60. }
  61. //Control tab
  62. $('.a-tabs').on("click", function () {
  63. updateDrawButtonState();
  64. htmlElemAttr.forEach((prop) => {
  65. finishToSet(prop);
  66. });
  67. clearSceneItemManual();
  68. endSimulation();
  69. unsetCurrentMesh();
  70. const pane_id = $(this).attr("aria-controls");
  71. tracking(56 + parseInt(menuTab.indexOf(pane_id.split('-')[3])));
  72. if (pane_id === "#main-tabs-pane-Price") {
  73. updateConnectorsPrice();
  74. if (userRole === g_UserRole.Sales) {
  75. if (g_priceChanged !== g_priceUpdated) {
  76. $('#waiting').show();
  77. }
  78. }
  79. }
  80. if (pane_id === "#main-tabs-pane-Export") {
  81. icubes.forEach((icube) => {
  82. icube.software.update();
  83. });
  84. }
  85. if (pane_id === "#main-tabs-pane-Simulation") {
  86. if (selectedIcube) {
  87. const samePos = selectedIcube.activedIOPorts.filter(e => e.portPosition === (selectedIcube.isHorizontal ? "bottom" : "left" ));
  88. if (samePos.length === selectedIcube.activedIOPorts.length)
  89. $('select[name="simLiftA"]').val(1);
  90. else
  91. $('select[name="simLiftA"]').val(0);
  92. }
  93. }
  94. if (pane_id === "#main-tabs-pane-Contact") {
  95. $('#con_fullName').val(userName);
  96. $('#con_email').val(userEmail);
  97. }
  98. $('.a-tabs').parent().removeClass("active");
  99. $('.a-tabs').attr("aria-selected", false).attr("tabindex", -1);
  100. if ($(pane_id).hasClass('show')) {
  101. $('.tab-pane').removeClass("show");
  102. $(pane_id).parent().addClass("hide");
  103. }
  104. else {
  105. $(this).parent().addClass("active");
  106. $(this).attr("aria-selected", true).removeAttr("tabindex");
  107. $('.tab-pane').removeClass("show");
  108. $(pane_id).parent().removeClass("hide");
  109. $(pane_id).addClass("show");
  110. }
  111. resizeRenderer();
  112. })
  113. //Control warehouse size
  114. $('.input-spinner').on("change", function (event) {
  115. if (!menuEnabled) return;
  116. let newVal = parseFloat(event.target.value);
  117. const controller = $(this).parent().attr('controller');
  118. switch (controller) {
  119. case 'width':
  120. if (!isNaN(parseFloat(newVal))) {
  121. newVal = useP(newVal) / useP(rateUnit);
  122. if (newVal < g_WarehouseMinWidth) {
  123. newVal = g_WarehouseMinWidth;
  124. } else if (newVal > g_WarehouseMaxWidth) {
  125. newVal = g_WarehouseMaxWidth;
  126. }
  127. } else {
  128. newVal = WHDimensions[0];
  129. }
  130. WHDimensions[0] = _round(newVal, 2);
  131. warehouse.update(WHDimensions);
  132. if (selectedIcube)
  133. selectedIcube.addRowLabels();
  134. tracking(55);
  135. Behavior.add(Behavior.type.WHDimensions);
  136. break;
  137. case 'length':
  138. if (!isNaN(parseFloat(newVal))) {
  139. newVal = useP(newVal) / useP(rateUnit);
  140. if (newVal < g_WarehouseMinLength) {
  141. newVal = g_WarehouseMinLength;
  142. }
  143. if (newVal > g_WarehouseMaxLength) {
  144. newVal = g_WarehouseMaxLength;
  145. }
  146. } else {
  147. newVal = WHDimensions[1];
  148. }
  149. WHDimensions[1] = _round(newVal, 2);
  150. warehouse.update(WHDimensions);
  151. if (selectedIcube)
  152. selectedIcube.addRowLabels();
  153. tracking(54);
  154. Behavior.add(Behavior.type.WHDimensions);
  155. break;
  156. case 'height':
  157. if (!isNaN(parseFloat(newVal))) {
  158. newVal = useP(newVal) / useP(rateUnit);
  159. if (newVal < g_WarehouseMinHeight) {
  160. newVal = g_WarehouseMinHeight;
  161. }
  162. if (newVal > g_WarehouseMaxHeight) {
  163. newVal = g_WarehouseMaxHeight;
  164. }
  165. } else {
  166. newVal = WHDimensions[2];
  167. }
  168. WHDimensions[2] = _round(newVal, 2);
  169. warehouse.update(WHDimensions);
  170. //Set ui
  171. updateRackingHighLevel();
  172. updateSelectedIcube();
  173. tracking(53);
  174. Behavior.add(Behavior.type.WHDimensions);
  175. break;
  176. case 'pallet-height':
  177. if (!isNaN(parseFloat(newVal))) {
  178. newVal = useP(newVal) / useP(rateUnit);
  179. if (newVal < g_PalletMinHeight) {
  180. newVal = g_PalletMinHeight;
  181. }
  182. if (newVal > g_PalletMaxHeight) {
  183. newVal = g_PalletMaxHeight;
  184. }
  185. } else {
  186. newVal = g_palletHeight;
  187. }
  188. g_palletHeight = useP(useP(newVal), false);
  189. tracking(52);
  190. //Set racking height
  191. updateRackingHighLevel();
  192. if (g_palletHeight > 0 && g_palletHeight <= 1.2) {
  193. simulateEvent('palletOverhang', 'change', 0.05);
  194. }
  195. else if (g_palletHeight > 1.2 && g_palletHeight <= 1.8) {
  196. simulateEvent('palletOverhang', 'change', 0.075);
  197. }
  198. else {
  199. simulateEvent('palletOverhang', 'change', 0.100);
  200. }
  201. // Behavior.add(Behavior.type.palletHeight);
  202. break;
  203. case 'pallet-weight':
  204. if (isNaN(parseFloat(newVal))) {
  205. newVal = g_palletHeight;
  206. }
  207. g_palletWeight = useP(useP(newVal), false);
  208. if (selectedIcube) selectedIcube.palletWeight = g_palletWeight;
  209. tracking(51);
  210. Behavior.add(Behavior.type.palletWeight);
  211. break;
  212. case 'layoutScale':
  213. if (newVal > 0 && newVal < 200) {
  214. layoutMap.scale = parseFloat((2 - parseFloat(newVal / 100)).toFixed(2));
  215. warehouse.update(WHDimensions);
  216. }
  217. break;
  218. default:
  219. break;
  220. }
  221. setUnitForInput();
  222. })
  223. $('.spinner-up').on("click", function () {
  224. if (!menuEnabled) return;
  225. const controller = $(this).parent().parent().attr('controller');
  226. switch (controller) {
  227. case 'width':
  228. if (WHDimensions[0] < g_WarehouseMaxWidth) {
  229. WHDimensions[0] += g_WarehouseIncValue;
  230. warehouse.update(WHDimensions);
  231. if (selectedIcube)
  232. selectedIcube.addRowLabels();
  233. tracking(55);
  234. Behavior.add(Behavior.type.WHDimensions);
  235. }
  236. break;
  237. case 'length':
  238. if (WHDimensions[1] < g_WarehouseMaxLength) {
  239. WHDimensions[1] += g_WarehouseIncValue;
  240. warehouse.update(WHDimensions);
  241. if (selectedIcube)
  242. selectedIcube.addRowLabels();
  243. tracking(54);
  244. Behavior.add(Behavior.type.WHDimensions);
  245. }
  246. break;
  247. case 'height':
  248. if (WHDimensions[2] < g_WarehouseMaxHeight) {
  249. WHDimensions[2] += g_WarehouseIncValue;
  250. warehouse.update(WHDimensions);
  251. updateRackingHighLevel();
  252. updateSelectedIcube();
  253. tracking(53);
  254. Behavior.add(Behavior.type.WHDimensions);
  255. }
  256. break;
  257. case 'pallet-height':
  258. if (g_palletHeight < g_PalletMaxHeight) {
  259. g_palletHeight += g_PalletIncValue;
  260. tracking(52);
  261. updateRackingHighLevel();
  262. if (g_palletHeight > 0 && g_palletHeight <= 1.2) {
  263. simulateEvent('palletOverhang', 'change', 0.05);
  264. }
  265. else if (g_palletHeight > 1.2 && g_palletHeight <= 1.8) {
  266. simulateEvent('palletOverhang', 'change', 0.075);
  267. }
  268. else {
  269. simulateEvent('palletOverhang', 'change', 0.100);
  270. }
  271. // Behavior.add(Behavior.type.palletHeight);
  272. }
  273. break;
  274. case 'pallet-weight':
  275. if (g_palletWeight < g_PalletMaxWeight) {
  276. g_palletWeight = parseFloat($('#input-pallet-weight').val()) + 100;
  277. $('#input-pallet-weight').val(g_palletWeight);
  278. if (selectedIcube) selectedIcube.palletWeight = g_palletWeight;
  279. tracking(51);
  280. Behavior.add(Behavior.type.palletWeight);
  281. }
  282. break;
  283. case 'layoutScale':
  284. if (layoutMap && layoutMap.scale > 0) {
  285. let newVal = parseFloat($('#layoutScale').val());
  286. newVal += 0.1;
  287. $('#layoutScale').val(parseFloat(newVal.toFixed(2)));
  288. layoutMap.scale = 2 - parseFloat(newVal / 100);
  289. warehouse.update(WHDimensions);
  290. }
  291. break;
  292. default:
  293. break;
  294. }
  295. setUnitForInput();
  296. });
  297. $('.spinner-down').on("click", function () {
  298. if (!menuEnabled) return;
  299. const controller = $(this).parent().parent().attr('controller');
  300. switch (controller) {
  301. case 'width':
  302. if (WHDimensions[0] > g_WarehouseMinWidth) {
  303. WHDimensions[0] -= g_WarehouseIncValue;
  304. $('#input-wh-width').val(WHDimensions[0]);
  305. warehouse.update(WHDimensions);
  306. if (selectedIcube)
  307. selectedIcube.addRowLabels();
  308. tracking(55);
  309. Behavior.add(Behavior.type.WHDimensions);
  310. }
  311. break;
  312. case 'length':
  313. if (WHDimensions[1] > g_WarehouseMinLength) {
  314. WHDimensions[1] -= g_WarehouseIncValue;
  315. $('#input-wh-length').val(WHDimensions[1]);
  316. warehouse.update(WHDimensions);
  317. if (selectedIcube)
  318. selectedIcube.addRowLabels();
  319. tracking(54);
  320. Behavior.add(Behavior.type.WHDimensions);
  321. }
  322. break;
  323. case 'height':
  324. if (WHDimensions[2] > g_WarehouseMinHeight) {
  325. WHDimensions[2] -= g_WarehouseIncValue;
  326. $('#input-wh-height').val(WHDimensions[2]);
  327. warehouse.update(WHDimensions);
  328. updateRackingHighLevel();
  329. updateSelectedIcube();
  330. tracking(53);
  331. Behavior.add(Behavior.type.WHDimensions);
  332. }
  333. break;
  334. case 'pallet-height':
  335. if (g_palletHeight > g_PalletMinHeight) {
  336. g_palletHeight -= g_PalletIncValue;
  337. tracking(52);
  338. updateRackingHighLevel();
  339. if (g_palletHeight > 0 && g_palletHeight <= 1.2) {
  340. simulateEvent('palletOverhang', 'change', 0.05);
  341. }
  342. else if (g_palletHeight > 1.2 && g_palletHeight <= 1.8) {
  343. simulateEvent('palletOverhang', 'change', 0.075);
  344. }
  345. else {
  346. simulateEvent('palletOverhang', 'change', 0.100);
  347. }
  348. // Behavior.add(Behavior.type.palletHeight);
  349. }
  350. break;
  351. case 'pallet-weight':
  352. if (g_palletWeight > g_PalletMinWeight) {
  353. g_palletWeight = parseFloat($('#input-pallet-weight').val()) - 100;
  354. $('#input-pallet-weight').val(g_palletWeight);
  355. if (selectedIcube) selectedIcube.palletWeight = g_palletWeight;
  356. tracking(51);
  357. Behavior.add(Behavior.type.palletWeight);
  358. }
  359. break;
  360. case 'layoutScale':
  361. if (layoutMap && layoutMap.scale < 2) {
  362. let newVal = parseFloat($('#layoutScale').val());
  363. newVal -= 0.1;
  364. $('#layoutScale').val(parseFloat(newVal.toFixed(2)));
  365. layoutMap.scale = 2 - parseFloat(newVal / 100);
  366. warehouse.update(WHDimensions);
  367. }
  368. break;
  369. default:
  370. break;
  371. }
  372. setUnitForInput();
  373. });
  374. $('#draw-baseline').on("click", function () {
  375. g_drawMode = 0;
  376. if ($(this).hasClass("active-icube-setting")) {
  377. updateDrawButtonState();
  378. }
  379. else {
  380. $('#draw-baseline').addClass('active-icube-setting');
  381. $('#draw-baseline').text('Confirm Drawing');
  382. if (currentView !== ViewType.top)
  383. switch_to_top_camera();
  384. tracking(30);
  385. g_sceneMode = sceneMode.draw;
  386. }
  387. });
  388. $('#draw-auto').on("click", function () {
  389. g_drawMode = 1;
  390. updateDrawButtonState();
  391. const manualsItems = getManualItems();
  392. if (icubes.length > 0 || manualsItems.length > 0) {
  393. Utils.logg('Clear the scene before to draw the racking!', 'custom');
  394. return;
  395. }
  396. tracking(31);
  397. recreateAutoIcube();
  398. });
  399. $('#remove-all-icubes').on("click", function () {
  400. updateDrawButtonState();
  401. removeAllIcubes();
  402. Behavior.add(Behavior.type.removeIcube);
  403. renderScene();
  404. });
  405. $('#remove-all-items').on("click", function () {
  406. if (confirm('This will remove all items from work area. Are you sure?')) {
  407. updateDrawButtonState();
  408. removeManualItems();
  409. Behavior.add(Behavior.type.deleteItem);
  410. renderScene();
  411. }
  412. });
  413. $('#input-upRightDistance').on("change", function (event) {
  414. tracking(50);
  415. let newVal = parseFloat(event.target.value);
  416. newVal = useP(newVal) / useP(rateUnit);
  417. if (newVal < g_MinDistUpRights * 0.6) {
  418. newVal = g_MinDistUpRights * 0.6;
  419. }
  420. if (newVal > g_MaxDistUpRights) {
  421. newVal = g_MaxDistUpRights;
  422. }
  423. g_distUpRight = useP(useP(newVal), false);
  424. //Set racking height
  425. updateRackingHighLevel();
  426. updateSelectedIcube();
  427. Behavior.add(Behavior.type.upRightDistance);
  428. });
  429. $('#palletDistr_0, #palletDistr_1, #palletDistr_2').on("change", function (event) {
  430. tracking(41);
  431. const attr = $(this).attr('id').split('_');
  432. updateDistrPallet(attr[1], parseInt(event.target.value));
  433. });
  434. function updateDistrPallet(id, val) {
  435. const prevMax = g_palletInfo.max;
  436. const prevVal = [...g_palletInfo.value];
  437. g_palletInfo.value[id] = val;
  438. g_palletInfo.type = optimizeDistrCalculation(id, g_palletInfo.value);
  439. updatePalletDistributions(g_palletInfo.value);
  440. g_xtrackFixedDim = (g_palletInfo.max !== 2 ? 1.350 : 1.550);
  441. if (g_palletInfo.max !== prevMax || (prevVal[0] == 0 && g_palletInfo.value[0] != 0) || (prevVal[1] == 0 && g_palletInfo.value[1] != 0) ||
  442. (prevVal[2] == 0 && g_palletInfo.value[2] != 0) || (prevVal[0] != 0 && g_palletInfo.value[0] == 0) || (prevVal[1] != 0 && g_palletInfo.value[1] == 0) || (prevVal[2] != 0 && g_palletInfo.value[2] == 0)) {
  443. if (selectedIcube && g_palletInfo.max !== prevMax)
  444. selectedIcube.activedPillers = [];
  445. updateSelectedIcube();
  446. }
  447. else {
  448. palletsNoJS();
  449. }
  450. Behavior.add(Behavior.type.palletType);
  451. renderScene();
  452. }
  453. $('#rackingHighLevel').on("change", function (event) {
  454. g_rackingHighLevel = parseInt(event.target.value);
  455. updateRackingHighLevel();
  456. updateSelectedIcube();
  457. tracking(49);
  458. Behavior.add(Behavior.type.rackingLevel);
  459. });
  460. $('#palletOverhang').on("change", function (event) {
  461. g_palletOverhang = parseFloat(event.target.value);
  462. updateSelectedIcube();
  463. tracking(48);
  464. Behavior.add(Behavior.type.palletOverhang);
  465. });
  466. $('#loadPalletOverhang').on("change", function (event) {
  467. g_loadPalletOverhang = parseFloat(event.target.value);
  468. g_palletInfo.type = g_palletInfo.value;
  469. updateSelectedIcube();
  470. tracking(47);
  471. Behavior.add(Behavior.type.palletOverhang);
  472. });
  473. $('#orientationRacking').on("change", function (event) {
  474. g_rackingOrientation = parseInt(event.target.value);
  475. if (selectedIcube !== null) {
  476. if (g_drawMode === 1) {
  477. recreateAutoIcube();
  478. }
  479. else {
  480. selectedIcube.resetIcubeData();
  481. updateSelectedIcube();
  482. }
  483. }
  484. tracking(46);
  485. Behavior.add(Behavior.type.rackingOrient);
  486. });
  487. function recreateAutoIcube() {
  488. if (currentView !== ViewType.free)
  489. switch_to_free_camera();
  490. else
  491. switchCamera(ViewType.free);
  492. removeAllIcubes();
  493. autoDrawIcube();
  494. }
  495. $('#numberOfSKU').on("change", function (event) {
  496. g_SKU = parseInt(event.target.value);
  497. const prevXtracksLnegth = g_recomandedXtrackAmount;
  498. if (selectedIcube !== null) {
  499. calculateProps(selectedIcube.baseLines);
  500. if (prevXtracksLnegth !== g_recomandedXtrackAmount) {
  501. selectedIcube.resetIcubeData();
  502. updateSelectedIcube();
  503. }
  504. }
  505. tracking(45);
  506. Behavior.add(Behavior.type.sku);
  507. });
  508. $('#numberOfPalletInOutPerHour').on("change", function (event) {
  509. g_movesPerHour = parseInt(event.target.value);
  510. if (selectedIcube !== null) {
  511. selectedIcube.updateThroughput(g_movesPerHour);
  512. selectedIcube.getEstimationPrice();
  513. }
  514. tracking(44);
  515. Behavior.add(Behavior.type.throughput);
  516. renderScene();
  517. });
  518. $('#extracarrierAmount').on("change", function (event) {
  519. if (selectedIcube) {
  520. g_extraCarrierAmount = parseInt(event.target.value) < 0 ? 0 : parseInt(event.target.value);
  521. selectedIcube.updateCarrier(g_extraCarrierAmount);
  522. selectedIcube.getEstimationPrice();
  523. Behavior.add(Behavior.type.addCharger);
  524. renderScene();
  525. }
  526. });
  527. function updateCarrierAmount (amount, extra) {
  528. if (selectedIcube !== null) {
  529. g_recomandedCarrierAmount = parseInt(amount);
  530. $('#carrierAmount').html(g_recomandedCarrierAmount);
  531. $('#extracarrierAmount').val(parseInt(extra));
  532. }
  533. }
  534. function updateLiftAmount (amount, extra) {
  535. g_recomandedLiftAmount = parseInt(amount);
  536. $('#liftAmount').html(g_recomandedLiftAmount);
  537. $('#extraliftAmount').html(parseInt(extra));
  538. }
  539. function updateXtrackAmount (amount, extra) {
  540. g_recomandedXtrackAmount = parseInt(amount);
  541. $('#xtrackAmount').html(g_recomandedXtrackAmount);
  542. $('#extraxtrackAmount').html(parseInt(extra));
  543. }
  544. $('#cameraView3D').on("click", function () {
  545. if (g_simMultipleView) return;
  546. switch_to_free_camera();
  547. });
  548. $('#cameraView2D').on("click", function () {
  549. if (g_simMultipleView) return;
  550. switch_to_top_camera();
  551. });
  552. $('#cameraFront').on("click", function () {
  553. if (g_simMultipleView) return;
  554. switch_to_front_camera();
  555. });
  556. $('#cameraSide').on("click", function () {
  557. if (g_simMultipleView) return;
  558. switch_to_side_camera();
  559. });
  560. $('#zoomIn').on("click", function () {
  561. switch (currentView) {
  562. case ViewType.top:
  563. zoom2DCamera(-1, false);
  564. break;
  565. case ViewType.free:
  566. scene.activeCamera.radius -= 1;
  567. break;
  568. case ViewType.front:
  569. case ViewType.side:
  570. zoom2DCamera(-1, true);
  571. break;
  572. default:
  573. break;
  574. }
  575. renderScene();
  576. });
  577. $('#zoomOut').on("click", function () {
  578. switch (currentView) {
  579. case ViewType.top:
  580. zoom2DCamera(1, false);
  581. break;
  582. case ViewType.free:
  583. scene.activeCamera.radius += 1;
  584. break;
  585. case ViewType.front:
  586. case ViewType.side:
  587. zoom2DCamera(1, true);
  588. break;
  589. default:
  590. break;
  591. }
  592. renderScene();
  593. });
  594. $('#resetCamera').on("click", function () {
  595. switchCamera(currentView);
  596. });
  597. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  598. //New, Save and Load
  599. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  600. $('.new-btn').on("click", function () {
  601. currenntDataBaseAction = DataBaseAction.new;
  602. $(".new-modal-close").show();
  603. if (hasUpdates()) {
  604. if (confirm("Do you want to save your work?")) {
  605. saveProject(() => {
  606. showModal('new-modal');
  607. });
  608. }
  609. else {
  610. showModal('new-modal');
  611. }
  612. }
  613. else {
  614. showModal('new-modal');
  615. }
  616. });
  617. $('.save-btn').on("click", function () {
  618. currenntDataBaseAction = DataBaseAction.save;
  619. if (documentName === "") {
  620. showModal('saveAs-modal');
  621. }
  622. else {
  623. if (hasUpdates()) {
  624. tracking(3);
  625. saveProject(() => {
  626. if (userRole === g_UserRole.Demo) {
  627. window.location.replace('home/logout');
  628. }
  629. });
  630. }
  631. }
  632. });
  633. $('.saveAs-btn').on("click", function () {
  634. currenntDataBaseAction = DataBaseAction.save;
  635. showModal('saveAs-modal');
  636. });
  637. $('.adminLoadAutoSave-btn').on("click", function () {
  638. currenntDataBaseAction = DataBaseAction.load;
  639. loadProject(documentName, documentInfo, true);
  640. });
  641. $('.load-btn').on("click", function () {
  642. currenntDataBaseAction = DataBaseAction.load;
  643. $(".load-modal-close").show();
  644. if (hasUpdates()) {
  645. if (confirm("Do you want to save your work?")) {
  646. saveProject(function () {
  647. getProjectList(function (datas) {
  648. createProjectList(datas);
  649. });
  650. });
  651. } else {
  652. getProjectList(function (datas) {
  653. createProjectList(datas);
  654. });
  655. }
  656. } else {
  657. getProjectList(function (datas) {
  658. createProjectList(datas);
  659. });
  660. }
  661. });
  662. $('.load-modal-close').on("click", function () {
  663. hideModal('load-modal');
  664. });
  665. $('.new-modal-close').on("click", function () {
  666. hideModal('new-modal');
  667. });
  668. $('.saveAs-modal-close').on("click", function () {
  669. hideModal('saveAs-modal');
  670. });
  671. $('.rating-modal-close').on("click", function () {
  672. Utils.request(g_BasePath + 'home/rating', 'POST', { complete: 0 }, () => {
  673. hideModal('rating-modal');
  674. });
  675. });
  676. $('.planAddInfo-modal-close').on("click", function () {
  677. hideModal('planAddInfo-modal');
  678. });
  679. $('.saveAs-modal-confirm').on("click", function () {
  680. if ($('#inputDocumentAs').val() == "") {
  681. $('#inputDocumentAs').focus();
  682. }
  683. else {
  684. old_documentName = documentName;
  685. documentName = $('#inputDocumentAs').val().trim();
  686. documentNameOverlapCheck(function (datas) {
  687. let isOverlap = false;
  688. datas.map(data => {
  689. if (data.document_name == documentName) {
  690. isOverlap = true;
  691. }
  692. });
  693. if (isOverlap) {
  694. documentName = old_documentName;
  695. Utils.logg("Project Name already exist. Choose another name.", 'error');
  696. $('#inputDocumentAs').val("").focus();
  697. }
  698. else {
  699. createBehavior();
  700. $('#project-name').html(documentName);
  701. hideModal('saveAs-modal');
  702. tracking(37);
  703. currenntDataBaseAction = DataBaseAction.save;
  704. saveProject();
  705. }
  706. });
  707. }
  708. });
  709. $('.new-modal-confirm').on("click", function () {
  710. if ($('#inputDocument').val() == "") {
  711. $('#inputDocument').focus();
  712. }
  713. else {
  714. old_documentName = documentName;
  715. documentName = $('#inputDocument').val().trim();
  716. documentNameOverlapCheck((datas) => {
  717. let isOverlap = false;
  718. datas.map(data => {
  719. if (data.document_name == documentName) {
  720. isOverlap = true;
  721. }
  722. });
  723. if (isOverlap) {
  724. documentName = "";
  725. Utils.logg("Project Name already exist. Choose another name.", 'error');
  726. $('#inputDocument').val("").focus();
  727. }
  728. else {
  729. $('#project-name').html(documentName);
  730. hideModal('new-modal');
  731. saveProject();
  732. currenntDataBaseAction = DataBaseAction.new;
  733. if (currenntDataBaseAction === DataBaseAction.new || currenntDataBaseAction === DataBaseAction.load || isEditByAdmin) {
  734. currentTemplateType.document_name = documentName;
  735. setProject(currentTemplateType);
  736. }
  737. }
  738. });
  739. }
  740. });
  741. $(".undo-btn").on("click", function () {
  742. Behavior.undo();
  743. });
  744. $(".redo-btn").on("click", function () {
  745. Behavior.redo();
  746. });
  747. //Change templates
  748. $(".img-rounded").on("click", function () {
  749. currentTemplateType = Template.values[Template.type[$(this).attr('key')]];
  750. const templateItems = $(".template-item-box");
  751. for (let i = 0; i < templateItems.length; i++) {
  752. templateItems[i].classList.remove("select");
  753. }
  754. $(this).parent().addClass("select");
  755. });
  756. function initToolBar() {
  757. SetUIUnits();
  758. ChangeUnits();
  759. setUnitForInput();
  760. $('#numberOfSKU').val(parseInt(g_SKU));
  761. $('#numberOfPalletInOutPerHour').val(parseInt(g_movesPerHour));
  762. $('#carrierAmount').html(parseInt(g_recomandedCarrierAmount));
  763. $('#liftAmount').html(parseInt(g_recomandedLiftAmount));
  764. $('#extracarrierAmount').val(parseInt(g_extraCarrierAmount));
  765. $('#extraliftAmount').html(parseInt(g_extraLiftAmount));
  766. $('#xtrackAmount').html(parseInt(g_recomandedXtrackAmount));
  767. $('#extraxtrackAmount').html(parseInt(g_extraXtrackAmount));
  768. updateRackingHighLevel(true);
  769. updatePalletDistributions(g_palletInfo.value);
  770. $('#input-pallet-weight').val(g_palletWeight);
  771. $('#palletOverhang').val(g_palletOverhang);
  772. $('#loadPalletOverhang').val(g_loadPalletOverhang);
  773. $('select[name="orientationRacking"]').val(g_rackingOrientation);
  774. $('#spacing_b_rows').val(g_spacingBetweenRows);
  775. if (g_palletAtLevel.length > 0) {
  776. $('#customLastRow').trigger('click');
  777. }
  778. if (g_drawMode === 0) {
  779. if ($('#custom-upRightDist').hasClass('active-icube-setting')) return;
  780. $('#auto-upRightDist').removeClass('active-icube-setting');
  781. $('#input-upRightDistance').attr('disabled', false);
  782. $('#custom-upRightDist').addClass('active-icube-setting');
  783. }
  784. else {
  785. if ($('#auto-upRightDist').hasClass('active-icube-setting')) return;
  786. $('#custom-upRightDist').removeClass('active-icube-setting');
  787. $('#input-upRightDistance').attr('disabled', true);
  788. $('#auto-upRightDist').addClass('active-icube-setting');
  789. }
  790. createPassThList();
  791. if (isEditByAdmin || g_palletAtLevel.length > 0 || g_palletInfo.order.length > 1) {
  792. if (!$('#settingsModeA1').hasClass('active-icube-setting')) {
  793. $('#settingsModeA1').trigger('click');
  794. }
  795. }
  796. }
  797. function initToolBarForICube(rackingHighLevel, rackingOrientation, palletHeight, palletWeight, palletOverhang, loadPalletOverhang, sku, throughput, calculatedCarriersNo, calculatedLiftsNo, extra, upRightDistance, calculatedXtracksNo, palletAtLevel, spacingBetweenRows) {
  798. g_rackingHighLevel = rackingHighLevel;
  799. g_rackingOrientation = rackingOrientation;
  800. g_palletHeight = palletHeight;
  801. g_palletWeight = palletWeight;
  802. g_palletOverhang = palletOverhang;
  803. g_loadPalletOverhang = loadPalletOverhang;
  804. g_SKU = sku;
  805. g_movesPerHour = throughput;
  806. g_recomandedCarrierAmount = calculatedCarriersNo;
  807. g_recomandedLiftAmount = calculatedLiftsNo;
  808. g_extraCarrierAmount = extra.carrier;
  809. g_extraLiftAmount = extra.lift;
  810. g_extraXtrackAmount = extra.xtrack;
  811. g_distUpRight = upRightDistance;
  812. g_palletAtLevel = palletAtLevel;
  813. g_spacingBetweenRows = spacingBetweenRows;
  814. currentUnits = unit_measurement;
  815. initToolBar();
  816. }
  817. function saveProject(callback) {
  818. const icubeData = getIcubeData();
  819. const itemMData = getManualItems();
  820. const measurements = getAllMeasurements();
  821. WHDimensions = WHDimensions.map(e => parseFloat((e).toFixed(unit_measurement ? 3 : 2)));
  822. const data = {
  823. document_name: documentName,
  824. warehouse_dimensions: WHDimensions,
  825. icubeData: icubeData,
  826. itemMData: itemMData,
  827. unit_measurement: unit_measurement,
  828. layoutMap: layoutMap,
  829. extraInfo: extraInfo,
  830. extraPrice: extraPrice,
  831. measurements: measurements,
  832. custom_values: custom_values
  833. }
  834. initData(data);
  835. Utils.request(g_BasePath + 'home/save', 'POST', {
  836. documentInfo: documentInfo,
  837. document_name: documentName,
  838. isEditByAdmin: parseInt(isEditByAdmin),
  839. warehouse_dimensions: JSON.stringify(WHDimensions),
  840. icubeData: JSON.stringify(icubeData),
  841. itemMData: JSON.stringify(itemMData),
  842. unit_measurement: JSON.stringify(unit_measurement),
  843. layoutMap: JSON.stringify(layoutMap),
  844. extraInfo: JSON.stringify(extraInfo),
  845. extraPrice:JSON.stringify(extraPrice),
  846. measurements:JSON.stringify(measurements),
  847. custom_values:JSON.stringify(custom_values),
  848. inventory: g_inventory
  849. }, (data) => {
  850. documentName = data['documentName'];
  851. $('#project-name').html(documentName);
  852. Utils.logg('Layout successfully saved!','success');
  853. Behavior.add(Behavior.type.saves);
  854. let rev = {
  855. document_name: documentName
  856. }
  857. if (documentInfo > 0) {
  858. rev = Object.assign({}, rev, { slid : documentInfo });
  859. }
  860. getRevisions(rev);
  861. if (callback) callback();
  862. }, () => {
  863. alert("Save Failed! Try again later.");
  864. });
  865. }
  866. function loadProject(document_name, slid = -1, useBackUp = false) {
  867. let data = {
  868. document_name: document_name
  869. }
  870. if (slid !== -1) {
  871. data = Object.assign({}, data, { slid : slid });
  872. }
  873. if (useBackUp) {
  874. data = Object.assign({}, data, { useBackUp : useBackUp });
  875. }
  876. Utils.request(g_BasePath + 'home/load', 'POST', data, (res) => {
  877. setProject(res);
  878. }, () => {
  879. alert("Load Failed! Try again later.");
  880. });
  881. }
  882. function setProject(data, newProject = true, versionIdx = -1) {
  883. if (currentView !== ViewType.top)
  884. switch_to_top_camera();
  885. extraInfo = data.extraInfo;
  886. extraPrice = data.extraPrice ? data.extraPrice : [];
  887. unit_measurement = data.unit_measurement || 0;
  888. msments = data.measurements ? data.measurements : [];
  889. custom_values = data.custom_values ? data.custom_values : [];
  890. documentInfo = (isEditByAdmin) ? data.documentInfo : "";
  891. documentName = data.document_name;
  892. if (!Array.isArray(data.warehouse_dimensions) || data.warehouse_dimensions.length === 0) {
  893. data.warehouse_dimensions = Template.values[Template.type.Default].warehouse_dimensions;
  894. }
  895. WHDimensions = [parseFloat(data.warehouse_dimensions[0]), parseFloat(data.warehouse_dimensions[1]), parseFloat(data.warehouse_dimensions[2])];
  896. // update html inputs
  897. initToolBar();
  898. // remove curent icubes
  899. removeAllIcubes();
  900. // remove manual items
  901. removeManualItems();
  902. // remove all measurements
  903. removeAllMeasurements();
  904. warehouse.update(WHDimensions);
  905. // need to set this to be able to set later the racking
  906. g_palletHeight = (data.icubeData.length !== 0) ? data.icubeData[data.icubeData.length - 1].palletHeight : g_palletHeight;
  907. resetConfigVariables();
  908. loadIcubeData(data.icubeData, data.itemMData, data.layoutMap);
  909. // load manual items inside loadIcube, after icube was draw
  910. // loadItemMData(data.itemMData);
  911. $('#customValue').html(custom_values.length > 0 ? `<b>⚠ This project contains custom values ⚠</b>` : ``);
  912. // show measurements
  913. for (let i = 0; i < msments.length; i++) {
  914. const msm = new Measurement({
  915. id: msments[i][2],
  916. pi: new BABYLON.Vector3(msments[i][0][0], 0, msments[i][0][1]),
  917. pf: new BABYLON.Vector3(msments[i][1][0], 0, msments[i][1][1])
  918. }, scene);
  919. msm.isCompleted();
  920. g_measurementList.push(msm);
  921. }
  922. if (!$('.tab-content').is(':visible'))
  923. $('#main-tabs-tab-Size').trigger('click');
  924. if (newProject) {
  925. initData(data);
  926. let rev = {
  927. document_name: documentName
  928. }
  929. if (documentInfo > 0) {
  930. rev = Object.assign({}, rev, { slid : documentInfo });
  931. }
  932. getRevisions(rev, versionIdx);
  933. Behavior.init();
  934. createBehavior();
  935. Behavior.add(Behavior.type.addIcube);
  936. $('#project-name').html(documentName);
  937. Utils.logg('Layout successfully loaded!','success');
  938. }
  939. }
  940. function deleteProject(document_name, slid = -1) {
  941. let data = {
  942. document_name: document_name
  943. }
  944. if (slid !== -1) {
  945. data = Object.assign({}, data, { slid : slid });
  946. }
  947. Utils.request(g_BasePath + 'home/delete', 'POST', data, () => {
  948. Utils.logg('Layout successfully deleted!','success');
  949. }, () => {
  950. alert("Delete Failed! Try again later.");
  951. });
  952. }
  953. function renameProject(document_name, slid) {
  954. Utils.request(g_BasePath + 'home/rename', 'POST', {
  955. document_name: document_name,
  956. slid: slid
  957. }, () => {
  958. Utils.logg('Layout successfully renamed!','success');
  959. }, () => {
  960. alert("Rename Failed! Try again later.");
  961. });
  962. }
  963. function sendProjectNotify(document_name, email) {
  964. Utils.request(g_BasePath + 'home/sentNotificationSA', 'POST', {
  965. docName: document_name,
  966. email: email
  967. }, () => {
  968. Utils.logg('Notification successfully sent!','success');
  969. }, () => {
  970. alert("Notification Failed! Try again later.");
  971. });
  972. }
  973. function showModal(name) {
  974. $('#' + name).removeClass('fade').show();
  975. if (name === 'new-modal') {
  976. $('#inputDocument').val("").focus();
  977. }
  978. if (name === 'saveAs-modal') {
  979. $('#inputDocumentAs').val("").focus();
  980. }
  981. if (name === 'load-modal') {
  982. $('#searchProject').val("").focus();
  983. }
  984. }
  985. function hideModal(name) {
  986. $('#' + name).addClass('fade').hide();
  987. $('.modal-backdrop').hide();
  988. }
  989. function createProjectList(datas) {
  990. let html = ``;
  991. $('.list-group').html("");
  992. for (let i = 0; i < datas.length; i++) {
  993. html += `<div class="form-group projectList">
  994. <div class="col-lg-11 loadP" style="cursor:pointer;">
  995. <h5 style="font-weight:bold;">` + datas[i].document_name + `</h5>
  996. <span>` + datas[i].saved_time + `</span>
  997. </div>
  998. <div class="col-lg-1">
  999. <button type="button" class="loadP-btn deleteP" title="Delete project"><i class="fa fa-times" aria-hidden="true"></i></button>`
  1000. + (datas[i].backup ? `<button type="button" class="loadP-btn loadBP" title="Restore project from auto-saves"><i class="fa fa-hdd-o" aria-hidden="true"></i></button>` : ``) +
  1001. `</div>
  1002. </div>`;
  1003. }
  1004. $(".list-group").append(html);
  1005. showModal('load-modal');
  1006. $('.loadP').click(function () {
  1007. const document_name = $(this).find('h5').html();
  1008. loadProject(document_name);
  1009. hideModal('load-modal');
  1010. });
  1011. $('.deleteP').click(function (e) {
  1012. //if (confirm('Are you sure you want to permanently delete this project?')) {
  1013. const document_name = $(this).parent().prev()[0].firstElementChild.innerHTML;
  1014. deleteProject(document_name);
  1015. $(this).parent().parent().remove();
  1016. //}
  1017. });
  1018. $('.loadBP').click(function () {
  1019. const document_name = $(this).parent().prev()[0].firstElementChild.innerHTML;
  1020. loadProject(document_name, -1, true);
  1021. hideModal("load-modal");
  1022. });
  1023. }
  1024. function initData(data) {
  1025. for (let key in data) {
  1026. if (Array.isArray(data[key])) {
  1027. init_data[key] = [];
  1028. if (data[key].length > 0) {
  1029. if (isNaN(parseInt(data[key]))) {
  1030. if (key === 'icubeData') {
  1031. for (let i = 0; i < data[key].length; i++) {
  1032. init_data[key][i] = {};
  1033. for (let key2 in data[key][i]) {
  1034. if (['name','uid','baseLines'].includes(key2)) continue;
  1035. if (Array.isArray(data[key][i][key2])) {
  1036. if (isNaN(parseInt(data[key][i][key2]))) {
  1037. if (key2 === 'activedCarrierInfos') {
  1038. init_data[key][i][key2] = [...data[key][i][key2]];
  1039. }
  1040. else {
  1041. init_data[key][i][key2] = data[key][i][key2].map(a => { return {...a}; });
  1042. }
  1043. }
  1044. else {
  1045. init_data[key][i][key2] = [...data[key][i][key2]];
  1046. }
  1047. }
  1048. else {
  1049. if (isNaN(parseInt(data[key][i][key2]))) {
  1050. init_data[key][i][key2] = JSON.parse(data[key][i][key2]);
  1051. }
  1052. else {
  1053. init_data[key][i][key2] = data[key][i][key2];
  1054. }
  1055. }
  1056. }
  1057. }
  1058. }
  1059. else {
  1060. init_data[key] = data[key].map(a => { return {...a}; });
  1061. }
  1062. }
  1063. else {
  1064. init_data[key] = [...data[key]];
  1065. }
  1066. }
  1067. }
  1068. else {
  1069. init_data[key] = data[key];
  1070. }
  1071. }
  1072. }
  1073. function hasUpdates() {
  1074. const icubeData = getIcubeData();
  1075. const itemMData = getManualItems();
  1076. const measurements = getAllMeasurements();
  1077. if (icubeData.length === 0 && itemMData.length === 0) return false;
  1078. if (JSON.stringify(init_data.layoutMap) == JSON.stringify(layoutMap) &&
  1079. JSON.stringify(init_data.extraInfo) == JSON.stringify(extraInfo) &&
  1080. JSON.stringify(init_data.extraPrice) == JSON.stringify(extraPrice) &&
  1081. JSON.stringify(init_data.measurements) == JSON.stringify(measurements) &&
  1082. JSON.stringify(init_data.custom_values) == JSON.stringify(custom_values) &&
  1083. JSON.stringify(init_data.warehouse_dimensions) == JSON.stringify(WHDimensions) &&
  1084. JSON.stringify(init_data.itemMData) == JSON.stringify(itemMData)
  1085. ) {
  1086. let hasChanges = true;
  1087. for (let i = 0; i < init_data.icubeData.length; i++) {
  1088. if (icubeData[i]) {
  1089. let changes = [];
  1090. for (let key in init_data.icubeData[i]) {
  1091. if (Array.isArray(init_data.icubeData[i][key])) {
  1092. changes.push(JSON.stringify(init_data.icubeData[i][key]) == JSON.stringify(icubeData[i][key]) ? false : true);
  1093. }
  1094. else {
  1095. changes.push(init_data.icubeData[i][key] == icubeData[i][key] ? false : true);
  1096. }
  1097. }
  1098. const change = changes.filter(e => e === true);
  1099. hasChanges = change.length > 0 ? true : false;
  1100. if (!hasChanges) break;
  1101. }
  1102. }
  1103. // console.log('if ', hasChanges)
  1104. return hasChanges;
  1105. }
  1106. else {
  1107. // console.log('else truuuue')
  1108. return true;
  1109. }
  1110. }
  1111. function documentNameOverlapCheck(callback) {
  1112. Utils.request(g_BasePath + 'home/documentNameOverlapCheck', 'GET', {}, (data) => {
  1113. callback(data);
  1114. }, null);
  1115. }
  1116. function getProjectList(callback) {
  1117. Utils.request(g_BasePath + 'home/getProjectList', 'GET', {}, (data) => {
  1118. callback(data);
  1119. }, null);
  1120. }
  1121. function getUserInfo(callback = null) {
  1122. Utils.request(g_BasePath + 'home/getUserInfo', 'POST', {
  1123. documentInfo: documentInfo
  1124. }, (data) => {
  1125. userName = data.name;
  1126. userEmail = data.email;
  1127. userPhone = data.phone;
  1128. loginCount = data.login_count;
  1129. if (parseInt(data.projects) === 0)
  1130. loginCount = 1;
  1131. if (userRole !== g_UserRole.Demo)
  1132. $('#emailP').val(userEmail);
  1133. if (!isEditByAdmin && userRole === g_UserRole.Sales)
  1134. getUsersSA();
  1135. if (callback)
  1136. callback();
  1137. }, null);
  1138. }
  1139. $("#btn-full-screen").on("click", function () {
  1140. scene.getEngine().enterFullscreen(false);
  1141. });
  1142. $("#btn-save-pdf").on("click", function () {
  1143. $('#waiting').show('fast', () => {
  1144. Export_PDF.generateFile(false);
  1145. tracking(8);
  1146. });
  1147. if (!isEditByAdmin)
  1148. Utils.request(g_BasePath + 'home/downloadPDF', 'POST', {}, null, null);
  1149. });
  1150. $("#btn-save-dxf").on("click", function () {
  1151. $('#waiting').show('fast', () => {
  1152. tracking(12);
  1153. if ($('#cadAsPDF').is(':checked')) {
  1154. Export_CAD.generateFile(false, true);
  1155. }
  1156. else {
  1157. const formData = new FormData();
  1158. formData.append('dxf', Export_CAD.generateFile(false, false));
  1159. formData.append('data', JSON.stringify({ documentName: documentName, documentInfo: documentInfo }));
  1160. Utils.requestFormData(g_BasePath + 'home/uploadCAD', 'POST', formData, async (result) => {
  1161. const res = JSON.parse(result);
  1162. if (res.url.length === 0) {
  1163. $('#waiting').hide();
  1164. Utils.logg('Save your project first', 'error'); return;
  1165. }
  1166. const newURL = res.url.replace(/ /g, "%20");
  1167. const ccURL = "https://api.cloudconvert.com/v2";
  1168. const name = res.url.split("/").pop().split('.').shift();
  1169. const job = {
  1170. "tasks": {
  1171. "file1": {
  1172. "operation": "import/url",
  1173. "url": newURL
  1174. },
  1175. "converttodwg": {
  1176. "operation": "convert",
  1177. "input_format": "dxf",
  1178. "output_format": "dwg",
  1179. "engine": "cadconverter",
  1180. "input": [ "file1" ],
  1181. "engine_version": "8.9",
  1182. "filename": name + ".dwg"
  1183. },
  1184. "converted": {
  1185. "operation": "export/url",
  1186. "input": [ "converttodwg" ],
  1187. "inline": false,
  1188. "archive_multiple_files": false
  1189. }
  1190. },
  1191. "tag": "logiqs"
  1192. }
  1193. const options = {
  1194. "method": "POST",
  1195. "body": JSON.stringify(job),
  1196. "headers": {
  1197. "Authorization": "Bearer " + res.key,
  1198. "Content-type": "application/json"
  1199. }
  1200. }
  1201. const response = await fetch(ccURL + "/jobs", options);
  1202. response.json().then(async (resJob) => {
  1203. const options2 = {
  1204. "method": "GET",
  1205. "headers": {
  1206. "Authorization": "Bearer " + res.key
  1207. }
  1208. }
  1209. const response2 = await fetch(ccURL + "/tasks/" + resJob.data.tasks[2].id + '/wait', options2);
  1210. response2.json().then((resTask) => {
  1211. $('#waiting').hide();
  1212. if ((!resTask.data.result) || (resTask.data.result && resTask.data.result.files.length === 0)) return;
  1213. const url = resTask.data.result.files[0].url;
  1214. const filename = name + ".dwg";
  1215. Utils.download(filename, url, false);
  1216. });
  1217. });
  1218. });
  1219. }
  1220. });
  1221. });
  1222. $("#btn-save-3ds").on("click", function () {
  1223. $('#waiting').show('fast', async () => {
  1224. await Export_OBJ.generateFile();
  1225. $('#waiting').hide();
  1226. tracking(43);
  1227. });
  1228. });
  1229. $("#btn-save-view").on("click", function () {
  1230. if (hasUpdates()) {
  1231. saveProject(()=>{
  1232. Export_PNG.generateFile();
  1233. tracking(40);
  1234. });
  1235. }
  1236. else {
  1237. Export_PNG.generateFile();
  1238. tracking(40);
  1239. }
  1240. });
  1241. $("#btnSubmission").on("click", function () {
  1242. $('#waiting').show('fast', () => {
  1243. Export_PDF.generateFile(true);
  1244. });
  1245. });
  1246. $('#contact-form').on("submit", function (e) {
  1247. e.preventDefault();
  1248. });
  1249. $('#contact_submit').on("click", async function () {
  1250. if ($('#contact-form').valid()) {
  1251. $('#waiting').show();
  1252. const doc = new window.jspdf.jsPDF('l', 'pt', 'a4', true);
  1253. doc.setFont('arial-unicode-ms');
  1254. // page 1
  1255. doc.setFontSize(15);
  1256. doc.text(50, 50, 'UserName : ' + $('#con_fullName').val());
  1257. doc.setFontSize(15);
  1258. doc.text(50, 80, 'Email : ' + $('#con_email').val());
  1259. doc.setFontSize(15);
  1260. doc.text(50, 110, 'Company : ' + $('#con_company').val());
  1261. doc.setFontSize(15);
  1262. doc.text(50, 140, 'Location : ' + $('#con_location').val());
  1263. doc.setFontSize(15);
  1264. doc.text(50, 170, 'Crop : ' + $('#con_crop').val());
  1265. doc.setFontSize(15);
  1266. doc.text(50, 200, $('#schedule_yes').is(":checked") ? "Client want to schedule an appointment with sales" : "Client don't want to schedule an appointment with sales");
  1267. doc.setFontSize(15);
  1268. doc.text(50, 230, 'Preferred date : ' + $('#con_preferred_date').val());
  1269. doc.setFontSize(15);
  1270. doc.text(50, 260, 'Question : ');
  1271. const splitTitle = doc.splitTextToSize($('#con_question').val(), 650);
  1272. doc.text(100, 290, splitTitle);
  1273. if ($('#include_yes').is(":checked")) {
  1274. doc.addPage();
  1275. const lastView = currentView;
  1276. const freeImage = await getImage(ViewType.free, true);
  1277. doc.addImage(freeImage, 'JPEG', 20, 40, 800, 500, undefined, 'FAST');
  1278. getImage(lastView);
  1279. }
  1280. const formData = new FormData();
  1281. formData.append('pdf', doc.output('blob'));
  1282. Utils.requestFormData(g_BasePath + 'home/contact', 'POST', formData, () => {
  1283. $('#waiting').hide();
  1284. Utils.logg('Your question has been successfully submitted!','success');
  1285. });
  1286. }
  1287. });
  1288. function SetUIUnits() {
  1289. if (currentUnits === Units.metric) {
  1290. $('#metric').attr("checked", true);
  1291. $('#usStand').attr("checked", false);
  1292. $('select[name="metric"]').attr("disabled", false);
  1293. $('select[name="usStand"]').attr("disabled", true);
  1294. $('.unit-text2').text(' mm ');
  1295. }
  1296. else if (currentUnits === Units.usStand) {
  1297. $('#metric').attr("checked", false);
  1298. $('#usStand').attr("checked", true);
  1299. $('select[name="metric"]').attr("disabled", true);
  1300. $('select[name="usStand"]').attr("disabled", false);
  1301. $('.unit-text2').text(' in ');
  1302. }
  1303. $('select[name="metric"]').val(currentMetric);
  1304. $('select[name="usStand"]').val(currentUSStand);
  1305. for (let i = 0; i < palletTypeNameM.length; i++) {
  1306. if (currentUnits === Units.metric) {
  1307. $('#palletDistr_' + i).prev().text(palletTypeNameM[i]);
  1308. $('#palletDistrC_' + i).prev().text(palletTypeNameM[i]);
  1309. }
  1310. else {
  1311. $('#palletDistr_' + i).prev().text(palletTypeNameU[i]);
  1312. $('#palletDistrC_' + i).prev().text(palletTypeNameU[i]);
  1313. }
  1314. }
  1315. for (let i = 0; i < palletTypeNameM.length; i++) {
  1316. if (currentUnits === Units.metric) {
  1317. $(".palletSizeList li:nth-child(" + (i + 1) + ") > label").html(palletTypeNameM[i]);
  1318. }
  1319. else {
  1320. $(".palletSizeList li:nth-child(" + (i + 1) + ") > label").html(palletTypeNameU[i]);
  1321. }
  1322. }
  1323. }
  1324. function ChangeUnits() {
  1325. rateUnit = 1;
  1326. unitChar = UnitChars.meters;
  1327. if (currentUnits === Units.metric) {
  1328. switch (currentMetric) {
  1329. case Metric.millimeters:
  1330. rateUnit = rateUnit * 1000;
  1331. unitChar = UnitChars.millimeters;
  1332. break;
  1333. case Metric.centimeters:
  1334. rateUnit = rateUnit * 100;
  1335. unitChar = UnitChars.centimeters;
  1336. break;
  1337. case Metric.meters:
  1338. rateUnit = rateUnit * 1;
  1339. unitChar = UnitChars.meters;
  1340. break;
  1341. }
  1342. }
  1343. else if (currentUnits === Units.usStand) {
  1344. switch (currentUSStand) {
  1345. case USStand.feet:
  1346. rateUnit = rateUnit * 3.28084;
  1347. unitChar = UnitChars.feet;
  1348. break;
  1349. case USStand.inches:
  1350. rateUnit = rateUnit * 39.3701;
  1351. unitChar = UnitChars.inches;
  1352. break;
  1353. }
  1354. }
  1355. setUnitForInput();
  1356. //Change unit of unitChar
  1357. $('.unit-text').each(function (index) {
  1358. $(this).text(unitChar);
  1359. });
  1360. updateIcubesDimensions();
  1361. }
  1362. //Setting
  1363. $('.units').on("change", function () {
  1364. if (currentUnits === Units.metric) {
  1365. currentUnits = Units.usStand;
  1366. }
  1367. else {
  1368. currentUnits = Units.metric;
  1369. }
  1370. unit_measurement = currentUnits;
  1371. tracking(36);
  1372. SetUIUnits();
  1373. ChangeUnits();
  1374. });
  1375. $('select[name="metric"]').on("change", function (event) {
  1376. currentMetric = parseInt(event.target.value);
  1377. ChangeUnits();
  1378. });
  1379. $('select[name="usStand"]').on("change", function (event) {
  1380. currentUSStand = parseInt(event.target.value);
  1381. ChangeUnits();
  1382. });
  1383. $('#con_preferred_date').datepicker({
  1384. minDate : '+1d',
  1385. beforeShowDay: $.datepicker.noWeekends
  1386. }).datepicker('setDate', '+1d');
  1387. $('#addInfo_delivery_date, #addInfo_delivery_date2').datepicker({
  1388. minDate : '+1m',
  1389. beforeShowDay: $.datepicker.noWeekends
  1390. }).datepicker('setDate', '+1m');
  1391. function setUnitForInput() {
  1392. $('#input-wh-width').val((WHDimensions[0] * rateUnit).toFixed(unitChar === UnitChars.millimeters ? 0 : 2));
  1393. $('#input-wh-length').val((WHDimensions[1] * rateUnit).toFixed(unitChar === UnitChars.millimeters ? 0 : 2));
  1394. $('#input-wh-height').val((WHDimensions[2] * rateUnit).toFixed(unitChar === UnitChars.millimeters ? 0 : 2));
  1395. $('#input-pallet-height').val((g_palletHeight * rateUnit).toFixed(unitChar === UnitChars.millimeters ? 0 : 2));
  1396. $('#input-upRightDistance').val((g_distUpRight * rateUnit).toFixed(unitChar === UnitChars.millimeters ? 0 : 3));
  1397. $('#spacing_b_rows').find("option").each(function () {
  1398. $(this).text(($(this).val() * rateUnit).toFixed(unitChar === UnitChars.millimeters ? 0 : 2));
  1399. });
  1400. $('#palletOverhang, #loadPalletOverhang').find("option").each(function () {
  1401. if (currentUnits === Units.metric) {
  1402. $(this).text(($(this).val() * 1000));
  1403. $('.unit-text2').text('mm');
  1404. }
  1405. else {
  1406. $(this).text(($(this).val() * 39.3701).toFixed(3));
  1407. $('.unit-text2').text('in');
  1408. }
  1409. });
  1410. if (currentUnits === Units.metric) {
  1411. $("#palletSize > label").html(palletTypeNameM[g_palletInfo.order[0]]);
  1412. }
  1413. else {
  1414. $("#palletSize > label").html(palletTypeNameU[g_palletInfo.order[0]]);
  1415. }
  1416. }
  1417. function formatIntNumber(num) {
  1418. return Math.round(num).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
  1419. }
  1420. //Tooltip
  1421. $(document).ready(function () {
  1422. $('[data-toggle="tooltip"]').tooltip();
  1423. document.addEventListener("contextmenu", e => e.preventDefault());
  1424. });
  1425. //Error handling
  1426. window.onerror = (message, url, lineNumber) => {
  1427. console.log(message, url, lineNumber);
  1428. const formData = new FormData();
  1429. formData.append("documentName", documentName);
  1430. formData.append("lineNumber", lineNumber);
  1431. formData.append("message", message);
  1432. formData.append("url", url);
  1433. BABYLON.Tools.CreateScreenshotAsync(scene.getEngine(), scene.activeCamera, { width: 1600, height: 1000 }).then((screenshot) => {
  1434. formData.append("screenshot", screenshot);
  1435. Utils.requestFormData(g_BasePath + "home/sendLog", "POST", formData);
  1436. });
  1437. return true;
  1438. }
  1439. function checkForUnknownTable() {
  1440. if (userRole !== g_UserRole.Sales) return;
  1441. const elem = document.getElementById('tablesHolder');
  1442. const kids = elem.childNodes.length;
  1443. for (let i = kids - 1; i >= 0; i -= 2) {
  1444. if (elem.childNodes[i].childNodes.length > 1) {
  1445. const body = elem.childNodes[i].childNodes[elem.childNodes[i].childNodes.length - 2];
  1446. if (body.id && icubes.filter(e => e.id === body.id).length === 0) {
  1447. elem.removeChild(elem.childNodes[i]);
  1448. elem.removeChild(elem.childNodes[i-2]);
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //Pricing
  1454. function setPriceTable(data, icube) {
  1455. if (g_tutorialIsRunning) return;
  1456. if (userRole !== g_UserRole.Sales) return;
  1457. checkForUnknownTable();
  1458. // console.log(extraPrice)
  1459. const dataInfo = {
  1460. 'racking' : 'Racking costs',
  1461. 'xtrack' : 'X-Track elements',
  1462. 'lift' : 'Vertical Transporters',
  1463. 'carrier' : '3D-Carriers',
  1464. 'wifi' : 'System WiFi connectivity',
  1465. 'data_control' : 'Dat-A-Control WMS Software',
  1466. 'software_implementation' : 'Software implementation and deployment',
  1467. 'central_panel' : 'Central control panel',
  1468. // 'extra_lift': 'Extra Vertical Transporters',
  1469. 'extra_carrier': 'Extra 3D-Carriers',
  1470. 'total_excluding' : 'Total price estimation \n (excluding transport and installation)'
  1471. }
  1472. const details = $('#priceDetails').is(':checked');
  1473. let html = "";
  1474. for (let item in data) {
  1475. if (!details && item != 'total_excluding') continue;
  1476. html += '<tr>';
  1477. html += '<td>' + dataInfo[item] + ((item == 'lift' && icube.extra.lift > 0) ? ' (' + icube.extra.lift + ' added by customer)' : '') + '</td>'; //name
  1478. html += '<td class="text-right">' + (data[item]['qty'] === -1 ? '&nbsp;' : formatIntNumber(data[item]['qty'])) + (item === 'racking' ? ' pallet positions' : '') + '</td>'; //qty
  1479. html += '<td class="text-right">' + '€' + formatIntNumber(data[item]['val']) + '</td>'; //price
  1480. html += '</tr>';
  1481. }
  1482. if (document.getElementById(icube.id)) {
  1483. document.getElementById(icube.id).innerHTML = html;
  1484. }
  1485. else {
  1486. const table = `
  1487. <div class="itemTable" style="margin-top:50px; padding: 10px; font-weight: bold;">` + icube.name + `</div>
  1488. <table class="table itemTable table-responsive-lg table-bordered table-striped table-sm mb-0 mt-0">
  1489. <colgroup>
  1490. <col width="30%">
  1491. <col width="8%">
  1492. <col width="10%">
  1493. </colgroup>
  1494. <thead>
  1495. <tr>
  1496. <th>` + (details === false ? 'Item name' : 'Automatic item name') + `</th>
  1497. <th class="text-right">Quantity</th>
  1498. <th class="text-right">Price estimation</th>
  1499. </tr>
  1500. </thead>
  1501. <tbody id="` + icube.id + `">` + html + `</tbody>
  1502. </table>`;
  1503. document.getElementById("tablesHolder").innerHTML += table;
  1504. }
  1505. g_totalPrice = parseFloat(updateExtraPriceTable());
  1506. g_totalPrice += parseFloat(document.getElementById('connectorPrice').innerHTML) * 1000;
  1507. for (let i = 0; i < icubes.length; i++) {
  1508. g_totalPrice += icubes[i].estimatedPrice;
  1509. }
  1510. $('#totalPrice').text('€' + formatIntNumber(g_totalPrice));
  1511. }
  1512. function updateInventory () {
  1513. if (!selectedIcube) return;
  1514. let cap = 0;
  1515. icubes.forEach((icube) => {
  1516. const icubePalletNo = icube.getPalletNoJS();
  1517. cap += icubePalletNo[0];
  1518. cap += icubePalletNo[1];
  1519. cap += icubePalletNo[2];
  1520. });
  1521. let sstores = [];
  1522. let railLengths = [0, 0, 0, 0, 0];
  1523. for (let i = 0; i < selectedIcube.stores.length; i++) {
  1524. for (let j = 0; j < selectedIcube.stores[i].dimension.length; j++) {
  1525. const length = _round(selectedIcube.stores[i].dimension[j][1] - selectedIcube.stores[i].dimension[j][0], 3);
  1526. if (length < 5) {
  1527. railLengths[0]++;
  1528. }
  1529. else {
  1530. if (length < 10 && length >= 5) {
  1531. railLengths[1]++;
  1532. }
  1533. else {
  1534. if (length < 25 && length >= 10) {
  1535. railLengths[2]++;
  1536. }
  1537. else {
  1538. if (length < 50 && length >= 25) {
  1539. railLengths[3]++;
  1540. }
  1541. else {
  1542. railLengths[4]++;
  1543. }
  1544. }
  1545. }
  1546. }
  1547. if (sstores.length === 0) {
  1548. sstores.push({
  1549. length: length,
  1550. pallets: selectedIcube.stores[i].capacity[j][g_palletInfo.max],
  1551. numbers: 1
  1552. });
  1553. }
  1554. else {
  1555. const filter = sstores.filter(e => (e.length == length));
  1556. if (filter.length > 0) {
  1557. filter[0].numbers += 1;
  1558. }
  1559. else {
  1560. sstores.push({
  1561. length: length,
  1562. pallets: selectedIcube.stores[i].capacity[j][g_palletInfo.max],
  1563. numbers: 1
  1564. });
  1565. }
  1566. }
  1567. }
  1568. }
  1569. // console.log(manualItemInfo[3].meshData)
  1570. g_inventory = {
  1571. 'stores': JSON.stringify(sstores),
  1572. 'dimension': JSON.stringify(WHDimensions),
  1573. 'pallet_800': g_palletInfo.value[0],
  1574. 'pallet_1000': g_palletInfo.value[1],
  1575. 'pallet_1200': g_palletInfo.value[2],
  1576. 'levelHeight': g_palletHeight,
  1577. 'rackingLevels': g_rackingHighLevel,
  1578. 'SKU': g_SKU,
  1579. 'throughput': g_movesPerHour,
  1580. 'g_lift': (selectedIcube.calculatedLiftsNo + selectedIcube.extra.lift),
  1581. 'g_carrier': (selectedIcube.calculatedCarriersNo + selectedIcube.extra.carrier),
  1582. 'g_port': selectedIcube.activedIOPorts.length,
  1583. 'g_capacity': cap,
  1584. 'g_rail_5': railLengths[0],
  1585. 'g_rail_5_10': railLengths[1],
  1586. 'g_rail_10_25': railLengths[2],
  1587. 'g_rail_25_50': railLengths[3],
  1588. 'g_rail_50': railLengths[4],
  1589. 'm_xtrack': manualItemInfo[0].meshData.length,
  1590. 'm_palletDropS': manualItemInfo[1].meshData.length,
  1591. 'm_palletDropSCS': manualItemInfo[9].meshData.length,
  1592. 'm_palletDropSCC': manualItemInfo[6].meshData.length,
  1593. 'm_chainC400': manualItemInfo[4].meshData.length,
  1594. 'm_chainC540': manualItemInfo[5].meshData.length,
  1595. 'm_rollerCC': manualItemInfo[8].meshData.length,
  1596. 'm_roller200': manualItemInfo[7].meshData.length,
  1597. 'm_sfence100': manualItemInfo[10].meshData.length,
  1598. 'm_sfence200': manualItemInfo[2].meshData.length,
  1599. 'm_sfenceDoor': manualItemInfo[11].meshData.length,
  1600. 'm_scanner': manualItemInfo[12].meshData.length,
  1601. 'm_stairs': manualItemInfo[13].meshData.length,
  1602. 'm_rail_5': 0,
  1603. 'm_rail_5_10': 0,
  1604. 'm_rail_10_25': 0,
  1605. 'm_rail_25_50': 0,
  1606. 'm_rail_50': 0,
  1607. 'm_others': 0
  1608. }
  1609. //console.log(g_inventory);
  1610. }
  1611. $('.faq').on("click", function () {
  1612. $('.faq').removeClass('faq_active');
  1613. $('.faq').next().addClass('hide');
  1614. $(this).addClass('faq_active');
  1615. $(this).next().removeClass('hide');
  1616. });
  1617. function showLoadingPopUp (callback) {
  1618. $("#loadingScene").fadeIn(1, callback);
  1619. }
  1620. function hideLoadingPopUp () {
  1621. $("#loadingScene").fadeOut(100);
  1622. }
  1623. function checkPlacedXtracklift () {
  1624. let allSet = true;
  1625. let xtracks, lifts;
  1626. for (let i = 0; i < icubes.length; i++) {
  1627. xtracks = parseInt(icubes[i].calculatedXtracksNo) - parseInt(icubes[i].activedXtrackIds.length);
  1628. lifts = parseInt(icubes[i].calculatedLiftsNo) + parseInt(icubes[i].extra.lift) - parseInt(icubes[i].activedLiftInfos.length);
  1629. if (xtracks !== 0 || lifts !== 0) {
  1630. allSet = false;
  1631. break;
  1632. }
  1633. }
  1634. let mess = '';
  1635. if (!allSet) {
  1636. if (xtracks !== 0 && lifts !== 0) {
  1637. mess += 'You have not placed the required x-Track(s) and Vertical Transporters to the layout.<br>';
  1638. mess += 'Are you sure you want to submit for pricing or would you like to first add the missing x-Track(s) and Vertical Transporters';
  1639. }
  1640. else {
  1641. if (xtracks !== 0) {
  1642. mess += 'You have not placed the required x-Track(s) to the layout.<br>';
  1643. mess += 'Are you sure you want to submit for pricing or would you like to first add the missing x-Track(s)';
  1644. }
  1645. else {
  1646. mess += 'You have not placed the required Vertical Transporters to the layout.<br>';
  1647. mess += 'Are you sure you want to submit for pricing or would you like to first add the missing Vertical Transporters';
  1648. }
  1649. }
  1650. }
  1651. return [allSet, mess];
  1652. }
  1653. $("#btnSubmissionPlan").on("click", function () {
  1654. const data = checkPlacedXtracklift();
  1655. if (data[0]) {
  1656. showModal('planAddInfo-modal');
  1657. }
  1658. else {
  1659. $('#submit-modal-mess').html(data[1]);
  1660. showModal('submit-modal');
  1661. }
  1662. });
  1663. $("#btnSubmissionPlanToManager").on("click", function () {
  1664. $('#waiting').show('fast', () => {
  1665. Export_PDF.generateFile(true);
  1666. });
  1667. hideModal('planAddInfo-modal');
  1668. });
  1669. $("#btnSubmissionPlanToManager2").on("click", function () {
  1670. const data = checkPlacedXtracklift();
  1671. extraInfo = {
  1672. email: $('#emailP').val(),
  1673. compName: (userRole === g_UserRole.Sales ? $('#addInfo_company').val() : $('#addInfo_company2').val()),
  1674. contactP: (userRole === g_UserRole.Sales ? $('#addInfo_contacter').val() : $('#addInfo_contacter2').val()),
  1675. location: (userRole === g_UserRole.Sales ? $('#addInfo_location').val() : $('#addInfo_location2').val()),
  1676. delDate: (userRole === g_UserRole.Sales ? $('#addInfo_delivery_date').val() : $('#addInfo_delivery_date2').val()),
  1677. temperature: (userRole === g_UserRole.Sales ? ($('#addInfo_temp').is(":checked") ? 'Yes' : 'No') : ($('#addInfo_temp2').is(":checked") ? 'Yes' : 'No')),
  1678. flammable: (userRole === g_UserRole.Sales ? ($('#addInfo_flammable').is(":checked") ? 'Yes' : 'No') : ($('#addInfo_flammable2').is(":checked") ? 'Yes' : 'No')),
  1679. food: (userRole === g_UserRole.Sales ? ($('#addInfo_food').is(":checked") ? 'Yes' : 'No') : ($('#addInfo_food2').is(":checked") ? 'Yes' : 'No')),
  1680. feedback: $('#help_feedback').val()
  1681. }
  1682. if (data[0]) {
  1683. if (userRole !== g_UserRole.Demo) {
  1684. $('#waiting').show('fast', () => {
  1685. Export_PDF.generateFile(true);
  1686. });
  1687. }
  1688. else {
  1689. if (extraInfo.contactP.length === 0) return;
  1690. if (extraInfo.email.length === 0) return;
  1691. if (!Utils.validateEmail(extraInfo.email)) return;
  1692. Utils.request(g_BasePath + 'home/createDemoAccount', 'POST', {
  1693. name: extraInfo.contactP,
  1694. email: extraInfo.email
  1695. }, (data) => {
  1696. documentInfo = data.documentInfo;
  1697. userEmail = extraInfo.email;
  1698. userName = extraInfo.contactP;
  1699. $('#waiting').show('fast', () => {
  1700. Export_PDF.generateFile(true);
  1701. });
  1702. }, () => {
  1703. Utils.logg('Account creation failed! Try again later', 'error');
  1704. });
  1705. }
  1706. }
  1707. else {
  1708. $('#submit-modal-mess').html(data[1]);
  1709. $('#submit-modal').removeClass('fade').show();
  1710. }
  1711. });
  1712. $('.submit-modal-close').on("click", function () {
  1713. $('#submit-modal').addClass('fade').hide();
  1714. document.getElementById('main-tabs-tab-Racking').dispatchEvent(new Event('click'));
  1715. });
  1716. $('.submit-modal-confirm').on("click", function () {
  1717. hideModal('submit-modal');
  1718. if (userRole === g_UserRole.Sales) {
  1719. showModal('planAddInfo-modal');
  1720. }
  1721. else {
  1722. $('#waiting').show('fast', () => {
  1723. Export_PDF.generateFile(true);
  1724. });
  1725. }
  1726. });
  1727. function _generateLabels (objectTransforms, text = '', transparency = false, rotationX = Math.PI/2, rotationY = 0, rotationZ = 0, alpha = 0) {
  1728. if (objectTransforms.length === 0)
  1729. return null;
  1730. const half = parseInt(Math.floor(Math.sqrt(objectTransforms.length)) + 1);
  1731. const cellWidth = 64;
  1732. const cellHeight = 32;
  1733. const dT = new BABYLON.DynamicTexture("DynamicTexture", { width: cellWidth * half, height: cellHeight * half }, scene);
  1734. dT.hasAlpha = transparency;
  1735. const offsetX = [28, 26, 22, 2];
  1736. for(let r = 0; r < half; r++) {
  1737. for(let c = 0; c < half; c++) {
  1738. let textStr = text + (r * half + c + 1);
  1739. if (objectTransforms[r * half + c] && objectTransforms[r * half + c][3]) {
  1740. textStr = text + objectTransforms[r * half + c][3];
  1741. }
  1742. if (transparency === true) {
  1743. dT.drawText(textStr, offsetX[textStr.length] + c * cellWidth, 25 + (half - r - 1) * cellHeight, "normal 26px monospace", "#ffffff", null);
  1744. }
  1745. else {
  1746. dT.drawText(textStr, offsetX[textStr.length] + c * cellWidth - 3, 27 + (half - r - 1) * cellHeight, "bold 40px monospace", "#adadad", null);
  1747. dT.drawText(textStr, offsetX[textStr.length] + c * cellWidth - 0.5, 25.5 + (half - r - 1) * cellHeight, "normal 38px monospace", "#ffffff", null);
  1748. }
  1749. }
  1750. }
  1751. const planeBase = new BABYLON.MeshBuilder.CreatePlane("TextPlane", { width: 1, height: 1, sideOrientation: 2 }, scene);
  1752. planeBase.isPickable = false;
  1753. const mat = new BABYLON.StandardMaterial("TextPlaneMaterial", scene);
  1754. mat.emissiveTexture = dT;
  1755. mat.emissiveTexture.hasAlpha = true;
  1756. mat.opacityTexture = dT;
  1757. mat.specularColor = BABYLON.Color3.Black();
  1758. mat.freeze();
  1759. // planeBase.material = mat;
  1760. const SPSLabels = new BABYLON.SolidParticleSystem('SPSLabels', scene);
  1761. SPSLabels.addShape(planeBase, objectTransforms.length);
  1762. const mesh = SPSLabels.buildMesh();
  1763. mesh.material = mat;
  1764. if (transparency) {
  1765. planeBase.position.y = 0.1;
  1766. }
  1767. else {
  1768. planeBase.position.y = 0.05;
  1769. }
  1770. planeBase.dispose();
  1771. SPSLabels.initParticles = function() {
  1772. for (let p = 0; p < this.nbParticles; p++) {
  1773. this.recycleParticle(this.particles[p]);
  1774. }
  1775. };
  1776. SPSLabels.recycleParticle = function(particle) {
  1777. const col = particle.idx % half;
  1778. const row = Math.floor(particle.idx / half);
  1779. particle.position.x = objectTransforms[particle.idx][0];
  1780. particle.position.y = objectTransforms[particle.idx][1] - alpha;
  1781. particle.position.z = objectTransforms[particle.idx][2];
  1782. particle.rotation.x = rotationX;
  1783. particle.rotation.z = rotationY;
  1784. particle.rotation.y = rotationZ;
  1785. particle.uvs.x = (col * cellWidth) / (cellWidth * half);
  1786. particle.uvs.y = (row * cellHeight) / (cellHeight * half);
  1787. particle.uvs.z = ((col + 1) * cellWidth) / (cellWidth * half);
  1788. particle.uvs.w = ((row + 1) * cellHeight) / (cellHeight * half);
  1789. };
  1790. SPSLabels.initParticles();
  1791. SPSLabels.setParticles();
  1792. SPSLabels.refreshVisibleSize();
  1793. SPSLabels.computeParticleRotation = false;
  1794. SPSLabels.computeParticleTexture = false;
  1795. SPSLabels.computeParticleColor = false;
  1796. SPSLabels.computeParticleVertex = false;
  1797. SPSLabels.mesh.freezeWorldMatrix();
  1798. SPSLabels.mesh.freezeNormals();
  1799. return SPSLabels;
  1800. }
  1801. function clickManualItem(itemId) {
  1802. scene.unfreezeActiveMeshes();
  1803. tracking(35);
  1804. // clear previous added Item features
  1805. clearSceneItemManual();
  1806. //Add item in scene
  1807. selectedItemMesh = addNewItem(manualItemInfo[parseInt(itemId)], "Item-" + manualItemInfo[parseInt(itemId)].name);
  1808. const fixedDirection = [
  1809. [ITEMDIRECTION.right, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.top, ITEMDIRECTION.bottom, ITEMDIRECTION.left, ITEMDIRECTION.left, ITEMDIRECTION.left, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom],
  1810. [ITEMDIRECTION.bottom, ITEMDIRECTION.left, ITEMDIRECTION.bottom, ITEMDIRECTION.left, ITEMDIRECTION.right, ITEMDIRECTION.left, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.left, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom, ITEMDIRECTION.bottom]
  1811. ]
  1812. if (itemId < 800) {
  1813. if (fixedDirection[0][parseInt(itemId)] === undefined) {
  1814. console.error('Set fixed direction first');
  1815. //TODO: refact this fixed rotation
  1816. return;
  1817. }
  1818. selectedItemMesh.direction = fixedDirection[0][parseInt(itemId)];
  1819. if (selectedIcube && !selectedIcube.isHorizontal)
  1820. selectedItemMesh.direction = fixedDirection[1][parseInt(itemId)];
  1821. selectedItemMesh.rotation.y = parseInt(selectedItemMesh.direction) * Math.PI / 2;
  1822. }
  1823. currentMesh = selectedItemMesh;
  1824. currentMesh.position = new BABYLON.Vector3(-g_WarehouseMaxWidth, 0, -g_WarehouseMaxLength);
  1825. startingPoint = null;
  1826. if (!currentMesh.ruler) {
  1827. currentMesh.ruler = new RulerMItems(currentMesh, scene);
  1828. currentMesh.ruler.buttons[0].isClicked = true;
  1829. for (let i = 0; i < currentMesh.ruler.buttons.length; i++) {
  1830. currentMesh.ruler.buttons[i].isPointerBlocker = false;
  1831. }
  1832. if (!matManager.matHighLight.hasMesh(currentMesh)) {
  1833. Utils.addMatHighLight(currentMesh);
  1834. }
  1835. setTimeout(() => {
  1836. // after object is placed not allow click to go through UI
  1837. if (currentMesh && currentMesh.ruler) {
  1838. for (let i = 0; i < currentMesh.ruler.buttons.length; i++) {
  1839. currentMesh.ruler.buttons[i].isPointerBlocker = true;
  1840. }
  1841. }
  1842. }, 150);
  1843. }
  1844. }
  1845. // Selected Item
  1846. $('.equipment-item').on('click', function () {
  1847. clickManualItem($(this).attr("idx"));
  1848. });
  1849. /**
  1850. *
  1851. * @param {*} meshData
  1852. * @param {*} name
  1853. */
  1854. function addNewItem (meshData, name) {
  1855. let item = meshData.originMesh.clone(name);
  1856. item.setEnabled(true);
  1857. if ([ITEMTYPE.Manual.ContourScanner, ITEMTYPE.Manual.ExteriorStairs].includes(meshData.type)) {
  1858. let heightOffset = g_palletHeight;
  1859. if (g_palletHeight >= 1)
  1860. heightOffset = g_palletHeight - (g_palletHeight - 1) * 0.26;
  1861. else
  1862. heightOffset = g_palletHeight + (1 - g_palletHeight) * 0.26;
  1863. item.scaling.y = heightOffset;
  1864. const material = item.material;
  1865. if (selectedIcube && g_rackingHighLevel > 2 && meshData.type === ITEMTYPE.Manual.ExteriorStairs) {
  1866. for(let i = 1; i < g_rackingHighLevel - 1; i++) {
  1867. const aux = meshData.originMesh.clone(meshData.originMesh);
  1868. aux.scaling.y = heightOffset;
  1869. aux.position.y = (g_palletHeight + g_railHeight) * i;
  1870. item = BABYLON.Mesh.MergeMeshes([item, aux], true, true, null, true, true);
  1871. }
  1872. item.material = material;
  1873. }
  1874. }
  1875. // machine placeholder can be placed at a specific distance
  1876. if (parseInt(meshData.type) >= 1000 && meshData.hasOwnProperty('atDist')) {
  1877. item.atDist = meshData.atDist;
  1878. }
  1879. // temporary
  1880. if (meshData.type === ITEMTYPE.Manual.RailOutside) {
  1881. meshData.atDist = 0;
  1882. item.atDist = meshData.atDist;
  1883. }
  1884. item.name = meshData.name;
  1885. item.type = meshData.type;
  1886. item.width = meshData.width;
  1887. item.height = meshData.height;
  1888. item.length = meshData.length;
  1889. item.multiply = meshData.multiply;
  1890. item.direction = meshData.direction;
  1891. item.isPickable = true;
  1892. item.actionManager = new BABYLON.ActionManager(scene);
  1893. item.actionManager.hoverCursor = "pointer";
  1894. item.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger, ()=>{}));
  1895. item.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnLeftPickTrigger, (evt)=>{
  1896. startingPoint = null;
  1897. if (currentMesh) {
  1898. if (currentMesh.ruler) {
  1899. if (currentMesh.ruler.multiplyPanel && currentMesh.ruler.multiplyPanel.isVisible) {
  1900. onOkNumMultiply(currentMesh.prevDirection);
  1901. }
  1902. else {
  1903. currentMesh.ruler.dispose();
  1904. delete currentMesh.ruler;
  1905. }
  1906. if (isCtrlPressed) {
  1907. itemsGroup.push(currentMesh);
  1908. }
  1909. }
  1910. if (currentMesh && matManager.matHighLight.hasMesh(currentMesh) && !isCtrlPressed) {
  1911. Utils.removeMatHighLight(currentMesh);
  1912. removeItemsGroup();
  1913. }
  1914. }
  1915. currentMesh = evt.meshUnderPointer;
  1916. if (!currentMesh.ruler) {
  1917. currentMesh.ruler = new RulerMItems(item, scene);
  1918. }
  1919. //Set Highlight Material
  1920. if (!matManager.matHighLight.hasMesh(currentMesh)) {
  1921. Utils.addMatHighLight(currentMesh);
  1922. }
  1923. setTimeout(() => {
  1924. // after object is placed not allow click to go through UI
  1925. if (currentMesh && currentMesh.ruler) {
  1926. for (let i = 0; i < currentMesh.ruler.buttons.length; i++) {
  1927. currentMesh.ruler.buttons[i].isPointerBlocker = true;
  1928. }
  1929. }
  1930. }, 150);
  1931. if (selectedItemMesh) {
  1932. manualItemInfo[parseInt(selectedItemMesh.type)].meshData.push(selectedItemMesh);
  1933. Behavior.add(Behavior.type.addItem);
  1934. selectedItemMesh = undefined;
  1935. }
  1936. }));
  1937. return item;
  1938. }
  1939. function removeItemsGroup(dispose = false) {
  1940. if (itemsGroup.length > 0) {
  1941. itemsGroup.forEach(element => {
  1942. Utils.removeMatHighLight(element);
  1943. if (dispose) {
  1944. removeItemData(element);
  1945. element.dispose();
  1946. }
  1947. });
  1948. }
  1949. itemsGroup = [];
  1950. }
  1951. // unset current mesh
  1952. function unsetCurrentMesh(dispose = false) {
  1953. if (currentMesh) {
  1954. Utils.removeMatHighLight(currentMesh);
  1955. removeItemsGroup();
  1956. if (currentMesh.ruler) {
  1957. currentMesh.ruler.dispose();
  1958. delete currentMesh.ruler;
  1959. }
  1960. if (dispose) {
  1961. removeItemData(currentMesh);
  1962. currentMesh.dispose();
  1963. }
  1964. currentMesh = null;
  1965. }
  1966. }
  1967. // close gui, unset curentMesh, dispose selected
  1968. function clearSceneItemManual() {
  1969. // Remove selected item if you didn't paste it in the scene
  1970. if (selectedItemMesh) {
  1971. selectedItemMesh.dispose();
  1972. selectedItemMesh = null;
  1973. }
  1974. if (currentMesh) {
  1975. if (currentMesh && currentMesh.ruler && (currentMesh.ruler.multiplyPanel && currentMesh.ruler.multiplyPanel.isVisible)) {
  1976. onOkNumMultiply(currentMesh.prevDirection);
  1977. }
  1978. else {
  1979. unsetCurrentMesh(false);
  1980. }
  1981. }
  1982. }
  1983. $('#show_tutorial_atFirst').on("click", function () {
  1984. switchCamera(currentView);
  1985. hideModal("hello-modal");
  1986. g_saveBehaviour = false;
  1987. if ($('.tab-content').is(':visible'))
  1988. $('#main-tabs-tab-Size').trigger('click');
  1989. tutorialTour.start(() => {
  1990. setProject(currentTemplateType, false);
  1991. initData(currentTemplateType);
  1992. onBegin();
  1993. });
  1994. });
  1995. $('#show_tutorial').on("click", function () {
  1996. switchCamera(currentView);
  1997. g_saveBehaviour = false;
  1998. const prevData = {
  1999. document_name: documentName,
  2000. warehouse_dimensions: [...WHDimensions],
  2001. icubeData: [...getIcubeData()],
  2002. itemMData: [...getManualItems()],
  2003. unit_measurement: unit_measurement,
  2004. extraInfo: extraInfo,
  2005. extraPrice: [...extraPrice],
  2006. measurements: [...getAllMeasurements()],
  2007. custom_values: [...custom_values],
  2008. layoutMap: {...layoutMap}
  2009. }
  2010. setProject(Template.values[Template.type.Default], false);
  2011. if ($('.tab-content').is(':visible'))
  2012. $('#main-tabs-tab-Size').trigger('click');
  2013. tutorialTour.start(() => {
  2014. setProject(prevData, false);
  2015. Behavior.init();
  2016. });
  2017. });
  2018. function saveTutorial (passed) {
  2019. Utils.request(g_BasePath + 'home/tutorial/' + passed, 'POST', {}, null, null);
  2020. }
  2021. $("#send_feedback").on("click", function () {
  2022. Utils.request(g_BasePath + 'home/sendFeedback', 'POST', {
  2023. fmessage: $('#help_feedback').val()
  2024. }, (data) => {
  2025. if (data)
  2026. Utils.logg('Feedback sent!','success');
  2027. }, null);
  2028. });
  2029. $('#gotoRacking').on("click", function () {
  2030. document.getElementById('main-tabs-tab-Racking').dispatchEvent(new Event('click'));
  2031. $('.tab-content').animate({ scrollTop: 0 }, 1);
  2032. });
  2033. $('#auto-upRightDist').on("click", function () {
  2034. if ($(this).hasClass('active-icube-setting')) return;
  2035. $('#custom-upRightDist').removeClass('active-icube-setting');
  2036. $('#input-upRightDistance').attr('disabled', true);
  2037. $(this).addClass('active-icube-setting');
  2038. });
  2039. $('#custom-upRightDist').on("click", function () {
  2040. if ($(this).hasClass('active-icube-setting')) return;
  2041. $('#auto-upRightDist').removeClass('active-icube-setting');
  2042. $('#input-upRightDistance').attr('disabled', false);
  2043. $(this).addClass('active-icube-setting');
  2044. });
  2045. $('#download_it').on("click", function () {
  2046. if (selectedIcube)
  2047. selectedIcube.software.download();
  2048. });
  2049. $('#download_it_wms').on("click", function () {
  2050. if (selectedIcube)
  2051. selectedIcube.software.download_wms();
  2052. });
  2053. $('#accountToCreate').on("click", function () {
  2054. const name = $('#nameToCreate').val();
  2055. const email = $('#emailToCreate').val();
  2056. if (name.length === 0) return;
  2057. if (email.length === 0) return;
  2058. if (!Utils.validateEmail(email)) return;
  2059. Utils.request(g_BasePath + 'home/createAccountSA', 'POST', {
  2060. name: name,
  2061. email: email
  2062. }, (data) => {
  2063. if (data === 'Error')
  2064. Utils.logg('This user already exists', 'error');
  2065. else
  2066. createUsersSAhtml(data);
  2067. }, () => {
  2068. Utils.logg('Account creation failed! Try again later', 'error');
  2069. });
  2070. });
  2071. function getUsersSA () {
  2072. Utils.request(g_BasePath + 'home/getUsersSA', 'GET', {}, (data) => {
  2073. createUsersSAhtml(data);
  2074. }, null);
  2075. }
  2076. function createUsersSAhtml (data) {
  2077. $('#createdAccounts').html('');
  2078. for (let i = 0; i < data.length; i++) {
  2079. // user data
  2080. const sec1 = document.createElement('div');
  2081. sec1.style.marginBottom = "5px";
  2082. sec1.classList.add("col-sm-12");
  2083. const row = document.createElement('div');
  2084. row.classList.add("col-sm-9", "padding-no");
  2085. row.style.fontWeight = "bold";
  2086. row.innerHTML = data[i].email;
  2087. sec1.appendChild(row);
  2088. const row2 = document.createElement('div');
  2089. row2.classList.add("col-sm-3", "padding-no");
  2090. row2.style.textAlign = "right";
  2091. sec1.appendChild(row2);
  2092. const but1 = createUsersSAbut("New project", "fa-plus", () => {
  2093. if (confirm('Do you want to save current layout as new project for user ' + data[i].name + '?')) {
  2094. documentInfo = data[i].id;
  2095. saveProject(() => {
  2096. documentInfo = '';
  2097. setProject(Template.values[Template.type.Default], false);
  2098. setTimeout(() => { getUsersSA(); }, 1000);
  2099. });
  2100. }
  2101. });
  2102. row2.appendChild(but1);
  2103. if (data[i].projects.length > 0) {
  2104. const but0 = createUsersSAbut("Projects list", "fa-bars", () => {
  2105. const doc = document.getElementById('slv_' + i);
  2106. if (doc.style.display === "none")
  2107. doc.style.display = "block";
  2108. else
  2109. doc.style.display = "none";
  2110. });
  2111. row2.appendChild(but0);
  2112. }
  2113. $('#createdAccounts').append(sec1);
  2114. // list of projects
  2115. const sec1a = document.createElement('div');
  2116. $(sec1a).attr('id', 'slv_' + i);
  2117. sec1a.style.display = "none";
  2118. for (let j = 0; j < data[i].projects.length; j++) {
  2119. const sec2 = document.createElement('div');
  2120. sec2.classList.add("col-lg-12");
  2121. sec1a.appendChild(sec2);
  2122. const row1 = document.createElement('div');
  2123. row1.classList.add("col-sm-6", "padding-no");
  2124. row1.innerHTML = (j + 1) + '. ' + data[i].projects[j].document_name;
  2125. $(row1).attr('title', data[i].projects[j].saved_time);
  2126. sec2.appendChild(row1);
  2127. const row2 = document.createElement('div');
  2128. row2.classList.add("col-sm-6", "padding-no");
  2129. row2.style.textAlign = "right";
  2130. sec2.appendChild(row2);
  2131. const but1a = createUsersSAbut("Rename", "fa-pencil", () => {
  2132. const sceneDocName = data[i].projects[j].document_name;
  2133. const projectName = prompt("Please enter project name:", data[i].projects[j].document_name);
  2134. if (projectName == null || projectName == "") {
  2135. return;
  2136. }
  2137. else {
  2138. if (documentName == sceneDocName)
  2139. documentName = projectName;
  2140. renameProject(projectName, data[i].projects[j].id);
  2141. setTimeout(() => { getUsersSA(); }, 1000);
  2142. }
  2143. });
  2144. row2.appendChild(but1a);
  2145. const but2 = createUsersSAbut("Delete", "fa-times", () => {
  2146. if (confirm('Do you want to delete this layout?')) {
  2147. deleteProject(data[i].projects[j].document_name, data[i].id);
  2148. setProject(Template.values[Template.type.Default], false);
  2149. setTimeout(() => { getUsersSA(); }, 1000);
  2150. }
  2151. });
  2152. row2.appendChild(but2);
  2153. const but3 = createUsersSAbut("Edit", "fa-edit", () => {
  2154. if (confirm('Do you want to view/edit this layout?')) {
  2155. loadProject(data[i].projects[j].document_name, data[i].id);
  2156. }
  2157. });
  2158. row2.appendChild(but3);
  2159. const but4 = createUsersSAbut("Overwrite", "fa-exchange", () => {
  2160. if (confirm('Do you want to overwrite this layout with your current layout?')) {
  2161. documentInfo = data[i].id;
  2162. const docName = documentName;
  2163. documentName = data[i].projects[j].document_name
  2164. saveProject(() => {
  2165. documentInfo = '';
  2166. documentName = docName;
  2167. setProject(Template.values[Template.type.Default], false);
  2168. setTimeout(() => { getUsersSA(); }, 1000);
  2169. });
  2170. }
  2171. });
  2172. row2.appendChild(but4);
  2173. const but5 = createUsersSAbut("Notify", "fa-envelope", () => {
  2174. if (confirm('Do you want to send an email notification?')) {
  2175. sendProjectNotify(data[i].projects[j].document_name, data[i].email);
  2176. }
  2177. });
  2178. row2.appendChild(but5);
  2179. }
  2180. $('#createdAccounts').append(sec1a);
  2181. const sec3 = document.createElement('div');
  2182. sec3.classList.add("col-lg-12");
  2183. const hr = document.createElement('hr');
  2184. hr.classList.add("short");
  2185. sec3.appendChild(hr);
  2186. $('#createdAccounts').append(sec3);
  2187. }
  2188. }
  2189. function createUsersSAbut (text, faClass, onclick) {
  2190. const but = document.createElement('div');
  2191. but.classList.add("fa", faClass, "fa_icon2");
  2192. $(but).attr('title', text);
  2193. but.addEventListener('click', onclick, false);
  2194. return but;
  2195. }
  2196. $("#uploadedLayout").on("change", function() {
  2197. const formData = new FormData($("#uploader").get(0));
  2198. Utils.requestFormData(g_BasePath + 'home/uploadCAD_layout', 'POST', formData, (data) => {
  2199. if (data.length === 0)
  2200. Utils.logg('Upload failed!', 'error');
  2201. else
  2202. Utils.logg('Upload done!', 'success');
  2203. if (!layoutMap || (layoutMap && !layoutMap.hasOwnProperty('url')))
  2204. layoutMap = { url: '', scale: 1, uOffset: 0, vOffset: 0 }
  2205. layoutMap.url = data;
  2206. layoutMap.scale = 1;
  2207. layoutMap.uOffset = 0;
  2208. layoutMap.vOffset = 0;
  2209. prepareTexture();
  2210. });
  2211. });
  2212. function prepareTexture () {
  2213. if (layoutMap && layoutMap.hasOwnProperty('url')) {
  2214. if (layoutMap.url !== '') {
  2215. const texture = new BABYLON.Texture(layoutMap.url, scene);
  2216. texture.uScale = layoutMap.scale;
  2217. texture.vScale = layoutMap.scale;
  2218. texture.uOffset = layoutMap.uOffset;
  2219. texture.vOffset = layoutMap.vOffset;
  2220. texture.wrapU = 0;
  2221. texture.wrapV = 0;
  2222. /* - to check
  2223. //offset the UVs
  2224. materialPlane1.diffuseTexture.uOffset = 0.2;
  2225. materialPlane1.diffuseTexture.vOffset = -0.2;
  2226. //clamp U, V => otherwise the texture will repeat itself while offsetting
  2227. materialPlane1.diffuseTexture.wrapV = 0;
  2228. materialPlane1.diffuseTexture.wrapU = 0;
  2229. */
  2230. warehouse.floor.material.albedoTexture = texture;
  2231. $('#layoutScale').val(parseFloat(((2 - layoutMap.scale) * 100).toFixed(2)));
  2232. }
  2233. else {
  2234. if (warehouse.floor.material.albedoTexture) {
  2235. warehouse.floor.material.albedoTexture.dispose();
  2236. warehouse.floor.material.albedoTexture = null;
  2237. }
  2238. }
  2239. }
  2240. else {
  2241. if (warehouse.floor.material.albedoTexture) {
  2242. warehouse.floor.material.albedoTexture.dispose();
  2243. warehouse.floor.material.albedoTexture = null;
  2244. }
  2245. }
  2246. renderScene();
  2247. }
  2248. $('#layoutDrawing').on("click", function () {
  2249. for (let i = layoutArrows.length - 1; i >= 0; i--) {
  2250. layoutArrows[i].dispose();
  2251. }
  2252. layoutArrows = [];
  2253. if ($(this).hasClass('active-icube-setting')) {
  2254. $(this).removeClass('active-icube-setting').text("Load building drawing (optional)");
  2255. $('#uploader').hide();
  2256. tracking(38);
  2257. }
  2258. else {
  2259. $(this).addClass('active-icube-setting').text("Confirm placement");
  2260. $('#uploader').show();
  2261. for (let i = 0; i < 4; i++) {
  2262. const arrow = otherItemInfo[ITEMTYPE.Other.PortArrow].originMesh.createInstance('inst_' + i);
  2263. arrow.rotationQuaternion = null;
  2264. arrow.scaling.y = 0.001;
  2265. if ( i % 2 === 0) {
  2266. arrow.position.x = (i === 0 ? -1 : 1) * warehouse.width / 1.8;
  2267. arrow.rotation.y = (i === 0 ? -Math.PI / 2 : Math.PI / 2);
  2268. }
  2269. else {
  2270. arrow.position.z = (i === 1 ? -1 : 1) * warehouse.length / 1.8;
  2271. arrow.rotation.y = (i === 1 ? Math.PI : 0);
  2272. }
  2273. arrow.actionManager = new BABYLON.ActionManager(scene);
  2274. arrow.actionManager.hoverCursor = "pointer";
  2275. arrow.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPointerOverTrigger, ()=>{}));
  2276. arrow.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickDownTrigger, (evt)=>{
  2277. if (!layoutMap) return;
  2278. switch (i) {
  2279. case 0:
  2280. layoutMap.uOffset += 0.1;
  2281. break;
  2282. case 1:
  2283. layoutMap.vOffset += 0.1;
  2284. break;
  2285. case 2:
  2286. layoutMap.uOffset -= 0.1;
  2287. break;
  2288. case 3:
  2289. layoutMap.vOffset -= 0.1;
  2290. break;
  2291. }
  2292. if (warehouse.floor.material.albedoTexture) {
  2293. warehouse.floor.material.albedoTexture.uOffset = layoutMap.uOffset;
  2294. warehouse.floor.material.albedoTexture.vOffset = layoutMap.vOffset;
  2295. }
  2296. }));
  2297. layoutArrows.push(arrow);
  2298. }
  2299. warehouse.update(WHDimensions);
  2300. }
  2301. renderScene(4000);
  2302. });
  2303. function createPassThList () {
  2304. $('#passthroughList').html('');
  2305. if (selectedIcube) {
  2306. for (let j = 0; j < selectedIcube.activedPassthrough.length; j++) {
  2307. const sec2 = document.createElement('div');
  2308. sec2.style.display = "inline-flex";
  2309. sec2.classList.add("col-lg-12");
  2310. $(sec2).attr('id', 'pass' + j);
  2311. const row1 = document.createElement('div');
  2312. row1.classList.add("col-lg-12");
  2313. row1.style.overflow = "hidden";
  2314. row1.innerHTML = 'Passthrough' + (j + 1);
  2315. sec2.appendChild(row1);
  2316. const but3 = createUsersSAbut("Edit", "fa-edit", () => {
  2317. $('#set-icube-passthrough').addClass('active-icube-setting').text("Confirm placement");
  2318. selectedIcube.property['passthrough'].selectors.forEach((item) => {
  2319. item.dispose();
  2320. });
  2321. selectedIcube.property['passthrough'].selectors = [];
  2322. selectedIcube.showSelectors(0, j);
  2323. selectedIcube.showSelectors(1, j);
  2324. selectedIcube.showSelectors(2, j);
  2325. });
  2326. sec2.appendChild(but3);
  2327. const but2 = createUsersSAbut("Delete", "fa-times", () => {
  2328. selectedIcube.activedPassthrough.splice(j, 1);
  2329. selectedIcube.updateRacking();
  2330. Behavior.add(Behavior.type.addPassthrough);
  2331. createPassThList();
  2332. renderScene();
  2333. });
  2334. sec2.appendChild(but2);
  2335. const hr = document.createElement('hr');
  2336. hr.classList.add("short");
  2337. sec2.appendChild(hr);
  2338. $('#passthroughList').append(sec2);
  2339. }
  2340. }
  2341. }
  2342. function optimizeDistrCalculation (id, type) {
  2343. let sum = 0;
  2344. for(let i = 0; i < type.length; i++) {
  2345. sum += type[i];
  2346. }
  2347. const diff = (sum > 100 || sum < 100) ? sum - 100 : 0;
  2348. if (diff !== 0) {
  2349. switch (parseInt(id)) {
  2350. case 0:
  2351. if (type[1] !== 0 && type[2] !== 0) {
  2352. if (diff < 0) {
  2353. type[1] += Math.abs(diff);
  2354. }
  2355. else {
  2356. if (type[1] >= diff) {
  2357. type[1] -= diff;
  2358. }
  2359. else {
  2360. const diff2 = diff - type[1];
  2361. type[1] = 0;
  2362. type[2] -= diff2;
  2363. }
  2364. }
  2365. }
  2366. else if (type[1] !== 0) {
  2367. type[1] = type[1] + (diff > 0 ? -1 : 1) * Math.abs(diff);
  2368. }
  2369. else if (type[2] !== 0) {
  2370. type[2] = type[2] + (diff > 0 ? -1 : 1) * Math.abs(diff);
  2371. }
  2372. else {
  2373. type[1] = Math.abs(diff);
  2374. }
  2375. break;
  2376. case 1:
  2377. if (type[0] !== 0 && type[2] !== 0) {
  2378. if (diff < 0) {
  2379. type[0] += Math.abs(diff);
  2380. }
  2381. else {
  2382. if (type[0] >= diff) {
  2383. type[0] -= diff;
  2384. }
  2385. else {
  2386. const diff2 = diff - type[0];
  2387. type[0] = 0;
  2388. type[2] -= diff2;
  2389. }
  2390. }
  2391. }
  2392. else if (type[0] !== 0) {
  2393. type[0] = type[0] + (diff > 0 ? -1 : 1) * Math.abs(diff);
  2394. }
  2395. else if (type[2] !== 0) {
  2396. type[2] = type[2] + (diff > 0 ? -1 : 1) * Math.abs(diff);
  2397. }
  2398. else {
  2399. type[0] = Math.abs(diff);
  2400. }
  2401. break;
  2402. case 2:
  2403. if (type[0] !== 0 && type[1] !== 0) {
  2404. if (diff < 0) {
  2405. type[0] += Math.abs(diff);
  2406. }
  2407. else {
  2408. if (type[0] >= diff) {
  2409. type[0] -= diff;
  2410. }
  2411. else {
  2412. const diff2 = diff - type[0];
  2413. type[0] = 0;
  2414. type[1] -= diff2;
  2415. }
  2416. }
  2417. }
  2418. else if (type[0] !== 0) {
  2419. type[0] = type[0] + (diff > 0 ? -1 : 1) * Math.abs(diff);
  2420. }
  2421. else if (type[1] !== 0) {
  2422. type[1] = type[1] + (diff > 0 ? -1 : 1) * Math.abs(diff);
  2423. }
  2424. else {
  2425. type[0] = Math.abs(diff);
  2426. }
  2427. break;
  2428. }
  2429. }
  2430. return type;
  2431. }
  2432. $('#customLastRow').on("click", function() {
  2433. if ($('#lastLSetting').is(':visible')) {
  2434. visibility = false
  2435. }
  2436. else {
  2437. visibility = true
  2438. }
  2439. $('#lastLSetting').css('display', (visibility ? 'block' : 'none'));
  2440. $('#input-pallet-height').attr('disabled', visibility);
  2441. $('#input-pallet-height').next().children().attr('disabled', visibility);
  2442. $('#input-pallet-weight').attr('disabled', visibility);
  2443. $('#input-pallet-weight').next().children().attr('disabled', visibility);
  2444. });
  2445. function updateInputPallet (idx, palletIdx) {
  2446. const value1 = $('#palletL_' + idx + '_' + palletIdx).val();
  2447. const value2 = $('#palletL_' + (1 - idx) + '_' + palletIdx).val();
  2448. let atLevelIdx = -1;
  2449. for (let i = 0; i < g_palletAtLevel.length; i++) {
  2450. if (g_palletAtLevel[i].idx === palletIdx) {
  2451. atLevelIdx = i;
  2452. break;
  2453. }
  2454. }
  2455. if (idx === 0) {
  2456. const tempH = parseFloat(value1);
  2457. const max = parseFloat((WHDimensions[2] - g_bottomLength - g_railHeight - (g_rackingHighLevel - 1) * parseFloat(g_palletHeight + g_railHeight)).toFixed(2));
  2458. if (tempH > max) {
  2459. $('#palletL_' + idx + '_' + palletIdx).val(max);
  2460. }
  2461. if (atLevelIdx !== -1) {
  2462. if (value1 === g_palletHeight && value2 === g_palletWeight) {
  2463. g_palletAtLevel.splice(atLevelIdx, 1);
  2464. }
  2465. else {
  2466. g_palletAtLevel[atLevelIdx].height = value1
  2467. }
  2468. }
  2469. else {
  2470. g_palletAtLevel.push({
  2471. idx: palletIdx,
  2472. height: value1,
  2473. weight: value2
  2474. });
  2475. }
  2476. updateRackingAtLevel();
  2477. Behavior.add(Behavior.type.palletHeight);
  2478. }
  2479. else {
  2480. if (atLevelIdx !== -1) {
  2481. if (value1 === g_palletWeight && value2 === g_palletHeight) {
  2482. g_palletAtLevel.splice(atLevelIdx, 1);
  2483. }
  2484. else {
  2485. g_palletAtLevel[atLevelIdx].weight = value1
  2486. }
  2487. }
  2488. else {
  2489. g_palletAtLevel.push({
  2490. idx: palletIdx,
  2491. height: value2,
  2492. weight: value1
  2493. });
  2494. }
  2495. updateRackingAtLevel(false);
  2496. Behavior.add(Behavior.type.palletWeight);
  2497. }
  2498. }
  2499. function updateRackingAtLevel(updateProps = true) {
  2500. if (updateProps) {
  2501. updateRackingHighLevel();
  2502. updateSelectedIcube();
  2503. }
  2504. else {
  2505. if (selectedIcube) {
  2506. selectedIcube.palletAtLevel = g_palletAtLevel;
  2507. }
  2508. }
  2509. }
  2510. $('#spacing_b_rows').on("change", function (event) {
  2511. g_spacingBetweenRows = parseFloat(event.target.value);
  2512. if (selectedIcube) {
  2513. selectedIcube.updateDistanceBetweenRows();
  2514. selectedIcube.getEstimationPrice();
  2515. }
  2516. });
  2517. $('#start_sim').on("click", function () {
  2518. if (simulation) {
  2519. updateSimulation(simulation);
  2520. const carrierList = document.getElementById('carriersHolder');
  2521. carrierList.childNodes.forEach(function (carrier) {
  2522. carrier.removeChild(carrier.childNodes[0]);
  2523. });
  2524. simulation.remove();
  2525. simulation = null;
  2526. $(this).text('Start');
  2527. $('#pause_sim').hide();
  2528. }
  2529. else {
  2530. document.getElementById("liftsHolder").innerHTML = '';
  2531. document.getElementById("carriersHolder").innerHTML = '';
  2532. simulation = new Simulation({
  2533. input : parseInt(document.querySelector('input[id="simIn"]').value),
  2534. output : parseInt(document.querySelector('input[id="simOut"]').value),
  2535. //mixed : (document.querySelector('input[name="simMixed"]:checked') ? true : false),
  2536. process : parseInt(document.querySelector('select[name="simProces"]').value),
  2537. strategy : parseInt(document.querySelector('select[name="simStrat"]').value),
  2538. multiply : parseInt(document.querySelector('select[name="simSpeed"]').value),
  2539. liftAssign: parseInt(document.querySelector('select[name="simLiftA"]').value),
  2540. sharePath : (document.querySelector('input[name="simHandoff"]:checked') ? true : false),
  2541. isReply : false,
  2542. onEnd: () => {
  2543. // console.log('done');
  2544. tracking(15);
  2545. endSimulation();
  2546. }
  2547. });
  2548. if (simulation.error !== '') {
  2549. simulation.remove();
  2550. simulation = null;
  2551. }
  2552. else {
  2553. tracking(14);
  2554. Behavior.add(Behavior.type.playAnimation);
  2555. saveSimulation(simulation);
  2556. $(this).text('Stop');
  2557. $('#pause_sim').text('Pause').show();
  2558. }
  2559. }
  2560. });
  2561. $('select[name="simSpeed"]').on("change", function () {
  2562. if (simulation)
  2563. simulation.multiply = parseInt($(this)[0].value);
  2564. });
  2565. $('#pause_sim').on("click", function () {
  2566. if (simulation.isPlaying) {
  2567. simulation.pause();
  2568. $(this).text('Resume');
  2569. }
  2570. else {
  2571. simulation.resume();
  2572. $(this).text('Pause');
  2573. }
  2574. });
  2575. $('#simMultipleView').on("change", function () {
  2576. g_simMultipleView = $(this).is(":checked");
  2577. toggleMultipleView();
  2578. });
  2579. $('#addPriceRow').on("click", function () {
  2580. if (!$('#extraPriceTable')[0]) {
  2581. const tab = `<table id="extraPriceTable" class="table itemTable table-responsive-lg table-bordered table-striped table-sm mb-0" style="margin-top: 10px;">
  2582. <colgroup>
  2583. <col width="30%">
  2584. <col width="8%">
  2585. <col width="10%">
  2586. <col width="3%">
  2587. </colgroup>
  2588. <tbody></tbody>
  2589. </table>`;
  2590. document.getElementById("extraPriceHolder").innerHTML = tab;
  2591. }
  2592. const info =`<tr id="extraP_` + extraPrice.length + `">
  2593. <td><input class="epName" type="text" style="width:100%" /></td>
  2594. <td><input class="epQuantity" type="number" style="width:100%;text-align:right" value="0" /></td>
  2595. <td><input class="epValue" type="number" style="width:100%;text-align:right" value="0" /></td>
  2596. <td><button style="width:100%;font-size:10px;padding:0" onclick="saveExtraPrice(` + extraPrice.length + `)">Save</button></td>
  2597. </tr>`;
  2598. $('#extraPriceTable tbody').append(info);
  2599. });
  2600. function updateExtraPriceTable() {
  2601. let price = 0;
  2602. $("#extraPriceHolder").html('');
  2603. if (Array.isArray(extraPrice) && extraPrice.length > 0) {
  2604. if (!$('#extraPriceTable')[0]) {
  2605. const tab = `<table id="extraPriceTable" class="table itemTable table-responsive-lg table-bordered table-striped table-sm mb-0" style="margin-top: 10px;">
  2606. <colgroup>
  2607. <col width="30%">
  2608. <col width="8%">
  2609. <col width="10%">
  2610. <col width="1%">
  2611. </colgroup>
  2612. <tbody></tbody>
  2613. </table>`;
  2614. document.getElementById("extraPriceHolder").innerHTML = tab;
  2615. }
  2616. extraPrice.forEach((extra, idx) => {
  2617. price += parseFloat(extra.quantity) * parseFloat(extra.value);
  2618. const info =`<tr id="extraP_` + idx + `">
  2619. <td class="epName">` + extra.name + `</td>
  2620. <td class="epQuantity" style="text-align:right">` + formatIntNumber(extra.quantity) + `</td>
  2621. <td class="epValue" style="text-align:right">€` + formatIntNumber(extra.value) + `</td>
  2622. <td style="text-align:right"><i class="fa fa-trash" title="Delete custom row" onclick="deleteExtraPrice(` + idx + `)"></i></td>
  2623. </tr>`;
  2624. $('#extraPriceTable tbody').append(info);
  2625. });
  2626. }
  2627. return price;
  2628. }
  2629. function saveExtraPrice (idx) {
  2630. const name = $("#extraP_" + idx + " > td > .epName")[0].value
  2631. const qty = $("#extraP_" + idx + " > td > .epQuantity")[0].value
  2632. const val = $("#extraP_" + idx + " > td > .epValue")[0].value
  2633. extraPrice.push({
  2634. name: name,
  2635. quantity: qty,
  2636. value: val
  2637. });
  2638. tracking(42);
  2639. saveProject(() => {
  2640. if (selectedIcube !== null) {
  2641. selectedIcube.getEstimationPrice();
  2642. }
  2643. });
  2644. }
  2645. function deleteExtraPrice (idx) {
  2646. extraPrice.splice(idx, 1);
  2647. tracking(43);
  2648. saveProject(() => {
  2649. if (selectedIcube !== null) {
  2650. selectedIcube.getEstimationPrice();
  2651. }
  2652. });
  2653. }
  2654. $("#viewer2d_it").on("click", function () {
  2655. const doc = document.getElementById('itHelper');
  2656. const canvas = $("#itHelper > canvas")[0];
  2657. if (doc.style.display === "none") {
  2658. doc.style.display = "block";
  2659. if (it3DEngine) {
  2660. it3DEngine.dispose();
  2661. it3DEngine = null;
  2662. }
  2663. it2DEngine = create2DViewerIt(canvas);
  2664. }
  2665. else {
  2666. doc.style.display = "none";
  2667. if (it2DEngine) {
  2668. it2DEngine.dispose();
  2669. it2DEngine = null;
  2670. }
  2671. }
  2672. });
  2673. $("#viewer3d_it").on("click", function () {
  2674. const doc = document.getElementById('itHelper');
  2675. const canvas = $("#itHelper > canvas")[0];
  2676. if (doc.style.display === "none") {
  2677. doc.style.display = "block";
  2678. if (it2DEngine) {
  2679. it2DEngine.dispose();
  2680. it2DEngine = null;
  2681. }
  2682. it3DEngine = create3DViewerIt(canvas);
  2683. }
  2684. else {
  2685. doc.style.display = "none";
  2686. if (it3DEngine) {
  2687. it3DEngine.dispose();
  2688. it3DEngine = null;
  2689. }
  2690. }
  2691. });
  2692. $('#submit-rating-btn').on("click", function () {
  2693. const stars = $('input[name=rating_star]:checked').val();
  2694. if (isNaN(parseFloat(stars))) {
  2695. $(this).parent().append('<p>Please choose a rating star</p>');
  2696. setTimeout(() => {
  2697. const list = document.getElementById("submit-rating-btn").parentNode;
  2698. list.removeChild(list.lastChild);
  2699. }, 2000);
  2700. return;
  2701. }
  2702. const comm = $('#rating_comment').val();
  2703. const agent = $('#rating_agent').is(":checked");
  2704. let data = {
  2705. stars: stars,
  2706. comm: comm,
  2707. agent: agent,
  2708. complete: 1
  2709. }
  2710. Utils.request(g_BasePath + 'home/rating', 'POST', data, () => {
  2711. Utils.logg('Feedback successfully sent!','success');
  2712. hideModal('rating-modal');
  2713. }, () => {
  2714. alert("Feedback Failed! Try again later.");
  2715. });
  2716. });
  2717. $('#manualItem-placeholder').on("change", function () {
  2718. $('#placeholder_data').toggle();
  2719. });
  2720. $('#add-placeholder').on("click", function () {
  2721. let maxKey = manualItemInfo.indexOf(manualItemInfo[manualItemInfo.length - 1]);
  2722. if (maxKey < 1000)
  2723. maxKey = 1000;
  2724. else
  2725. maxKey = maxKey + 1;
  2726. createFakeManualItem({
  2727. type: maxKey,
  2728. name: $('#machine_name').val(),
  2729. width: parseFloat($('#machine_width').val()),
  2730. length: parseFloat($('#machine_length').val()),
  2731. height: parseFloat($('#machine_height').val()),
  2732. colors: $('#machine_color').val(),
  2733. atDist: parseFloat($('#machine_atDist').val())
  2734. });
  2735. clickManualItem(maxKey);
  2736. });
  2737. function createFakeManualItem (params) {
  2738. const itemInfo = {
  2739. display: params.name, name: params.name, type: params.type, direction: ITEMDIRECTION.bottom, multiply: (params.length + 0.2),
  2740. width: params.width, length: params.length, height: params.height, meshData: [], originMesh: null, colors: params.colors, atDist: params.atDist
  2741. }
  2742. let faceUV = new Array(6);
  2743. for (let i = 0; i < 6; i++) {
  2744. faceUV[i] = new BABYLON.Vector4(0, 0, 0, 0);
  2745. }
  2746. faceUV[4] = new BABYLON.Vector4(0, 0, 1, 1);
  2747. const placeholder = BABYLON.MeshBuilder.CreateBox(itemInfo.display, {height: 1, width: 1, depth: 1, faceUV: faceUV }, scene);
  2748. placeholder.position.y = 1 / 2;
  2749. placeholder.bakeCurrentTransformIntoVertices();
  2750. placeholder.setEnabled(false);
  2751. placeholder.isPickable = false;
  2752. placeholder.scaling = new BABYLON.Vector3(itemInfo.width, itemInfo.height, itemInfo.length);
  2753. placeholder.freezeWorldMatrix();
  2754. const DTWidth = itemInfo.width * 120;
  2755. const DTHeight = itemInfo.length * 120;
  2756. const albedoText = new BABYLON.DynamicTexture("dynamic texture", { width: DTHeight, height: DTWidth }, scene, false);
  2757. const ctx = albedoText.getContext();
  2758. const size = 12;
  2759. ctx.font = size + "px Arial";
  2760. const textWidth = ctx.measureText(itemInfo.display).width;
  2761. const ratio = textWidth / size;
  2762. let font_size = Math.floor(Math.min(DTWidth, DTHeight) / ratio);
  2763. font_size = font_size < 100 ? font_size : font_size / 2;
  2764. const font = parseInt(font_size) + "px Arial";
  2765. albedoText.drawText(itemInfo.display, null, null, font, "white", itemInfo.colors);
  2766. const placeholderM = new BABYLON.PBRMaterial("placeholderM", scene);
  2767. placeholderM.albedoTexture = albedoText;
  2768. placeholderM.alpha = 0.5;
  2769. placeholderM.roughness = 1;
  2770. placeholderM.freeze();
  2771. placeholder.material = placeholderM;
  2772. itemInfo.originMesh = placeholder;
  2773. manualItemInfo[params.type] = itemInfo;
  2774. }
  2775. $('#add-people').on("click", function () {
  2776. clickManualItem(899);
  2777. });
  2778. $('.fa-question-circle').on("mouseenter", function () {
  2779. document.getElementById($(this)[0].dataset.info).style.display = 'block';
  2780. }).on("mouseout", function () {
  2781. document.getElementById($(this)[0].dataset.info).style.display = 'none';
  2782. });
  2783. $('#add-pdfPage').on("click", function () {
  2784. const items = `
  2785. <div class="form-group mb10" style="text-align:center;">
  2786. <label class="col-sm-1 control-label padding-no labelpad">` + parseInt(custompPdf.length + 1) + `</label>
  2787. <input class="col-sm-5 form-control" style="width:41%;" type="text" placeholder="Title" value="" onchange="addTitleToPage(this, ` + custompPdf.length + `)">
  2788. <button class="icube-tool btn btn-primary col-sm-5" onclick="addScreenToPage(this, ` + custompPdf.length + `)">Add image</button>
  2789. <label class="col-sm-1 control-label padding-no labelpad" style="text-align:center;cursor:pointer;" onclick=removeFromPage(` + custompPdf.length + `)><i class="el fa fa-trash" href="#"></i></label>
  2790. </div>`;
  2791. $('#pdfPages').append(items);
  2792. custompPdf.push({ title: '', image: '' });
  2793. });
  2794. $('#gen-pdf').on("click", function () {
  2795. $('#waiting').show('fast', () => {
  2796. Export_PDF.generateCustomFile();
  2797. tracking(39);
  2798. });
  2799. });
  2800. function addTitleToPage (elem, page) {
  2801. custompPdf[page].title = $(elem).val();
  2802. }
  2803. function addScreenToPage (elem, page) {
  2804. scene.render();
  2805. BABYLON.Tools.CreateScreenshot(scene.getEngine(), scene.activeCamera, { width: 1440, height: 870 }, function (data) {
  2806. custompPdf[page].image = data;
  2807. renderScene();
  2808. $(elem).html('Add image <i class="el fa fa-check"></i>');
  2809. });
  2810. }
  2811. function removeFromPage (page) {
  2812. custompPdf.splice(page, 1);
  2813. $('#pdfPages').html('');
  2814. for (let i = 0; i < custompPdf.length; i++) {
  2815. const items = `
  2816. <div class="form-group mb10" style="text-align:center;">
  2817. <label class="col-sm-1 control-label padding-no labelpad">` + parseInt(i + 1) + `</label>
  2818. <input class="col-sm-5 form-control" style="width:41%;" type="text" placeholder="Title" onchange="addTitleToPage(this, ` + i + `)" value="` + custompPdf[i].title + `">
  2819. <button class="icube-tool btn btn-primary col-sm-5" onclick="addScreenToPage(this, ` + i + `)">Add image ` + (custompPdf[i].image !== '' ? `<i class="el fa fa-check"></i>` : ``) + `</button>
  2820. <label class="col-sm-1 control-label padding-no labelpad" style="text-align:center;cursor:pointer;" onclick=removeFromPage(` + i + `)><i class="el fa fa-trash" href="#"></i></label>
  2821. </div>`;
  2822. $('#pdfPages').append(items);
  2823. }
  2824. }
  2825. $('#add-measurement').on("click", function () {
  2826. g_measureEnabled = !g_measureEnabled;
  2827. clickableItems(!g_measureEnabled);
  2828. });
  2829. $('#settingsModeS1').on("click", function () {
  2830. $('#advancedSettings01').hide();
  2831. $('#advancedSettings11').hide();
  2832. $('#advancedSettings12').hide();
  2833. $('#simpleSettings12').show();
  2834. if ($('#lastLSetting').is(':visible')) {
  2835. $('#customLastRow').trigger('click');
  2836. }
  2837. $('#customLastRow').attr('disabled', true);
  2838. if (!$(this).hasClass('active-icube-setting')) {
  2839. $(this).addClass('active-icube-setting');
  2840. }
  2841. if ($("#settingsModeA1").hasClass('active-icube-setting')) {
  2842. $("#settingsModeA1").removeClass('active-icube-setting');
  2843. }
  2844. if (!$('#settingsModeS2').hasClass('active-icube-setting')) {
  2845. $('#settingsModeS2').trigger('click');
  2846. }
  2847. });
  2848. $('#settingsModeA1').on("click", function () {
  2849. $('#advancedSettings01').show();
  2850. $('#advancedSettings11').show();
  2851. $('#advancedSettings12').show();
  2852. $('#simpleSettings12').hide();
  2853. $('#customLastRow').attr('disabled', false);
  2854. if (!$(this).hasClass('active-icube-setting')) {
  2855. $(this).addClass('active-icube-setting');
  2856. }
  2857. if ($("#settingsModeS1").hasClass('active-icube-setting')) {
  2858. $("#settingsModeS1").removeClass('active-icube-setting');
  2859. }
  2860. if (!$('#settingsModeA2').hasClass('active-icube-setting')) {
  2861. $('#settingsModeA2').trigger('click');
  2862. }
  2863. });
  2864. $('#settingsModeS2').on("click", function () {
  2865. $('#advancedSettings22').hide();
  2866. $('#set-icube-charger').hide();
  2867. $('#set-icube-liftpreloading').hide();
  2868. if (!$(this).hasClass('active-icube-setting')) {
  2869. $(this).addClass('active-icube-setting');
  2870. }
  2871. if ($("#settingsModeA2").hasClass('active-icube-setting')) {
  2872. $("#settingsModeA2").removeClass('active-icube-setting');
  2873. }
  2874. if (!$('#settingsModeS1').hasClass('active-icube-setting')) {
  2875. $('#settingsModeS1').trigger('click');
  2876. }
  2877. });
  2878. $('#settingsModeA2').on("click", function () {
  2879. $('#advancedSettings22').show();
  2880. $('#set-icube-charger').show();
  2881. $('#set-icube-liftpreloading').show();
  2882. if (!$(this).hasClass('active-icube-setting')) {
  2883. $(this).addClass('active-icube-setting');
  2884. }
  2885. if ($("#settingsModeS2").hasClass('active-icube-setting')) {
  2886. $("#settingsModeS2").removeClass('active-icube-setting');
  2887. }
  2888. if (!$('#settingsModeA1').hasClass('active-icube-setting')) {
  2889. $('#settingsModeA1').trigger('click');
  2890. }
  2891. });
  2892. $('#palletSize').on("click", function () {
  2893. $('.palletSizeList').toggle();
  2894. });
  2895. $(".palletSizeList li").on("click", function() {
  2896. tracking(41);
  2897. $(this).parent().hide();
  2898. const colors = ['#3bf582','#fc3f3f','#d2fa41'];
  2899. $('#palletSize > span').css('color', colors[$(this).index()]);
  2900. $('#palletSize > label').html($(this).children('label').text());
  2901. updateDistrPallet($(this).index(), 100);
  2902. });
  2903. $('#searchProject').on("keyup", function (e) {
  2904. const value = e.target.value;
  2905. $('.list-group').children().show();
  2906. if (value === '') return;
  2907. $('.list-group').children().filter(function() {
  2908. return $(this)[0].children[0].innerHTML.toLowerCase().indexOf(value.toLowerCase()) === -1;
  2909. }).hide();
  2910. });
  2911. $("#optimizeRacking").on("click", function() {
  2912. if (selectedIcube)
  2913. selectedIcube.optimizeRacking();
  2914. tracking(34);
  2915. });
  2916. $('.dupl').on("click", function () {
  2917. const key = parseInt($(this).attr("control"));
  2918. if (key === 5) {
  2919. $('#duplicate-tab').hide();
  2920. }
  2921. else {
  2922. if (key === 4) {
  2923. multiplyIcube();
  2924. $('#duplicate-tab').hide();
  2925. }
  2926. else {
  2927. duplData[1] = key;
  2928. $('.dupl').css('color', '#ffffff');
  2929. $(this).css('color', '#333333');
  2930. }
  2931. }
  2932. });
  2933. $('.dupl2').on("click", function () {
  2934. const key = parseInt($(this).attr("control"));
  2935. duplData[3] = key === 6 ? true : false;
  2936. $('.dupl2').css('color', '#ffffff');
  2937. $(this).css('color', '#333333');
  2938. });
  2939. $('#dupl_distance').on("change", function () {
  2940. duplData[0] = parseFloat(event.target.value);
  2941. });
  2942. $('input[name="optimize"]').on("change", function (event) {
  2943. g_optimizeDirectTL = !!parseInt(event.target.value);
  2944. });
  2945. $('#revisions').on("click", function () {
  2946. $('#revisions_list').toggle();
  2947. });
  2948. function getRevisions(data, index = -1) {
  2949. Utils.request(g_BasePath + 'home/getRevisions', 'POST', data, (data) => {
  2950. revisions = data;
  2951. $('#revisions_list').html('');
  2952. if (data.length > 0) {
  2953. for (let i = 0; i < data.length; i++) {
  2954. let div = ``, clas = ``;
  2955. if (index !== -1) {
  2956. if (i === index) clas = `btn-primary`;
  2957. }
  2958. else {
  2959. if (i === data.length - 1) clas = `btn-primary`;
  2960. }
  2961. if (i === data.length - 1) {
  2962. div = `
  2963. <div class="price_rev ` + clas + `" style="display:inline-flex;">
  2964. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2965. <span onclick="loadVersion(` + i + `)" title="` + data[i].saved_time + `" style="overflow:hidden;min-width:150px;">` + documentName + ` - Latest</span>
  2966. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2967. </div>`;
  2968. }
  2969. else {
  2970. div = `
  2971. <div class="price_rev ` + clas + `" style="display:inline-flex;">
  2972. <i class="fa fa-pencil" onclick="editRevisionName(this)" title="Rename" style="line-height:24px;"></i>
  2973. &nbsp;&nbsp;
  2974. <span onclick="loadVersion(` + i + `)" title="` + data[i].saved_time + `" style="overflow:hidden;min-width:150px;">` + data[i].name + `</span>
  2975. <input class="price_rev_input hide" value="` + data[i].name + `" onchange="updateVersionName(this, ` + i + `)" onfocusout="cancelRevisionEdit(this)" />
  2976. &nbsp;&nbsp;
  2977. <i class="fa fa-times" onclick="deleteVersion(` + i + `)" title="Delete" style="line-height:24px;"></i>
  2978. </div>`;
  2979. }
  2980. $('#revisions_list').append(div);
  2981. }
  2982. }
  2983. else {
  2984. $('#revisions_list').append('<div style="padding: 5px;">No previous versions</div>');
  2985. }
  2986. }, null);
  2987. }
  2988. function updateVersionName(elem, versionIdx) {
  2989. cancelRevisionEdit(elem);
  2990. $(elem).prev().html($(elem).val());
  2991. Utils.request(g_BasePath + 'home/renameVersion', 'POST', {
  2992. saved_time: revisions[versionIdx].saved_time,
  2993. name: $(elem).val()
  2994. });
  2995. }
  2996. function deleteVersion(versionIdx) {
  2997. $('#revisions_list').children().eq(versionIdx).remove();
  2998. Utils.request(g_BasePath + 'home/deleteVersion', 'POST', {
  2999. saved_time: revisions[versionIdx].saved_time
  3000. }, () => {
  3001. let data = {
  3002. document_name: documentName
  3003. }
  3004. if (documentInfo > 0) {
  3005. data = Object.assign({}, data, { slid : documentInfo });
  3006. }
  3007. loadVersion(revisions.length - 2);
  3008. });
  3009. }
  3010. function loadVersion(versionIdx) {
  3011. const docData = JSON.parse(revisions[versionIdx].documentData);
  3012. let icubeData = JSON.parse(revisions[versionIdx].icubeData);
  3013. if (!icubeData || !Array.isArray(icubeData)) icubeData = [];
  3014. icubeData.forEach((icube) => {
  3015. for (key in icube) {
  3016. if (!['name', 'uid'].includes(key)) {
  3017. icube[key] = JSON.parse(icube[key]);
  3018. }
  3019. }
  3020. });
  3021. const data = {
  3022. extraInfo : JSON.parse(docData.extraInfo),
  3023. extraPrice : JSON.parse(docData.extraPrice),
  3024. measurements : JSON.parse(docData.measurements),
  3025. custom_values : JSON.parse(docData.custom_values),
  3026. documentInfo : (isEditByAdmin) ? documentInfo : "",
  3027. document_name : revisions[versionIdx].document_name,
  3028. itemMData : JSON.parse(docData.itemMData),
  3029. layoutMap : JSON.parse(docData.layoutMap),
  3030. unit_measurement : JSON.parse(docData.unit_measurement),
  3031. warehouse_dimensions: JSON.parse(docData.warehouse_dimensions),
  3032. icubeData : icubeData
  3033. }
  3034. setProject(data, true, versionIdx);
  3035. if (versionIdx < revisions.length - 1) {
  3036. $('#project-name').html((revisions[versionIdx].hasOwnProperty('name') ? revisions[versionIdx].name : documentName));
  3037. }
  3038. }
  3039. function editRevisionName(elem) {
  3040. $(elem).next().addClass('hide');
  3041. $(elem).next().next().removeClass('hide').focus();
  3042. }
  3043. function cancelRevisionEdit(elem) {
  3044. $(elem).addClass('hide');
  3045. $(elem).prev().removeClass('hide');
  3046. }
  3047. $("#newProject").on("click", function () {
  3048. $(".new-modal-close").hide();
  3049. showModal("new-modal");
  3050. hideModal("hello-modal");
  3051. g_tutorialIsRunning = false;
  3052. });
  3053. $("#loadProject").on("click", function () {
  3054. getProjectList(function (datas) {
  3055. $(".load-modal-close").hide();
  3056. createProjectList(datas);
  3057. hideModal("hello-modal");
  3058. g_tutorialIsRunning = false;
  3059. });
  3060. });
  3061. $(".checkbox-dropdown").on("click", function () {
  3062. $(this).toggleClass("is-active");
  3063. });
  3064. $(".checkbox-dropdown ul").on("click", function (e) {
  3065. e.stopPropagation();
  3066. });
  3067. $("#send_report").on("click", function () {
  3068. showModal("report-modal");
  3069. });
  3070. $(".report-modal-close").on("click", function () {
  3071. hideModal("report-modal");
  3072. });
  3073. $('.report-modal-confirm').on("click", async function () {
  3074. const formData = new FormData();
  3075. formData.append("documentName", documentName);
  3076. formData.append("name", $("#reportName").val());
  3077. formData.append("description", $("#reportDesc").val());
  3078. const image = await BABYLON.Tools.CreateScreenshotAsync(scene.getEngine(), scene.activeCamera, { width: 1600, height: 1000 });
  3079. formData.append("screenshot", image);
  3080. for (let i = 0; i < $("#reportFile")[0].files.length; i++) {
  3081. formData.append("file_" + i, $("#reportFile")[0].files[i]);
  3082. }
  3083. Utils.requestFormData(g_BasePath + "home/saveReport", "POST", formData);
  3084. Utils.logg("Bug report sent!", "success");
  3085. hideModal("report-modal");
  3086. });
  3087. $("#configVariables").on("click", function () {
  3088. if (custom_values[0] && custom_values[0] !== -1) {
  3089. $("#var_palletWidth").val(custom_values[0]);
  3090. }
  3091. if (custom_values[1] && custom_values[1] !== -1) {
  3092. $("#var_palletLength").val(custom_values[1]);
  3093. }
  3094. if (custom_values[2] && custom_values[2] !== -1) {
  3095. $("#var_palletOverhang").val(custom_values[2]);
  3096. }
  3097. if (custom_values[3] && custom_values[3] !== -1) {
  3098. $("#var_railHeight").val(custom_values[3]);
  3099. }
  3100. if (custom_values[4] && custom_values[4] !== -1) {
  3101. $("#var_distToXtrack").val(custom_values[4]);
  3102. }
  3103. if (custom_values[5] && custom_values[5] !== -1) {
  3104. $("#var_distToMargin").val(custom_values[5]);
  3105. }
  3106. if (custom_values[6] && custom_values[6] !== -1) {
  3107. $("#var_distTo1stStore").val(custom_values[6]);
  3108. }
  3109. if (custom_values[7] && custom_values[7] !== -1) {
  3110. $("#var_distToNextStore").val(custom_values[7]);
  3111. }
  3112. showModal("configVariables-modal");
  3113. });
  3114. $(".configVariables-modal-close").on("click", function () {
  3115. hideModal("configVariables-modal");
  3116. });
  3117. $(".configVariables-modal-confirm").on("click", function () {
  3118. const var_distToNextStore= parseFloat($("#var_distToNextStore").val());
  3119. const var_distTo1stStore = parseFloat($("#var_distTo1stStore").val());
  3120. const var_distToMargin = parseFloat($("#var_distToMargin").val());
  3121. const var_distToXtrack = parseFloat($("#var_distToXtrack").val());
  3122. const var_railHeight = parseFloat($("#var_railHeight").val());
  3123. const var_palletOverhang = parseFloat($("#var_palletOverhang").val());
  3124. const var_palletLength = parseFloat($("#var_palletLength").val());
  3125. const var_palletWidth = parseFloat($("#var_palletWidth").val());
  3126. custom_values = [
  3127. isNaN(var_palletWidth) ? -1 : var_palletWidth,
  3128. isNaN(var_palletLength) ? -1 : var_palletLength,
  3129. isNaN(var_palletOverhang) ? -1 : var_palletOverhang,
  3130. isNaN(var_railHeight) ? -1 : var_railHeight,
  3131. isNaN(var_distToXtrack) ? -1 : var_distToXtrack,
  3132. isNaN(var_distToMargin) ? -1 : var_distToMargin,
  3133. isNaN(var_distTo1stStore) ? -1 : var_distTo1stStore,
  3134. isNaN(var_distToNextStore)? -1 : var_distToNextStore
  3135. ];
  3136. updateConfigVariables();
  3137. hideModal("configVariables-modal");
  3138. $('#customValue').html(custom_values.length > 0 ? `<b>⚠ This project contains custom values ⚠</b>` : ``);
  3139. });
  3140. function updateConfigVariables() {
  3141. const palletIdx = g_palletInfo.max;
  3142. const sum = custom_values.filter(e => e === -1);
  3143. if (sum.length === custom_values.length) {
  3144. custom_values = [];
  3145. }
  3146. resetConfigVariables();
  3147. if (custom_values[0] && custom_values[0] > 800 && custom_values[0] < 1400) {
  3148. g_PalletW[palletIdx] = useP(custom_values[0], false);
  3149. }
  3150. if (custom_values[1] && custom_values[1] > 1000 && custom_values[1] < 1400) {
  3151. g_PalletH[palletIdx] = useP(custom_values[1], false);
  3152. }
  3153. if (custom_values[2] && custom_values[2] >= 0 && custom_values[2] <= 200) {
  3154. g_palletOverhang = parseFloat((custom_values[2] / 1000).toFixed(4));
  3155. }
  3156. if (custom_values[3] && custom_values[3] >= 0 && custom_values[3] <= 1000) {
  3157. g_railHeight = useP(custom_values[3], false);
  3158. }
  3159. if (custom_values[4] && custom_values[4] >= 0 && custom_values[4] <= 500) {
  3160. g_difftoXtrack[palletIdx] = useP(custom_values[4], false);
  3161. }
  3162. if (custom_values[5] && custom_values[5] >= 0 && custom_values[5] <= 500) {
  3163. g_diffToEnd[palletIdx] = useP(custom_values[5], false);
  3164. g_railOutside = g_diffToEnd[palletIdx];
  3165. }
  3166. if (custom_values[6] && custom_values[6] >= 0 && custom_values[6] <= 500) {
  3167. g_bottomLength = useP(custom_values[6], false);
  3168. }
  3169. if (custom_values[7] && custom_values[7] >= 0 && custom_values[7] <= 500) {
  3170. g_StoreTopGap = useP(custom_values[7], false);
  3171. }
  3172. g_palletInfo.type = g_palletInfo.value;
  3173. updateSelectedIcube();
  3174. }
  3175. function resetConfigVariables() {
  3176. g_PalletW = [0.8, 1, 1.2];
  3177. g_PalletH = [1.2, 1.2, 1.2];
  3178. g_palletOverhang = 0.05;
  3179. g_difftoXtrack = [0.15, 0.05, 0.05];
  3180. g_diffToEnd = [0.175, 0.175, 0.175];
  3181. g_railOutside = 0.175;
  3182. g_railHeight = 0.38;
  3183. g_bottomLength = 0.27;
  3184. g_StoreTopGap = 0;
  3185. g_palletInfo.type = g_palletInfo.value;
  3186. }