Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

app copy.js 82KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034
  1. var routerTimeout = 50000; //See router.js; (TODO)
  2. var apyKey = '';
  3. var ajaxRunning = false;
  4. var ajaxRef = null;
  5. var homeHash = 'dashboard';
  6. var rtl = false;
  7. var appWebSocket;
  8. var wsData = null;
  9. var wsConnectionCounter = 0;
  10. var wsRequestDataDreamPDF = null;
  11. //Reset to refresh
  12. var gobalUpload = null;
  13. var globalUploadInProgress = false;
  14. var globalUploadList = [];
  15. var globalUploadCounter = 0;
  16. var globalUploadTimeout = null;
  17. var gloabalUploadErrorHandling = false;
  18. var globalICD10List = [];
  19. //TODO: delete
  20. var globalUploadInterval = null;
  21. var globalUploadBytesPerItem = 0;
  22. var apiKeyElement = document.getElementById('api-key');
  23. if (apiKeyElement !== null) {
  24. apyKey = document.getElementById('api-key').value;
  25. }
  26. window.addEventListener('online', function() {
  27. $('#tm-status-label').html('Online');
  28. });
  29. window.addEventListener('offline', function() {
  30. $('#tm-status-label').html('Offline');
  31. });
  32. /*window.onbeforeunload = function() {
  33. return "";
  34. }*/
  35. $(document).ready(function () {
  36. resizeTranfer();
  37. //Timer event listener
  38. setInterval(function() {
  39. //Start: Patient age
  40. if($('.check-birth-type').length > 0) {
  41. var ageType = $('.check-birth-type:checked').val();
  42. if (ageType == 'date') {
  43. var dateYear = parseInt($('#request_birth_year').val());
  44. var dateMonth = parseInt($('#request_birth_month').val());
  45. var dateDay = parseInt($('#request_birth_month_day').val());
  46. var dateNow = new Date();
  47. var dateNowYear = dateNow.getFullYear();
  48. var dateNowMonth = dateNow.getMonth();
  49. var dateNowDay = dateNow.getDate();
  50. var age = dateNowYear - dateYear;
  51. var ageTime = glbYearsLabel;
  52. var ageString = '';
  53. if (dateYear == 0 || dateMonth == 0 || dateDay == 0) {
  54. $('#calculated-age-number').empty();
  55. return;
  56. }
  57. if (dateNowMonth < (dateMonth - 1)) {
  58. age--;
  59. }
  60. if (((dateMonth - 1) == dateNowMonth) && (dateNowDay < dateDay)) {
  61. age--;
  62. }
  63. if (age == 0) {
  64. if (dateNowMonth > dateMonth) {
  65. age = dateNowMonth - dateMonth;
  66. } else {
  67. age = dateMonth - dateNowMonth;
  68. }
  69. if (dateYear == dateNowYear) {
  70. age = dateNowMonth - dateMonth;
  71. } else {
  72. age = (12-dateMonth)+dateNowMonth;
  73. }
  74. ageTime = glbMonthsLabel;
  75. }
  76. if (age > 0) {
  77. ageString = age+' '+ageTime.toLowerCase().substr(0, 1);
  78. } else {
  79. ageString = '';
  80. }
  81. $('#calculated-age-number').html(ageString);
  82. } else {
  83. $('#calculated-age-number').empty();
  84. }
  85. }
  86. //End: Patient age
  87. }, 100);
  88. });
  89. $(window).resize(function() {
  90. resizeTranfer();
  91. });
  92. $(document)
  93. .on('click', 'a', function(e) {
  94. e.preventDefault();
  95. var href = $(this).attr('href');
  96. if ($(this).hasClass('external')) {
  97. var target = $(this).attr('target');
  98. if (target == '_blank') {
  99. open(href);
  100. } else {
  101. document.location.href = href;
  102. }
  103. return false;
  104. }
  105. if ($(this).hasClass('prevent-default')) {
  106. return false;
  107. }
  108. if ($(this).hasClass('download')) {
  109. var forceDownload = parseInt($(this).data('forcedownload'));
  110. if (forceDownload == 1) {
  111. document.location.href = href;
  112. }
  113. return false;
  114. }
  115. //Typically an AJAX link (or link without href)
  116. if (href == '#' || typeof href === 'undefined') return false;
  117. if (!isOnline()) {
  118. showMessage(glbAppOffline);
  119. } else {
  120. window.location.hash = href;
  121. return false;
  122. }
  123. })
  124. .on('click', '.btn-run-process', function() {
  125. //var processPath = $(this).data('processpath');
  126. //L'elmento process-path si trova nell'element wizard-oto (è una modale)
  127. if ($('#process-path').length > 0) {
  128. var processPath = $('#process-path').val();
  129. showConfirmCancel(glbAppTitle, glbRunProcess, function() {
  130. wsSend(JSON.stringify({op:"run-process", processpath:processPath}), true);
  131. });
  132. }
  133. })
  134. //Login / Logout
  135. .on('submit', '#form-login', function () {
  136. request('/api/login/access', $(this).serialize(), function(ret) {
  137. //gotoDest('success-login');
  138. showLoader();
  139. document.location.href = '/dashboard-redirect';
  140. //loadGlobalVariables();
  141. });
  142. return false;
  143. })
  144. //Logout in nav bar (user menu)
  145. .on('click', '.btn-logout', function(e) {
  146. e.preventDefault();
  147. showConfirmCancel('Log out', glbLogoutMsg, function() {
  148. request('/api/login/logout', {}, function(ret) {
  149. showLoader();
  150. //Reset Upload Manager
  151. hideTranfer();
  152. //gotoDest();
  153. document.location.href = '/';
  154. });
  155. });
  156. })
  157. .on('click', '.btn-recovery-password', function() {
  158. $('#recovery_email').removeClass('is-invalid');
  159. $('#recovery_email').val('');
  160. $('.recovery-password-form').show();
  161. $('.btn-send-temporary-password').show();
  162. $('.recovery-password-done-msg').hide();
  163. $('#password-recovery-dialog').modal();
  164. })
  165. .on('click', '.btn-edit-survey', function(e) {
  166. e.preventDefault();
  167. var data = $('#survey-form-edit').serialize();
  168. request('/api/survey/surveySave', data,
  169. function(ret) {
  170. console.log('send data', ret.data);
  171. showMessage(ret.msg, ret.jsArgs);
  172. }, function(ret) {
  173. showMessage(ret.msg, ret.jsArgs);
  174. if (typeof ret.class !== 'undefined')
  175. $('.'+ret.class).addClass('is-invalid');
  176. if (typeof ret.log !== 'undefined')
  177. console.log(ret.log);
  178. });
  179. return false;
  180. })
  181. //Private editing (managers)
  182. .on('submit', '#survey-form-send', function(e) {
  183. e.preventDefault();
  184. request('/api/survey/surveySave', $(this).serialize(), function(ret) {
  185. console.log('send data', ret.data);
  186. });
  187. return false;
  188. })
  189. //Public anwer survey
  190. .on('click', '.btn-public-survey-send', function() {
  191. var input_files = $('.is_fileinput_field');
  192. var max_size = 1048576*20; //20 MB
  193. if (input_files.length > 0) {
  194. for (var i in input_files) {
  195. if (input_files[i].files) {
  196. if (input_files[i].files[0]) {
  197. if (input_files[i].files[0].size > max_size) {
  198. eModal.alert({
  199. title:glbAppTitle,
  200. message:"Il file <b>"+input_files[i].files[0].name+"</b> supera le dimensioni di file consentite (20 MB).",
  201. buttons: [{text: 'OK', style: 'primary', close: true}]
  202. });
  203. return;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. if (!$('.is_privacy_field').is(':checked')) {
  210. eModal.alert({
  211. title:glbAppTitle,
  212. message:"Prima di inviare il questionario è necessario confermare di aver ricevuto e accettato l'informativa sul trattamento dei dati personali.",
  213. buttons: [{text: 'OK', style: 'primary', close: true}]
  214. });
  215. return;
  216. }
  217. requestUpload($('#public-survey-send')[0], '/api/survey/surveyPublicSend',
  218. function(ret) { //success (ret.status ok)
  219. $('#public-survey-send').fadeOut('fast', function() {
  220. $('#survey-success-msg').fadeIn();
  221. });
  222. //console.log(ret);
  223. if (typeof ret.log !== 'undefined')
  224. console.log(ret.log);
  225. },
  226. function(ret) { //error (ret.status err)
  227. //showMessage(ret.msg, ret.jsArgs);
  228. //showMessage("Errore temporaneo, si prega di riprovare.", ret.jsArgs);
  229. eModal.alert({
  230. title:glbAppTitle,
  231. message:"Errore temporaneo, si prega di riprovare.",
  232. buttons: [
  233. {text: 'Riprova', style: 'primary', close: true, click:function() {
  234. $('.btn-public-survey-send').trigger('click');
  235. }},
  236. {text: glbCancelButton, style: 'warning', close: true}
  237. ]
  238. });
  239. if (typeof ret.log !== 'undefined')
  240. console.log(ret.log);
  241. }
  242. );
  243. })
  244. .on('click', '.btn-survey-preview', function() {
  245. var survey_id = $(this).data('surveyid');
  246. $('#dialog-survey-preview').modal();
  247. $('#dialog-loader').show();
  248. $('.modal-body-survey-preview').empty();
  249. request('/api/survey/getSurveyAnswers', {survey_id:survey_id},
  250. function(ret) { //success (ret.status ok)
  251. console.log(ret);
  252. $('#dialog-loader').hide();
  253. $('.modal-body-survey-preview').html(ret.html);
  254. },
  255. function(ret) { //error (ret.status err)
  256. showMessage(ret.msg, ret.jsArgs);
  257. if (typeof ret.log !== 'undefined')
  258. console.log(ret.log);
  259. },
  260. false
  261. );
  262. })
  263. .on('click', '.btn-edit-survey-preview', function() {
  264. var survey_type_id = $('#survey_type_list').val();
  265. if (survey_type_id > 0) {
  266. $('#dialog-survey-preview').modal();
  267. $('#dialog-loader').show();
  268. $('.modal-body-survey-preview').empty();
  269. request('/api/survey/getSurveyEmptyForm', {survey_type_id:survey_type_id},
  270. function(ret) { //success (ret.status ok)
  271. $('#dialog-loader').hide();
  272. $('.modal-body-survey-preview').html(ret.html);
  273. },
  274. function(ret) { //error (ret.status err)
  275. showMessage(ret.msg, ret.jsArgs);
  276. if (typeof ret.log !== 'undefined')
  277. console.log(ret.log);
  278. },
  279. false
  280. );
  281. }
  282. })
  283. .on('click', '.btn-survey-resend', function() {
  284. var survey_id = $(this).data('surveyid');
  285. var survey_recipient = $(this).data('recipient');
  286. var survey_uuid = $(this).data('surveyuuid');
  287. eModal
  288. .alert({
  289. message:"Reinviare il questionario <b>#"+survey_id+"</b> a <b>"+survey_recipient+"</b>?",
  290. title:glbAppTitle,
  291. buttons: [
  292. {text: 'Reinvia', style: 'primary', close: true, click: function() {
  293. request('/api/survey/sendbackSurveyMessage', {survey_uuid:survey_uuid, recipient:survey_recipient},
  294. function(ret) { //success (ret.status ok)
  295. showMessage(ret.msg, ret.jsArgs);
  296. if (typeof ret.log !== 'undefined')
  297. console.log(ret.log);
  298. document.location.reload();
  299. },
  300. function(ret) { //error (ret.status err)
  301. showMessage(ret.msg, ret.jsArgs);
  302. if (typeof ret.log !== 'undefined')
  303. console.log(ret.log);
  304. },
  305. true
  306. );
  307. }},
  308. {text: glbCancelButton, style: 'warning', close: true, click: function() {}}
  309. ]
  310. });
  311. })
  312. .on('click', '.btn-survey-delete', function() {
  313. var survey_id = $(this).data('surveyid');
  314. var survey_recipient = $(this).data('recipient');
  315. var survey_uuid = $(this).data('surveyuuid');
  316. eModal
  317. .alert({
  318. message:"<div class=\"alert alert-danger\">Eliminare il questionario <b>#"+survey_id+"</b> inviato a <b>"+survey_recipient+"</b>?</div>",
  319. title:glbAppTitle,
  320. buttons: [
  321. {text: 'Elimina', style: 'danger', close: true, click: function() {
  322. request('/api/survey/deleteSurvey', {survey_uuid:survey_uuid, survey_id:survey_id},
  323. function(ret) { //success (ret.status ok)
  324. showMessage(ret.msg, ret.jsArgs);
  325. if (typeof ret.log !== 'undefined')
  326. console.log(ret.log);
  327. document.location.reload();
  328. },
  329. function(ret) { //error (ret.status err)
  330. showMessage(ret.msg, ret.jsArgs);
  331. if (typeof ret.log !== 'undefined')
  332. console.log(ret.log);
  333. },
  334. true
  335. );
  336. }},
  337. {text: glbCancelButton, style: 'warning', close: true, click: function() {}}
  338. ]
  339. });
  340. })
  341. .on('click', '.btn-print-request', function() {
  342. var requestId = $(this).data('requestid');
  343. var context = $(this).data('context');
  344. var operation = $(this).data('op');
  345. var self = $(this);
  346. request('/api/request/generatePDF', {requestId:requestId, context:context, operation:operation},
  347. function(ret) { //success (ret.status ok)
  348. if (typeof ret.log !== 'undefined')
  349. console.log(ret.log);
  350. //console.log(ret.outputFilePath);
  351. if (operation == 'print') {
  352. var fileTitle = self.data('filetitle');
  353. $.fancybox.open({
  354. src : 'print/'+fileTitle+'?fileTitle='+escape(ret.fileTitle)+'&filePath='+escape(ret.outputFilePath),
  355. type : 'iframe'
  356. });
  357. } else {
  358. showMessage(ret.msg, ret.jsArgs);
  359. }
  360. },
  361. function(ret) { //error (ret.status err)
  362. alert(ret.msg);
  363. if (typeof ret.log !== 'undefined')
  364. console.log(ret.log);
  365. }
  366. );
  367. })
  368. .on('click', '.btn-send-pdf', function() {
  369. var requestId = $(this).data('requestid');
  370. var context = $(this).data('context');
  371. var operation = $(this).data('op');
  372. var has_attach = parseInt($(this).data('hasattachments'));
  373. var attach_list = $(this).data('attachments');
  374. var self = $(this);
  375. var comment = $.trim($('#request-message-text').val());
  376. if (comment != '') {
  377. showMessage('Prima di inviare la risposta al paziente salvare il nuovo testo inserito o gli eventuali allegati aggiunti.');
  378. return;
  379. }
  380. $('#request-attach-list').empty();
  381. if (has_attach == 1) {
  382. console.log('attach', attach_list);
  383. if (Array.isArray(attach_list)) {
  384. var html = '<div class="margin-top-20"><small><p>Se necessario, selezionare uno dei seguenti file da allegare all\'e-mail di risposta:</p>';
  385. html += '<ul class="list-no-type">';
  386. for(var i in attach_list) {
  387. html += '<li><input type="checkbox" class="attach-ids" value="'+attach_list[i].id+'"> '+attach_list[i].file_title+'</li>';
  388. }
  389. html += '</ul></small></div>';
  390. $('#request-attach-list').html(html);
  391. }
  392. }
  393. $('#modal-sendpdf-dialog').modal();
  394. })
  395. .on('click', '.btn-pdf-perform-send', function() {
  396. var requestId = $('#request-id').val();
  397. var context = $(this).data('context');
  398. var operation = $(this).data('op');
  399. var attach_ids = [];
  400. //var delay = $('#pdf_postponed_date').val();
  401. var delay = '';
  402. if ($('.attach-ids').length > 0) {
  403. $('.attach-ids').each(function() {
  404. if ($(this).is(':checked')) {
  405. attach_ids.push($(this).val());
  406. }
  407. });
  408. }
  409. $('#modal-sendpdf-dialog').modal('hide');
  410. request('/api/request/generatePDF', {requestId:requestId, context:context, operation:operation, attach_ids:attach_ids, delay:delay},
  411. function(ret) { //success (ret.status ok)
  412. if (typeof ret.log !== 'undefined')
  413. console.log(ret.log);
  414. showMessage(ret.msg, ret.jsArgs);
  415. },
  416. function(ret) { //error (ret.status err)
  417. //alert(ret.msg);
  418. showMessage(ret.msg);
  419. if (typeof ret.log !== 'undefined')
  420. console.log(ret.log);
  421. }
  422. );
  423. })
  424. .on('click', '.btn-delete-survey-msg-queue', function() {
  425. var date_string = $(this).data('delaytstring');
  426. var date_iso = $(this).data('delaytiso');
  427. var request_id = $(this).data('requestid');
  428. var mail_id = $(this).data('mailid');
  429. showConfirmCancel('Annullamento ricezione', "Annullare la ricezione programmata per il "+date_string+"?", function() {
  430. request('/api/request/deleteSurveyMailQueue', {request_id:request_id, mail_id:mail_id},
  431. function(ret) { //success (ret.status ok)
  432. if (typeof ret.log !== 'undefined')
  433. console.log(ret.log);
  434. //showMessage(ret.msg, ret.jsArgs);
  435. document.location.reload();
  436. },
  437. function(ret) { //error (ret.status err)
  438. //alert(ret.msg);
  439. showMessage(ret.msg);
  440. if (typeof ret.log !== 'undefined')
  441. console.log(ret.log);
  442. }
  443. );
  444. });
  445. })
  446. .on('click', '.btn-show-responders', function() {
  447. $('#modal-show-responders').modal();
  448. var requestId = $(this).data('requestid');
  449. $('#dialog-loader-responders').show();
  450. $('.modal-body-responders').empty();
  451. request('/api/request/getRequestResponders', {requestId:requestId},
  452. function(ret) { //success (ret.status ok)
  453. $('#dialog-loader-responders').hide();
  454. $('.modal-body-responders').html(ret.html);
  455. if (typeof ret.log !== 'undefined')
  456. console.log(ret.log);
  457. },
  458. function(ret) { //error (ret.status err)
  459. alert(ret.msg);
  460. if (typeof ret.log !== 'undefined')
  461. console.log(ret.log);
  462. }
  463. );
  464. })
  465. .on('click', '.btn-send-temporary-password', function() {
  466. var email = $('#recovery_email').val();
  467. request('/api/public/recoveryPassword', {email:email},
  468. function(ret) { //success (ret.status ok)
  469. $('#recovery_email').removeClass('is-invalid');
  470. $('.recovery-password-form').hide();
  471. $('.recovery-password-done-msg').fadeIn('fast', function() {
  472. $('.btn-send-temporary-password').hide();
  473. });
  474. if (typeof ret.debug !== 'undefined')
  475. console.log(ret.debug);
  476. },
  477. function(ret) { //error (ret.status err)
  478. //showMessage(ret.msg, ret.jsArgs);
  479. $('#recovery_email').addClass('is-invalid');
  480. if (typeof ret.log !== 'undefined')
  481. console.log(ret.log);
  482. }
  483. );
  484. })
  485. //Save the profile user information from Profile page
  486. .on('click', '.btn-edit-profile', function() {
  487. var formElement = $('#profile-form-edit')[0];
  488. requestUpload(formElement, '/api/user/editProfile',
  489. function(ret) { //success (ret.status ok)
  490. showMessage(ret.msg, ret.jsArgs);
  491. if (typeof ret.log !== 'undefined')
  492. console.log(ret.log);
  493. },
  494. function(ret) { //error (ret.status err)
  495. showMessage(ret.msg, ret.jsArgs)
  496. if (typeof ret.class !== 'undefined')
  497. $('.'+ret.class).addClass('is-invalid');
  498. if (typeof ret.log !== 'undefined')
  499. console.log(ret.log);
  500. }
  501. );
  502. })
  503. //Save the user information from User edit page (only Administrators)
  504. .on('click', '.btn-edit-user', function() {
  505. var formElement = $('#user-form-edit')[0];
  506. requestUpload(formElement, '/api/user/usersSave',
  507. function(ret) { //success (ret.status ok)
  508. showMessage(ret.msg, ret.jsArgs);
  509. },
  510. function(ret) { //error (ret.status err)
  511. showMessage(ret.msg, ret.jsArgs);
  512. if (typeof ret.class !== 'undefined')
  513. $('.'+ret.class).addClass('is-invalid');
  514. if (typeof ret.log !== 'undefined')
  515. console.log(ret.log);
  516. }
  517. );
  518. })
  519. //Save the Clinical Center information <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  520. .on('click', '.btn-center-save', function() {
  521. var formElement = $('#center-form')[0];
  522. requestUpload(formElement, '/api/center/centerSave',
  523. function(ret) { //success (ret.status ok)
  524. showMessage(ret.msg, ret.jsArgs);
  525. handlePage(ret);
  526. if(typeof rel.log !== 'undefined');
  527. console.log(ret.log);
  528. },
  529. function(ret) { //error (ret.status err)
  530. showMessage(ret.msg, ret.jsArgs);
  531. if (typeof ret.class !== 'undefined')
  532. $('.'+ret.class).addClass('is-invalid');
  533. if (typeof ret.log !== 'undefined')
  534. console.log(ret.log);
  535. }
  536. );
  537. })
  538. .on('change', '#profile_continent_code', function() {
  539. var continent_code = $(this).val();
  540. console.log(continent_code);
  541. $('#profile_country_code').attr('disabled');
  542. $('#profile_country_code').empty();
  543. request(
  544. 'api/center/filterCountries',
  545. {continent_code:continent_code},
  546. function(ret) { //success (ret.status ok)
  547. //console.log(ret.countries);
  548. $('#profile_country_code').empty();
  549. $.each(ret.countries, function(code, name) {
  550. $('#profile_country_code').append('<option value=' + code + '>' + name + '</option>');
  551. });
  552. $('#profile_country_code').removeAttr('disabled');
  553. },
  554. function(ret) { //error (ret.status err)
  555. //showMessage(ret.msg, ret.jsArgs);
  556. console.log(ret);
  557. $('#profile_country_code').attr('disabled');
  558. },
  559. false
  560. );
  561. })
  562. .on('click', '.btn-all-medical_specialties', function() {
  563. var action = true;
  564. if($(this).data("action") == "deselect") action = false;
  565. $('.medical_specialty').prop('selected', action);
  566. $('.medical_specialty').trigger('chosen:updated');
  567. })
  568. .on('keypress', '.user-search-ctrl', function(event) {
  569. if (event.which == 13) {
  570. event.preventDefault();
  571. var hash = replaceHashParameter(document.location.hash, 1, 5); //Set page 1
  572. document.location.hash = replaceTimestamp(hash, 2);
  573. }
  574. })
  575. .on('keypress', '.request-search-ctrl', function(event) {
  576. if (event.which == 13) {
  577. event.preventDefault();
  578. //var hash = replaceHashParameter(document.location.hash, 1, 5); //Set page 1
  579. var hash = replaceTimestamp(document.location.hash, 2);
  580. document.location.hash = replaceTimestamp(hash, 2);
  581. }
  582. })
  583. .on('click', '.btn-search-clean', function() {
  584. request('/api/user/searchClean', null,
  585. function(ret) { //success (ret.status ok)
  586. document.location.reload();
  587. },
  588. function(ret) { //error (ret.status err)
  589. showMessage(ret.msg, ret.jsArgs);
  590. if (typeof ret.log !== 'undefined')
  591. console.log(ret.log);
  592. }
  593. );
  594. })
  595. .on('change', '#change-language-list', function() {
  596. var lang = $(this).val();
  597. request('/api/login/changeLang', {passedLng:lang}, function(ret) {
  598. location.reload();
  599. });
  600. })
  601. .on('click', '.btn-dash-show-sess', function() {
  602. request('/api/dashboard/loadLastSessions', {}, function(ret) {
  603. $('#admin-last-sessions').html(ret.html);
  604. });
  605. })
  606. .on('click', '.btn-dash-show-subscrip', function() {
  607. request('/api/dashboard/loadLastSubscriptions', {}, function(ret) {
  608. $('#admin-last-subscriptions').html(ret.html);
  609. });
  610. })
  611. .on('click', '.btn-dash-show-accesses', function() {
  612. request('/api/dashboard/loadLastAccesses', {}, function(ret) {
  613. $('#admin-last-accesses').html(ret.html);
  614. });
  615. })
  616. .on('click', '.btn-load-stats', function() {
  617. var roleId = $(this).data('roleid');
  618. request('/api/dashboard/loadStatistics', {roleId:roleId}, function(ret) {
  619. $('#statistics-'+roleId).html(ret.html);
  620. //console.log(ret);
  621. var barOptions = {
  622. scales: {
  623. yAxes: [{
  624. ticks: {
  625. beginAtZero:true
  626. }
  627. }]
  628. },
  629. legend: {
  630. display: false,
  631. labels: {
  632. fontColor: 'rgb(0, 0, 0)'
  633. }
  634. },
  635. title: {
  636. display: false,
  637. text: ret.chartTitle
  638. }
  639. };
  640. var triageBar = new Chart($('#triage-bar-char-role-'+roleId), {
  641. type: 'bar',
  642. data: {
  643. labels: ret.barTriageLabels,
  644. datasets: [{
  645. label: ret.chartTitle,
  646. data: ret.TriageValues,
  647. backgroundColor: ret.TriageColors,
  648. borderColor: ret.TriageBorders,
  649. borderWidth: 1
  650. }]
  651. },
  652. options: barOptions
  653. });
  654. var triagePie = new Chart($('#triage-doughnut-char-role-'+roleId), {
  655. type: 'doughnut',
  656. data: {
  657. datasets: [{
  658. data: ret.TriagePerc,
  659. backgroundColor: ret.TriageColors
  660. }],
  661. // These labels appear in the legend and in the tooltips when hovering different arcs
  662. labels: ret.pieTriageLabels
  663. },
  664. options: null
  665. });
  666. var statusBar = new Chart($('#status-bar-char-role-'+roleId), {
  667. type: 'bar',
  668. data: {
  669. labels: ret.barStatusLabels,
  670. datasets: [{
  671. label: ret.chartTitle,
  672. data: ret.StatusValues,
  673. backgroundColor: ret.StatusColors,
  674. //borderColor: ret.barStatusBorders,
  675. //borderWidth: 1
  676. }]
  677. },
  678. options: barOptions
  679. });
  680. var statusPie = new Chart($('#status-doughnut-char-role-'+roleId), {
  681. type: 'doughnut',
  682. data: {
  683. datasets: [{
  684. data: ret.StatusPerc,
  685. backgroundColor: ret.StatusColors
  686. }],
  687. // These labels appear in the legend and in the tooltips when hovering different arcs
  688. labels: ret.pieStatusLabels
  689. },
  690. options: null
  691. });
  692. });
  693. })
  694. .on('click', '.goto-link', function(e) {
  695. e.preventDefault();
  696. var hash = $(this).data('goto');
  697. var parent = $(this).parent();
  698. if (parent.hasClass('nav-item')) {
  699. $('.nav-item').removeClass('active');
  700. parent.addClass('active');
  701. }
  702. if (hash == 'home') {
  703. gotoDest(homeHash);
  704. } else {
  705. gotoDest(hash);
  706. }
  707. })
  708. .on('focusin', '.form-control', function() {
  709. $(this).removeClass('is-invalid');
  710. })
  711. .on('click', '.recycle-bin-checkbox', function() {
  712. var counter = $('.recycle-bin-checkbox:checked').length;
  713. if (counter > 0) {
  714. $('.btn-recycle-bin').show();
  715. $('.bin-label').html('('+counter+')');
  716. } else {
  717. $('.btn-recycle-bin').hide();
  718. $('.bin-label').html('');
  719. }
  720. })
  721. .on('click', '.btn-show-tranfer', function(e) {
  722. e.preventDefault();
  723. toggleTranfer();
  724. })
  725. .on('click', '#tm-arrow', function() {
  726. hideTranfer();
  727. })
  728. .on('click', '#tus-upload-select-dialog', function() {
  729. var postId = $('#request-id').length > 0 ? parseInt($('#request-id').val()) : -1;
  730. var postCode = $('#request-unique-code').length > 0 ? $('#request-unique-code').val() : '';
  731. //Post code is an hidden element in New/Edit Request page (requestEdit.view.php)
  732. if (postCode == '') {
  733. showMessage(glbNoPostCodeMsg);
  734. return;
  735. }
  736. $('#tus-upload-control').trigger('click');
  737. })
  738. .on('click', '.btn-delete-upload-item', function() {
  739. var itemIndex = $(this).data('itemindex');
  740. if (typeof globalUploadList[itemIndex] !== 'undefined') {
  741. globalUploadList[itemIndex]['skip'] = true;
  742. $('#upload-item-btn-delete_'+itemIndex).hide();
  743. $('#upload-item-row_'+itemIndex).addClass('upload-row-delete-bg');
  744. $('#upload-item-name_'+itemIndex).addClass('upload-row-deleted-wave');
  745. }
  746. //console.log(globalUploadList);
  747. })
  748. .on('change', '#tus-upload-control', function(e) {
  749. //console.log($(this)[0].files);
  750. prepareFileList($(this)[0].files);
  751. //readSingleFile(e);
  752. })
  753. .on('click', '#btn-tus-upload', function() {
  754. var file = getCurrentFileToUpload();
  755. if (file === false) {
  756. showMessage(glbFileUploadEmpty);
  757. return;
  758. }
  759. uploadTusFile(file);
  760. })
  761. .on('dragenter', '#tm-container', function(e) {
  762. e.stopPropagation();
  763. e.preventDefault();
  764. })
  765. .on('dragover', '#tm-container', function(e) {
  766. e.stopPropagation();
  767. e.preventDefault();
  768. $(this).addClass('drag-hover');
  769. })
  770. .on('dragleave', '#tm-container', function(e) {
  771. $(this).removeClass('drag-hover');
  772. })
  773. .on('drop', '#tm-container', function(e) {
  774. e.stopPropagation();
  775. e.preventDefault();
  776. $(this).removeClass('drag-hover');
  777. var dt = e.dataTransfer || (e.originalEvent && e.originalEvent.dataTransfer);
  778. var files = e.target.files || (dt && dt.files);
  779. if (files) {
  780. prepareFileList(files);
  781. }
  782. })
  783. .on('dragend', '#tm-container', function(e) {
  784. $(this).removeClass('drag-hover');
  785. })
  786. .on('click', '.btn-clean-upload-list', function() {
  787. cleanUploadItems();
  788. })
  789. .on('change', '.field-file', function() {
  790. $(this).next('.custom-file-label').html($(this).val().replace(/^.*\\/, ""));
  791. })
  792. .on('click', '.btn-countries-hand', function() {
  793. var leftHandId = $(this).data('lefthand');
  794. var rightHandId = $(this).data('righthand');
  795. var ids = [];
  796. $('#'+leftHandId+' option:selected').each(function(){
  797. ids.push(this.value);
  798. });
  799. if (ids.length > 0) {
  800. request('api/user/getCCentersByCountries', {ids:ids}, function(ret) {
  801. $('#'+rightHandId+' option:selected').prop('selected', false);
  802. $('#'+rightHandId).trigger("chosen:updated");
  803. for(var i = 0; i<ret.ids.length; i++) {
  804. $('#'+rightHandId+' option[value="'+ret.ids[i]+'"]').prop('selected', true);
  805. $('#'+rightHandId).trigger("chosen:updated");
  806. }
  807. });
  808. }
  809. })
  810. .on('click', '.check-birth-type', function() {
  811. var value = $(this).val();
  812. $('.birth-date-placeholder').hide();
  813. $('.birth-as-date').removeClass('birth-as-date-visible');
  814. if (value == 'date') {
  815. $('.birth-as-date').show();
  816. $('.birth-as-number').hide();
  817. } else {
  818. $('.birth-as-date').hide();
  819. $('.birth-as-number').show();
  820. }
  821. })
  822. .on('click', '.btn-request-sending-preview', function() {
  823. $('#request-preview-loader').show();
  824. $('#request-preview-content').empty();
  825. $('.btn-request-save-popup').prop('disabled', true);
  826. var data = $('#request-save').serialize();
  827. $('#modal-sending-preview').modal();
  828. request('/api/request/requestPreview', data,
  829. function(ret) { //success (ret.status ok)
  830. $('#request-preview-loader').hide();
  831. $('#request-preview-content').html(ret.html);
  832. //$('.btn-request-save-popup').prop('disabled', true);
  833. if (typeof ret.jsonData.userCount !== 'undefined') {
  834. if (parseInt(ret.jsonData.userCount) > 0) {
  835. $('.btn-request-save-popup').prop('disabled', false);
  836. } else {
  837. $('.btn-request-save-popup').prop('disabled', true);
  838. }
  839. }
  840. },
  841. function(ret) { //error (ret.status err)
  842. showMessage(ret.msg, ret.jsArgs);
  843. $('#request-preview-loader').show();
  844. $('#request-preview-content').empty();
  845. $('.btn-request-save-popup').prop('disabled', true);
  846. if (typeof ret.log !== 'undefined')
  847. console.log(ret.log);
  848. }
  849. );
  850. })
  851. .on('click', '.btn-request-save', function() {
  852. var data = $('#request-save').serialize();
  853. var operation = $(this).data('operation');
  854. var fileCounter = 0;
  855. var attachment = getCurrentFileToUpload();
  856. var postCode = $('#request-unique-code').length > 0 ? $('#request-unique-code').val() : null;
  857. data += '&data%5Boperation%5D%5Bvalue%5D='+operation;
  858. //Count the files to upload (by tus protocol)
  859. if (globalUploadList.length > 0) {
  860. for(var i = 0; i < globalUploadList.length; i++) {
  861. if (typeof globalUploadList[i].skip === 'undefined') {
  862. if (typeof globalUploadList[i].postCode !== 'undefined') {
  863. if (globalUploadList[i].postCode == postCode) {
  864. fileCounter++;
  865. }
  866. }
  867. }
  868. }
  869. }
  870. //Has files or doesn't
  871. if (fileCounter > 0) {
  872. data += '&data%5Bhas_files%5D%5Bvalue%5D=1&data%5Bfiles_counter%5D%5Bvalue%5D='+fileCounter;
  873. } else {
  874. data += '&data%5Bhas_files%5D%5Bvalue%5D=0&data%5Bfiles_counter%5D%5Bvalue%5D=0';
  875. }
  876. //console.log(fileCounter);
  877. request('/api/request/requestSave', data,
  878. function(ret) { //success (ret.status ok)
  879. /*if ($('#dream_code').length > 0) {
  880. var rcode = $('#request-unique-code').val();
  881. var idCartella = $.trim($('#dream_code').val());
  882. if (idCartella != '')
  883. wsSend(JSON.stringify({op:"write-record", rcode:rcode, username:$('#user-username').val(), idCartella:idCartella}), false);
  884. console.log({op:"write-record", rcode:rcode, username:$('#user-username').val(), idCartella:idCartella});
  885. }*/
  886. showMessage(ret.msg, ret.jsArgs);
  887. /*$('#request-preview-loader').hide();
  888. $('#request-preview-content').html(ret.html);
  889. $('#modal-sending-preview').modal();*/
  890. globalICD10List = [];
  891. if (attachment !== false) {
  892. if (!globalUploadInProgress) {
  893. uploadTusFile(attachment);
  894. }
  895. }
  896. if (typeof ret.log !== 'undefined')
  897. console.log(ret.log);
  898. },
  899. function(ret) { //error (ret.status err)
  900. showMessage(ret.msg, ret.jsArgs);
  901. if (typeof ret.class !== 'undefined')
  902. $('.'+ret.class).addClass('is-invalid');
  903. if (typeof ret.log !== 'undefined')
  904. console.log(ret.log);
  905. }
  906. );
  907. })
  908. .on('click', '.delete-attach', function() {
  909. var attachId = $(this).data('attachid');
  910. var attachName = $(this).data('attachname');
  911. var attachTitle = $(this).data('attachtitle');
  912. showConfirmCancel(glbAppTitle, gblDeleteAttachMsg+'<br><br>'+attachTitle, function() {
  913. request('/api/request/requestDeleteAttach', {attachId:attachId, attachName:attachName, attachTitle:attachTitle},
  914. function(ret) { //Success
  915. if (typeof ret.attachId !== 'undefined') {
  916. $('#attach-row-id-'+ret.attachId).remove();
  917. }
  918. },
  919. function(ret) {
  920. showMessage(ret.msg, ret.jsArgs);
  921. }, //Error
  922. true //Show the loader
  923. );
  924. });
  925. })
  926. .on('click', '.btn-icd10-open', function() {
  927. $('#modal-icd10-dialog').modal();
  928. })
  929. //ECD-10 dialog (New/Edit Request)
  930. .on('click', '.icd10-get-list', function() {
  931. var icd10Id = $(this).data('icd10id'); //Category id
  932. var getList = $(this).hasClass('icd10-list-empty') ? true : false;
  933. var element = $(this);
  934. var selectedDeseases = [];
  935. $('#card-body-'+icd10Id).show();
  936. $('#dialog-loader-'+icd10Id).show();
  937. //In Draft mode some deseases could be already selected
  938. if ($('.icd10-selected-desease').length > 0) { //The div list of choosen deseases in ICD-10 box
  939. $('.icd10-selected-desease').each(function() {
  940. selectedDeseases.push($(this).data('deseaseid'));
  941. });
  942. }
  943. //Get the deseases list only if the list is currently empty
  944. if (getList) {
  945. request('/api/request/requestGetDeseases', {icd10Id:icd10Id, selectedDeseases:selectedDeseases},
  946. function(ret) { //success (ret.status ok)
  947. if (typeof ret.html !== 'undefined') {
  948. element.removeClass('icd10-list-empty');
  949. $('#desease-list-'+icd10Id).html(ret.html);
  950. }
  951. if (typeof ret.log !== 'undefined')
  952. console.log(ret.log);
  953. },
  954. function(ret) { //error (ret.status err)
  955. showMessage(ret.msg, ret.jsArgs);
  956. },
  957. false
  958. );
  959. } else {
  960. if ($('#desease-list-'+icd10Id).is(':visible')) {
  961. $('#desease-list-'+icd10Id).slideUp();
  962. $('#card-body-'+icd10Id).hide();
  963. } else {
  964. $('#desease-list-'+icd10Id).slideDown();
  965. $('#card-body-'+icd10Id).show();
  966. }
  967. }
  968. })
  969. //Click on ICD-10 checkboxes
  970. .on('click', '.desease-id-checkbox', function() {
  971. //setDeseaseCheckboxesList();
  972. var label = $(this).data('label');
  973. var id = $(this).val();
  974. if ($(this).is(':checked')) {
  975. globalICD10List[id] = label;
  976. } else {
  977. delete globalICD10List[id];
  978. }
  979. $('#icd10-list-content').empty();
  980. for (var id in globalICD10List) {
  981. $('#icd10-list-content').append('<div><small><span class="icon-checkmark"></span> '+globalICD10List[id]+'</small></div>');
  982. }
  983. //console.log(globalICD10List);
  984. })
  985. .on('keyup', '#icd10-search', function(event) {
  986. if (event.which != 13) {
  987. var len = $(this).val().length;
  988. var keyword = $(this).val();
  989. var elem = $(this);
  990. var lang = $('input:radio.search-langs:checked').val();
  991. var selectedDeseases = [];
  992. //In Draft mode some deseases could be already selected
  993. if ($('.icd10-selected-desease').length > 0) { //The div list of choosen deseases in ICD-10 box
  994. $('.icd10-selected-desease').each(function() {
  995. selectedDeseases.push($(this).data('deseaseid'));
  996. });
  997. }
  998. if (len > 2) {
  999. $(this).addClass('ajax-loader-search');
  1000. //$(this).prop('readonly', true);
  1001. request('/api/request/requestSearchDesease', {keyword:keyword, lang:lang, selectedDeseases:selectedDeseases},
  1002. function(ret) { //success (ret.status ok)
  1003. elem.removeClass('ajax-loader-search');
  1004. elem.prop('readonly', false);
  1005. if (typeof ret.html !== 'undefined') {
  1006. $('#icd10-search-results').html(ret.html);
  1007. }
  1008. if (typeof ret.log !== 'undefined')
  1009. console.log(ret.log);
  1010. },
  1011. function(ret) { //error (ret.status err)
  1012. //showMessage(ret.msg, ret.jsArgs);
  1013. elem.removeClass('ajax-loader-search');
  1014. elem.prop('readonly', false);
  1015. },
  1016. false
  1017. );
  1018. } else {
  1019. $('#icd10-search-results').empty();
  1020. $(this).removeClass('ajax-loader-search');
  1021. elem.prop('readonly', false);
  1022. }
  1023. //console.log(len);
  1024. }
  1025. })
  1026. .on('click', '.derma-image-wrapper', function() {
  1027. var type = $(this).data('type');
  1028. var checkId = 'derma-position-check-'+type;
  1029. var label = $(this).find('.derma-title').html();
  1030. var wrapperType = $(this).data('wrappertype');
  1031. var checkBoxClass = $(this).data('checkboxclass');
  1032. if (wrapperType == '' || wrapperType == null) {
  1033. wrapperType = 'position-wrapper-derma';
  1034. }
  1035. if (checkBoxClass == '' || checkBoxClass == null) {
  1036. checkBoxClass = 'derma-position-check';
  1037. }
  1038. if ($(this).hasClass('derma-image-selected')) {
  1039. $(this).removeClass('derma-image-selected');
  1040. $('#'+checkId).prop('checked', false);
  1041. } else {
  1042. $(this).addClass('derma-image-selected');
  1043. $('#'+checkId).prop('checked', true);
  1044. }
  1045. setWizardCheckboxesList(checkBoxClass, wrapperType);
  1046. })
  1047. .on('click', '.search-langs', function() {
  1048. $('#icd10-search').val('');
  1049. $('#icd10-search-results').empty();
  1050. $('#icd10-search').focus();
  1051. })
  1052. /*.on('click', '.btn-request-choose-op', function() {
  1053. $('#modal-request-choose-op').modal();
  1054. })
  1055. .on('click', '.btn-perform-saving', function() {
  1056. var value = $("input[name='choose_save']:checked").val();
  1057. alert(value);
  1058. })*/
  1059. .on('click', '.btn-send-message', function() {
  1060. var requestID = $('#request-id').val();
  1061. var centerID = $('#center-id').val();
  1062. var message = $('#request-message-text').val();
  1063. var newStatus = '';
  1064. var attachment = getCurrentFileToUpload();
  1065. var requestSpecialtyList = $('#request-spec-list').val(); //Request medical specialties
  1066. var specialtyFwList = $('#request-fw-spec-list').val(); //Added medical specialties
  1067. var hasAttachments = attachment !== false ? true : false;
  1068. //Check
  1069. var postCode = $('#request-unique-code').length > 0 ? $('#request-unique-code').val() : null;
  1070. if ($('#request-new-status').length > 0) {
  1071. newStatus = $('#request-new-status').val();
  1072. }
  1073. //specialtyList = specialtyFwList != '' ? requestSpecialtyList+','+specialtyFwList : requestSpecialtyList;
  1074. specialtyList = specialtyFwList != '' ? specialtyFwList : '';
  1075. request('/api/request/requestSendMessage', {requestID:requestID, centerID:centerID, message:message, newStatus:newStatus, specialtyList:escape(specialtyList), hasAttachments:hasAttachments},
  1076. function(ret) { //success (ret.status ok)
  1077. if (typeof ret.html !== 'undefined') {
  1078. $('#request-comment-id').val(ret.commentID);
  1079. $('#request-comment-wrapper').html(ret.html);
  1080. $('#request-message-text').val('');
  1081. if (typeof ret.action !== 'undefined' && ret.action == 'refresh') {
  1082. document.location.hash = replaceTimestamp(document.location.hash, 2);
  1083. }
  1084. if (attachment !== false) {
  1085. if (!globalUploadInProgress) {
  1086. uploadTusFile(attachment);
  1087. }
  1088. }
  1089. }
  1090. if (typeof ret.log !== 'undefined')
  1091. console.log(ret.log);
  1092. },
  1093. function(ret) { //error (ret.status err)
  1094. showMessage(ret.msg, ret.jsArgs);
  1095. },
  1096. true
  1097. );
  1098. })
  1099. .on('click', '.btn-show-referral-list', function() {
  1100. var elem = $(this);
  1101. $('.request-referral-ms-list').slideDown('fast', function() {
  1102. elem.fadeOut();
  1103. });
  1104. })
  1105. //Open the Objective (General) Wizard Dialog
  1106. .on('click', '.btn-wiz-obj-open', function() {
  1107. $('#modal-wizard-objective-dialog').modal();
  1108. })
  1109. .on('click', '.btn-wiz-derma-open', function() {
  1110. $('#modal-wizard-derma-dialog').modal();
  1111. })
  1112. .on('click', '.btn-wiz-oto-open', function() {
  1113. $('#modal-wizard-oto-dialog').modal();
  1114. })
  1115. .on('click', '.btn-wiz-cardio-open', function() {
  1116. $('#modal-wizard-cardio-dialog').modal();
  1117. })
  1118. //Click on the Wizard Dialogs' checkbox (to populate the list in the page)
  1119. .on('click', '.request-exam-checkbox', function() {
  1120. var checkboxClass = $(this).data('checkboxclass');
  1121. var WizardContainer = $(this).data('wizardcontainer');
  1122. setWizardCheckboxesList(checkboxClass, WizardContainer);
  1123. })
  1124. .on('click', '.btn-refresh-list', function() {
  1125. document.location.hash = replaceTimestamp(document.location.hash, 2);
  1126. })
  1127. .on('click', '.btn-cc-dialog', function(e) {
  1128. e.preventDefault();
  1129. var lat = $(this).data('cclat');
  1130. var lng = $(this).data('cclng');
  1131. $('#modal-cc-dialog').one('shown.bs.modal', function() {
  1132. initMap(lat, lng);
  1133. }).modal();
  1134. })
  1135. //Also launched router.js #/requests-edit/
  1136. .on('change', '#request_cc', function() {
  1137. var centerId = parseInt($(this).val());
  1138. var elem = $('#request-referral-ms');
  1139. var elemList = $('#request_referral_ms_chosen .chosen-choices');
  1140. elemList.addClass('chosen-ajax-loader');
  1141. if (centerId == 114) { //DREAM_ITALY
  1142. $('.cc-wrapper').removeClass('col-lg-5');
  1143. $('.cc-wrapper').addClass('col-lg-2');
  1144. $('.dream-italy-wrapper').show();
  1145. $('.sportellocura-wrapper').hide();
  1146. } else if (centerId == 7 || centerId == 115 || centerId == 116) { //Sportello Cura
  1147. $('.cc-wrapper').removeClass('col-lg-5');
  1148. $('.cc-wrapper').addClass('col-lg-2');
  1149. $('.dream-italy-wrapper').hide();
  1150. $('.sportellocura-wrapper').show();
  1151. } else {
  1152. $('.cc-wrapper').removeClass('col-lg-2');
  1153. $('.cc-wrapper').addClass('col-lg-5');
  1154. $('.dream-italy-wrapper').hide();
  1155. $('.sportellocura-wrapper').hide();
  1156. //clearCareGiverFields();
  1157. }
  1158. if (!isNaN(centerId)) {
  1159. request('/api/request/getSpecialtiesPerCenter', {centerId:centerId},
  1160. function(ret) { //success (ret.status ok)
  1161. if (typeof ret.specialties !== 'undefined') {
  1162. elem.empty();
  1163. $.each(ret.specialties, function() {
  1164. elem.append('<option value="'+ this.value +'">'+ this.text +'</option>');
  1165. });
  1166. elem.trigger("chosen:updated");
  1167. elemList.removeClass('chosen-ajax-loader');
  1168. }
  1169. if (typeof ret.log !== 'undefined')
  1170. console.log(ret.log);
  1171. },
  1172. function(ret) { //error (ret.status err)
  1173. showMessage(ret.msg, ret.jsArgs);
  1174. elemList.removeClass('chosen-ajax-loader');
  1175. },
  1176. false,
  1177. true
  1178. );
  1179. } else {
  1180. elem.empty();
  1181. elem.trigger("chosen:updated");
  1182. elemList.removeClass('chosen-ajax-loader');
  1183. }
  1184. })
  1185. .on('click', '.btn-delete-request', function() {
  1186. showConfirmCancel(glbAppTitle, glbDeleteRequest, function() {
  1187. var requestId = $('.btn-delete-request').data('requestid');
  1188. request('/api/request/requestDelete', {requestId:requestId},
  1189. function(ret) { //success (ret.status ok)
  1190. if (typeof ret.redirect !== 'undefined')
  1191. gotoDest(ret.redirect);
  1192. if (typeof ret.log !== 'undefined')
  1193. console.log(ret.log);
  1194. },
  1195. function(ret) { //error (ret.status err)
  1196. //showMessage(ret.msg, ret.jsArgs);
  1197. alert(ret.msg);
  1198. },
  1199. true
  1200. );
  1201. });
  1202. })
  1203. .on('click', '.btn-ws-send-code', function() {
  1204. var code = $.trim($('#dream_code').val());
  1205. if (code != '') {
  1206. wsSend(JSON.stringify({op:"sending-code", code:code}));
  1207. }
  1208. })
  1209. .on('click', '.btn-request-trigger-open', function() {
  1210. var requestId = $(this).data('requestid');
  1211. $('#btn-open-request-'+requestId).trigger('click');
  1212. })
  1213. .on('click', '.btn-show-dream', function() {
  1214. $('#modal-dream-dialog').modal();
  1215. var requestId = $('.btn-show-dream').data('requestid');
  1216. $('.modal-body-dream').empty();
  1217. $('#dialog-loader-dream').show();
  1218. request('/api/request/getDreamInformation', {requestId:requestId},
  1219. function(ret) { //success (ret.status ok)
  1220. //var MONTHS = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
  1221. if (typeof ret.html !== 'undefined') {
  1222. $('.modal-body-dream').html(ret.html);
  1223. for (var i in ret.chartYears) {
  1224. var currentYear = ret.chartYears[i];
  1225. var config = {
  1226. type: 'line',
  1227. data: {
  1228. labels: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
  1229. datasets: [{
  1230. label: 'TAmin',
  1231. backgroundColor: window.chartColors.red,
  1232. borderColor: window.chartColors.red,
  1233. data: ret.dataValues[currentYear].TAmin,
  1234. fill: false,
  1235. spanGaps: true
  1236. }, {
  1237. label: 'TAmax',
  1238. fill: false,
  1239. backgroundColor: window.chartColors.blue,
  1240. borderColor: window.chartColors.blue,
  1241. data: ret.dataValues[currentYear].TAmax,
  1242. spanGaps: true
  1243. }, {
  1244. label: 'FC',
  1245. fill: false,
  1246. backgroundColor: window.chartColors.green,
  1247. borderColor: window.chartColors.green,
  1248. data: ret.dataValues[currentYear].FC,
  1249. spanGaps: true
  1250. }]
  1251. },
  1252. options: {
  1253. responsive: true,
  1254. title: {
  1255. display: true,
  1256. text: currentYear
  1257. },
  1258. tooltips: {
  1259. mode: 'index',
  1260. intersect: false,
  1261. },
  1262. hover: {
  1263. mode: 'nearest',
  1264. intersect: true
  1265. },
  1266. scales: {
  1267. xAxes: [{
  1268. display: true,
  1269. scaleLabel: {
  1270. display: true,
  1271. labelString: 'Month'
  1272. }
  1273. }],
  1274. yAxes: [{
  1275. display: true,
  1276. scaleLabel: {
  1277. display: true,
  1278. labelString: 'Value'
  1279. }
  1280. }]
  1281. }
  1282. }
  1283. };
  1284. var ctx = document.getElementById('daily-chart-values-'+ret.chartYears[i]).getContext('2d');
  1285. window.myLine = new Chart(ctx, config);
  1286. }
  1287. }
  1288. if (typeof ret.log !== 'undefined')
  1289. console.log(ret.log);
  1290. $('#dialog-loader-dream').hide();
  1291. },
  1292. function(ret) { //error (ret.status err)
  1293. //showMessage(ret.msg, ret.jsArgs);
  1294. alert(ret.msg);
  1295. $('#dialog-loader-dream').hide();
  1296. },
  1297. false
  1298. );
  1299. })
  1300. .on('click', '.btn-rqst-dwnl-logs', function() {
  1301. var userId = $('#rqs-lgs-user').val();
  1302. var reqId = $('#rqs-lgs-id').val();
  1303. document.location.href='/download-logs?userId='+userId+'&reqId='+reqId;
  1304. })
  1305. .on('click', '#checkall', function() {
  1306. $('.check-list-item').prop('checked', $(this).prop('checked'));
  1307. })
  1308. .on('click', '.btn-export-users', function() {
  1309. var formData = $('#users-advanced-search-list').serialize();
  1310. request('/api/user/exportUsers', {formData:formData},
  1311. function(ret) { //success (ret.status ok)
  1312. document.location.href = '/download-userexport/index.php?fileName='+ret.dwnFileName+'&filePath='+ret.dwnFilePath;
  1313. console.log(ret);
  1314. },
  1315. function(ret) { //error (ret.status err)
  1316. //showMessage(ret.msg, ret.jsArgs);
  1317. showMessage(ret.msg, ret.jsArgs);
  1318. console.log(ret);
  1319. },
  1320. true
  1321. );
  1322. })
  1323. .on('click', '.handle-more-details', function() {
  1324. if ($('.field-moredetails').hasClass('show-moredtails')) {
  1325. $('.field-moredetails').removeClass('show-moredtails');
  1326. $('.field-moredetails').addClass('hide-moredtails');
  1327. } else {
  1328. $('.field-moredetails').removeClass('hide-moredtails');
  1329. $('.field-moredetails').addClass('show-moredtails');
  1330. }
  1331. })
  1332. .on('change', '#request_cgprovince', function() {
  1333. var province_id = parseInt($(this).val());
  1334. var selected_city_id = $('#request_cgcity_selected').val()
  1335. $('#request_cgcity').empty();
  1336. $('#request_cgcity').prop('disabled', true);
  1337. if (province_id > 0) {
  1338. request('/api/request/getCitiesByProvince', {province_id:province_id, selected_city_id:selected_city_id},
  1339. function(ret) { //success (ret.status ok)
  1340. $('#request_cgcity').append(ret.html);
  1341. $('#request_cgcity').prop('disabled', false);
  1342. },
  1343. function(ret) { //error (ret.status err)
  1344. showMessage(ret.msg, ret.jsArgs);
  1345. $('#request_cgcity').prop('disabled', true);
  1346. console.log(ret);
  1347. },
  1348. false,
  1349. true
  1350. );
  1351. }
  1352. })
  1353. .on('click', '.btn-sportellocura-send-code', function() {
  1354. var url = $('#sportellocura-endpoint').val();
  1355. var apyKey = $('#sportellocura-apikey').val();
  1356. var survey_id = $('#sportellocura_code').val();
  1357. clearCareGiverFields();
  1358. request('/api/request/getSportelloCura', {survey_id:survey_id},
  1359. function(ret) { //success (ret.status ok)
  1360. console.log(ret);
  1361. var empty_text = 'Vedi scheda paziente';
  1362. if (ret.output.status == 'err') {
  1363. showMessage(ret.output.msg);
  1364. $('#sportellocura-survey-data').val('');
  1365. $('#sportellocura_code').val('');
  1366. return;
  1367. }
  1368. $('#sportellocura-survey-data').empty();
  1369. if (ret.output.survey != null && typeof ret.output.survey.id !== 'undefined') {
  1370. $('#request_name').val(ret.output.survey.name);
  1371. $('#request_surname').val(ret.output.survey.surname);
  1372. }
  1373. $('#request_gender').val(ret.output.survey.sex);
  1374. ///Birt date///
  1375. if (ret.output.survey.birthdate != null) {
  1376. var birthDate = new Date(ret.output.survey.birthdate);
  1377. var year = birthDate.getFullYear();
  1378. var month = parseInt(birthDate.getMonth())+1;
  1379. var day = birthDate.getDate();
  1380. $('#request_birth_year').val(year);
  1381. $('#request_birth_month').val(month);
  1382. $('#request_birth_month_day').val(day);
  1383. $('#birth-as-date-radio').trigger('click');
  1384. }
  1385. ///Birt date///
  1386. if (ret.output.survey.notes != null && $.trim(ret.output.survey.notes) != '') {
  1387. $('.field-request_mainquestion').html(stringfyNull(ret.output.survey.notes));
  1388. } else {
  1389. $('.field-request_mainquestion').html(empty_text);
  1390. }
  1391. $('#request_medremarks').html(empty_text);
  1392. $('#request_medicalhistory').html(empty_text);
  1393. $('#sportellocura-survey-data').val(JSON.stringify(ret.output.survey));
  1394. $('#request_cgphone').val(stringfyNull(ret.output.survey.phone));
  1395. $('#request_cgemail').val(stringfyNull(ret.output.survey.email));
  1396. //Show more details controls
  1397. if ($('.field-moredetails').hasClass('hide-moredtails')) $('.field-moredetails').removeClass('hide-moredtails');
  1398. if (!$('.field-moredetails').hasClass('show-moredtails')) $('.field-moredetails').addClass('show-moredtails');
  1399. $('#request-referral-ms').val('');
  1400. $('#request-referral-ms').val(ret.output.survey.ms);
  1401. $('#request-referral-ms').trigger('chosen:updated');
  1402. $('#request-privacy-0').prop('checked', true);
  1403. //Attachments
  1404. var f_name = '';
  1405. if (ret.output.attach.length > 0) {
  1406. for (var i in ret.output.attach) {
  1407. var file_title = ret.output.attach[i].file_title != null ? ret.output.attach[i].file_title : 'file_'+Math.random().toString(36).substr(2, 9);
  1408. $('#request_cg_file_list').append('<li class="list-group-item">'+file_title+'</li>');
  1409. $('#request_cg_input_list').append('<input type="hidden" name="data[cg]['+i+'][filename]" value="'+file_title+'"><input type="hidden" name="data[cg]['+i+'][filedata]" value="'+ret.output.attach[i].data+'">');
  1410. }
  1411. }
  1412. },
  1413. function(ret) { //error (ret.status err)
  1414. showMessage(ret.msg, ret.jsArgs);
  1415. console.log(ret);
  1416. },
  1417. true
  1418. );
  1419. })
  1420. .on('click', '.btn-show-sportellocura', function() {
  1421. $('#modal-sportellocura-dialog').modal();
  1422. })
  1423. .on('click', '.btn-dream-italy-send-code', function() {
  1424. var url = $('#dream-italy-endpoint').val();
  1425. var apyKey = $('#dream-italy-apikey').val();
  1426. var code = $('#dream_italy_code').val();
  1427. clearCareGiverFields();
  1428. request('/api/request/getDreamItaly', {code:code},
  1429. function(ret) { //success (ret.status ok)
  1430. //console.log(ret);
  1431. var file_name_numbs = [1, 2, 3, 4, 5, 6];
  1432. if (ret.output != null && typeof ret.output.id !== 'undefined') {
  1433. $('#request_name').val(ret.output.r_nome);
  1434. $('#request_surname').val(ret.output.r_cognome);
  1435. if (ret.output.r_sesso != null) {
  1436. $('#request_gender').val(ret.output.r_sesso.toLowerCase());
  1437. }
  1438. ///Birt date///
  1439. if (ret.output.r_datanascita != null) {
  1440. var birthDate = new Date(ret.output.r_datanascita);
  1441. var year = birthDate.getFullYear();
  1442. var month = parseInt(birthDate.getMonth())+1;
  1443. var day = birthDate.getDate();
  1444. $('#request_birth_year').val(year);
  1445. $('#request_birth_month').val(month);
  1446. $('#request_birth_month_day').val(day);
  1447. $('#birth-as-date-radio').trigger('click');
  1448. }
  1449. ///Birt date///
  1450. $('#request_medremarks').html(stringfyNull(ret.output.r_patologie)+"\n\n"+stringfyNull(ret.output.r_motivochiamata)+'\n\n'+stringfyNull(ret.output.r_terapia));
  1451. $('#request_cgnamesurname').val($.trim(stringfyNull(ret.output.cg_nome)+' '+stringfyNull(ret.output.cg_cognome)));
  1452. $('#request_cgphone').val(stringfyNull(ret.output.r_telefono));
  1453. $('#request_cgemail').val(stringfyNull(ret.output.r_email));
  1454. $('#request_cgmmgnamesurname').val($.trim(stringfyNull(ret.output.me_nome)+' '+stringfyNull(ret.output.me_cognome)));
  1455. $('#request_cgmmgphone').val(stringfyNull(ret.output.me_telefono));
  1456. $('#request_cgmmgemail').val(stringfyNull(ret.output.me_email));
  1457. if (parseInt(ret.output.r_provincia_id) > 0) {
  1458. $('#request_cgprovince').val(ret.output.r_provincia_id);
  1459. $('#request_cgprovince').trigger('change');
  1460. setTimeout(function() {
  1461. if (parseInt(ret.output.r_provincia_id) > 0) {
  1462. $('#request_cgcity').val(ret.output.r_citta_id);
  1463. }
  1464. }, 200);
  1465. }
  1466. //Show more details controls
  1467. if ($('.field-moredetails').hasClass('hide-moredtails')) $('.field-moredetails').removeClass('hide-moredtails');
  1468. if (!$('.field-moredetails').hasClass('show-moredtails')) $('.field-moredetails').addClass('show-moredtails');
  1469. //Attachments
  1470. var f_name = '';
  1471. for (var i in file_name_numbs) {
  1472. if (ret.output['f_'+i] != null && $.trim(ret.output['f_'+i]) != '') {
  1473. f_name = ret.output['f'+i+'_filename'];
  1474. if (f_name == null || $.trim(f_name) == '') f_name = 'f_'+i;
  1475. $('#request_cg_file_list').append('<li class="list-group-item">'+f_name+'</li>');
  1476. $('#request_cg_input_list').append('<input type="hidden" name="data[cg]['+i+'][filename]" value="'+f_name+'"><input type="hidden" name="data[cg]['+i+'][filedata]" value="'+ret.output['f_'+i]+'">');
  1477. }
  1478. }
  1479. } else {
  1480. //alert('');
  1481. $('#dream_italy_code').addClass('is-invalid');
  1482. }
  1483. },
  1484. function(ret) { //error (ret.status err)
  1485. showMessage(ret.msg, ret.jsArgs);
  1486. console.log(ret);
  1487. },
  1488. true
  1489. );
  1490. })
  1491. .on('change', '#simply_viewer', function() {
  1492. var checked = $(this).is(':checked') ? 1 : 0;
  1493. request('/api/request/setViewerType', {checked_value:checked},
  1494. function(ret) { //success (ret.status ok)
  1495. showConfirmCancel(glbAppTitle, "Per rendere effettive le modifiche è necessario aggiornare la pagina, perdendo eventuali modifiche non ancora salvate. Procedere ora?", function() {
  1496. document.location.hash = replaceTimestamp(document.location.hash, 2);
  1497. });
  1498. },
  1499. function(ret) { //error (ret.status err)
  1500. showMessage(ret.msg, ret.jsArgs);
  1501. //console.log(ret);
  1502. },
  1503. true
  1504. );
  1505. });
  1506. window.chartColors = {
  1507. red: 'rgb(255, 99, 132)',
  1508. orange: 'rgb(255, 159, 64)',
  1509. yellow: 'rgb(255, 205, 86)',
  1510. green: 'rgb(75, 192, 192)',
  1511. blue: 'rgb(54, 162, 235)',
  1512. purple: 'rgb(153, 102, 255)',
  1513. grey: 'rgb(201, 203, 207)'
  1514. };
  1515. function randomScalingFactor() {
  1516. var min = -100;
  1517. var max = 100;
  1518. return Math.random() * (max - min) + min;
  1519. }
  1520. ///////// FUNCTIONS /////////
  1521. function loadGlobalVariables() {
  1522. var head = document.getElementsByTagName('head')[0];
  1523. var script = document.createElement('script');
  1524. $('#global-js-variables').remove();
  1525. $(script).attr('id', 'global-js-variables');
  1526. script.src = '/global-js?t='+new Date().getTime();
  1527. head.appendChild(script);
  1528. }
  1529. function prepareFileList(files) {
  1530. var postCode = $('#request-unique-code').length > 0 ? $('#request-unique-code').val() : '';
  1531. if (postCode != '') {
  1532. if (files.length > 0) {
  1533. var fileData = null;
  1534. var html = '';
  1535. var percentage = 0;
  1536. var alreadyUplaoded = false;
  1537. var cancelButton = '';
  1538. var index = 0;
  1539. for (var i = 0; i < files.length; i++) {
  1540. files[i].postCode = postCode;
  1541. globalUploadList.push(files[i]);
  1542. index = globalUploadList.length-1;
  1543. fileData = files[i];
  1544. html = '<tr id="upload-item-row_'+index+'">';
  1545. //html += '<td>'+postCode+'</td>';
  1546. html += '<td class="upload-item-icon" id="upload-item-icon_'+index+'"></td>';
  1547. html += '<td><span id="upload-item-name_'+index+'">'+fileData.name+'</span></td>';
  1548. //html += '<td width="1%"><input type="radio" name="fileecg" value="'+index+'"> ECG</td>';
  1549. html += '<td><div class="progress" style="margin-top:3px;"><div class="progress-bar bg-info" id="upload-current-progress_'+index+'" role="progressbar" style="width:'+percentage+'%"></div></div></td>';
  1550. html += '<td>'+numbLocalize((fileData.size/1024/1024).toFixed(2))+'</td>';
  1551. html += '<td class="text-center"><button id="upload-item-btn-delete_'+index+'" type="button" data-itemindex="'+index+'" class="btn btn-danger btn-sm btn-delete-upload-item">&times;</button></td>';
  1552. html += '</tr>';
  1553. $('#tus-upload-file-list tbody').append(html);
  1554. }
  1555. console.log(globalUploadList);
  1556. }
  1557. } else {
  1558. showMessage(glbNoPostCodeMsg);
  1559. }
  1560. }
  1561. function uploadTusFile(file) {
  1562. //var postId = $('#request-id').length > 0 ? parseInt($('#request-id').val()) : 0; //Deprecated (not used)
  1563. //var postCode = $('#request-unique-code').length > 0 ? $('#request-unique-code').val() : '';
  1564. var groupId = $('#group-id').length > 0 ? parseInt($('#group-id').val()) : 0; //In main layout
  1565. var userId = $('#user-id').length > 0 ? parseInt($('#user-id').val()) : 0; //In main layout
  1566. var commentId = $('#request-comment-id').length > 0 ? parseInt($('#request-comment-id').val()) : 0; //In Request View
  1567. var staticUri = $('#static-uri').val();
  1568. var apiKey = $('#api-key').val();
  1569. if (!isOnline()) {
  1570. showMessage(glbAppOffline);
  1571. return;
  1572. }
  1573. if (gloabalUploadErrorHandling) {
  1574. showConfirmCancel(glbAppTitle, glbUploadBusy, function() {
  1575. uploadReset();
  1576. });
  1577. return;
  1578. }
  1579. //Pause
  1580. if (globalUploadInProgress && gobalUpload !== null) {
  1581. gobalUpload.abort();
  1582. globalUploadInProgress = false;
  1583. uploadSetPlayBtn();
  1584. uploadSetPauseProgress('#upload-current-progress_'+globalUploadCounter);
  1585. uploadSetItemPauseIcon('#upload-item-icon_'+globalUploadCounter);
  1586. return;
  1587. }
  1588. //Resume
  1589. if (!globalUploadInProgress && gobalUpload !== null) {
  1590. gobalUpload.start();
  1591. uploadSetPauseBtn();
  1592. return;
  1593. }
  1594. //Start
  1595. if (!globalUploadInProgress && gobalUpload == null) {
  1596. uploadSetPauseBtn();
  1597. }
  1598. // Create a new tus upload
  1599. gobalUpload = new tus.Upload(file, {
  1600. endpoint: staticUri,
  1601. retryDelays: [0, 1000, 3000, 5000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000],
  1602. metadata: {
  1603. filename: file.name,
  1604. filetype: file.type,
  1605. groupId: groupId,
  1606. userId: userId,
  1607. postCode: file.postCode,
  1608. commentId: commentId,
  1609. apiKey: apiKey, //Required by pre-create hook
  1610. op: 'ght-upload-attach' //Required by post-finish hook
  1611. },
  1612. onError: function(error) {
  1613. console.log('tus client error: '+error)
  1614. globalUploadInProgress = false;
  1615. uploadRemovePauseProgress('#upload-current-progress_'+globalUploadCounter);
  1616. if (error.originalRequest) {
  1617. gloabalUploadErrorHandling = true;
  1618. globalUploadTimeout = setTimeout(function() {
  1619. gobalUpload.start();
  1620. }, 60000);
  1621. } else {
  1622. showMessage(error);
  1623. uploadReset();
  1624. }
  1625. },
  1626. onProgress: function(bytesUploaded, bytesTotal) {
  1627. showUploadWarning();
  1628. $('#btn-tus-upload').show();
  1629. globalUploadInProgress = true;
  1630. gloabalUploadErrorHandling = false;
  1631. uploadRemovePauseProgress('#upload-current-progress_'+globalUploadCounter);
  1632. $('#upload-item-btn-delete_'+globalUploadCounter).hide();
  1633. uploadSetItemPlayIcon('#upload-item-icon_'+globalUploadCounter);
  1634. var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
  1635. $('#upload-current-progress_'+globalUploadCounter).css({width:percentage+'%'});
  1636. },
  1637. onSuccess: function() {
  1638. //console.log("Download %s from %s", gobalUpload.file.name, gobalUpload.url);
  1639. //Append the file attach list
  1640. var postCode = globalUploadList[globalUploadCounter].postCode;
  1641. if ($('#attach-list-'+postCode).length > 0) {
  1642. request('/api/request/requestAttachs', {postCode: postCode},
  1643. function(ret) { //Success
  1644. var html = '';
  1645. if (typeof ret.attachData !== 'undefined') {
  1646. for(var i = 0; i<ret.attachData.length; i++) {
  1647. html += '<tr id="attach-row-id-'+ret.attachData[i].id+'">';
  1648. html += '<td>';
  1649. html += '<a class="download" data-forcedownload="'+ret.attachData[i].forceDownload+'" data-fileext="'+ret.attachData[i].ext+'" href="/downlaod/?attach_id='+ret.attachData[i].id+'">'+ret.attachData[i].title+'</a>';
  1650. html += '</td>';
  1651. html += '<td width="1%" class="text-right">';
  1652. html += '<button type="button" class="btn btn-danger btn-sm rounded-button delete-attach" data-attachtitle="'+ret.attachData[i].title+'" data-attachname="'+ret.attachData[i].name+'" data-attachid="'+ret.attachData[i].id+'"><span class="icon-cross"></span></button>';
  1653. html += '</td>';
  1654. html += '</tr>';
  1655. }
  1656. $('#attach-list-'+postCode+' tbody').html(html);
  1657. }
  1658. },
  1659. function() {}, //Error
  1660. false //Don't show the loader
  1661. );
  1662. }
  1663. //Mark this file as skipable
  1664. globalUploadList[globalUploadCounter].skip = true;
  1665. gobalUpload = null;
  1666. gloabalUploadErrorHandling = false;
  1667. uploadRemovePauseProgress('#upload-current-progress_'+globalUploadCounter);
  1668. //uploadCleanItemIcons();
  1669. uploadSetItemCheckIcon('#upload-item-icon_'+globalUploadCounter);
  1670. globalUploadCounter++;
  1671. var file = getCurrentFileToUpload();
  1672. if (file !== false) {
  1673. uploadTusFile(file);
  1674. //Operations after upload finished
  1675. //In Request page (Edit/View)
  1676. if ($('#request-page-type').length > 0) {
  1677. switch($('#request-page-type').val()) {
  1678. case 'request-edit':
  1679. //Load the attachment list
  1680. break;
  1681. case 'request-view':
  1682. break;
  1683. }
  1684. }
  1685. } else {
  1686. //Upload loop complete
  1687. uploadSetPlayBtn();
  1688. globalUploadInProgress = false;
  1689. hideUploadWarning();
  1690. $('#btn-tus-upload').hide();
  1691. //Operations after upload loop finished
  1692. //In Request page (Edit/View)
  1693. if ($('#request-page-type').length > 0) {
  1694. switch($('#request-page-type').val()) {
  1695. case 'request-edit':
  1696. break;
  1697. case 'request-view':
  1698. document.location.hash = replaceTimestamp(document.location.hash, 2);
  1699. //Load all comments to show the attachemts
  1700. /*var requestID = $('#request-id').length > 0 ? parseInt($('#request-id').val()) : 0;
  1701. var centerID = $('#center-id').length > 0 ? parseInt($('#center-id').val()) : 0;
  1702. if (requestID > 0 && centerID > 0) {
  1703. request('/api/request/requestLoadAllComments', {requestID:requestID, centerID:centerID},
  1704. function(ret) { //success (ret.status ok)
  1705. if (typeof ret.html !== 'undefined')
  1706. $('#request-comment-wrapper').html(ret.html);
  1707. if (typeof ret.log !== 'undefined')
  1708. console.log(ret.log);
  1709. },
  1710. function(ret) { //error (ret.status err)
  1711. },
  1712. false
  1713. );
  1714. }*/
  1715. break;
  1716. }
  1717. }
  1718. console.log('List complete');
  1719. }
  1720. }
  1721. });
  1722. // Start the upload
  1723. gobalUpload.start();
  1724. }
  1725. function uploadReset() {
  1726. if (globalUploadTimeout != null) {
  1727. clearTimeout(globalUploadTimeout);
  1728. globalUploadTimeout = null;
  1729. }
  1730. if (gobalUpload != null) {
  1731. gobalUpload.abort();
  1732. gobalUpload = null;
  1733. }
  1734. globalUploadInProgress = false;
  1735. gloabalUploadErrorHandling = false;
  1736. globalUploadCounter = 0;
  1737. globalUploadList = [];
  1738. uploadSetPlayBtn();
  1739. uploadRemovePauseProgress('#upload-current-progress_'+globalUploadCounter);
  1740. uploadCleanItemIcons();
  1741. $('#tus-upload-control').trigger('reset');
  1742. }
  1743. function request(url, data, successFunc, errorFunc, allowLoader, synchronous) {
  1744. if (!isOnline()) {
  1745. showMessage(glbAppOffline);
  1746. return false;
  1747. }
  1748. if (typeof allowLoader === 'undefined') allowLoader = true;
  1749. if (typeof synchronous !== 'undefined' && synchronous) ajaxRunning = false;
  1750. //console.log(isOnline());
  1751. if (!ajaxRunning) {
  1752. if (allowLoader) showLoader();
  1753. ajaxRunning = true;
  1754. ajaxRef = $.ajax({
  1755. dataType: 'json',
  1756. url: url,
  1757. data: data,
  1758. headers : {'api-key':apyKey, 'appRequestType':'web'},
  1759. method: 'POST',
  1760. success: function(ret) {
  1761. ajaxRunning = false;
  1762. hideLoader();
  1763. if (ret.status.toLowerCase() == 'ok') {
  1764. if (typeof ret.userLang !== 'undefined') {
  1765. document.documentElement.lang = ret.userLang;
  1766. }
  1767. if (typeof ret.userId !== 'undefined') {
  1768. $('#user-id').val(ret.userId);
  1769. }
  1770. if (typeof ret.groupId !== 'undefined') {
  1771. $('#group-id').val(ret.groupId);
  1772. }
  1773. //For Dream Integration
  1774. if (typeof ret.username !== 'undefined') {
  1775. $('#user-username').val(ret.username);
  1776. }
  1777. successFunc(ret);
  1778. } else {
  1779. if (typeof errorFunc === 'undefined') {
  1780. showMessage(ret.msg, ret.jsArgs);
  1781. } else {
  1782. errorFunc(ret);
  1783. }
  1784. }
  1785. },
  1786. error: function(XMLHttpRequest, textStatus, errorThrown) {
  1787. ajaxRunning = false;
  1788. hideLoader();
  1789. if (XMLHttpRequest.readyState == 4) {
  1790. if (errorThrown != '') {
  1791. showMessage(errorThrown);
  1792. } else {
  1793. showMessage(glbGenericError+' (Err. cod. 0)');
  1794. }
  1795. //showMessage(errorThrown);
  1796. //showMessage(glbGenericError+' (Err. cod. 0)');
  1797. }
  1798. else if (XMLHttpRequest.readyState == 0) {
  1799. showMessage(glbGenericError+' (Err. cod. 1)');
  1800. }
  1801. else {
  1802. showMessage(glbGenericError+' (Err. cod. 2)');
  1803. }
  1804. }
  1805. });
  1806. }
  1807. }
  1808. function requestUpload(formElement, url, successFunc, errorFunc, allowLoader) {
  1809. if (!isOnline()) {
  1810. showMessage(glbAppOffline);
  1811. return false;
  1812. }
  1813. if (typeof allowLoader === 'undefined') allowLoader = true;
  1814. if (!ajaxRunning) {
  1815. if (allowLoader) showLoader();
  1816. ajaxRunning = true;
  1817. var data = new FormData(formElement);
  1818. ajaxRef = $.ajax({
  1819. dataType: 'json',
  1820. url: url,
  1821. data: data,
  1822. headers : {'api-key':apyKey, 'appRequestType':'web'},
  1823. method: 'POST',
  1824. enctype: 'multipart/form-data',
  1825. processData: false,
  1826. contentType: false,
  1827. cache: false,
  1828. success: function(ret) {
  1829. ajaxRunning = false;
  1830. hideLoader();
  1831. if (ret.status.toLowerCase() == 'ok') {
  1832. successFunc(ret);
  1833. } else {
  1834. errorFunc(ret);
  1835. }
  1836. },
  1837. error: function(XMLHttpRequest, textStatus, errorThrown) {
  1838. ajaxRunning = false;
  1839. hideLoader();
  1840. showMessage(XMLHttpRequest.statusText);
  1841. }
  1842. });
  1843. }
  1844. }
  1845. //ICD-10 dialog
  1846. //WARNING: this HTML code also is in requestEdit.view (ECD-10 section)
  1847. function setDeseaseCheckboxesList() {
  1848. var list = [];
  1849. $('.desease-id-checkbox').each(function() {
  1850. var label = $(this).data('label');
  1851. var id = $(this).val();
  1852. if ($(this).is(':checked')) {
  1853. list.push('<div><small><span class="icon-checkmark"></span> '+label+'</small></div>');
  1854. globalICD10List[id] = label;
  1855. }
  1856. });
  1857. //Also in requestEdit.view!!
  1858. if (list.length > 0) {
  1859. $('#icd10-list-content').empty();
  1860. for(var i = 0; i < list.length; i++) {
  1861. $('#icd10-list-content').append(list[i]);
  1862. }
  1863. $('#icd10-list-content').append('<hr>');
  1864. } else {
  1865. $('#icd10-list-content').empty();
  1866. }
  1867. }
  1868. //Wizard dialogs
  1869. //WARNING: this HTML code also is in requestEdit.view (Wizards section)
  1870. function setWizardCheckboxesList(checkboxClass, WizardContainer) {
  1871. var list = [];
  1872. $('.'+checkboxClass).each(function() {
  1873. var label = $(this).data('label');
  1874. if ($(this).is(':checked')) {
  1875. list.push('<div><small><span class="icon-checkmark"></span> '+label+'</small></div>');
  1876. }
  1877. });
  1878. //Also in requestEdit.view!!
  1879. if (list.length > 0) {
  1880. $('#'+WizardContainer).empty();
  1881. for(var i = 0; i < list.length; i++) {
  1882. $('#'+WizardContainer).append(list[i]);
  1883. }
  1884. $('#'+WizardContainer).append('<hr>');
  1885. } else {
  1886. $('#'+WizardContainer).empty();
  1887. }
  1888. }
  1889. //https://stackoverflow.com/questions/18299806/how-to-check-file-mime-type-with-javascript-before-upload
  1890. function checkImageFile(fileElement) {
  1891. //var fileElement = document.getElementById("your-files");
  1892. if (window.FileReader && window.Blob) {
  1893. var files = fileElement.files
  1894. for (var i = 0; i < files.length; i++) {
  1895. console.log("Filename: " + files[i].name);
  1896. console.log("Type: " + files[i].type);
  1897. console.log("Size: " + (files[i].size/1024).toFixed(2) + " mb");
  1898. }
  1899. }
  1900. return false;
  1901. }
  1902. function preparePage() {
  1903. showLoader();
  1904. }
  1905. function handlePage(ret, element, callbackFunc) {
  1906. if (typeof element === 'undefined' || element == null)
  1907. element = '#main';
  1908. $(element).html(ret.html);
  1909. if (isFunction(callbackFunc))
  1910. callbackFunc();
  1911. }
  1912. function toggleTranfer() { //Show/Hide Transfer Manager
  1913. var windowHeight = $(window).height();
  1914. $('#transfer-manager').height((windowHeight/1.5));
  1915. var elementHeight = $('#transfer-manager').height();
  1916. var position = $('#transfer-manager').offset();
  1917. var topLimit = (windowHeight-elementHeight);
  1918. var bottomLimit = (windowHeight+elementHeight);
  1919. var toPosition = 0;
  1920. if (position.top <= topLimit) {
  1921. toPosition = bottomLimit;
  1922. } else {
  1923. toPosition = topLimit;
  1924. }
  1925. $('#transfer-manager').animate({
  1926. top:toPosition
  1927. }, 'fast', function() {
  1928. resizeTranfer();
  1929. });
  1930. }
  1931. function resizeTranfer() {
  1932. var position = $('#transfer-manager').offset();
  1933. var windowHeight = $(window).height();
  1934. var elementHeight = $('#transfer-manager').height();
  1935. var topLimit = (windowHeight-elementHeight);
  1936. if (position.top <= topLimit) {
  1937. $('#transfer-manager').css({top:topLimit});
  1938. }
  1939. $('#upload-list-table-wrapper').height(elementHeight-80);
  1940. }
  1941. function hideTranfer() {
  1942. var windowHeight = $(window).height();
  1943. var elementHeight = $('#transfer-manager').height();
  1944. var position = $('#transfer-manager').offset();
  1945. $('#transfer-manager').animate({
  1946. top:(windowHeight+elementHeight)
  1947. }, 'fast');
  1948. }
  1949. function cleanUploadItems() {
  1950. if (globalUploadList.length > 0) {
  1951. var c = 0;
  1952. for(var i = 0; i < globalUploadList.length; i++) {
  1953. if (typeof globalUploadList[i].skip !== 'undefined') {
  1954. $('#upload-item-row_'+i).remove();
  1955. c++;
  1956. }
  1957. }
  1958. if (c == globalUploadList.length) {
  1959. //globalUploadList = [];
  1960. }
  1961. }
  1962. }
  1963. function uploadReset() {
  1964. if (gobalUpload != null) {
  1965. gobalUpload.abort();
  1966. gobalUpload = null;
  1967. }
  1968. if (globalUploadInterval != null) {
  1969. clearInterval(globalUploadInterval);
  1970. globalUploadInterval = null;
  1971. }
  1972. globalUploadInProgress = false;
  1973. globalUploadList = [];
  1974. globalUploadCounter = 0;
  1975. $('#tus-upload-control').reset();
  1976. }
  1977. function uploadSetPauseBtn() {
  1978. $('#btn-tus-upload').removeClass('btn-primary').addClass('btn-warning').find('span').removeClass('icon-play2').addClass('icon-pause');
  1979. }
  1980. function uploadSetPlayBtn() {
  1981. $('#btn-tus-upload').removeClass('btn-warning').addClass('btn-primary').find('span').removeClass('icon-pause').addClass('icon-play2');
  1982. }
  1983. function uploadSetItemPlayIcon(jQueryElement) {
  1984. //uploadCleanItemIcons();
  1985. $(jQueryElement).html('<span class="icon-play2"></span>');
  1986. }
  1987. function uploadSetItemPauseIcon(jQueryElement) {
  1988. //uploadCleanItemIcons();
  1989. $(jQueryElement).html('<span class="icon-pause"></span>');
  1990. }
  1991. function uploadSetItemCheckIcon(jQueryElement) {
  1992. $(jQueryElement).html('<span class="icon-checkmark"></span>');
  1993. }
  1994. function uploadCleanItemIcons() {
  1995. $('.upload-item-icon').html('');
  1996. }
  1997. function uploadRemovePauseProgress(jQueryElement) {
  1998. $(jQueryElement).removeClass('progress-bar-animated');
  1999. $(jQueryElement).removeClass('progress-bar-striped');
  2000. }
  2001. function uploadSetPauseProgress(jQueryElement) {
  2002. $(jQueryElement).addClass('progress-bar-animated');
  2003. $(jQueryElement).addClass('progress-bar-striped');
  2004. }
  2005. function getCurrentFileToUpload() {
  2006. if (globalUploadList.length > 0) {
  2007. for(var i = globalUploadCounter; i < globalUploadList.length; i++) {
  2008. if (typeof globalUploadList[i].skip === 'undefined') {
  2009. globalUploadCounter = i;
  2010. return globalUploadList[i];
  2011. }
  2012. }
  2013. }
  2014. return false;
  2015. }
  2016. function gotoDest(destination) {
  2017. if (typeof destination === 'undefined') destination = '';
  2018. document.location.hash = '#/'+destination;
  2019. }
  2020. function showLoader() {
  2021. $('#loader-wrapper').show();
  2022. $('#overlay').show();
  2023. }
  2024. function hideLoader() {
  2025. $('#loader-wrapper').fadeOut();
  2026. $('#overlay').hide();
  2027. }
  2028. function showAnimatedLoader() {
  2029. $('#overlay').show();
  2030. }
  2031. function hideAnimatedLoader() {
  2032. $('#overlay').hide();
  2033. }
  2034. function isFunction(functionToCheck) {
  2035. return functionToCheck && {}.toString.call(functionToCheck) === '[object Function]';
  2036. }
  2037. function replaceTimestamp(currentHash, position) {
  2038. var s = currentHash.split('/');
  2039. s[position] = new Date().getTime();
  2040. return s.join('/');
  2041. }
  2042. function replaceHashParameter(hash, value, position) {
  2043. var s = hash.split('/');
  2044. s[position] = value;
  2045. return s.join('/');
  2046. }
  2047. function showUploadWarning() {
  2048. $('#upload-warning-wrapper').show();
  2049. }
  2050. function hideUploadWarning() {
  2051. $('#upload-warning-wrapper').fadeOut();
  2052. }
  2053. function showMessage(msg, params) {
  2054. var btnData = [{text: 'Ok', style: 'primary', close: true, click: function() {}}];
  2055. if (typeof params !== 'undefined' && params != null) {
  2056. if (typeof params.button !== 'undefined') {
  2057. switch (params.button) {
  2058. case 'login':
  2059. btnData[0].text = glbCancelButton;
  2060. btnData[0].style = 'light';
  2061. btnData.push({text: glbLoginButton, style: 'warning', close: true, click: function() {
  2062. //gotoDest();
  2063. document.location.href = '/';
  2064. }});
  2065. break;
  2066. case 'refresh-page':
  2067. btnData[0].click = function() {
  2068. document.location.reload();
  2069. }
  2070. break;
  2071. case 'refresh-hash':
  2072. btnData[0].click = function() {
  2073. //Update also the record ID in address bar
  2074. if (typeof params.recordId !== 'undefined' && typeof params.idPosition !== 'undefined') {
  2075. var hash = document.location.hash;
  2076. hash = replaceHashParameter(hash, params.recordId, params.idPosition);
  2077. document.location.hash = replaceTimestamp(hash, 2);
  2078. } else {
  2079. //Just update the timestamp
  2080. document.location.hash = replaceTimestamp(document.location.hash, 2);
  2081. }
  2082. }
  2083. break;
  2084. case 'refresh-user-edit':
  2085. btnData[0].click = function() {
  2086. var hash = replaceTimestamp(document.location.hash, 2);
  2087. document.location.hash = replaceHashParameter(hash, params.userId, 3);
  2088. }
  2089. break;
  2090. case 'goto':
  2091. if (typeof params.destination !== 'undefined')
  2092. gotoDest(params.destination);
  2093. /*btnData[0].click = function() {
  2094. if (typeof params.destination !== 'undefined')
  2095. gotoDest(params.destination);
  2096. }*/
  2097. break;
  2098. }
  2099. }
  2100. if (typeof params.dialogType !== 'undefined') {
  2101. switch(params.dialogType) {
  2102. case 'sessionExpired':
  2103. msg = glbSessionExpired;
  2104. break;
  2105. }
  2106. }
  2107. }
  2108. eModal.alert({
  2109. title:glbAppTitle,
  2110. message:msg,
  2111. buttons: btnData
  2112. });
  2113. }
  2114. function showConfirmCancel(title, msg, callback) {
  2115. eModal.alert({
  2116. title:title,
  2117. message:msg,
  2118. buttons: [
  2119. {text: 'Ok', style: 'primary', close: true, click: function() {
  2120. callback();
  2121. }},
  2122. {text: glbCancelButton, style: 'warning', close: true, click: function() {}}
  2123. ]
  2124. });
  2125. }
  2126. function isOnline() {
  2127. return window.navigator.onLine;
  2128. }
  2129. function getLanguage() {
  2130. var lang = $.trim($('html').attr('lang'));
  2131. if (lang == '') lang = 'en';
  2132. return lang;
  2133. }
  2134. function numbLocalize(numb) {
  2135. var lang = getLanguage();
  2136. if (lang != 'en') {
  2137. numb = numb.replace('.', ',');
  2138. }
  2139. return numb;
  2140. }
  2141. function choosenHideDeleteCross() {
  2142. $('.search-choice-close').hide();
  2143. $('.chosen-container-multi .chosen-choices .search-choice').addClass('chosen-remove-padding');
  2144. }
  2145. // Initialize and add the map
  2146. function initMap(lat, lng) {
  2147. if ($('#map').length > 0) {
  2148. var place = {lat: parseFloat(lat), lng: parseFloat(lng)};
  2149. var map = new google.maps.Map(
  2150. document.getElementById('map'), {zoom: 4, center: place});
  2151. var marker = new google.maps.Marker({position: place, map: map});
  2152. }
  2153. }
  2154. function wsConnect() {
  2155. if (typeof appWebSocket !== 'undefined') {
  2156. appWebSocket.close();
  2157. }
  2158. //console.log('Connecting...');
  2159. if (typeof appWebSocket !== 'undefined' && appWebSocket.readyState == 1) return; //Already opened
  2160. appWebSocket = new WebSocket(glbWSEndpoint);
  2161. appWebSocket.onmessage = function(event) {
  2162. try {
  2163. wsData = $.parseJSON(event.data); //Global variable
  2164. //showDreamForm(wsData.centerName);
  2165. if (wsData.op == 'show-integration') {
  2166. showDreamForm(wsData.centerName);
  2167. /*if ($('#process-path').length > 0) {
  2168. var processPath = $('#process-path').val();
  2169. wsSend(JSON.stringify({op:"check-process", processpath:processPath}), false);
  2170. }*/
  2171. }
  2172. if (wsData.op == 'show-process-button') {
  2173. if ($('#process-path').length > 0) {
  2174. var processPath = $('#process-path').val();
  2175. wsSend(JSON.stringify({op:"check-process", processpath:processPath}), false);
  2176. }
  2177. }
  2178. if (wsData.op == 'hide-integration') {
  2179. hideDreamForm();
  2180. hideAnimatedLoader();
  2181. }
  2182. //wsConnectionCounter++;
  2183. if (wsData.op == 'response-data') {
  2184. //console.log(data.dreamData)
  2185. if (typeof wsData.dreamData != 'undefined') {
  2186. hideAnimatedLoader();
  2187. if ($('#request_dream_data').length > 0) {
  2188. $('#request_dream_data').val(JSON.stringify(wsData.dreamData));
  2189. if (typeof wsData.dreamData.Anagrafica !== 'undefined') {
  2190. if (!$.isEmptyObject(wsData.dreamData.Anagrafica)) {
  2191. var registry = wsData.dreamData.Anagrafica;
  2192. if (typeof registry.Nome !== 'undefined') {
  2193. $('#request_name').val(registry.Nome.trim());
  2194. }
  2195. if (typeof registry.Cognome !== 'undefined') {
  2196. $('#request_surname').val(registry.Cognome.trim());
  2197. }
  2198. if (typeof registry.sesso !== 'undefined') {
  2199. $('#request_gender').val(registry.sesso.toLowerCase().trim());
  2200. }
  2201. if (typeof registry.dataNascita !== 'undefined') {
  2202. var birthDate = new Date(registry.dataNascita);
  2203. var year = birthDate.getFullYear();
  2204. var month = parseInt(birthDate.getMonth())+1;
  2205. var day = birthDate.getDate();
  2206. $('#request_birth_year').val(year);
  2207. $('#request_birth_month').val(month);
  2208. $('#request_birth_month_day').val(day);
  2209. $('#birth-as-date-radio').trigger('click');
  2210. }
  2211. var rcode = $('#request-unique-code').val();
  2212. wsSend(JSON.stringify({op:"write-record", rcode:rcode, username:$('#user-username').val(), idAnagrafica:registry.idAnagrafica}), false);
  2213. } else {
  2214. $('#request_name').val('');
  2215. $('#request_surname').val('');
  2216. $('#request_surname').val('');
  2217. $('#request_birth_year').val('0');
  2218. $('#request_birth_month').val('0');
  2219. $('#request_birth_month_day').val('0');
  2220. $('#request_dream_data').val('');
  2221. $('#dream_code').addClass('is-invalid');
  2222. }
  2223. }
  2224. }
  2225. //console.log(wsData.dreamData);
  2226. }
  2227. }
  2228. if (wsData.op == 'response-evt-id') {
  2229. $('#request-dream-evt-id').val(wsData.evtId);
  2230. console.log('Evt id: '+wsData.evtId);
  2231. }
  2232. if (wsData.op == 'response-data-error') {
  2233. //console.log(wsData.dreamData)
  2234. hideAnimatedLoader();
  2235. showMessage(wsData.msg);
  2236. }
  2237. if (wsData.op == 'process-error') {
  2238. hideAnimatedLoader();
  2239. showMessage(wsData.msg);
  2240. }
  2241. if (wsData.op == 'process-opened') {
  2242. hideAnimatedLoader();
  2243. }
  2244. if (wsData.op == 'process-check') {
  2245. hideAnimatedLoader();
  2246. console.log('process', wsData.msg);
  2247. if (wsData.msg) { //true
  2248. $('.btn-run-process').show();
  2249. }
  2250. }
  2251. $('.ws-cc-code-container').prop('disabled', false);
  2252. } catch (error) {
  2253. showMessage(error);
  2254. console.log('Parser error: '+error);
  2255. hideAnimatedLoader();
  2256. }
  2257. //console.log(event.data);
  2258. }
  2259. appWebSocket.onopen = function(evt) {
  2260. console.log('WS Opened');
  2261. };
  2262. appWebSocket.onclose = function(evt) {
  2263. hideDreamForm();
  2264. $('.btn-run-process').hide();
  2265. hideAnimatedLoader();
  2266. //showReconnectBtn();
  2267. console.log('WS Closed');
  2268. };
  2269. appWebSocket.onerror = function(evt) {
  2270. hideDreamForm();
  2271. $('.btn-run-process').hide();
  2272. hideAnimatedLoader();
  2273. console.log('WS Error');
  2274. };
  2275. }
  2276. function wsSend(message, showLoader) {
  2277. if (typeof showLoader === 'undefined')
  2278. showLoader = true;
  2279. if (typeof appWebSocket === 'undefined') {
  2280. appWebSocket.close();
  2281. wsConnect();
  2282. }
  2283. if (appWebSocket.readyState != 1) {
  2284. appWebSocket.close();
  2285. wsConnect();
  2286. }
  2287. if (typeof appWebSocket !== 'undefined') {
  2288. if (appWebSocket.readyState == 1) { //Open
  2289. if (showLoader) {
  2290. showAnimatedLoader();
  2291. $('.ws-cc-code-container').prop('disabled', true);
  2292. }
  2293. appWebSocket.send(message);
  2294. }
  2295. }
  2296. }
  2297. function wsClose() {
  2298. if (typeof appWebSocket !== 'undefined') {
  2299. appWebSocket.close();
  2300. }
  2301. }
  2302. function hideDreamForm() {
  2303. //Hide the Dream integration in new/edit request page
  2304. //hideReconnectBtn();
  2305. $('.dream-wrapper').hide();
  2306. $('.cc-wrapper').removeClass('col-lg-2');
  2307. $('.cc-wrapper').addClass('col-lg-5');
  2308. }
  2309. function showDreamForm(centerName) {
  2310. //hideReconnectBtn();
  2311. $('.dream-italy-wrapper').hide();
  2312. $('.cc-wrapper').removeClass('col-lg-5');
  2313. $('.cc-wrapper').addClass('col-lg-2');
  2314. $('.ws-cc-name').html(unescape(centerName));
  2315. $('.dream-wrapper').show();
  2316. }
  2317. function showReconnectBtn() {
  2318. if (wsConnectionCounter > 0)
  2319. $('.ws-reconnect-wrapper').show();
  2320. else
  2321. hideReconnectBtn();
  2322. }
  2323. function hideReconnectBtn() {
  2324. $('.ws-reconnect-wrapper').hide();
  2325. }
  2326. function stringfyNull(value) {
  2327. if (value == null) {
  2328. return '';
  2329. } else {
  2330. return value;
  2331. }
  2332. }
  2333. function clearCareGiverFields() {
  2334. $('#request_cgprovince').val('0');
  2335. $('#request_cgcity').prop('disabled', true).empty();
  2336. $('#request_name').val('');
  2337. $('#request_surname').val('');
  2338. $('#request_gender').val('');
  2339. $('#request_birth_year').val('0');
  2340. $('#request_birth_month').val('0');
  2341. $('#request_birth_month_day').val('0');
  2342. $('#birth-as-date-radio').trigger('click');
  2343. $('#request_medremarks').html('');
  2344. $('#request_cgnamesurname').val('');
  2345. $('#request_cgphone').val('');
  2346. $('#request_cgemail').val('');
  2347. $('#request_cgmmgnamesurname').val('');
  2348. $('#request_cgmmgphone').val('');
  2349. $('#request_cgmmgemail').val('');
  2350. $('#request_cg_file_list').empty();
  2351. $('#request_cg_input_list').empty();
  2352. }
  2353. function readSingleFile(e) {
  2354. var file = e.target.files[0];
  2355. if (!file) {
  2356. return;
  2357. }
  2358. var reader = new FileReader();
  2359. reader.onload = function(e) {
  2360. var contents = e.target.result;
  2361. displayContents(contents);
  2362. };
  2363. reader.readAsText(file);
  2364. }
  2365. function displayContents(contents) {
  2366. console.log(contents);
  2367. }