yemi.js 33 KB

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