yemi.js 39 KB

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