選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

app.js 84KB

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