yemi.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. if (typeof focusOn == 'undefined') {
  2. var focusOn = 'globalSearch';
  3. }
  4. var ajaxGoing = false;
  5. var showMask = function (_text = '') {
  6. $('body').css('opacity', 0.6);
  7. $('#mask').show();
  8. if(!!_text) {
  9. $('<div class="mask-text-addition" />').text('Initializing note. Please wait...').appendTo('body');
  10. }
  11. }
  12. var hideMask = function () {
  13. $('body').css('opacity', 1);
  14. $('#mask').hide();
  15. $('.mask-text-addition').remove();
  16. }
  17. var showMoeFormMask = function (_additionalClass = false) {
  18. if(_additionalClass) {
  19. $('#moe-form-mask').addClass(_additionalClass);
  20. }
  21. $('#moe-form-mask').show();
  22. }
  23. var hideMoeFormMask = function () {
  24. if($('body').is('.blocking-mode')) return false;
  25. $('#moe-form-mask').hide().removeClass();
  26. $('#create-shortcut-form').hide();
  27. }
  28. $(document).ready(function () {
  29. hideMask();
  30. });
  31. $(document).ready(function () {
  32. $("input[type=number]").keydown(function (e) {
  33. // Allow: backspace, delete, tab, escape, enter and .
  34. if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  35. // Allow: Ctrl+A, Command+A
  36. (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  37. // Allow: home, end, left, right, down, up
  38. (e.keyCode >= 35 && e.keyCode <= 40)) {
  39. // let it happen, don't do anything
  40. return;
  41. }
  42. // Ensure that it is a number and stop the keypress
  43. if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  44. e.preventDefault();
  45. }
  46. });
  47. });
  48. $(function () {
  49. $('input[type=checkbox][forceCb]').on('click', function () {
  50. var name = $(this).attr('forceCb');
  51. var code = $(this).attr('code');
  52. var form = $(this).closest('form');
  53. var hiddenField = $(form).find('input[code=\'' + code + '\']');
  54. var value = $(this).prop('checked') ? 'on' : 'off';
  55. console.log('name', name, 'code', code, 'value', value);
  56. $(hiddenField).val(value);
  57. });
  58. });
  59. var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply) {
  60. console.log(data);
  61. if (ajaxGoing) {
  62. console.log('ajax stopped!');
  63. //return; TODO: fix and re-enable return
  64. }
  65. ajaxGoing = true;
  66. if (!shouldHideMask) {
  67. showMask();
  68. }
  69. jQuery.ajax(url, {
  70. dataType: 'json',
  71. data: data,
  72. type: 'POST',
  73. beforeSend: function () {
  74. if (pre) {
  75. pre();
  76. }
  77. }
  78. })
  79. .done(function (response, b) {
  80. console.log(response);
  81. var success = response.success;
  82. if (success) {
  83. if (onSuccess) {
  84. onSuccess(response.data);
  85. }
  86. } else {
  87. if (onFailure) {
  88. onFailure(response.message);
  89. }
  90. if (!suppressErrorMessage) {
  91. //toast the error message
  92. //alert(response.message);
  93. toastr.error(response.message); // , toastr.success("message") ... .warning(), .error()
  94. }
  95. hideMask();
  96. }
  97. if (immediatelyHideMaskOnReply) {
  98. hideMask();
  99. }
  100. ajaxGoing = false;
  101. })
  102. .fail(function (jqXHR, textStatus) {
  103. hideMask();
  104. toastr.error('Unable to process');
  105. if (onHttpFailure) {
  106. onHttpFailure(textStatus);
  107. }
  108. ajaxGoing = false;
  109. })
  110. .always(function () {
  111. if (post) {
  112. post();
  113. }
  114. ajaxGoing = false;
  115. });
  116. };
  117. var doAjaxFormData = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply) {
  118. console.log(data);
  119. if (ajaxGoing) {
  120. console.log('ajax stopped!');
  121. //return; TODO: fix and re-enable return
  122. }
  123. ajaxGoing = true;
  124. if (!shouldHideMask) {
  125. showMask();
  126. }
  127. jQuery.ajax(url, {
  128. dataType: 'json',
  129. data: data,
  130. processData: false,
  131. contentType: false,
  132. type: 'POST',
  133. beforeSend: function () {
  134. if (pre) {
  135. pre();
  136. }
  137. }
  138. })
  139. .done(function (response, b) {
  140. console.log(response);
  141. var success = response.success;
  142. if (success) {
  143. if (onSuccess) {
  144. onSuccess(response.data);
  145. }
  146. } else {
  147. if (onFailure) {
  148. onFailure(response.message);
  149. }
  150. if (!suppressErrorMessage) {
  151. //toast the error message
  152. //alert(response.message);
  153. toastr.error(response.message); // , toastr.success("message") ... .warning(), .error()
  154. }
  155. hideMask();
  156. }
  157. if (immediatelyHideMaskOnReply) {
  158. hideMask();
  159. }
  160. ajaxGoing = false;
  161. })
  162. .fail(function (jqXHR, textStatus) {
  163. hideMask();
  164. toastr.error('Unable to process');
  165. if (onHttpFailure) {
  166. onHttpFailure(textStatus);
  167. }
  168. ajaxGoing = false;
  169. })
  170. .always(function () {
  171. if (post) {
  172. post();
  173. }
  174. ajaxGoing = false;
  175. });
  176. };
  177. var justLog = false; //THIS IS FOR TEST MODE, FORMS WILL NOT TRIGGER REFRESH/REDIR
  178. var pageReload = function (_target) {
  179. setTimeout(function () {
  180. hideMoeFormMask();
  181. fastReload(_target);
  182. }, 500);
  183. };
  184. if (typeof String.prototype.startsWith != 'function') {
  185. // see below for better implementation!
  186. String.prototype.startsWith = function (str) {
  187. return this.indexOf(str) === 0;
  188. };
  189. }
  190. $(function () {
  191. $('[addressLine1]').each(function () {
  192. var moe = $(this).closest('[moe]');
  193. var a = {};
  194. a.addressLine1 = $(this);
  195. a.addressLine2 = $(moe).find('[addressLine2]');
  196. a.addressCity = $(moe).find('[addressCity]');
  197. a.addressState = $(moe).find('[addressState]');
  198. a.addressPostcode = $(moe).find('[addressPostcode]');
  199. var getAddress = function () {
  200. var address = {};
  201. for (var prop in a) {
  202. var val = $(a[prop]).val();
  203. address[prop] = val;
  204. }
  205. return address;
  206. }
  207. var getFormattedAddress = function (address) {
  208. var x = '<p>';
  209. x += address.addressLine1 + (address.addressLine2 ? ', ' + address.addressLine2 : '') + '<br/>' + address.addressCity + ', ' + address.addressState + ' ' + address.addressPostcode;
  210. x += '</p>';
  211. return x;
  212. }
  213. var suggestAddress = function () {
  214. var address = getAddress();
  215. //var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask)
  216. var onSuccess = function (data) {
  217. console.log('SUCCESS!!!', data);
  218. }
  219. var onFailure = function (message) {
  220. if (message.startsWith('Invalid:: INVALID ADDRESS - SUGGESTED:')) {
  221. var suggestionText = message.substring(message.indexOf('{'));
  222. var suggestion = JSON.parse(suggestionText);
  223. console.log('SUGGESTION!!!', suggestion);
  224. $('#myModal').attr('title', 'Address suggestion');
  225. $('#myModal').html('<h3>Currently set address:</h3>' + getFormattedAddress(address) + '<h3>Suggestion:</h3>' + getFormattedAddress(suggestion));
  226. $('#myModal').dialog({
  227. height: 400,
  228. width: 500,
  229. modal: true,
  230. buttons: [{
  231. text: 'Use suggestion',
  232. click: function () {
  233. for (var prop in a) {
  234. $(a[prop]).val(suggestion[prop]);
  235. }
  236. $(this).dialog('close');
  237. }
  238. },
  239. {
  240. text: 'Keep original',
  241. click: function () {
  242. $(this).dialog('close');
  243. }
  244. }
  245. ]
  246. });
  247. } else if (message.startsWith('Invalid:: INVALID ADDRESS')) {
  248. console.log('NO SUGGESTION!!!');
  249. $('#myModal').attr('title', 'No address found');
  250. $('#myModal').html('<h3>Currently set address:</h3>' + getFormattedAddress(address) + '<h3>No suggestion!</h3>');
  251. $('#myModal').dialog({
  252. height: 400,
  253. width: 500,
  254. modal: true,
  255. buttons: [{
  256. text: 'Erase address fields',
  257. click: function () {
  258. for (var prop in a) {
  259. $(a[prop]).val('');
  260. }
  261. $(this).dialog('close');
  262. }
  263. },
  264. {
  265. text: 'Keep original',
  266. click: function () {
  267. $(this).dialog('close');
  268. }
  269. }
  270. ]
  271. });
  272. }
  273. }
  274. doAjax('/api/service/verifyAddress', address, null, null, onSuccess, onFailure, true, null, false, true);
  275. }
  276. var isAddressComplete = function () {
  277. var address = getAddress();
  278. return address.addressLine1 && ((address.addressCity && address.addressState) || address.addressPostcode) ? true : false;
  279. }
  280. for (var prop in a) {
  281. var part = a[prop];
  282. $(part).on('change', function () {
  283. console.log(getAddress());
  284. var isComplete = isAddressComplete();
  285. if (isComplete) {
  286. suggestAddress();
  287. }
  288. });
  289. $(part).attr('autocomplete', 'off');
  290. }
  291. });
  292. });
  293. var initMoes = function() {
  294. $('[moe]').each(function () {
  295. if($(this).is('[initialized]')) { // skip to next moe
  296. return true;
  297. }
  298. var moe = $(this);
  299. moe.isProcessing = false;
  300. var info = moe.find('[info]')[0]; // OPTIONAL
  301. var start = moe.find('[start]')[0]; // OPTIONAL
  302. var form = moe.find('[url]')[0]; // REQUIRED
  303. var url = $(form).attr('url'); // REQUIRED
  304. var redir = $(form).attr('redir'); // OPTIONAL
  305. var target = $(form).attr('target'); // OPTIONAL
  306. var noreload = $(form).is('[noreload]'); // OPTIONAL
  307. var submit = moe.find('[submit]'); // REQUIRED
  308. var cancel = moe.find('[cancel]')[0]; // OPTIONAL
  309. // ajax load - OPTIONAL
  310. var moeParent = $(form).closest('[moe-parent][url]');
  311. if ($(this).attr('formOff') != null) {
  312. $(form).find(':input').attr('disabled', true);
  313. var formOn = $(this).find('[formOn]');
  314. $(formOn).attr('disabled', false);
  315. $(submit).hide();
  316. $(formOn).click(function () {
  317. $(form).find(':input').attr('disabled', false);
  318. $(submit).show();
  319. $(formOn).hide();
  320. return false;
  321. });
  322. }
  323. var realForm = form;
  324. //init set display inline so toggle remembers inline state
  325. var formToggle = false;
  326. var infoToggle = false;
  327. if (start) {
  328. $(start).off('click.moe');
  329. $(start).on('click.moe', function () {
  330. // if any div based moes are visible, hide first
  331. $('[moe]>div[url]:visible').hide();
  332. $('.dropdown-menu[aria-labelledby="practice-management"]')
  333. .removeClass('show')
  334. .prev('.dropdown-toggle').attr('aria-expanded', 'false');
  335. if ($(realForm).attr('show') == null) {
  336. if (!formToggle && $(realForm).attr('liner') != null) {
  337. $(realForm).css('display', 'inline');
  338. formToggle = true;
  339. } else {
  340. var isRealFormVisible = $(realForm).is(':visible');
  341. if(isRealFormVisible){
  342. hideMoeFormMask();
  343. $(realForm).toggle(100);
  344. }else{
  345. // keep data in moes, don't force reset
  346. // if($(realForm).is('form')) $(realForm)[0].reset();
  347. if(!$(realForm).closest('[moe]').is('[no-mask]')) {
  348. showMoeFormMask();
  349. }
  350. setTimeout(function() {
  351. $('[moe]>[url]:not([show]):visible').hide();
  352. $(realForm).toggle(100);
  353. initPrimaryForm($(realForm));
  354. setTimeout(function() {
  355. let submitButton = $(realForm).find('[submit]');
  356. if(submitButton.length) submitButton[0].scrollIntoView({behavior : "smooth", block: "nearest"});
  357. // if any callback, trigger it
  358. if($(realForm).is('[onshow]')) {
  359. window[$(realForm).attr('onshow')].call($(realForm)[0]);
  360. }
  361. }, 150);
  362. }, 100);
  363. }
  364. }
  365. }
  366. if (!infoToggle && info && $(info).attr('show') == null) {
  367. if ($(info).attr('liner') != null) {
  368. $(info).css('display', 'inline');
  369. infoToggle = true;
  370. } else {
  371. $(info).toggle(100);
  372. }
  373. }
  374. if ($(start).attr('show') == null) {
  375. $(start).toggle(100);
  376. }
  377. var focusOnStart = $(realForm).find('[focusOnStart]');
  378. if (focusOnStart) {
  379. $(focusOnStart).focus();
  380. }
  381. return false;
  382. });
  383. $(start).attr('href', '#');
  384. }
  385. if (cancel) {
  386. $(cancel).off('click.moe');
  387. $(cancel).on('click.moe', function (e) {
  388. e.preventDefault();
  389. e.stopImmediatePropagation();
  390. if ($(realForm).attr('show') == null) {
  391. $(realForm).hide(100);
  392. }
  393. if (info && $(info).attr('show') == null) {
  394. $(info).show(100);
  395. }
  396. if (start && $(start).attr('show') == null) {
  397. $(start).show(100);
  398. }
  399. hideMoeFormMask();
  400. });
  401. }
  402. $(submit).off('click.moe');
  403. $(submit).on('click.moe', function (e) {
  404. e.preventDefault();
  405. e.stopImmediatePropagation();
  406. if (moe.isProcessing) {
  407. return false;
  408. }
  409. if ($(submit).attr('confirm')) {
  410. var question = $(submit).attr('confirm');
  411. var cont = confirm(question);
  412. if (cont) {} else {
  413. console.log("ABORTED!");
  414. return;
  415. }
  416. }
  417. if($(form).is('form')) {
  418. // trigger validation
  419. if (!$(form)[0].checkValidity()) {
  420. $(form)[0].reportValidity();
  421. return;
  422. }
  423. // check and trigger onbeforesubmit
  424. if($(form).is('[onbeforesubmit]')) {
  425. window[$(form).attr('onbeforesubmit')].call($(realForm)[0]);
  426. }
  427. // submit
  428. moe.isProcessing = true;
  429. var data = {};
  430. var formData = $(form).serializeArray();
  431. formData.forEach(function (field) {
  432. if (data[field.name]) {
  433. if (data[field.name] instanceof Array) {
  434. data[field.name].push(field.value);
  435. } else {
  436. var arr = [];
  437. arr.push(data[field.name]);
  438. arr.push(field.value);
  439. data[field.name] = arr;
  440. }
  441. } else {
  442. data[field.name] = field.value;
  443. }
  444. });
  445. console.log(data);
  446. //var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply)
  447. // override with FormData if the form has any files
  448. let useFormData = false;
  449. if($(form).find('input[type="file"]').length) {
  450. let formData = new FormData();
  451. for(let x in data) {
  452. if(data.hasOwnProperty(x)) {
  453. formData.set(x, data[x]);
  454. }
  455. }
  456. $(form).find('input[type="file"]').each(function() {
  457. let fieldName = this.name;
  458. if(this.files && this.files.length) {
  459. formData.append(fieldName, this.files[0]);
  460. }
  461. });
  462. data = formData;
  463. useFormData = true;
  464. }
  465. if(!useFormData) {
  466. doAjax(url, data, null, function () {
  467. moe.isProcessing = false;
  468. }, function (data) {
  469. if(noreload) {
  470. $(cancel).trigger('click.moe');
  471. hideMoeFormMask();
  472. hideMask();
  473. toastr.success('Done');
  474. return;
  475. }
  476. if (justLog) { // this is to test!
  477. console.log('RETURNED', data);
  478. } else if(isDynamicStagPopupPresent()) {
  479. refreshDynamicStagPopup();
  480. } else if (redir) {
  481. if (redir == "back") {
  482. window.top.history.back();
  483. } else {
  484. if (redir.indexOf('[data]') > -1) {
  485. redir = redir.replace('[data]', data);
  486. }
  487. fastLoad(redir, true, false);
  488. }
  489. } else if (moeParent.length) {
  490. showMask();
  491. $.get(moeParent.attr('url'), function (_data) {
  492. moeParent.html(_data);
  493. hideMask();
  494. hideMoeFormMask();
  495. initMoes();
  496. initFastLoad(moeParent);
  497. initAutoRxAndICDComplete();
  498. });
  499. } else {
  500. pageReload(target);
  501. }
  502. }, function (errorMessage) {
  503. }, false);
  504. }
  505. else {
  506. doAjaxFormData(url, data, null, function () {
  507. moe.isProcessing = false;
  508. }, function (data) {
  509. if(noreload) {
  510. $(cancel).trigger('click.moe');
  511. hideMoeFormMask();
  512. hideMask();
  513. toastr.success('Done');
  514. return;
  515. }
  516. if (justLog) { // this is to test!
  517. console.log('RETURNED', data);
  518. } else if(isDynamicStagPopupPresent()) {
  519. refreshDynamicStagPopup();
  520. } else if (redir) {
  521. if (redir == "back") {
  522. window.top.history.back();
  523. } else {
  524. if (redir.indexOf('[data]') > -1) {
  525. redir = redir.replace('[data]', data);
  526. }
  527. fastLoad(redir, true, false);
  528. }
  529. } else if (moeParent.length) {
  530. showMask();
  531. $.get(moeParent.attr('url'), function (_data) {
  532. moeParent.html(_data);
  533. hideMask();
  534. hideMoeFormMask();
  535. initMoes();
  536. initFastLoad(moeParent);
  537. initAutoRxAndICDComplete();
  538. });
  539. } else {
  540. pageReload(target);
  541. }
  542. }, function (errorMessage) {
  543. }, false);
  544. }
  545. }
  546. });
  547. moe.attr('initialized', 1); // mark as initialized
  548. });
  549. }
  550. jQuery(document).ready(function () {
  551. var $ = jQuery;
  552. $('body').mousedown(function(e){
  553. if($(e.target).closest('[moe]').length ||
  554. $(e.target).closest('#create-shortcut-form').length ||
  555. $(e.target).is('#create-shortcut-form') ||
  556. $(e.target).is('.stag-shortcuts .sc') ||
  557. $(e.target).closest('.ui-datepicker').length) {
  558. return;
  559. }
  560. $('[moe] [url]:not([show])').hide();
  561. hideMoeFormMask();
  562. });
  563. initMoes();
  564. $('table[info] input').each(function () {
  565. $(this).prop('readonly', true);
  566. });
  567. //...for checkboxes readonly
  568. $('input[type=checkbox][readonly],input[type=radio][readonly]').each(function () {
  569. var x = this;
  570. var isChecked = $(x).attr('checked');
  571. $(x).change(function () {
  572. $(x).attr('checked', isChecked);
  573. });
  574. });
  575. $('[show-if]').each(function () { //TODO show-if="isOpen" show-if="isTimeSpecific" show-if="refillFrequency=MONTH"
  576. var x = this;
  577. var sel = $(x).attr('show-if');
  578. var selParts = sel.split('=');
  579. var selName = selParts[0];
  580. var selValue = selParts[1];
  581. var useOpposite = selName[0] == '!';
  582. if (useOpposite) {
  583. selName = selName.slice(1);
  584. }
  585. var form = $(x).closest('form');
  586. var conditionFields = $(form).find('[name=' + selName + ']');
  587. function hideX() {
  588. $(x).hide();
  589. }
  590. function showX() {
  591. $(x).show();
  592. }
  593. var go = function () {
  594. if (selValue) {
  595. var value = $(conditionFields).val();
  596. if (value == selValue) {
  597. if (useOpposite) {
  598. hideX()
  599. } else {
  600. showX()
  601. }
  602. } else {
  603. if (useOpposite) {
  604. showX()
  605. } else {
  606. hideX()
  607. }
  608. }
  609. } else {
  610. var isChecked = $(conditionFields).prop('checked');
  611. if (isChecked) {
  612. if (useOpposite) {
  613. hideX()
  614. } else {
  615. showX()
  616. }
  617. } else {
  618. if (useOpposite) {
  619. showX()
  620. } else {
  621. hideX()
  622. }
  623. }
  624. }
  625. };
  626. go();
  627. $(conditionFields).change(function () {
  628. go();
  629. });
  630. });
  631. });
  632. //now goTo is a plugin...
  633. (function ($) {
  634. $.fn.goTo = function (x) {
  635. $('html, body').animate({
  636. scrollTop: ($(this).offset().top - x) + 'px'
  637. }, 1);
  638. return this; // for chaining...
  639. };
  640. })(jQuery);
  641. $(document).ready(function () {
  642. $(".expander").on("click", function () {
  643. var expandedID = $(this).attr("id");
  644. if ($(this).text() == "-") {
  645. $(this).text("+");
  646. } else {
  647. $(this).text("-");
  648. }
  649. $("." + expandedID).toggle();
  650. return false;
  651. });
  652. });
  653. $(document).ready(function () {
  654. $('[showMap]').each(function () {
  655. var mapper = $(this);
  656. var adr = mapper.attr('showMap');
  657. mapper.on('click', function () {
  658. showAddr(adr);
  659. return false;
  660. });
  661. });
  662. });
  663. $(document).ready(function () {
  664. $('[dateRanger]').each(function () {
  665. var dr = $(this);
  666. var rangeTypeSelect = dr.find('select')[0];
  667. var date1Input = dr.find('[date1]')[0];
  668. var date2Input = dr.find('[date2]')[0];
  669. var d1Val = '';
  670. var d2Val = '';
  671. var d1 = function (enable) {
  672. if (enable) {
  673. var hasVal = $(date1Input).val();
  674. if (!hasVal) {
  675. $(date1Input).val(d1Val);
  676. }
  677. $(date1Input).show();
  678. } else {
  679. d1Val = $(date1Input).val();
  680. $(date1Input).val('');
  681. $(date1Input).hide();
  682. }
  683. };
  684. var d2 = function (enable) {
  685. if (enable) {
  686. var hasVal = $(date2Input).val();
  687. if (!hasVal) {
  688. $(date2Input).val(d2Val);
  689. }
  690. $(date2Input).show();
  691. } else {
  692. d2Val = $(date2Input).val();
  693. $(date2Input).val('');
  694. $(date2Input).hide();
  695. }
  696. };
  697. var adjustFields = function () {
  698. var rangeType = $(rangeTypeSelect).val();
  699. if (rangeType == 'all') {
  700. d1();
  701. d2();
  702. } else if (rangeType == 'on-or-before') {
  703. d1(true);
  704. d2();
  705. } else if (rangeType == 'on-or-after') {
  706. d1(true);
  707. d2();
  708. } else if (rangeType == 'between') {
  709. d1(true);
  710. d2(true);
  711. } else if (rangeType == 'on') {
  712. d1(true);
  713. d2();
  714. } else if (rangeType == 'not-on') {
  715. d1(true);
  716. d2();
  717. } else if (rangeType == 'not-in-between') {
  718. d1(true);
  719. d2(true);
  720. }
  721. };
  722. adjustFields();
  723. $(rangeTypeSelect).change(function () {
  724. adjustFields();
  725. });
  726. });
  727. $('[numRanger]').each(function () {
  728. var nr = $(this);
  729. var rangeTypeSelect = nr.find('select')[0];
  730. var num1Input = nr.find('[num1]')[0];
  731. var num2Input = nr.find('[num2]')[0];
  732. var n1 = function (enable) {
  733. if (enable) {
  734. $(num1Input).show();
  735. } else {
  736. $(num1Input).hide();
  737. }
  738. };
  739. var n2 = function (enable) {
  740. if (enable) {
  741. $(num2Input).show();
  742. } else {
  743. $(num2Input).hide();
  744. }
  745. };
  746. var adjustFields = function () {
  747. var rangeType = $(rangeTypeSelect).val();
  748. if (rangeType == 'all') {
  749. n1();
  750. n2();
  751. } else if (rangeType == 'less-than') {
  752. n1(true);
  753. n2();
  754. } else if (rangeType == 'greater-than') {
  755. n1(true);
  756. n2();
  757. } else if (rangeType == 'equal-to') {
  758. n1(true);
  759. n2();
  760. } else if (rangeType == 'between') {
  761. n1(true);
  762. n2(true);
  763. } else if (rangeType == 'not-equal-to') {
  764. n1(true);
  765. n2();
  766. } else if (rangeType == 'not-in-between') {
  767. n1(true);
  768. n2(true);
  769. }
  770. };
  771. adjustFields('all');
  772. $(rangeTypeSelect).change(function () {
  773. adjustFields();
  774. });
  775. });
  776. });
  777. $(document).ready(function () {
  778. $('[minzero]').on('change', function () {
  779. var val = $(this).val();
  780. val = parseFloat(val);
  781. if (val < 0) {
  782. alert('This number cannot be less than zero.');
  783. $(this).val('');
  784. $(this).focus();
  785. }
  786. });
  787. });
  788. var showAddr = function (adr) {
  789. window.open('http://192.241.155.210/geo.php?adr=' + adr, new Date().getTime(), "height=400,width=520");
  790. };
  791. $(document).ready(function () {
  792. var globalSearch = function () {
  793. var substring = $('#globalSearch').val();
  794. console.log("SUBSTRING", substring);
  795. if (substring.length > 2) {
  796. $("#results").show();
  797. $("#results").load("/global-search?substring=" + encodeURIComponent(substring));
  798. } else {
  799. $("#results").hide();
  800. }
  801. };
  802. $("#globalSearch").on('keyup', function (evnt) {
  803. globalSearch();
  804. });
  805. $("#globalSearch").on('focus', function (evnt) {
  806. globalSearch();
  807. });
  808. $("#globalSearch").on('blur', function (evt) {
  809. setTimeout(function () {
  810. $("#results").hide();
  811. }, 500);
  812. });
  813. });
  814. $('a[aller]').attr('href', '#');
  815. var selectAll = true;
  816. $('a[aller]').click(function () {
  817. $('input[type=checkbox][aller]').each(function () {
  818. if (!$(this).is(':disabled')) {
  819. $(this).prop('checked', selectAll);
  820. }
  821. });
  822. selectAll = !selectAll;
  823. return false;
  824. });
  825. $(function () {
  826. $('.showOnLoad').show();
  827. });
  828. $(function () {
  829. var i = 0;
  830. function pulsate() {
  831. $(".urgentIndicator").
  832. animate({
  833. opacity: 0.2
  834. }, 200, 'linear').
  835. animate({
  836. opacity: 1
  837. }, 200, 'linear', pulsate);
  838. }
  839. pulsate();
  840. });
  841. $(function () {
  842. $('[remote-searcher]').each(function () {
  843. var me = this;
  844. $(me).hide();
  845. var selections = [];
  846. var isMulti = typeof $(me).attr('multiple') == 'string';
  847. $(me).find('[rid]').each(function () {
  848. selections.push({
  849. id: $(this).attr('rid'),
  850. display: $(this).attr('display')
  851. });
  852. });
  853. if (!isMulti && selections[0]) {
  854. selections = [selections[0]];
  855. }
  856. $(me).html('');
  857. var url = $(me).attr('remote-searcher');
  858. var charMin = $(me).attr('char-min');
  859. var name = $(me).attr('name');
  860. $(me).append('<select multiple style="display:none;" name="' + name + '"></select><span choices></span><input type="text" style="border:none;margin:5px;width:100%;outline:none;display:none;"/></span>');
  861. $(me).append('<div style="margin-top:2px;background:white;border:1px lightgray solid;display:none;width:99%;position:absolute;z-index:999"></div>');
  862. var choices = $(me).find('span[choices]');
  863. var selectField = $(me).find('select');
  864. var textField = $(me).find('input[type=text]');
  865. var resultDiv = $(me).find('div');
  866. var setResultMask = function () {
  867. $(resultDiv).html('<div style="background-image: url(/icons/vanillaspin.gif); background-repeat: no-repeat; width:100%; height:60px;background-position: center;"></div>');
  868. }
  869. var fillSelected = function (selected) {
  870. $(selectField).html('');
  871. $(choices).html('');
  872. selected.forEach(function (choice, index) {
  873. if (isMulti || (!isMulti && index == 0)) {
  874. $(selectField).append('<option selected value="' + choice.id + '">' + choice.display + '</option>');
  875. $(choices).append('<button style="margin:2px;" rid="' + choice.id + '" index="' + index + '">' + choice.display + ' x</button>');
  876. }
  877. });
  878. $(choices).find('button').on('click', function () {
  879. var btn = this;
  880. var rid = $(btn).attr('rid');
  881. var index = $(btn).attr('index');
  882. selections.splice(index, 1);
  883. fillSelected(selected);
  884. return false;
  885. });
  886. }
  887. fillSelected(selections);
  888. var setValue = function (val, display) {
  889. if (!isMulti) {
  890. selections = [];
  891. }
  892. // get rid of earliers
  893. for (var i = 0; i < selections.length; i++) {
  894. var sel = selections[i];
  895. if (sel.id == parseInt(val)) {
  896. selections.splice(i, 1);
  897. }
  898. }
  899. selections.push({
  900. id: val,
  901. display: display
  902. });
  903. fillSelected(selections);
  904. $(textField).val('');
  905. $(textField).hide();
  906. }
  907. var getMatches = function () {
  908. var substring = $(textField).val();
  909. if (charMin > substring.length) {
  910. return;
  911. }
  912. setResultMask();
  913. $(resultDiv).show();
  914. //url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask
  915. doAjax(url, {
  916. substring: substring
  917. }, null, null, function (matches) {
  918. $(resultDiv).find('[rid]').each(function () {
  919. $(this).off()
  920. });
  921. $(resultDiv).html('');
  922. matches.forEach(function (match) {
  923. if (typeof match == 'string') {
  924. match = {
  925. id: match,
  926. display: match
  927. }
  928. }
  929. if (typeof match == 'object' && !match.id) {
  930. match.id = match.display;
  931. }
  932. $(resultDiv).append('<a href="#" class="searcher-result" display="' + match.display + '" rid="' + match.id + '">' + match.display + '</a>');
  933. });
  934. $(resultDiv).find('[rid]').each(function () {
  935. var result = this;
  936. $(result).mousedown('click', function () {
  937. var val = $(result).attr('rid');
  938. var display = $(result).attr('display');
  939. setValue(val, display);
  940. //$(textField).hide();
  941. return false;
  942. });
  943. });
  944. }, null, true, null, true);
  945. };
  946. $(textField).on('keyup', function () {
  947. getMatches();
  948. });
  949. $(textField).on('blur', function () {
  950. $(textField).val('');
  951. $(textField).hide();
  952. if ($(resultDiv).is(':visible')) {
  953. $(resultDiv).hide();
  954. };
  955. });
  956. $(textField).on('focus', function () {
  957. getMatches();
  958. });
  959. $(me).on('click', function () {
  960. $(textField).show();
  961. $(textField).focus();
  962. });
  963. $(me).show();
  964. });
  965. });
  966. $(document).ready(function () {
  967. // setInterval(function () {
  968. // doAjax('/api/session/test', null, null, null, null, function () {
  969. // window.location.reload(true);
  970. // }, true, null, true);
  971. // }, 10000);
  972. });
  973. $(document).ready(function () {
  974. if (focusOn) {
  975. $('#' + focusOn).focus();
  976. }
  977. });
  978. $(function () {
  979. $('[setMaskOnClick]').click(function () {
  980. showMask();
  981. });
  982. });
  983. $(function () {
  984. $('input[type=file][ajaxload]').each(function () {
  985. var me = this;
  986. var name = $(me).attr('ajaxload');
  987. $(me).wrap('<span class="ajaxload"></span>');
  988. $(me).closest('span').append('<input type="hidden" name="' + name + '"/>');
  989. $(me).on('change', function (event) {
  990. console.log("file received.");
  991. var fileField = me;
  992. var files = event.target.files;
  993. var data = new FormData();
  994. $.each(files, function (key, value) {
  995. data.append(key, value);
  996. });
  997. $.ajax({
  998. url: '/api/systemFile/upload',
  999. type: 'POST',
  1000. data: data,
  1001. cache: false,
  1002. dataType: 'json',
  1003. processData: false, // Don't process the files
  1004. contentType: false, // Set content type to false as jQuery will tell the server its a query string request
  1005. success: function (data, textStatus, jqXHR) {
  1006. var systemFileID = data.data;
  1007. console.log("UPLOAD WORKED::", data);
  1008. $(me).closest('span').find('input[type=hidden]').val(systemFileID);
  1009. },
  1010. error: function (jqXHR, textStatus, errorThrown) {
  1011. console.log('ERRORS: ' + textStatus);
  1012. }
  1013. });
  1014. });
  1015. });
  1016. });
  1017. // catch ESC and discard any visible moes
  1018. $(document).ready(function () {
  1019. $(document)
  1020. .off('keydown.moe-escape')
  1021. .on('keydown.moe-escape', function (e) {
  1022. if(e.which === 27) {
  1023. let visibleMoes = $('[moe] [url]:not([show]):visible');
  1024. if (visibleMoes.length) {
  1025. hideMoeFormMask();
  1026. visibleMoes.hide();
  1027. window.moeClosedAt = (new Date()).getTime();
  1028. markEventAsConsumed(e);
  1029. return false;
  1030. }
  1031. }
  1032. });
  1033. });