yemi.js 31 KB

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