yemi.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  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. let targetUrl = false;
  486. if (redir) {
  487. if (redir.indexOf('[data]') > -1) {
  488. targetUrl = redir.replace('[data]', data);
  489. }
  490. }
  491. refreshDynamicStagPopup(targetUrl, target);
  492. } else if (redir) {
  493. if (redir == "back") {
  494. window.top.history.back();
  495. } else {
  496. if (redir.indexOf('[data]') > -1) {
  497. redir = redir.replace('[data]', data);
  498. }
  499. fastLoad(redir, true, false);
  500. }
  501. } else if (moeParent.length) {
  502. showMask();
  503. $.get(moeParent.attr('url'), function (_data) {
  504. moeParent.html(_data);
  505. hideMask();
  506. hideMoeFormMask();
  507. initMoes();
  508. initFastLoad(moeParent);
  509. initAutoRxAndICDComplete();
  510. });
  511. } else {
  512. pageReload(target);
  513. }
  514. }, function (errorMessage) {
  515. }, false);
  516. }
  517. else {
  518. doAjaxFormData(url, data, null, function () {
  519. moe.isProcessing = false;
  520. }, function (data) {
  521. if(noreload) {
  522. $(cancel).trigger('click.moe');
  523. hideMoeFormMask();
  524. hideMask();
  525. toastr.success('Done');
  526. return;
  527. }
  528. if (justLog) { // this is to test!
  529. console.log('RETURNED', data);
  530. } else if (hook) {
  531. $(cancel).trigger('click.moe');
  532. hideMoeFormMask();
  533. hideMask();
  534. runMCHook(hook);
  535. } else if(isDynamicStagPopupPresent()) {
  536. let targetUrl = false;
  537. if (redir) {
  538. if (redir.indexOf('[data]') > -1) {
  539. targetUrl = redir.replace('[data]', data);
  540. }
  541. }
  542. refreshDynamicStagPopup(targetUrl);
  543. } else if (redir) {
  544. if (redir == "back") {
  545. window.top.history.back();
  546. } else {
  547. if (redir.indexOf('[data]') > -1) {
  548. redir = redir.replace('[data]', data);
  549. }
  550. fastLoad(redir, true, false);
  551. }
  552. } else if (moeParent.length) {
  553. showMask();
  554. $.get(moeParent.attr('url'), function (_data) {
  555. moeParent.html(_data);
  556. hideMask();
  557. hideMoeFormMask();
  558. initMoes();
  559. initFastLoad(moeParent);
  560. initAutoRxAndICDComplete();
  561. });
  562. } else {
  563. pageReload(target);
  564. }
  565. }, function (errorMessage) {
  566. }, false);
  567. }
  568. }
  569. });
  570. moe.attr('initialized', 1); // mark as initialized
  571. });
  572. }
  573. jQuery(document).ready(function () {
  574. var $ = jQuery;
  575. $('body').mousedown(function(e){
  576. if($(e.target).closest('[moe]').length ||
  577. $(e.target).closest('#create-shortcut-form').length ||
  578. $(e.target).is('#create-shortcut-form') ||
  579. $(e.target).is('.stag-shortcuts .sc') ||
  580. $(e.target).closest('.ui-datepicker').length) {
  581. return;
  582. }
  583. $('[moe] [url]:not([show])').hide();
  584. hideMoeFormMask();
  585. });
  586. initMoes();
  587. $('table[info] input').each(function () {
  588. $(this).prop('readonly', true);
  589. });
  590. //...for checkboxes readonly
  591. $('input[type=checkbox][readonly],input[type=radio][readonly]').each(function () {
  592. var x = this;
  593. var isChecked = $(x).attr('checked');
  594. $(x).change(function () {
  595. $(x).attr('checked', isChecked);
  596. });
  597. });
  598. $('[show-if]').each(function () { //TODO show-if="isOpen" show-if="isTimeSpecific" show-if="refillFrequency=MONTH"
  599. var x = this;
  600. var sel = $(x).attr('show-if');
  601. var selParts = sel.split('=');
  602. var selName = selParts[0];
  603. var selValue = selParts[1];
  604. var useOpposite = selName[0] == '!';
  605. if (useOpposite) {
  606. selName = selName.slice(1);
  607. }
  608. var form = $(x).closest('form');
  609. var conditionFields = $(form).find('[name=' + selName + ']');
  610. function hideX() {
  611. $(x).hide();
  612. }
  613. function showX() {
  614. $(x).show();
  615. }
  616. var go = function () {
  617. if (selValue) {
  618. var value = $(conditionFields).val();
  619. if (value == selValue) {
  620. if (useOpposite) {
  621. hideX()
  622. } else {
  623. showX()
  624. }
  625. } else {
  626. if (useOpposite) {
  627. showX()
  628. } else {
  629. hideX()
  630. }
  631. }
  632. } else {
  633. var isChecked = $(conditionFields).prop('checked');
  634. if (isChecked) {
  635. if (useOpposite) {
  636. hideX()
  637. } else {
  638. showX()
  639. }
  640. } else {
  641. if (useOpposite) {
  642. showX()
  643. } else {
  644. hideX()
  645. }
  646. }
  647. }
  648. };
  649. go();
  650. $(conditionFields).change(function () {
  651. go();
  652. });
  653. });
  654. });
  655. //now goTo is a plugin...
  656. (function ($) {
  657. $.fn.goTo = function (x) {
  658. $('html, body').animate({
  659. scrollTop: ($(this).offset().top - x) + 'px'
  660. }, 1);
  661. return this; // for chaining...
  662. };
  663. })(jQuery);
  664. $(document).ready(function () {
  665. $(".expander").on("click", function () {
  666. var expandedID = $(this).attr("id");
  667. if ($(this).text() == "-") {
  668. $(this).text("+");
  669. } else {
  670. $(this).text("-");
  671. }
  672. $("." + expandedID).toggle();
  673. return false;
  674. });
  675. });
  676. $(document).ready(function () {
  677. $('[showMap]').each(function () {
  678. var mapper = $(this);
  679. var adr = mapper.attr('showMap');
  680. mapper.on('click', function () {
  681. showAddr(adr);
  682. return false;
  683. });
  684. });
  685. });
  686. $(document).ready(function () {
  687. $('[dateRanger]').each(function () {
  688. var dr = $(this);
  689. var rangeTypeSelect = dr.find('select')[0];
  690. var date1Input = dr.find('[date1]')[0];
  691. var date2Input = dr.find('[date2]')[0];
  692. var d1Val = '';
  693. var d2Val = '';
  694. var d1 = function (enable) {
  695. if (enable) {
  696. var hasVal = $(date1Input).val();
  697. if (!hasVal) {
  698. $(date1Input).val(d1Val);
  699. }
  700. $(date1Input).show();
  701. } else {
  702. d1Val = $(date1Input).val();
  703. $(date1Input).val('');
  704. $(date1Input).hide();
  705. }
  706. };
  707. var d2 = function (enable) {
  708. if (enable) {
  709. var hasVal = $(date2Input).val();
  710. if (!hasVal) {
  711. $(date2Input).val(d2Val);
  712. }
  713. $(date2Input).show();
  714. } else {
  715. d2Val = $(date2Input).val();
  716. $(date2Input).val('');
  717. $(date2Input).hide();
  718. }
  719. };
  720. var adjustFields = function () {
  721. var rangeType = $(rangeTypeSelect).val();
  722. if (rangeType == 'all') {
  723. d1();
  724. d2();
  725. } else if (rangeType == 'on-or-before') {
  726. d1(true);
  727. d2();
  728. } else if (rangeType == 'on-or-after') {
  729. d1(true);
  730. d2();
  731. } else if (rangeType == 'between') {
  732. d1(true);
  733. d2(true);
  734. } else if (rangeType == 'on') {
  735. d1(true);
  736. d2();
  737. } else if (rangeType == 'not-on') {
  738. d1(true);
  739. d2();
  740. } else if (rangeType == 'not-in-between') {
  741. d1(true);
  742. d2(true);
  743. }
  744. };
  745. adjustFields();
  746. $(rangeTypeSelect).change(function () {
  747. adjustFields();
  748. });
  749. });
  750. $('[numRanger]').each(function () {
  751. var nr = $(this);
  752. var rangeTypeSelect = nr.find('select')[0];
  753. var num1Input = nr.find('[num1]')[0];
  754. var num2Input = nr.find('[num2]')[0];
  755. var n1 = function (enable) {
  756. if (enable) {
  757. $(num1Input).show();
  758. } else {
  759. $(num1Input).hide();
  760. }
  761. };
  762. var n2 = function (enable) {
  763. if (enable) {
  764. $(num2Input).show();
  765. } else {
  766. $(num2Input).hide();
  767. }
  768. };
  769. var adjustFields = function () {
  770. var rangeType = $(rangeTypeSelect).val();
  771. if (rangeType == 'all') {
  772. n1();
  773. n2();
  774. } else if (rangeType == 'less-than') {
  775. n1(true);
  776. n2();
  777. } else if (rangeType == 'greater-than') {
  778. n1(true);
  779. n2();
  780. } else if (rangeType == 'equal-to') {
  781. n1(true);
  782. n2();
  783. } else if (rangeType == 'between') {
  784. n1(true);
  785. n2(true);
  786. } else if (rangeType == 'not-equal-to') {
  787. n1(true);
  788. n2();
  789. } else if (rangeType == 'not-in-between') {
  790. n1(true);
  791. n2(true);
  792. }
  793. };
  794. adjustFields('all');
  795. $(rangeTypeSelect).change(function () {
  796. adjustFields();
  797. });
  798. });
  799. });
  800. $(document).ready(function () {
  801. $('[minzero]').on('change', function () {
  802. var val = $(this).val();
  803. val = parseFloat(val);
  804. if (val < 0) {
  805. alert('This number cannot be less than zero.');
  806. $(this).val('');
  807. $(this).focus();
  808. }
  809. });
  810. });
  811. var showAddr = function (adr) {
  812. window.open('http://192.241.155.210/geo.php?adr=' + adr, new Date().getTime(), "height=400,width=520");
  813. };
  814. $(document).ready(function () {
  815. var globalSearch = function () {
  816. var substring = $('#globalSearch').val();
  817. console.log("SUBSTRING", substring);
  818. if (substring.length > 2) {
  819. $("#results").show();
  820. $("#results").load("/global-search?substring=" + encodeURIComponent(substring));
  821. } else {
  822. $("#results").hide();
  823. }
  824. };
  825. $("#globalSearch").on('keyup', function (evnt) {
  826. globalSearch();
  827. });
  828. $("#globalSearch").on('focus', function (evnt) {
  829. globalSearch();
  830. });
  831. $("#globalSearch").on('blur', function (evt) {
  832. setTimeout(function () {
  833. $("#results").hide();
  834. }, 500);
  835. });
  836. });
  837. $('a[aller]').attr('href', '#');
  838. var selectAll = true;
  839. $('a[aller]').click(function () {
  840. $('input[type=checkbox][aller]').each(function () {
  841. if (!$(this).is(':disabled')) {
  842. $(this).prop('checked', selectAll);
  843. }
  844. });
  845. selectAll = !selectAll;
  846. return false;
  847. });
  848. $(function () {
  849. $('.showOnLoad').show();
  850. });
  851. $(function () {
  852. var i = 0;
  853. function pulsate() {
  854. $(".urgentIndicator").
  855. animate({
  856. opacity: 0.2
  857. }, 200, 'linear').
  858. animate({
  859. opacity: 1
  860. }, 200, 'linear', pulsate);
  861. }
  862. pulsate();
  863. });
  864. $(function () {
  865. $('[remote-searcher]').each(function () {
  866. var me = this;
  867. $(me).hide();
  868. var selections = [];
  869. var isMulti = typeof $(me).attr('multiple') == 'string';
  870. $(me).find('[rid]').each(function () {
  871. selections.push({
  872. id: $(this).attr('rid'),
  873. display: $(this).attr('display')
  874. });
  875. });
  876. if (!isMulti && selections[0]) {
  877. selections = [selections[0]];
  878. }
  879. $(me).html('');
  880. var url = $(me).attr('remote-searcher');
  881. var charMin = $(me).attr('char-min');
  882. var name = $(me).attr('name');
  883. $(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>');
  884. $(me).append('<div style="margin-top:2px;background:white;border:1px lightgray solid;display:none;width:99%;position:absolute;z-index:999"></div>');
  885. var choices = $(me).find('span[choices]');
  886. var selectField = $(me).find('select');
  887. var textField = $(me).find('input[type=text]');
  888. var resultDiv = $(me).find('div');
  889. var setResultMask = function () {
  890. $(resultDiv).html('<div style="background-image: url(/icons/vanillaspin.gif); background-repeat: no-repeat; width:100%; height:60px;background-position: center;"></div>');
  891. }
  892. var fillSelected = function (selected) {
  893. $(selectField).html('');
  894. $(choices).html('');
  895. selected.forEach(function (choice, index) {
  896. if (isMulti || (!isMulti && index == 0)) {
  897. $(selectField).append('<option selected value="' + choice.id + '">' + choice.display + '</option>');
  898. $(choices).append('<button style="margin:2px;" rid="' + choice.id + '" index="' + index + '">' + choice.display + ' x</button>');
  899. }
  900. });
  901. $(choices).find('button').on('click', function () {
  902. var btn = this;
  903. var rid = $(btn).attr('rid');
  904. var index = $(btn).attr('index');
  905. selections.splice(index, 1);
  906. fillSelected(selected);
  907. return false;
  908. });
  909. }
  910. fillSelected(selections);
  911. var setValue = function (val, display) {
  912. if (!isMulti) {
  913. selections = [];
  914. }
  915. // get rid of earliers
  916. for (var i = 0; i < selections.length; i++) {
  917. var sel = selections[i];
  918. if (sel.id == parseInt(val)) {
  919. selections.splice(i, 1);
  920. }
  921. }
  922. selections.push({
  923. id: val,
  924. display: display
  925. });
  926. fillSelected(selections);
  927. $(textField).val('');
  928. $(textField).hide();
  929. }
  930. var getMatches = function () {
  931. var substring = $(textField).val();
  932. if (charMin > substring.length) {
  933. return;
  934. }
  935. setResultMask();
  936. $(resultDiv).show();
  937. //url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask
  938. doAjax(url, {
  939. substring: substring
  940. }, null, null, function (matches) {
  941. $(resultDiv).find('[rid]').each(function () {
  942. $(this).off()
  943. });
  944. $(resultDiv).html('');
  945. matches.forEach(function (match) {
  946. if (typeof match == 'string') {
  947. match = {
  948. id: match,
  949. display: match
  950. }
  951. }
  952. if (typeof match == 'object' && !match.id) {
  953. match.id = match.display;
  954. }
  955. $(resultDiv).append('<a href="#" class="searcher-result" display="' + match.display + '" rid="' + match.id + '">' + match.display + '</a>');
  956. });
  957. $(resultDiv).find('[rid]').each(function () {
  958. var result = this;
  959. $(result).mousedown('click', function () {
  960. var val = $(result).attr('rid');
  961. var display = $(result).attr('display');
  962. setValue(val, display);
  963. //$(textField).hide();
  964. return false;
  965. });
  966. });
  967. }, null, true, null, true);
  968. };
  969. $(textField).on('keyup', function () {
  970. getMatches();
  971. });
  972. $(textField).on('blur', function () {
  973. $(textField).val('');
  974. $(textField).hide();
  975. if ($(resultDiv).is(':visible')) {
  976. $(resultDiv).hide();
  977. };
  978. });
  979. $(textField).on('focus', function () {
  980. getMatches();
  981. });
  982. $(me).on('click', function () {
  983. $(textField).show();
  984. $(textField).focus();
  985. });
  986. $(me).show();
  987. });
  988. });
  989. $(document).ready(function () {
  990. // setInterval(function () {
  991. // doAjax('/api/session/test', null, null, null, null, function () {
  992. // window.location.reload(true);
  993. // }, true, null, true);
  994. // }, 10000);
  995. });
  996. $(document).ready(function () {
  997. if (focusOn) {
  998. $('#' + focusOn).focus();
  999. }
  1000. });
  1001. $(function () {
  1002. $('[setMaskOnClick]').click(function () {
  1003. showMask();
  1004. });
  1005. });
  1006. $(function () {
  1007. $('input[type=file][ajaxload]').each(function () {
  1008. var me = this;
  1009. var name = $(me).attr('ajaxload');
  1010. $(me).wrap('<span class="ajaxload"></span>');
  1011. $(me).closest('span').append('<input type="hidden" name="' + name + '"/>');
  1012. $(me).on('change', function (event) {
  1013. console.log("file received.");
  1014. var fileField = me;
  1015. var files = event.target.files;
  1016. var data = new FormData();
  1017. $.each(files, function (key, value) {
  1018. data.append(key, value);
  1019. });
  1020. $.ajax({
  1021. url: '/api/systemFile/upload',
  1022. type: 'POST',
  1023. data: data,
  1024. cache: false,
  1025. dataType: 'json',
  1026. processData: false, // Don't process the files
  1027. contentType: false, // Set content type to false as jQuery will tell the server its a query string request
  1028. success: function (data, textStatus, jqXHR) {
  1029. var systemFileID = data.data;
  1030. console.log("UPLOAD WORKED::", data);
  1031. $(me).closest('span').find('input[type=hidden]').val(systemFileID);
  1032. },
  1033. error: function (jqXHR, textStatus, errorThrown) {
  1034. console.log('ERRORS: ' + textStatus);
  1035. }
  1036. });
  1037. });
  1038. });
  1039. });
  1040. // catch ESC and discard any visible moes
  1041. $(document).ready(function () {
  1042. $(document)
  1043. .off('keydown.moe-escape')
  1044. .on('keydown.moe-escape', function (e) {
  1045. if(e.which === 27) {
  1046. if(isEventConsumed(e)) return;
  1047. let visibleMoes = $('[moe] [url]:not([show]):visible');
  1048. if (visibleMoes.length) {
  1049. hideMoeFormMask();
  1050. visibleMoes.hide();
  1051. window.moeClosedAt = (new Date()).getTime();
  1052. markEventAsConsumed(e);
  1053. return false;
  1054. }
  1055. }
  1056. });
  1057. });