yemi.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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. if($(realForm).is('form')) $(realForm)[0].reset();
  288. showMoeFormMask();
  289. setTimeout(function() {
  290. $('[moe]>form:not([show]):visible').hide();
  291. $(realForm).toggle(100);
  292. initPrimaryForm($(realForm));
  293. setTimeout(function() {
  294. let submitButton = $(realForm).find('[submit]');
  295. if(submitButton.length) submitButton[0].scrollIntoView({behavior : "smooth", block: "nearest"});
  296. // if any callback, trigger it
  297. if($(realForm).is('[onshow]')) {
  298. window[$(realForm).attr('onshow')].call($(realForm)[0]);
  299. }
  300. }, 150);
  301. }, 100);
  302. }
  303. }
  304. }
  305. if (!infoToggle && info && $(info).attr('show') == null) {
  306. if ($(info).attr('liner') != null) {
  307. $(info).css('display', 'inline');
  308. infoToggle = true;
  309. } else {
  310. $(info).toggle(100);
  311. }
  312. }
  313. if ($(start).attr('show') == null) {
  314. $(start).toggle(100);
  315. }
  316. var focusOnStart = $(realForm).find('[focusOnStart]');
  317. if (focusOnStart) {
  318. $(focusOnStart).focus();
  319. }
  320. return false;
  321. });
  322. $(start).attr('href', '#');
  323. }
  324. if (cancel) {
  325. $(cancel).off('click.moe');
  326. $(cancel).on('click.moe', function (e) {
  327. e.preventDefault();
  328. e.stopImmediatePropagation();
  329. if ($(realForm).attr('show') == null) {
  330. $(realForm).hide(100);
  331. }
  332. if (info && $(info).attr('show') == null) {
  333. $(info).show(100);
  334. }
  335. if (start && $(start).attr('show') == null) {
  336. $(start).show(100);
  337. }
  338. hideMoeFormMask();
  339. });
  340. }
  341. $(submit).off('click.moe');
  342. $(submit).on('click.moe', function (e) {
  343. e.preventDefault();
  344. e.stopImmediatePropagation();
  345. if (moe.isProcessing) {
  346. return false;
  347. }
  348. if ($(submit).attr('confirm')) {
  349. var question = $(submit).attr('confirm');
  350. var cont = confirm(question);
  351. if (cont) {} else {
  352. console.log("ABORTED!");
  353. return;
  354. }
  355. }
  356. if($(form).is('form')) {
  357. // trigger validation
  358. if (!$(form)[0].checkValidity()) {
  359. $(form)[0].reportValidity();
  360. return;
  361. }
  362. // submit
  363. moe.isProcessing = true;
  364. var data = {};
  365. var formData = $(form).serializeArray();
  366. formData.forEach(function (field) {
  367. if (data[field.name]) {
  368. if (data[field.name] instanceof Array) {
  369. data[field.name].push(field.value);
  370. } else {
  371. var arr = [];
  372. arr.push(data[field.name]);
  373. arr.push(field.value);
  374. data[field.name] = arr;
  375. }
  376. } else {
  377. data[field.name] = field.value;
  378. }
  379. });
  380. console.log(data);
  381. //var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply)
  382. doAjax(url, data, null, function () {
  383. moe.isProcessing = false;
  384. }, function (data) {
  385. if (justLog) { // this is to test!
  386. console.log('RETURNED', data);
  387. } else if (redir) {
  388. if (redir == "back") {
  389. window.top.history.back();
  390. } else {
  391. if (redir.indexOf('[data]') > -1) {
  392. redir = redir.replace('[data]', data);
  393. }
  394. fastLoad(redir, true, false);
  395. }
  396. } else if (moeParent.length) {
  397. showMask();
  398. $.get(moeParent.attr('url'), function (_data) {
  399. moeParent.html(_data);
  400. hideMask();
  401. hideMoeFormMask();
  402. initMoes();
  403. initFastLoad(moeParent);
  404. initAutoRxAndICDComplete();
  405. });
  406. } else {
  407. pageReload();
  408. }
  409. }, function (errorMessage) {
  410. }, false);
  411. }
  412. });
  413. moe.attr('initialized', 1); // mark as initialized
  414. });
  415. }
  416. jQuery(document).ready(function () {
  417. var $ = jQuery;
  418. $('body').mousedown(function(e){
  419. if($(e.target).closest('[moe]').length || $(e.target).closest('#create-shortcut-form').length || $(e.target).is('#create-shortcut-form')){
  420. return;
  421. }
  422. $('[moe] [url]:not([show])').hide();
  423. hideMoeFormMask();
  424. });
  425. initMoes();
  426. $('table[info] input').each(function () {
  427. $(this).prop('readonly', true);
  428. });
  429. //...for checkboxes readonly
  430. $('input[type=checkbox][readonly],input[type=radio][readonly]').each(function () {
  431. var x = this;
  432. var isChecked = $(x).attr('checked');
  433. $(x).change(function () {
  434. $(x).attr('checked', isChecked);
  435. });
  436. });
  437. $('[show-if]').each(function () { //TODO show-if="isOpen" show-if="isTimeSpecific" show-if="refillFrequency=MONTH"
  438. var x = this;
  439. var sel = $(x).attr('show-if');
  440. var selParts = sel.split('=');
  441. var selName = selParts[0];
  442. var selValue = selParts[1];
  443. var useOpposite = selName[0] == '!';
  444. if (useOpposite) {
  445. selName = selName.slice(1);
  446. }
  447. var form = $(x).closest('form');
  448. var conditionFields = $(form).find('[name=' + selName + ']');
  449. function hideX() {
  450. $(x).hide();
  451. }
  452. function showX() {
  453. $(x).show();
  454. }
  455. var go = function () {
  456. if (selValue) {
  457. var value = $(conditionFields).val();
  458. if (value == selValue) {
  459. if (useOpposite) {
  460. hideX()
  461. } else {
  462. showX()
  463. }
  464. } else {
  465. if (useOpposite) {
  466. showX()
  467. } else {
  468. hideX()
  469. }
  470. }
  471. } else {
  472. var isChecked = $(conditionFields).prop('checked');
  473. if (isChecked) {
  474. if (useOpposite) {
  475. hideX()
  476. } else {
  477. showX()
  478. }
  479. } else {
  480. if (useOpposite) {
  481. showX()
  482. } else {
  483. hideX()
  484. }
  485. }
  486. }
  487. };
  488. go();
  489. $(conditionFields).change(function () {
  490. go();
  491. });
  492. });
  493. });
  494. //now goTo is a plugin...
  495. (function ($) {
  496. $.fn.goTo = function (x) {
  497. $('html, body').animate({
  498. scrollTop: ($(this).offset().top - x) + 'px'
  499. }, 1);
  500. return this; // for chaining...
  501. };
  502. })(jQuery);
  503. $(document).ready(function () {
  504. $(".expander").on("click", function () {
  505. var expandedID = $(this).attr("id");
  506. if ($(this).text() == "-") {
  507. $(this).text("+");
  508. } else {
  509. $(this).text("-");
  510. }
  511. $("." + expandedID).toggle();
  512. return false;
  513. });
  514. });
  515. $(document).ready(function () {
  516. $('[showMap]').each(function () {
  517. var mapper = $(this);
  518. var adr = mapper.attr('showMap');
  519. mapper.on('click', function () {
  520. showAddr(adr);
  521. return false;
  522. });
  523. });
  524. });
  525. $(document).ready(function () {
  526. $('[dateRanger]').each(function () {
  527. var dr = $(this);
  528. var rangeTypeSelect = dr.find('select')[0];
  529. var date1Input = dr.find('[date1]')[0];
  530. var date2Input = dr.find('[date2]')[0];
  531. var d1Val = '';
  532. var d2Val = '';
  533. var d1 = function (enable) {
  534. if (enable) {
  535. var hasVal = $(date1Input).val();
  536. if (!hasVal) {
  537. $(date1Input).val(d1Val);
  538. }
  539. $(date1Input).show();
  540. } else {
  541. d1Val = $(date1Input).val();
  542. $(date1Input).val('');
  543. $(date1Input).hide();
  544. }
  545. };
  546. var d2 = function (enable) {
  547. if (enable) {
  548. var hasVal = $(date2Input).val();
  549. if (!hasVal) {
  550. $(date2Input).val(d2Val);
  551. }
  552. $(date2Input).show();
  553. } else {
  554. d2Val = $(date2Input).val();
  555. $(date2Input).val('');
  556. $(date2Input).hide();
  557. }
  558. };
  559. var adjustFields = function () {
  560. var rangeType = $(rangeTypeSelect).val();
  561. if (rangeType == 'all') {
  562. d1();
  563. d2();
  564. } else if (rangeType == 'on-or-before') {
  565. d1(true);
  566. d2();
  567. } else if (rangeType == 'on-or-after') {
  568. d1(true);
  569. d2();
  570. } else if (rangeType == 'between') {
  571. d1(true);
  572. d2(true);
  573. } else if (rangeType == 'on') {
  574. d1(true);
  575. d2();
  576. } else if (rangeType == 'not-on') {
  577. d1(true);
  578. d2();
  579. } else if (rangeType == 'not-in-between') {
  580. d1(true);
  581. d2(true);
  582. }
  583. };
  584. adjustFields();
  585. $(rangeTypeSelect).change(function () {
  586. adjustFields();
  587. });
  588. });
  589. $('[numRanger]').each(function () {
  590. var nr = $(this);
  591. var rangeTypeSelect = nr.find('select')[0];
  592. var num1Input = nr.find('[num1]')[0];
  593. var num2Input = nr.find('[num2]')[0];
  594. var n1 = function (enable) {
  595. if (enable) {
  596. $(num1Input).show();
  597. } else {
  598. $(num1Input).hide();
  599. }
  600. };
  601. var n2 = function (enable) {
  602. if (enable) {
  603. $(num2Input).show();
  604. } else {
  605. $(num2Input).hide();
  606. }
  607. };
  608. var adjustFields = function () {
  609. var rangeType = $(rangeTypeSelect).val();
  610. if (rangeType == 'all') {
  611. n1();
  612. n2();
  613. } else if (rangeType == 'less-than') {
  614. n1(true);
  615. n2();
  616. } else if (rangeType == 'greater-than') {
  617. n1(true);
  618. n2();
  619. } else if (rangeType == 'equal-to') {
  620. n1(true);
  621. n2();
  622. } else if (rangeType == 'between') {
  623. n1(true);
  624. n2(true);
  625. } else if (rangeType == 'not-equal-to') {
  626. n1(true);
  627. n2();
  628. } else if (rangeType == 'not-in-between') {
  629. n1(true);
  630. n2(true);
  631. }
  632. };
  633. adjustFields('all');
  634. $(rangeTypeSelect).change(function () {
  635. adjustFields();
  636. });
  637. });
  638. });
  639. $(document).ready(function () {
  640. $('[minzero]').on('change', function () {
  641. var val = $(this).val();
  642. val = parseFloat(val);
  643. if (val < 0) {
  644. alert('This number cannot be less than zero.');
  645. $(this).val('');
  646. $(this).focus();
  647. }
  648. });
  649. });
  650. var showAddr = function (adr) {
  651. window.open('http://192.241.155.210/geo.php?adr=' + adr, new Date().getTime(), "height=400,width=520");
  652. };
  653. $(document).ready(function () {
  654. var globalSearch = function () {
  655. var substring = $('#globalSearch').val();
  656. console.log("SUBSTRING", substring);
  657. if (substring.length > 2) {
  658. $("#results").show();
  659. $("#results").load("/global-search?substring=" + encodeURIComponent(substring));
  660. } else {
  661. $("#results").hide();
  662. }
  663. };
  664. $("#globalSearch").on('keyup', function (evnt) {
  665. globalSearch();
  666. });
  667. $("#globalSearch").on('focus', function (evnt) {
  668. globalSearch();
  669. });
  670. $("#globalSearch").on('blur', function (evt) {
  671. setTimeout(function () {
  672. $("#results").hide();
  673. }, 500);
  674. });
  675. });
  676. $('a[aller]').attr('href', '#');
  677. var selectAll = true;
  678. $('a[aller]').click(function () {
  679. $('input[type=checkbox][aller]').each(function () {
  680. if (!$(this).is(':disabled')) {
  681. $(this).prop('checked', selectAll);
  682. }
  683. });
  684. selectAll = !selectAll;
  685. return false;
  686. });
  687. $(function () {
  688. $('.showOnLoad').show();
  689. });
  690. $(function () {
  691. var i = 0;
  692. function pulsate() {
  693. $(".urgentIndicator").
  694. animate({
  695. opacity: 0.2
  696. }, 200, 'linear').
  697. animate({
  698. opacity: 1
  699. }, 200, 'linear', pulsate);
  700. }
  701. pulsate();
  702. });
  703. $(function () {
  704. $('[remote-searcher]').each(function () {
  705. var me = this;
  706. $(me).hide();
  707. var selections = [];
  708. var isMulti = typeof $(me).attr('multiple') == 'string';
  709. $(me).find('[rid]').each(function () {
  710. selections.push({
  711. id: $(this).attr('rid'),
  712. display: $(this).attr('display')
  713. });
  714. });
  715. if (!isMulti && selections[0]) {
  716. selections = [selections[0]];
  717. }
  718. $(me).html('');
  719. var url = $(me).attr('remote-searcher');
  720. var charMin = $(me).attr('char-min');
  721. var name = $(me).attr('name');
  722. $(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>');
  723. $(me).append('<div style="margin-top:2px;background:white;border:1px lightgray solid;display:none;width:99%;position:absolute;z-index:999"></div>');
  724. var choices = $(me).find('span[choices]');
  725. var selectField = $(me).find('select');
  726. var textField = $(me).find('input[type=text]');
  727. var resultDiv = $(me).find('div');
  728. var setResultMask = function () {
  729. $(resultDiv).html('<div style="background-image: url(/icons/vanillaspin.gif); background-repeat: no-repeat; width:100%; height:60px;background-position: center;"></div>');
  730. }
  731. var fillSelected = function (selected) {
  732. $(selectField).html('');
  733. $(choices).html('');
  734. selected.forEach(function (choice, index) {
  735. if (isMulti || (!isMulti && index == 0)) {
  736. $(selectField).append('<option selected value="' + choice.id + '">' + choice.display + '</option>');
  737. $(choices).append('<button style="margin:2px;" rid="' + choice.id + '" index="' + index + '">' + choice.display + ' x</button>');
  738. }
  739. });
  740. $(choices).find('button').on('click', function () {
  741. var btn = this;
  742. var rid = $(btn).attr('rid');
  743. var index = $(btn).attr('index');
  744. selections.splice(index, 1);
  745. fillSelected(selected);
  746. return false;
  747. });
  748. }
  749. fillSelected(selections);
  750. var setValue = function (val, display) {
  751. if (!isMulti) {
  752. selections = [];
  753. }
  754. // get rid of earliers
  755. for (var i = 0; i < selections.length; i++) {
  756. var sel = selections[i];
  757. if (sel.id == parseInt(val)) {
  758. selections.splice(i, 1);
  759. }
  760. }
  761. selections.push({
  762. id: val,
  763. display: display
  764. });
  765. fillSelected(selections);
  766. $(textField).val('');
  767. $(textField).hide();
  768. }
  769. var getMatches = function () {
  770. var substring = $(textField).val();
  771. if (charMin > substring.length) {
  772. return;
  773. }
  774. setResultMask();
  775. $(resultDiv).show();
  776. //url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask
  777. doAjax(url, {
  778. substring: substring
  779. }, null, null, function (matches) {
  780. $(resultDiv).find('[rid]').each(function () {
  781. $(this).off()
  782. });
  783. $(resultDiv).html('');
  784. matches.forEach(function (match) {
  785. if (typeof match == 'string') {
  786. match = {
  787. id: match,
  788. display: match
  789. }
  790. }
  791. if (typeof match == 'object' && !match.id) {
  792. match.id = match.display;
  793. }
  794. $(resultDiv).append('<a href="#" class="searcher-result" display="' + match.display + '" rid="' + match.id + '">' + match.display + '</a>');
  795. });
  796. $(resultDiv).find('[rid]').each(function () {
  797. var result = this;
  798. $(result).mousedown('click', function () {
  799. var val = $(result).attr('rid');
  800. var display = $(result).attr('display');
  801. setValue(val, display);
  802. //$(textField).hide();
  803. return false;
  804. });
  805. });
  806. }, null, true, null, true);
  807. };
  808. $(textField).on('keyup', function () {
  809. getMatches();
  810. });
  811. $(textField).on('blur', function () {
  812. $(textField).val('');
  813. $(textField).hide();
  814. if ($(resultDiv).is(':visible')) {
  815. $(resultDiv).hide();
  816. };
  817. });
  818. $(textField).on('focus', function () {
  819. getMatches();
  820. });
  821. $(me).on('click', function () {
  822. $(textField).show();
  823. $(textField).focus();
  824. });
  825. $(me).show();
  826. });
  827. });
  828. $(document).ready(function () {
  829. // setInterval(function () {
  830. // doAjax('/api/session/test', null, null, null, null, function () {
  831. // window.location.reload(true);
  832. // }, true, null, true);
  833. // }, 10000);
  834. });
  835. $(document).ready(function () {
  836. if (focusOn) {
  837. $('#' + focusOn).focus();
  838. }
  839. });
  840. $(function () {
  841. $('[setMaskOnClick]').click(function () {
  842. showMask();
  843. });
  844. });
  845. $(function () {
  846. $('input[type=file][ajaxload]').each(function () {
  847. var me = this;
  848. var name = $(me).attr('ajaxload');
  849. $(me).wrap('<span class="ajaxload"></span>');
  850. $(me).closest('span').append('<input type="hidden" name="' + name + '"/>');
  851. $(me).on('change', function (event) {
  852. console.log("file received.");
  853. var fileField = me;
  854. var files = event.target.files;
  855. var data = new FormData();
  856. $.each(files, function (key, value) {
  857. data.append(key, value);
  858. });
  859. $.ajax({
  860. url: '/api/systemFile/upload',
  861. type: 'POST',
  862. data: data,
  863. cache: false,
  864. dataType: 'json',
  865. processData: false, // Don't process the files
  866. contentType: false, // Set content type to false as jQuery will tell the server its a query string request
  867. success: function (data, textStatus, jqXHR) {
  868. var systemFileID = data.data;
  869. console.log("UPLOAD WORKED::", data);
  870. $(me).closest('span').find('input[type=hidden]').val(systemFileID);
  871. },
  872. error: function (jqXHR, textStatus, errorThrown) {
  873. console.log('ERRORS: ' + textStatus);
  874. }
  875. });
  876. });
  877. });
  878. });