12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109 |
- if (typeof focusOn == 'undefined') {
- var focusOn = 'globalSearch';
- }
- var ajaxGoing = false;
- var showMask = function (_text = '') {
- $('body').css('opacity', 0.6);
- $('#mask').show();
- if(!!_text) {
- $('<div class="mask-text-addition" />').text('Initializing note. Please wait...').appendTo('body');
- }
- }
- var hideMask = function () {
- $('body').css('opacity', 1);
- $('#mask').hide();
- $('.mask-text-addition').remove();
- }
- var showMoeFormMask = function (_additionalClass = false) {
- if(_additionalClass) {
- $('#moe-form-mask').addClass(_additionalClass);
- }
- $('#moe-form-mask').show();
- }
- var hideMoeFormMask = function () {
- if($('body').is('.blocking-mode')) return false;
- $('#moe-form-mask').hide().removeClass();
- $('#create-shortcut-form').hide();
- }
- $(document).ready(function () {
- hideMask();
- });
- $(document).ready(function () {
- $("input[type=number]").keydown(function (e) {
- // Allow: backspace, delete, tab, escape, enter and .
- if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
- // Allow: Ctrl+A, Command+A
- (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
- // Allow: home, end, left, right, down, up
- (e.keyCode >= 35 && e.keyCode <= 40)) {
- // let it happen, don't do anything
- return;
- }
- // Ensure that it is a number and stop the keypress
- if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
- e.preventDefault();
- }
- });
- });
- $(function () {
- $('input[type=checkbox][forceCb]').on('click', function () {
- var name = $(this).attr('forceCb');
- var code = $(this).attr('code');
- var form = $(this).closest('form');
- var hiddenField = $(form).find('input[code=\'' + code + '\']');
- var value = $(this).prop('checked') ? 'on' : 'off';
- console.log('name', name, 'code', code, 'value', value);
- $(hiddenField).val(value);
- });
- });
- var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply) {
- console.log(data);
- if (ajaxGoing) {
- console.log('ajax stopped!');
- //return; TODO: fix and re-enable return
- }
- ajaxGoing = true;
- if (!shouldHideMask) {
- showMask();
- }
- jQuery.ajax(url, {
- dataType: 'json',
- data: data,
- type: 'POST',
- beforeSend: function () {
- if (pre) {
- pre();
- }
- }
- })
- .done(function (response, b) {
- console.log(response);
- var success = response.success;
- if (success) {
- if (onSuccess) {
- onSuccess(response.data);
- }
- } else {
- if (onFailure) {
- onFailure(response.message);
- }
- if (!suppressErrorMessage) {
- //toast the error message
- //alert(response.message);
- toastr.error(response.message); // , toastr.success("message") ... .warning(), .error()
- }
- hideMask();
- }
- if (immediatelyHideMaskOnReply) {
- hideMask();
- }
- ajaxGoing = false;
- })
- .fail(function (jqXHR, textStatus) {
- hideMask();
- toastr.error('Unable to process');
- if (onHttpFailure) {
- onHttpFailure(textStatus);
- }
- ajaxGoing = false;
- })
- .always(function () {
- if (post) {
- post();
- }
- ajaxGoing = false;
- });
- };
- var doAjaxFormData = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply) {
- console.log(data);
- if (ajaxGoing) {
- console.log('ajax stopped!');
- //return; TODO: fix and re-enable return
- }
- ajaxGoing = true;
- if (!shouldHideMask) {
- showMask();
- }
- jQuery.ajax(url, {
- dataType: 'json',
- data: data,
- processData: false,
- contentType: false,
- type: 'POST',
- beforeSend: function () {
- if (pre) {
- pre();
- }
- }
- })
- .done(function (response, b) {
- console.log(response);
- var success = response.success;
- if (success) {
- if (onSuccess) {
- onSuccess(response.data);
- }
- } else {
- if (onFailure) {
- onFailure(response.message);
- }
- if (!suppressErrorMessage) {
- //toast the error message
- //alert(response.message);
- toastr.error(response.message); // , toastr.success("message") ... .warning(), .error()
- }
- hideMask();
- }
- if (immediatelyHideMaskOnReply) {
- hideMask();
- }
- ajaxGoing = false;
- })
- .fail(function (jqXHR, textStatus) {
- hideMask();
- toastr.error('Unable to process');
- if (onHttpFailure) {
- onHttpFailure(textStatus);
- }
- ajaxGoing = false;
- })
- .always(function () {
- if (post) {
- post();
- }
- ajaxGoing = false;
- });
- };
- var justLog = false; //THIS IS FOR TEST MODE, FORMS WILL NOT TRIGGER REFRESH/REDIR
- var pageReload = function () {
- setTimeout(function () {
- hideMoeFormMask();
- fastReload();
- }, 500);
- };
- var fastReload = function() {
- var targetLocation = window.top.location.pathname + window.top.location.search;
- if(targetLocation.indexOf('/mc') === 0) {
- targetLocation = targetLocation.substr(3);
- }
- if(targetLocation === '' || targetLocation[0] !== '/') targetLocation = '/' + targetLocation;
- fastLoad(targetLocation, false, false);
- return false;
- }
- if (typeof String.prototype.startsWith != 'function') {
- // see below for better implementation!
- String.prototype.startsWith = function (str) {
- return this.indexOf(str) === 0;
- };
- }
- $(function () {
- $('[addressLine1]').each(function () {
- var moe = $(this).closest('[moe]');
- var a = {};
- a.addressLine1 = $(this);
- a.addressLine2 = $(moe).find('[addressLine2]');
- a.addressCity = $(moe).find('[addressCity]');
- a.addressState = $(moe).find('[addressState]');
- a.addressPostcode = $(moe).find('[addressPostcode]');
- var getAddress = function () {
- var address = {};
- for (var prop in a) {
- var val = $(a[prop]).val();
- address[prop] = val;
- }
- return address;
- }
- var getFormattedAddress = function (address) {
- var x = '<p>';
- x += address.addressLine1 + (address.addressLine2 ? ', ' + address.addressLine2 : '') + '<br/>' + address.addressCity + ', ' + address.addressState + ' ' + address.addressPostcode;
- x += '</p>';
- return x;
- }
- var suggestAddress = function () {
- var address = getAddress();
- //var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask)
- var onSuccess = function (data) {
- console.log('SUCCESS!!!', data);
- }
- var onFailure = function (message) {
- if (message.startsWith('Invalid:: INVALID ADDRESS - SUGGESTED:')) {
- var suggestionText = message.substring(message.indexOf('{'));
- var suggestion = JSON.parse(suggestionText);
- console.log('SUGGESTION!!!', suggestion);
- $('#myModal').attr('title', 'Address suggestion');
- $('#myModal').html('<h3>Currently set address:</h3>' + getFormattedAddress(address) + '<h3>Suggestion:</h3>' + getFormattedAddress(suggestion));
- $('#myModal').dialog({
- height: 400,
- width: 500,
- modal: true,
- buttons: [{
- text: 'Use suggestion',
- click: function () {
- for (var prop in a) {
- $(a[prop]).val(suggestion[prop]);
- }
- $(this).dialog('close');
- }
- },
- {
- text: 'Keep original',
- click: function () {
- $(this).dialog('close');
- }
- }
- ]
- });
- } else if (message.startsWith('Invalid:: INVALID ADDRESS')) {
- console.log('NO SUGGESTION!!!');
- $('#myModal').attr('title', 'No address found');
- $('#myModal').html('<h3>Currently set address:</h3>' + getFormattedAddress(address) + '<h3>No suggestion!</h3>');
- $('#myModal').dialog({
- height: 400,
- width: 500,
- modal: true,
- buttons: [{
- text: 'Erase address fields',
- click: function () {
- for (var prop in a) {
- $(a[prop]).val('');
- }
- $(this).dialog('close');
- }
- },
- {
- text: 'Keep original',
- click: function () {
- $(this).dialog('close');
- }
- }
- ]
- });
- }
- }
- doAjax('/api/service/verifyAddress', address, null, null, onSuccess, onFailure, true, null, false, true);
- }
- var isAddressComplete = function () {
- var address = getAddress();
- return address.addressLine1 && ((address.addressCity && address.addressState) || address.addressPostcode) ? true : false;
- }
- for (var prop in a) {
- var part = a[prop];
- $(part).on('change', function () {
- console.log(getAddress());
- var isComplete = isAddressComplete();
- if (isComplete) {
- suggestAddress();
- }
- });
- $(part).attr('autocomplete', 'off');
- }
- });
- });
- var initMoes = function() {
- $('[moe]').each(function () {
- if($(this).is('[initialized]')) { // skip to next moe
- return true;
- }
- var moe = $(this);
- moe.isProcessing = false;
- var info = moe.find('[info]')[0]; // OPTIONAL
- var start = moe.find('[start]')[0]; // OPTIONAL
- var form = moe.find('[url]')[0]; // REQUIRED
- var url = $(form).attr('url'); // REQUIRED
- var redir = $(form).attr('redir'); // OPTIONAL
- var submit = moe.find('[submit]'); // REQUIRED
- var cancel = moe.find('[cancel]')[0]; // OPTIONAL
- // ajax load - OPTIONAL
- var moeParent = $(form).closest('[moe-parent][url]');
- if ($(this).attr('formOff') != null) {
- $(form).find(':input').attr('disabled', true);
- var formOn = $(this).find('[formOn]');
- $(formOn).attr('disabled', false);
- $(submit).hide();
- $(formOn).click(function () {
- $(form).find(':input').attr('disabled', false);
- $(submit).show();
- $(formOn).hide();
- return false;
- });
- }
- var realForm = form;
- //init set display inline so toggle remembers inline state
- var formToggle = false;
- var infoToggle = false;
- if (start) {
- $(start).off('click.moe');
- $(start).on('click.moe', function () {
- // if any div based moes are visible, hide first
- $('[moe]>div[url]:visible').hide();
- $('.dropdown-menu[aria-labelledby="practice-management"]')
- .removeClass('show')
- .prev('.dropdown-toggle').attr('aria-expanded', 'false');
- if ($(realForm).attr('show') == null) {
- if (!formToggle && $(realForm).attr('liner') != null) {
- $(realForm).css('display', 'inline');
- formToggle = true;
- } else {
- var isRealFormVisible = $(realForm).is(':visible');
- if(isRealFormVisible){
- hideMoeFormMask();
- $(realForm).toggle(100);
- }else{
- // keep data in moes, don't force reset
- // if($(realForm).is('form')) $(realForm)[0].reset();
- if(!$(realForm).closest('[moe]').is('[no-mask]')) {
- showMoeFormMask();
- }
- setTimeout(function() {
- $('[moe]>[url]:not([show]):visible').hide();
- $(realForm).toggle(100);
- initPrimaryForm($(realForm));
- setTimeout(function() {
- let submitButton = $(realForm).find('[submit]');
- if(submitButton.length) submitButton[0].scrollIntoView({behavior : "smooth", block: "nearest"});
- // if any callback, trigger it
- if($(realForm).is('[onshow]')) {
- window[$(realForm).attr('onshow')].call($(realForm)[0]);
- }
- }, 150);
- }, 100);
- }
- }
- }
- if (!infoToggle && info && $(info).attr('show') == null) {
- if ($(info).attr('liner') != null) {
- $(info).css('display', 'inline');
- infoToggle = true;
- } else {
- $(info).toggle(100);
- }
- }
- if ($(start).attr('show') == null) {
- $(start).toggle(100);
- }
- var focusOnStart = $(realForm).find('[focusOnStart]');
- if (focusOnStart) {
- $(focusOnStart).focus();
- }
- return false;
- });
- $(start).attr('href', '#');
- }
- if (cancel) {
- $(cancel).off('click.moe');
- $(cancel).on('click.moe', function (e) {
- e.preventDefault();
- e.stopImmediatePropagation();
- if ($(realForm).attr('show') == null) {
- $(realForm).hide(100);
- }
- if (info && $(info).attr('show') == null) {
- $(info).show(100);
- }
- if (start && $(start).attr('show') == null) {
- $(start).show(100);
- }
- hideMoeFormMask();
- });
- }
- $(submit).off('click.moe');
- $(submit).on('click.moe', function (e) {
- e.preventDefault();
- e.stopImmediatePropagation();
- if (moe.isProcessing) {
- return false;
- }
- if ($(submit).attr('confirm')) {
- var question = $(submit).attr('confirm');
- var cont = confirm(question);
- if (cont) {} else {
- console.log("ABORTED!");
- return;
- }
- }
- if($(form).is('form')) {
- // trigger validation
- if (!$(form)[0].checkValidity()) {
- $(form)[0].reportValidity();
- return;
- }
- // check and trigger onbeforesubmit
- if($(form).is('[onbeforesubmit]')) {
- window[$(form).attr('onbeforesubmit')].call($(realForm)[0]);
- }
- // submit
- moe.isProcessing = true;
- var data = {};
- var formData = $(form).serializeArray();
- formData.forEach(function (field) {
- if (data[field.name]) {
- if (data[field.name] instanceof Array) {
- data[field.name].push(field.value);
- } else {
- var arr = [];
- arr.push(data[field.name]);
- arr.push(field.value);
- data[field.name] = arr;
- }
- } else {
- data[field.name] = field.value;
- }
- });
- console.log(data);
- //var doAjax = function (url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask, immediatelyHideMaskOnReply)
- // override with FormData if the form has any files
- let useFormData = false;
- if($(form).find('input[type="file"]').length) {
- let formData = new FormData();
- for(let x in data) {
- if(data.hasOwnProperty(x)) {
- formData.set(x, data[x]);
- }
- }
- $(form).find('input[type="file"]').each(function() {
- let fieldName = this.name;
- if(this.files && this.files.length) {
- formData.append(fieldName, this.files[0]);
- }
- });
- data = formData;
- useFormData = true;
- }
- if(!useFormData) {
- doAjax(url, data, null, function () {
- moe.isProcessing = false;
- }, function (data) {
- if (justLog) { // this is to test!
- console.log('RETURNED', data);
- } else if(isDynamicStagPopupPresent()) {
- refreshDynamicStagPopup();
- } else if (redir) {
- if (redir == "back") {
- window.top.history.back();
- } else {
- if (redir.indexOf('[data]') > -1) {
- redir = redir.replace('[data]', data);
- }
- fastLoad(redir, true, false);
- }
- } else if (moeParent.length) {
- showMask();
- $.get(moeParent.attr('url'), function (_data) {
- moeParent.html(_data);
- hideMask();
- hideMoeFormMask();
- initMoes();
- initFastLoad(moeParent);
- initAutoRxAndICDComplete();
- });
- } else {
- pageReload();
- }
- }, function (errorMessage) {
- }, false);
- }
- else {
- doAjaxFormData(url, data, null, function () {
- moe.isProcessing = false;
- }, function (data) {
- if (justLog) { // this is to test!
- console.log('RETURNED', data);
- } else if(isDynamicStagPopupPresent()) {
- refreshDynamicStagPopup();
- } else if (redir) {
- if (redir == "back") {
- window.top.history.back();
- } else {
- if (redir.indexOf('[data]') > -1) {
- redir = redir.replace('[data]', data);
- }
- fastLoad(redir, true, false);
- }
- } else if (moeParent.length) {
- showMask();
- $.get(moeParent.attr('url'), function (_data) {
- moeParent.html(_data);
- hideMask();
- hideMoeFormMask();
- initMoes();
- initFastLoad(moeParent);
- initAutoRxAndICDComplete();
- });
- } else {
- pageReload();
- }
- }, function (errorMessage) {
- }, false);
- }
- }
- });
- moe.attr('initialized', 1); // mark as initialized
- });
- }
- jQuery(document).ready(function () {
- var $ = jQuery;
- $('body').mousedown(function(e){
- if($(e.target).closest('[moe]').length ||
- $(e.target).closest('#create-shortcut-form').length ||
- $(e.target).is('#create-shortcut-form') ||
- $(e.target).is('.stag-shortcuts .sc')){
- return;
- }
- $('[moe] [url]:not([show])').hide();
- hideMoeFormMask();
- });
- initMoes();
- $('table[info] input').each(function () {
- $(this).prop('readonly', true);
- });
- //...for checkboxes readonly
- $('input[type=checkbox][readonly],input[type=radio][readonly]').each(function () {
- var x = this;
- var isChecked = $(x).attr('checked');
- $(x).change(function () {
- $(x).attr('checked', isChecked);
- });
- });
- $('[show-if]').each(function () { //TODO show-if="isOpen" show-if="isTimeSpecific" show-if="refillFrequency=MONTH"
- var x = this;
- var sel = $(x).attr('show-if');
- var selParts = sel.split('=');
- var selName = selParts[0];
- var selValue = selParts[1];
- var useOpposite = selName[0] == '!';
- if (useOpposite) {
- selName = selName.slice(1);
- }
- var form = $(x).closest('form');
- var conditionFields = $(form).find('[name=' + selName + ']');
- function hideX() {
- $(x).hide();
- }
- function showX() {
- $(x).show();
- }
- var go = function () {
- if (selValue) {
- var value = $(conditionFields).val();
- if (value == selValue) {
- if (useOpposite) {
- hideX()
- } else {
- showX()
- }
- } else {
- if (useOpposite) {
- showX()
- } else {
- hideX()
- }
- }
- } else {
- var isChecked = $(conditionFields).prop('checked');
- if (isChecked) {
- if (useOpposite) {
- hideX()
- } else {
- showX()
- }
- } else {
- if (useOpposite) {
- showX()
- } else {
- hideX()
- }
- }
- }
- };
- go();
- $(conditionFields).change(function () {
- go();
- });
- });
- });
- //now goTo is a plugin...
- (function ($) {
- $.fn.goTo = function (x) {
- $('html, body').animate({
- scrollTop: ($(this).offset().top - x) + 'px'
- }, 1);
- return this; // for chaining...
- };
- })(jQuery);
- $(document).ready(function () {
- $(".expander").on("click", function () {
- var expandedID = $(this).attr("id");
- if ($(this).text() == "-") {
- $(this).text("+");
- } else {
- $(this).text("-");
- }
- $("." + expandedID).toggle();
- return false;
- });
- });
- $(document).ready(function () {
- $('[showMap]').each(function () {
- var mapper = $(this);
- var adr = mapper.attr('showMap');
- mapper.on('click', function () {
- showAddr(adr);
- return false;
- });
- });
- });
- $(document).ready(function () {
- $('[dateRanger]').each(function () {
- var dr = $(this);
- var rangeTypeSelect = dr.find('select')[0];
- var date1Input = dr.find('[date1]')[0];
- var date2Input = dr.find('[date2]')[0];
- var d1Val = '';
- var d2Val = '';
- var d1 = function (enable) {
- if (enable) {
- var hasVal = $(date1Input).val();
- if (!hasVal) {
- $(date1Input).val(d1Val);
- }
- $(date1Input).show();
- } else {
- d1Val = $(date1Input).val();
- $(date1Input).val('');
- $(date1Input).hide();
- }
- };
- var d2 = function (enable) {
- if (enable) {
- var hasVal = $(date2Input).val();
- if (!hasVal) {
- $(date2Input).val(d2Val);
- }
- $(date2Input).show();
- } else {
- d2Val = $(date2Input).val();
- $(date2Input).val('');
- $(date2Input).hide();
- }
- };
- var adjustFields = function () {
- var rangeType = $(rangeTypeSelect).val();
- if (rangeType == 'all') {
- d1();
- d2();
- } else if (rangeType == 'on-or-before') {
- d1(true);
- d2();
- } else if (rangeType == 'on-or-after') {
- d1(true);
- d2();
- } else if (rangeType == 'between') {
- d1(true);
- d2(true);
- } else if (rangeType == 'on') {
- d1(true);
- d2();
- } else if (rangeType == 'not-on') {
- d1(true);
- d2();
- } else if (rangeType == 'not-in-between') {
- d1(true);
- d2(true);
- }
- };
- adjustFields();
- $(rangeTypeSelect).change(function () {
- adjustFields();
- });
- });
- $('[numRanger]').each(function () {
- var nr = $(this);
- var rangeTypeSelect = nr.find('select')[0];
- var num1Input = nr.find('[num1]')[0];
- var num2Input = nr.find('[num2]')[0];
- var n1 = function (enable) {
- if (enable) {
- $(num1Input).show();
- } else {
- $(num1Input).hide();
- }
- };
- var n2 = function (enable) {
- if (enable) {
- $(num2Input).show();
- } else {
- $(num2Input).hide();
- }
- };
- var adjustFields = function () {
- var rangeType = $(rangeTypeSelect).val();
- if (rangeType == 'all') {
- n1();
- n2();
- } else if (rangeType == 'less-than') {
- n1(true);
- n2();
- } else if (rangeType == 'greater-than') {
- n1(true);
- n2();
- } else if (rangeType == 'equal-to') {
- n1(true);
- n2();
- } else if (rangeType == 'between') {
- n1(true);
- n2(true);
- } else if (rangeType == 'not-equal-to') {
- n1(true);
- n2();
- } else if (rangeType == 'not-in-between') {
- n1(true);
- n2(true);
- }
- };
- adjustFields('all');
- $(rangeTypeSelect).change(function () {
- adjustFields();
- });
- });
- });
- $(document).ready(function () {
- $('[minzero]').on('change', function () {
- var val = $(this).val();
- val = parseFloat(val);
- if (val < 0) {
- alert('This number cannot be less than zero.');
- $(this).val('');
- $(this).focus();
- }
- });
- });
- var showAddr = function (adr) {
- window.open('http://192.241.155.210/geo.php?adr=' + adr, new Date().getTime(), "height=400,width=520");
- };
- $(document).ready(function () {
- var globalSearch = function () {
- var substring = $('#globalSearch').val();
- console.log("SUBSTRING", substring);
- if (substring.length > 2) {
- $("#results").show();
- $("#results").load("/global-search?substring=" + encodeURIComponent(substring));
- } else {
- $("#results").hide();
- }
- };
- $("#globalSearch").on('keyup', function (evnt) {
- globalSearch();
- });
- $("#globalSearch").on('focus', function (evnt) {
- globalSearch();
- });
- $("#globalSearch").on('blur', function (evt) {
- setTimeout(function () {
- $("#results").hide();
- }, 500);
- });
- });
- $('a[aller]').attr('href', '#');
- var selectAll = true;
- $('a[aller]').click(function () {
- $('input[type=checkbox][aller]').each(function () {
- if (!$(this).is(':disabled')) {
- $(this).prop('checked', selectAll);
- }
- });
- selectAll = !selectAll;
- return false;
- });
- $(function () {
- $('.showOnLoad').show();
- });
- $(function () {
- var i = 0;
- function pulsate() {
- $(".urgentIndicator").
- animate({
- opacity: 0.2
- }, 200, 'linear').
- animate({
- opacity: 1
- }, 200, 'linear', pulsate);
- }
- pulsate();
- });
- $(function () {
- $('[remote-searcher]').each(function () {
- var me = this;
- $(me).hide();
- var selections = [];
- var isMulti = typeof $(me).attr('multiple') == 'string';
- $(me).find('[rid]').each(function () {
- selections.push({
- id: $(this).attr('rid'),
- display: $(this).attr('display')
- });
- });
- if (!isMulti && selections[0]) {
- selections = [selections[0]];
- }
- $(me).html('');
- var url = $(me).attr('remote-searcher');
- var charMin = $(me).attr('char-min');
- var name = $(me).attr('name');
- $(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>');
- $(me).append('<div style="margin-top:2px;background:white;border:1px lightgray solid;display:none;width:99%;position:absolute;z-index:999"></div>');
- var choices = $(me).find('span[choices]');
- var selectField = $(me).find('select');
- var textField = $(me).find('input[type=text]');
- var resultDiv = $(me).find('div');
- var setResultMask = function () {
- $(resultDiv).html('<div style="background-image: url(/icons/vanillaspin.gif); background-repeat: no-repeat; width:100%; height:60px;background-position: center;"></div>');
- }
- var fillSelected = function (selected) {
- $(selectField).html('');
- $(choices).html('');
- selected.forEach(function (choice, index) {
- if (isMulti || (!isMulti && index == 0)) {
- $(selectField).append('<option selected value="' + choice.id + '">' + choice.display + '</option>');
- $(choices).append('<button style="margin:2px;" rid="' + choice.id + '" index="' + index + '">' + choice.display + ' x</button>');
- }
- });
- $(choices).find('button').on('click', function () {
- var btn = this;
- var rid = $(btn).attr('rid');
- var index = $(btn).attr('index');
- selections.splice(index, 1);
- fillSelected(selected);
- return false;
- });
- }
- fillSelected(selections);
- var setValue = function (val, display) {
- if (!isMulti) {
- selections = [];
- }
- // get rid of earliers
- for (var i = 0; i < selections.length; i++) {
- var sel = selections[i];
- if (sel.id == parseInt(val)) {
- selections.splice(i, 1);
- }
- }
- selections.push({
- id: val,
- display: display
- });
- fillSelected(selections);
- $(textField).val('');
- $(textField).hide();
- }
- var getMatches = function () {
- var substring = $(textField).val();
- if (charMin > substring.length) {
- return;
- }
- setResultMask();
- $(resultDiv).show();
- //url, data, pre, post, onSuccess, onFailure, suppressErrorMessage, onHttpFailure, shouldHideMask
- doAjax(url, {
- substring: substring
- }, null, null, function (matches) {
- $(resultDiv).find('[rid]').each(function () {
- $(this).off()
- });
- $(resultDiv).html('');
- matches.forEach(function (match) {
- if (typeof match == 'string') {
- match = {
- id: match,
- display: match
- }
- }
- if (typeof match == 'object' && !match.id) {
- match.id = match.display;
- }
- $(resultDiv).append('<a href="#" class="searcher-result" display="' + match.display + '" rid="' + match.id + '">' + match.display + '</a>');
- });
- $(resultDiv).find('[rid]').each(function () {
- var result = this;
- $(result).mousedown('click', function () {
- var val = $(result).attr('rid');
- var display = $(result).attr('display');
- setValue(val, display);
- //$(textField).hide();
- return false;
- });
- });
- }, null, true, null, true);
- };
- $(textField).on('keyup', function () {
- getMatches();
- });
- $(textField).on('blur', function () {
- $(textField).val('');
- $(textField).hide();
- if ($(resultDiv).is(':visible')) {
- $(resultDiv).hide();
- };
- });
- $(textField).on('focus', function () {
- getMatches();
- });
- $(me).on('click', function () {
- $(textField).show();
- $(textField).focus();
- });
- $(me).show();
- });
- });
- $(document).ready(function () {
- // setInterval(function () {
- // doAjax('/api/session/test', null, null, null, null, function () {
- // window.location.reload(true);
- // }, true, null, true);
- // }, 10000);
- });
- $(document).ready(function () {
- if (focusOn) {
- $('#' + focusOn).focus();
- }
- });
- $(function () {
- $('[setMaskOnClick]').click(function () {
- showMask();
- });
- });
- $(function () {
- $('input[type=file][ajaxload]').each(function () {
- var me = this;
- var name = $(me).attr('ajaxload');
- $(me).wrap('<span class="ajaxload"></span>');
- $(me).closest('span').append('<input type="hidden" name="' + name + '"/>');
- $(me).on('change', function (event) {
- console.log("file received.");
- var fileField = me;
- var files = event.target.files;
- var data = new FormData();
- $.each(files, function (key, value) {
- data.append(key, value);
- });
- $.ajax({
- url: '/api/systemFile/upload',
- type: 'POST',
- data: data,
- cache: false,
- dataType: 'json',
- processData: false, // Don't process the files
- contentType: false, // Set content type to false as jQuery will tell the server its a query string request
- success: function (data, textStatus, jqXHR) {
- var systemFileID = data.data;
- console.log("UPLOAD WORKED::", data);
- $(me).closest('span').find('input[type=hidden]').val(systemFileID);
- },
- error: function (jqXHR, textStatus, errorThrown) {
- console.log('ERRORS: ' + textStatus);
- }
- });
- });
- });
- });
- // catch ESC and discard any visible moes
- $(document).ready(function () {
- $(document)
- .off('keydown.moe-escape')
- .on('keydown.moe-escape', function (e) {
- if(e.which === 27) {
- let visibleMoes = $('[moe] [url]:not([show]):visible');
- if (visibleMoes.length) {
- hideMoeFormMask();
- visibleMoes.hide();
- window.moeClosedAt = (new Date()).getTime();
- return false;
- }
- }
- });
- });
|