yemi.js 37 KB

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