(function ($) { $.fn.loadDD = function (options) { var settings = $.extend({ // These are the defaults. backgroundColor: "white", width: "240px", allowadd: true, allowedit: true }, options); var idbase = this.attr('id').replace('Div', ''); var bEdit = true; if (this.closest('.DropAEL').attr('elid') == '-1') { bEdit = false; } var curVal = ""; var curItm = ""; var valData = this.attr('val'); if (valData != null && valData.replace(/\s*$/, "") != '0·') { curVal = 'value="' + valData.split('·')[1] + '" val="' + valData.split('·')[0] + '"'; curItm = "
" + valData.split('·')[1] + "
"; } else { curVal = "value='' val='0'"; } var disabled = ""; if (this.attr('disabled') != null) { disabled = " readonly "; } var disableUntil = this.closest('.DropAEL').attr("diaeu") == 'y'; var addblock = ""; var editblock = ""; if (!settings.allowadd) { addblock = "
"; } if (settings.allowedit && bEdit) { if (curItm != "") { editblock = "edit"; } else { editblock = ""; } } this.html("
" + editblock + "
" + curItm + "
" + addblock + "
"); this.attr("initd", "y"); return this; }; }(jQuery)); var eTimeStamp; var GFR = false; var openDD = []; $(window).click(function (e) { if (openDD.length>0) { if (e.target.id != "" && openDD.indexOf(e.target.id) > 0) { } else { HideDD($('#' + openDD[0])); } } }); $(window).on('keyup', function (e) { if (e.which == 9) { if (openDD.length>0) { if (e.target.id != "" && openDD.indexOf(e.target.id) > 0) { } else { HideDD($('#' + openDD[0])); } } } }); function EvalShow(n) { if (openDD.length>0) { if (openDD.indexOf($(n).attr('id')) > 0) { } else { } } else { if ($(n).attr('val') == '' || $(n).attr('val') == '0') { ShowDD($(n)); } } } function ShowDD(n) { // 'n' is the element that triggered the show. could be either the textbox or the image to the right of it var imgArr = $('#' + $(n).attr('id')); var d = $('#' + $(n).attr('id').replace('Img', '') + 'Mnu'); //menu if (openDD.length>0) { if (openDD.indexOf($(d).attr('id')) < 0) { HideDD($('#' + openDD[0])); } } var r = $(n).closest('tr'); var dv = $(r).closest('div'); if ($(dv).attr('disabled') != null) { if ($(dv).attr('disabled') == 'disabled') { return; } } var menuParent = $(d).parent(); menuParent.width($(r).width() - 2); var theTR = r.parent(); var positionMenu = function () { menuParent.position({ my: "left top", at: "left bottom", of: theTR, collision: "none" }); }; // we need to show the element before positioning it, but we want to animate it when it's actually shown...but it needs to animate once it's been positioned // so make it invisible and "show" it now for the purpose of positioning it, then hide it again and then we'll show it with the animation now that it's positioned menuParent.css({ visibility: 'hidden' }); menuParent.show(); positionMenu(); menuParent.hide(); menuParent.css({ visibility: 'visible' }); // need to reposition upon scroll, but only if the dvFormContents div actually exists var scrollingDiv = $('#dvFormContents'); if (scrollingDiv.length) { scrollingDiv.on('scroll.dropael', function () { positionMenu(); }); } // now we can actually show with the animation menuParent.show('blind'); var m = 0; var sm = 0; var fld = ''; var smm = ''; var vbf = ''; m = $(dv).attr('mod'); sm = $(dv).attr('smod'); fld = $(dv).attr('kfld'); smm = $(dv).attr('srch'); //Search Method vbf = $(dv).attr('vbf'); //value based filter $(r).find('input').on('change keyup', function (e) { if (e.type == "keyup") { if (e.which == 38 || e.which == 40) { if (e.timeStamp != eTimeStamp) { Arrows($(r), e.which); eTimeStamp = e.timeStamp; } return; } if (e.which == 8 || e.which == 46) { $(this).attr('val', ''); } } if ($(dv).attr('filter') == '') { setTimeout(function () { GetData(m, sm, fld, $(r), $(d), smm, vbf); }, 500); } else { setTimeout(function () { GetDataFiltered(m, sm, fld, $(r), $(d), smm, vbf); }, 500); } }); if ($(r).find('input').attr('val') != null) { if ($(r).find('input').attr('val') != '') { $(r).closest('div').find('.mnuDropAEL').find('div').removeClass('seldDrop'); var seld = $(r).closest('div').find('.mnuDropAEL').find('div[val="' + $(r).find('input').attr('val') + '"]'); $(seld).addClass('seldDrop'); } } openDD = ($(d).attr('id') + ',' + $(r).find('input').attr('id') + ',' + $(r).find('.tdDropAEL').find('img').attr('id') + ',' + $(r).find('.clrDropAEL').find('img').attr('id')).split(','); if ($(d).html() == '') { if ($(dv).attr('filter') == '') { $(d).prepend('
Loading...
'); } $(r).find('input').change(); } if (window.top.$('.e-iframe:visible').length == 0) { if (window.top.$('.ifrm').length > 0) { if ($(d).parent().position().top + $(d).height() > window.top.$('.ifrm').height()) { var hght = window.top.$('.ifrm').height() - ($(d).parent().position().top + 10); $(d).css('height', hght); } } } else { if (window.top.$('.e-iframe:visible').length > 0) { if ($(d).parent().position().top + $(d).height() > window.top.$('.e-iframe').height()) { var hght = window.top.$('.e-iframe').height() - ($(d).parent().position().top + 10); $(d).css('height', hght); } } } $(d).closest('.DropAEL').find('.inpDropAEL').blur(function () { var mnu = $(this).closest('.DropAEL').find('.mnuDropAEL'); if ($(this).val() != "" && ($(this).attr('val') == '0' || $(this).attr('val') == '')) { if ($(mnu).find('.dditem').length > 0) { if ($(mnu).find('.seldDrop').length == 0) { $(mnu).find('.dditem').first().click(); } } } }); } function SelectFirst(r) { $(r).closest('div').find('.mnuDropAEL').find('div').removeClass('seldDrop'); var seld = $(r).closest('div').find('.mnuDropAEL').find('.dditem').first(); $(seld).addClass('seldDrop'); } function clearVal(n) { var r = $(n).closest('tr'); var $parentDiv = $(n).parent().closest('div'); if ($(r).closest('div').attr('disabled')=='disabled') { return; } $(r).find('input').val(''); $(r).find('input').attr('val', ''); $(r).closest('div').find('.mnuDropAELWrap').find('.mnuDropAEL').html(''); ShowDD($(r).find('input')); ConsiderScheduler($parentDiv); } function GetData(m, sm, fld, r, d, smm, vbf) { if (GFR) { //already running return; } GFR = true; var fuid = '0'; if ($('.hidFUID').length > 0) { fuid = $('.hidFUID').val(); } $.post('../handlers/HTMLCRUD.ashx?pageaction=getDataLike', { mod: m, smod: sm, fld: fld, val: $(r).find('input').val(), smm: smm, vbf: vbf, fuid: fuid }, function (data) { $(d).empty(); $($.parseJSON(data)).map(function () { var finVal = this.name; var ttl = this.name; if (this.name.indexOf('\n') > -1) { finVal = this.name.split('\n')[0] + "..."; } else if (this.name.length > 25) { finVal = this.name.substr(0, 25) + '...'; } else { ttl = ''; } var rVal = $('
' + finVal + '
'); $(d).append(rVal); }); GFR = false; var lid = $(d).closest('.DropAEL').attr('lid'); var disableUntil = $(d).closest('.DropAEL').attr("diaeu") == 'y'; if (lid != '-1') { if (window.location.href.indexOf('rel=yes') < 0) { if ($(d).parent().html().indexOf('RelAddPop') < 0) { $('
- Add New -
').insertAfter($(d)); $(d).css('height', ''); if (window.top.$('.ifrm').length > 0) { if ($(d).parent().position().top + $(d).height() + $(d).parent().find('.AddNewDropAEL').height() > window.top.$('.ifrm').height()) { var hght = window.top.$('.ifrm').height() - ($(d).parent().position().top + 40); $(d).css('height', hght); } } } } } SelectFirst($(r)); }); } function GetDataFiltered(m, sm, kfld, r, d, smm, vbf) { if (GFR) { //already running return; } GFR = true; var fuid = '0'; if ($('.hidFUID').length > 0) { fuid = $('.hidFUID').val(); } $.post('../handlers/HTMLCRUD.ashx?pageaction=getDataLikeFilter', { mod: m, smod: sm, kfld: kfld, fld: $(r).find('input').attr('id'), val: $(r).find('input').val(), fltr: $(r).closest('div').attr('filter'), sctrl: $(r).closest('div').attr('dependent'), smm: smm, vbf: vbf, fuid: fuid }, function (data) { $(d).empty(); $($.parseJSON(data)).map(function () { var finVal = this.name; var ttl = this.name; if (this.name.indexOf('\n') > -1) { finVal = this.name.split('\n')[0] + "..."; } else if (this.name.length > 25) { finVal = this.name.substr(0, 25) + '...'; } else { ttl = ''; } var rVal = $('
' + finVal + '
'); $(d).append(rVal); }); GFR = false; var lid = $(d).closest('.DropAEL').attr('lid'); if (lid != '-1') { if (window.location.href.indexOf('rel=yes') < 0) { //$(d).append('
- Add New -
'); if ($(d).parent().html().indexOf('RelAddPop') < 0) { $('
- Add New -
').insertAfter($(d)); } } } SelectFirst($(r)); }); } function SetVal(n) { var inp = $(n).parent().parent().parent().find('input'); $(inp).attr('val', $(n).attr('val')); if ($('#' + $(inp).attr('id') + '_rel').length > 0) { $('#' + $(inp).attr('id') + '_rel').val($(n).attr('val')); } if ($(n).html() == '') { $(inp).val(''); } else { $(inp).val($(n).html().replace('&','&')); } $(n).parent().find('div').removeClass('seldDrop'); $(n).addClass('seldDrop'); var $parentDiv = $(inp).parent().closest('div'); if ($parentDiv.attr('chg') != null) { Depends2($(inp)); } if ($(inp).parent().closest('div').attr('trig') != null) { RepopDTTs($(inp)); } //Scheduler Related ConsiderScheduler($parentDiv); if ($(n).closest('.DropAEL').attr('elid') != -1 && $(n).attr('val') != '0' && $(n).attr('val') != '') { $(n).closest('.DropAEL').find('a').show(); } else { $(n).closest('.DropAEL').find('a').hide(); } if ($(inp).attr('runCS') == 'yes') { var trigger = $('div.DropAEL[schedTrig="yes"]').last(); ConsiderScheduler($(trigger)); } $(inp).change(); } function ConsiderScheduler($parDiv) { if ($parDiv.attr('schedtrig') != null) { var inp = $parDiv.find('.inpDropAEL'); RepopSchedulers($(inp), $(inp).attr('id'), $parDiv.attr('schedfield')); EvalShedulerLineItemShow(); AdjustIframeHeight(); } } function AdjustIframeHeight() { if (window.top.sizeIFrame != null) { window.top.sizeIFrame(); } } function Arrows(r, val) { switch (val) { case 38: var sd = $(r).find('input').closest('div').find('.seldDrop'); if (sd.length == 0) { SetVal($(r).find('input').closest('div').find('.dditem').first()); event.preventDefault(); return false; } else { sd = $(sd).prev(); if (sd.length != 0) { SetVal($(sd)); event.preventDefault(); return false; } } break; case 40: var sd = $(r).find('input').closest('div').find('.seldDrop'); if (sd.length == 0) { SetVal($(r).find('input').closest('div').find('.dditem').first()); event.preventDefault(); return false; } else { sd = $(sd).next(); if (sd.length != 0) { SetVal($(sd)); event.preventDefault(); return false; } } break; } } function HideDD(n) { openDD = []; $(n).parent().hide('blind'); // need to turn off the scroll event, but only if this div exists var scrollingDiv = $('#dvFormContents'); if (scrollingDiv.length) { $('#dvFormContents').off('scroll.dropael'); } if ($(n).closest('.DropAEL').attr('elid') != -1 && $(n).closest('.DropAEL').find('input').attr('val') != '0' && $(n).closest('.DropAEL').find('input').attr('val') != '') { $(n).closest('.DropAEL').find('a').show(); } else { $(n).closest('.DropAEL').find('a').hide(); } } function RelAddPop(n, lid, doDisableUntil) { var parentModId = $(n).closest('.DropAEL').attr('smod'); var dependentMod = $(n).closest('.DropAEL').attr('dependent'); var dependentValue = ''; if (dependentMod != null && dependentMod != "") { dependentValue = $('#' + dependentMod).attr('val'); if (doDisableUntil && (dependentValue == '0' || dependentValue == '')) { alert("Adding a new record to this drop down is not allowed until all the dependencies are met."); return; } window.top.ShowDialogURL2("addnewfast.aspx?rel=yes&lid=" + lid + "&mid=" + $(n).attr('mid') + "&pmid=" + parentModId + "&dvid=" + dependentMod + "·" + dependentValue, '80%', '80%', ""); } else { window.top.ShowDialogURL2("addnewfast.aspx?rel=yes&lid=" + lid + "&mid=" + $(n).attr('mid'), '80%', '80%', ""); } } function RelEditPop(n) { var lid = $(n).closest('.DropAEL').attr('elid'); var mid = $(n).closest('.DropAEL').attr('mod'); var val = $(n).closest('.DropAEL').find('input').attr('val'); window.top.ShowDialogURL2("editfast.aspx?rel=yes&ie=y&sid=" + val + "&lid=" + lid + "&mid=" + mid, '80%', '80%', ""); } function PutValue(n, v) { var d = $('#' + n); //gets the DropAEL div $(d).attr('val', v); $(d).html(''); $(d).loadDD(); if ($(d).attr('dependent') != null) { var depF = $('#' + $(d).attr('dependent') + 'Div'); var depV = $(depF).attr('val').split('·')[0]; $(d).attr('filter', depV); } }