yemi.js 33 KB

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