yemi.js 37 KB

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