yemi.js 39 KB

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