123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146 |
- 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 (_target) {
- setTimeout(function () {
- hideMoeFormMask();
- fastReload(_target);
- }, 500);
- };
- 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 target = $(form).attr('target'); // OPTIONAL
- var noreload = $(form).is('[noreload]'); // OPTIONAL
- var hook = $(form).attr('hook'); // OPTIONAL
- var submit = moe.find('[submit]'); // REQUIRED
- var cancel = moe.find('[cancel]')[0]; // OPTIONAL
- let moeRefreshContainer = moe.closest('[moe-refresh-container][id]');
- if(!target && moeRefreshContainer.length) {
- target = '#' + moeRefreshContainer.attr('id');
- }
- // 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(noreload) {
- $(cancel).trigger('click.moe');
- hideMoeFormMask();
- hideMask();
- toastr.success('Done');
- return;
- }
- if (justLog) { // this is to test!
- console.log('RETURNED', data);
- } else if (hook) {
- $(cancel).trigger('click.moe');
- hideMoeFormMask();
- hideMask();
- runMCHook(hook);
- } else if(typeof isDynamicStagPopupPresent !== 'undefined' && isDynamicStagPopupPresent()) {
- let targetUrl = false;
- if (redir) {
- if (redir.indexOf('[data]') > -1) {
- targetUrl = redir.replace('[data]', data);
- }
- }
- refreshDynamicStagPopup(targetUrl, target);
- } 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(target);
- }
- }, function (errorMessage) {
- }, false);
- }
- else {
- doAjaxFormData(url, data, null, function () {
- moe.isProcessing = false;
- }, function (data) {
- if(noreload) {
- $(cancel).trigger('click.moe');
- hideMoeFormMask();
- hideMask();
- toastr.success('Done');
- return;
- }
- if (justLog) { // this is to test!
- console.log('RETURNED', data);
- } else if (hook) {
- $(cancel).trigger('click.moe');
- hideMoeFormMask();
- hideMask();
- runMCHook(hook);
- } else if(typeof isDynamicStagPopupPresent !== 'undefined' && isDynamicStagPopupPresent()) {
- let targetUrl = false;
- if (redir) {
- if (redir.indexOf('[data]') > -1) {
- targetUrl = redir.replace('[data]', data);
- }
- }
- refreshDynamicStagPopup(targetUrl);
- } 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(target);
- }
- }, 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') ||
- $(e.target).closest('.ui-datepicker').length) {
- 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) {
- if(isEventConsumed(e)) return;
- let visibleMoes = $('[moe] [url]:not([show]):visible');
- if (visibleMoes.length) {
- hideMoeFormMask();
- visibleMoes.hide();
- window.moeClosedAt = (new Date()).getTime();
- markEventAsConsumed(e);
- return false;
- }
- }
- });
- });
|