yemi.js 40 KB

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