yemi.js 38 KB

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