yemi.js 40 KB

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