yemi.js 38 KB

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