// ------------------------------------------------------------------------------------------------------------------ // Many To Many Scripts // ------------------------------------------------------------------------------------------------------------------ var oneOffStatus = []; function DelManyToManyRow(fldName, modId, modRefId, relModId, relModRefId) { $.ajax({ url: "ManyToMany.ashx?pageaction=delete&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&relmodrefid=" + relModRefId + "&ctrl=" + fldName, success: function (result) { $('.tr' + fldName + relModRefId).remove(); if (window.top.sizeIFrame != null) { window.top.sizeIFrame(); } } }); } function DelManyToManyRowAdd(n) { $(n).closest('tr').remove(); if (window.top.sizeIFrame != null) { window.top.sizeIFrame(); } } function ToggleManyToManyEdit(ctrl, fldName) { if ($(ctrl).text() == 'edit') { $('.TeamAEL').each(function () { $(this).loadTM(); }); if ($('.spnM2M' + fldName).find('select').length == 0) { //its the teammember/recordowner plugin so hide the add $('.spnM2M' + fldName).find('#hypSave').hide(); } $('.spnM2M' + fldName).show(); $(ctrl).text('done'); $('.tblM2M' + fldName).css("display", "block"); } else if ($(ctrl).text() == 'done') { $('.spnM2M' + fldName).hide(); $(ctrl).text('edit'); if ($('.tblM2M' + fldName + ' tr').length == 1) { $('.tblM2M' + fldName).css("display", "none"); } else { $('.tblM2M' + fldName).css("display", "block"); } RefreshPanel($('.hidProfileUnique').val()); } $('.M2MModRecs' + fldName).val('0'); } function ShowAssociatedMTMAddNew(modName, fldName) { $.fn.colorbox({ onClosed: function () { ReloadAssociatedMTMDropDown(modName, fldName); }, close: '', href: 'addnew.aspx?module=' + modName + '&MTMAssoc=yes', iframe: true, width: 850, height: 775 }); } function ReloadAssociatedMTMDropDown(modName, fldName) { $.get("../Data/ManyToMany.ashx?pageaction=reloadAssoc&modName=" + modName + "&ts=" + new Date().getTime(), function (data) { $('.M2MDepModRecs' + fldName).html(data); }); } function ReloadMTMT(fldName) { var $td = $('.plidiv[fld="' + fldName + '"]'); var modId = $td.find('.hidModId').val(); var modRefId = $td.find('.hidModRefId').val(); var relModId = $td.find('.hidRelatedModId').val(); ToggleManyToManyTemplateEditOnly(fldName, modId, modRefId, relModId) } function RepopSchedulers(n, fieldId, fldName) { var filterVal = $(n).attr('val'); var $td = $('.plidiv[fld="' + fldName + '"]'); var modId = $td.find('.hidModId').val(); var modRefId = $td.find('.hidModRefId').val(); var relModId = $td.find('.hidRelatedModId').val(); var filterField = fieldId; var isClone = $('.clonemsg').length > 0; var lifc = ''; if ($td.find('.hidLIFC').length > 0) { lifc = $td.find('.hidLIFC').val(); } var lifcVal = ''; if (lifc != "") { //if it has a lifc value, if the field is blank, then don't try the repop yet. var lifcFldVal = lifc.split('·')[0]; lifcVal = $('#' + lifcFldVal).attr('val'); MarkLIFCRepop(); if (lifcVal == '') { return; } } $('.divM2MT' + fldName).html(""); $.post('manytomany.ashx?pageaction=reloadmtmtonfly', { m2mtctrlid: fldName, modid: modId, modrefid: modRefId, relmodid: relModId, fltrfld: filterField, fltrval: filterVal, clone: isClone, lifc: lifc, lifcVal: lifcVal }, function (data) { $('.divM2MT' + fldName).html(data); //replace Sheduler Add button if clone and make it an add if (isClone) { if ($('.newSchedAdd').length > 0) { $('.newSchedAdd').parent().append("
You must save this record before adding additional Scheduler Items
"); $('.newSchedAdd').hide(); var pliDiv = $('.epoOnEdit'); $(pliDiv).removeClass('epoOnEdit'); $(pliDiv).addClass('apoOnEdit'); } } $('.plisavebutton').hide(); if (window.top.sizeIFrame != null) { window.top.sizeIFrame(); } } ); } function QueueOneOff(n, recordId) { if ($(n).hasClass('oneoffbuttonlong')) { return; } $(n).val('Generating...'); $(n).removeClass('oneoffbutton'); $(n).addClass('oneoffbuttonlong'); var $td = $(n).closest('div').closest('.plidiv'); var $div = $(n).closest('div').closest('.divMTMT'); var modId, modRefId, relModId; if ($div.length > 0) { modId = $div.attr('modid'); modRefId = $div.attr('sid'); relModId = $div.attr('rmod'); } else { modId = $td.find('.hidModId').val(); modRefId = $td.find('.hidModRefId').val(); relModId = $td.find('.hidRelatedModId').val(); } if ($(n).hasClass('oneoffpopup')) { window.top.ShowDialogURL2('../tools/shortform.aspx?modid=' + relModId, 400, 500); } else { DoOneOffQueueing($(n), modId, modRefId, relModId, recordId, ''); } } function CancelOneOffQueueing() { var n = $('.oneoffbuttonlong'); $(n).val('One Off'); $(n).removeClass('oneoffbuttonlong'); $(n).addClass('oneoffbutton'); } function FinishOneOffQueueing(vals) { var n = $('.oneoffbuttonlong'); var recordId = $(n).attr('recId'); var $td = $(n).closest('div').closest('.plidiv'); var $div = $(n).closest('div').closest('.divMTMT'); var modId, modRefId, relModId; if ($div.length > 0) { modId = $div.attr('modid'); modRefId = $div.attr('sid'); relModId = $div.attr('rmod'); } else { modId = $td.find('.hidModId').val(); modRefId = $td.find('.hidModRefId').val(); relModId = $td.find('.hidRelatedModId').val(); } DoOneOffQueueing($(n), modId, modRefId, relModId, recordId, vals); } function DoOneOffQueueing(n, modId, modRefId, relModId, recordId, ctrlVals) { $.post('../handlers/scheduler.ashx?pageaction=queueoneoff', { modid: modId, modrefid: modRefId, relmodid: relModId, schedid: recordId, cvals: ctrlVals }, function (data) { if (data.indexOf('OK:') > -1) { var queueRecId = data.split(':')[1]; oneOffStatus.push(queueRecId); $(n).attr('queId', queueRecId); alert("The creation of a One Off record has been initiated.\nThis may take a couple of minutes.\nThe One Off button will show Complete once the new record has been created.") CheckOneOffStatus(false); } else { alert(data); } } ); } var isRunning = false; function CheckOneOffStatus(isLoop) { if (isRunning && !isLoop) { return; } isRunning = true; $.post('../handlers/scheduler.ashx?pageaction=checkoneoffstatus', { arr: oneOffStatus.join(',') }, function (data) { var results = data.split(','); for (var z in results) { $('.oneoffbuttonlong[queId="' + results[z] + '"]').val('Complete'); } var keepGoing = false; $('.oneoffbuttonlong').each(function () { if ($(this).val() == 'Generating...') { keepGoing = true; } }); if (keepGoing) { setTimeout(function () { CheckOneOffStatus(true); }, 5000); } else { isRunning = false; //Refresh the tabs $('.dataContainer').each(function () { if ($(this).attr('content_url').indexOf('queue.ashx') > -1) { RefreshPanel($(this).attr('uniquename')); } }); } } ); } function SaveManyToManyAdd(fldName, modId, relModId) { var ddl = $('.M2MModRecs' + fldName); var ddlD = $('.M2MDepModRecs' + fldName); if (ddl.val() != '0') { if ($('.tr' + fldName + ddl.val()).length == 0) { $(".trWithStuffInIt" + fldName).after("" + $('.M2MModRecs' + fldName + ' :selected').text() + "  "); ddl.val('0'); if (window.top.sizeIFrame != null) { window.top.sizeIFrame(); } } else { alert('This record is already linked.'); ddl.val('0'); } if (ddlD != null) { ddlD.val('0'); } } } function SaveManyToMany(fldName, modId, modRefId, relModId, boa) { var ddl = $('.M2MModRecs' + fldName); var ddlD = $('.M2MDepModRecs' + fldName); if (ddl.val() != '0') { if ($('.tr' + fldName + ddl.val()).length == 0) { $.ajax({ url: "../Data/ManyToMany.ashx?pageaction=add&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&relmodrefid=" + ddl.val() + "&fld=" + fldName + "&depmodrefid=" + ddlD.val() }); if (boa == null) { boa = 'Before'; } if (boa == 'Before') { $(".trWithStuffInIt" + fldName).before("" + $('.M2MModRecs' + fldName + ' :selected').text() + "  "); } else { $(".trWithStuffInIt" + fldName).after("" + $('.M2MModRecs' + fldName + ' :selected').text() + "  "); } ddl.val('0'); if (window.top.sizeIFrame != null) { window.top.sizeIFrame(); } } else { alert('This record is already linked.'); ddl.val('0'); } if (ddlD != null) { ddlD.val('0'); } } } function SaveManyToManyFromPlugin(selVal, selText, fldName, modId, modRefId, relModId, boa) { if (selVal != '0') { if ($('.tr' + fldName + selVal).length == 0) { var addClass = ' m2madd'; if (modRefId != '0' && modRefId != '') { addClass = ''; $.ajax({ url: "../Data/ManyToMany.ashx?pageaction=add&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&relmodrefid=" + selVal + "&fld=" + fldName + "&depmodrefid=0" }); } if (boa == null) { boa = 'Before'; } if (boa == 'Before') { $(".trWithStuffInIt" + fldName).before("" + selText + "  "); } else { $(".trWithStuffInIt" + fldName).after("" + selText + "  "); } if (window.top.sizeIFrame != null) { window.top.sizeIFrame(); } } else { alert('This record is already linked.'); } } } // ------------------------------------------------------------------------------------------------------------------ // Many To Many (Template) Scripts // ------------------------------------------------------------------------------------------------------------------ function AddManyToManyTemplateRow(fldName,isValiCtrl) { //var trClone = $('.tblM2MT' + fldName + ' tr:last').clone(); //$('.tblM2MT' + fldName).append(trClone); if (isValiCtrl == 'True') { var trClone = $('.tblM2MT' + fldName + ' tr:last').clone(); $(trClone).find('input').each(function () { $(this).val(""); if ($(this).attr("id").slice(0, 2) == "dp") { $(this).attr("id", $(this).attr("id") + "z"); $(this).removeClass('hasDatepicker'); $(this).datepicker(); } }); $('.tblM2MT' + fldName).append(trClone); // $('.datepicker').each(function () { // $(this).datepicker(); // }); } else { $('.tblM2MT' + fldName).find('.trAddNew').show(); } SetIframeHeight(); } function AddEmptyManyToManyTemplateRow(fldName) { var tbl = $('.tblM2MT' + fldName); var firstRow = $(tbl).find('tr.Update').first(); SetIframeHeight(); if ($(firstRow).length > 0) { var clone = $(firstRow).clone(); $(clone).find("input[type='text']").val(''); $(clone).find("input[type='radio']").prop('checked', false); $(clone).find("textarea").val(''); $(clone).find("select").val(''); $(clone).find("input[type='hidden']").val(''); //for pictures and such $(clone).find("input[type='hidden']").first().val('0'); //for record id if ($(clone).find("input[type='radio']").length > 0) { var newName = makeName(5); $(clone).find("input[type='radio']").each(function () { $(this).attr('name', newName); }) } $(clone).removeClass("Update"); $(clone).addClass("Insert"); $(tbl).append($(clone)); SetPickers(); SetLabelListeners(); } else { var pliDiv = $(tbl).closest('.plidiv'); var mid = $(pliDiv).find('.hidModId').val(); var refid = $(pliDiv).find('.hidModRefId').val(); var rmid = $(pliDiv).find('.hidRelatedModId').val(); var fld = $(pliDiv).attr('fld'); $.post("../Data/ManyToMany.ashx?pageaction=getemptymanytomanytemplaterow", { modid: mid, modrefid: refid, relmodid: rmid, fld: fld }, function (data) { $(tbl).append(data); }); } SetIframeHeight(); MarkAsChanged(); } function AddNewSchedulerRecord(fldName) { var tbl = $('.tblM2MT' + fldName); var mainMod = $('.hidModId').val(); var mainModSystemId = $('.hidModRefId').val(); var pliMod = $(tbl).closest('.plidiv').find('.hidRelatedModId').val(); if (mainModSystemId == '0') { alert("You must save the main record before you can add additional scheduler records."); return; } window.top.ShowDialogURL2('addnewfast.aspx?schedrec=y&pmid=' + mainMod + '&parentRecordId=' + mainModSystemId + '&mid=' + pliMod, '80%', '80%', function () { window.top.location.href = window.top.location.href; //reload }); } function EditSchedulerRecord(n) { $('.spinner-overlay').show(); noLo = true; var sysId = $(n).closest('td').find('input').first().val(); var modId = $(n).closest('.divMTMT').attr('rmod'); if (window.top.$('#dialoggg').length > 0) { window.top.$('#dialoggg').html(''); //clear it out from previous activities } window.top.ShowDialogURL2('editfast.aspx?schedrec=y&sid=' + sysId + '&mid=' + modId, '90%', '90%', function () { noLo = false; RefreshPanel($('.SelectedTab:first').attr('reallyuniqueid')); if (window.top.RefreshHtml != null) { RefreshHTML(); } }); } function GrabHVRecordArray(n) { var arr = []; $(n).find('[hvsid]').each(function () { arr.push($(this).attr('hvsid')); }); return arr; } function ShowAdditionalInfo(n) { //alert("Additional Info Will Appear"); } function EvalShedulerLineItemShow() { var schedTrigDiv = $.find('.DropAEL[schedtrig="yes"]'); if ($(schedTrigDiv).length == 1) { var inpFieldValue = $(schedTrigDiv).find('.inpDropAEL').attr('val'); if (inpFieldValue == "0" || inpFieldValue == "") { $('.plidiv').hide(); } else { $('.plidiv').show(); } } } var dialogReturnValue = true; var _fldName; var _relModRefId; function SetDialogReturnValue(b) { dialogReturnValue = b; } function DelManyToManyTemplateRow(ctrl, fldName, relModRefId) { if ($(ctrl).closest('tr').hasClass('Insert')) { $(ctrl).closest('tr').remove(); } else { MarkAsChanged(ctrl); dialogReturnValue = true; //if ($(ctrl).closest('a').attr('scheditem') == 'y') { // dialogReturnValue = false; // _fldName = fldName; // _relModRefId = relModRefId; // window.top.ShowDialogURL2("../tools/schedulerupdatemsg.aspx?scheddel=" + relModRefId, 400, 400, finishDeleting); //} if (dialogReturnValue) { $('.tr' + fldName + relModRefId).hide(); $('.tr' + fldName + relModRefId).addClass("Delete"); $('.tr' + fldName + relModRefId).removeClass("Update"); } } } function finishDeleting() { if (window.top.dialogReturnValue) { $('.tr' + _fldName + _relModRefId).hide(); $('.tr' + _fldName + _relModRefId).addClass("Delete"); $('.tr' + _fldName + _relModRefId).removeClass("Update"); } } function GetManyToManyTemplate(fldName, modId, modRefId, relModId, editPageOnly, layoutId) { if (editPageOnly == null) { editPageOnly = false; } var setLay = ''; if (layoutId != null) { setLay = '&lid=' + layoutId; } //////$.ajax({ ////// url: "../Data/ManyToMany.ashx", ////// type: "GET", ////// async: true, ////// data: { ////// m2mtctrlid: fldName, ////// pageaction: "getM2MTDisplay", ////// modid: modId, ////// modrefid: modRefId, ////// setLay: setLay, ////// relmodid: relModId, ////// x: (new Date).getTime() ////// }, ////// success: function (response) { ////// $('.divM2MT' + fldName).html(response); ////// if (editPageOnly) { ////// var isClone = $('.clonemsg').length > 0; ////// var isScheduler = $('.DropAEL[schedtrig="yes"]').length > 0; ////// if (isClone && isScheduler) { ////// ConsiderScheduler($('.DropAEL[schedtrig="yes"]').first()); ////// } else { ////// ToggleManyToManyTemplateEditOnly(fldName, modId, modRefId, relModId); ////// } ////// } ////// if (SetIframeHeight) { ////// SetIframeHeight(); ////// } ////// }, ////// error: function (xhr, status, error) { ////// // Handle errors here ////// } //////}); $('.divM2MT' + fldName).load("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTDisplay&modid=" + modId + "&modrefid=" + modRefId + setLay + "&relmodid=" + relModId + "&x=" + (new Date).getTime(), function () { if (editPageOnly) { var isClone = $('.clonemsg').length > 0; var isScheduler = $('.DropAEL[schedtrig="yes"]').length > 0 if (isClone && isScheduler) { ConsiderScheduler($('.DropAEL[schedtrig="yes"]').first()); } else { ToggleManyToManyTemplateEditOnly(fldName, modId, modRefId, relModId); } } if (SetIframeHeight) { SetIframeHeight(); } }); } function Pause() { //does nothing } var rmItem; function DTRemoveItem(n) { rmItem = $(n).val(); } var cFldName; var cmodId; var crelModId; var cmodRefId; var ctrOrig; var cdps; function AddNewRowFromDialog(relModRefId, isFromTracerLibrary) { var fldName = cFldName; var modId = cmodId; var modRefId = cmodRefId; var relModId = crelModId; var trOrig = ctrOrig; var dps = cdps; var trOrig = $('.tblM2MT' + fldName).find('.trAddNew'); var trClone = $('.tblM2MT' + fldName).find('.trAddNew').clone(); trClone.css('display', 'none'); $('.tblM2MT' + fldName).append(trClone); trOrig.removeClass(); if (isFromTracerLibrary != null) { trOrig.addClass("Update tracer tr" + fldName + relModRefId); trOrig.attr("tracerid", relModRefId); } else { trOrig.addClass("Insert tr" + fldName + relModRefId); } trOrig.html("Loading..."); //$.post('../Data/ManyToMany.ashx?pageaction=getM2MTRow&modid=' + modId + '&modrefid=' + modRefId + '&relmodid=' + relModId); $.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTRow&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&relmodrefid=" + relModRefId + "&deps=" + dps + "&x=" + (new Date).getTime(), function (data) { if (trOrig.length == 0) { //just append the data to the table? var tr = $(data); $(tr).removeClass('Insert'); $(tr).addClass('Update tracer tr' + fldName + relModRefId); $('.tblM2MT' + fldName).append($(tr)); } else { trOrig.html(data); } SetPLIPicsFiles(); $('.tblM2MT' + fldName).find('.imgHover').hover(function () { $(this).find('.mainImg').fadeTo(200, 0.55).end().children('.hover').show(); }, function () { $(this).find('.mainImg').fadeTo(200, 1).end().children('.hover').hide(); }); if (isFromTracerLibrary != null) { AddNextRow(isFromTracerLibrary); } else { AddNextRow(); } //$.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getnextYMM&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&rval=" + "" + "&ndx=" + -1 + "&deps=" + dps + "&YMMs=" + "", // function (datas) { // $('.tblM2MT' + fldName).find('.trAddNew td').html(datas); // }); }); } function GetManyToManyTemplateRow(fldName, modId, relModId, modRefId, tempRecId) { var dps = ""; if (modRefId == "0") { dps = $('#hidDeps').val(); } var templateRecordId = 0; if (tempRecId != undefined) { templateRecordId = tempRecId; } else { templateRecordId = $('.AddNew' + fldName).val(); } if (templateRecordId == 'AN') { //add new record functionality for Default/Template var pmid = $('.hidModId').val(); var pmsid = $('.hidSid').val(); cFldName = fldName; cmodId = modId; crelModId = relModId; cmodRefId = modRefId; ctrOrig = trOrig; cdps = dps; window.top.ShowDialogURL2('addnewfast.aspx?istq=y&pmid=' + pmid + '&pmsid=' + pmsid + '&mid=' + relModId, '80%', '80%', function () { cFldName = null; cmodId = null; crelModId = null; cmodRefId = null; ctrOrig = null; cdps = null; }); } else { var trOrig = $('.tblM2MT' + fldName).find('.trAddNew'); var trClone = $('.tblM2MT' + fldName).find('.trAddNew').clone(); trClone.css('display', 'none'); $('.tblM2MT' + fldName).append(trClone); trOrig.removeClass(); trOrig.addClass("Insert tr" + fldName + templateRecordId); trOrig.html("Loading..."); $.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTRow&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&relmodrefid=" + templateRecordId + "&deps=" + dps + "&x=" + (new Date).getTime(), function (data) { trOrig.html(data); SetPLIPicsFiles(); $('.tblM2MT' + fldName).find('.imgHover').hover(function () { $(this).find('.mainImg').fadeTo(200, 0.55).end().children('.hover').show(); }, function () { $(this).find('.mainImg').fadeTo(200, 1).end().children('.hover').hide(); }); SetSortables(); $.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getnextYMM&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&rval=" + "" + "&ndx=" + -1 + "&deps=" + dps + "&YMMs=" + "", function (datas) { $('.tblM2MT' + fldName).find('.trAddNew td').html(datas); var sel = $('.tblM2MT' + fldName).find('.trAddNew td').find('select'); if (rmItem != null) { var tbl = $('.tblM2MT' + fldName).find('.trAddNew').closest('table'); var arr = []; $(tbl).find('.Insert').each(function () { arr.push($(this).find('td').first().find('input[type="hidden"]').val()); }); $(sel).find('option').each(function () { if (arr.indexOf($(this).val()) > -1) { $(this).remove(); rmItem = null; } }); } SetSortables(); }); }); } } function GetManyToManyTemplateGroup(fldName, modId, relModId, modRefId, groupfield) { var vals = ""; $('.selMulti').each(function () { if ($(this).prop('checked')) { if (vals != "") { vals += ","; } vals += $(this).val(); $(this).removeAttr('checked'); } }); var trOrig = $('.tblM2MT' + fldName).find('.trAddNew'); var trClone = $('.tblM2MT' + fldName).find('.trAddNew').clone(); trClone.css('display', 'none'); trOrig.removeClass(); trOrig.html("Loading..."); $.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTGroup&modid=" + modId + "&sVals=" + vals + "&grpfield=" + groupfield + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&x=" + (new Date).getTime(), function (data) { var ds = data.split('¹'); for (var i = 0; i < ds.length; i++) { if (ds[i] != "") { if (i > 0) { trOrig = trOrig.clone(); $('.tblM2MT' + fldName).append(trOrig); trOrig.removeClass(); } trOrig.addClass("Insert tr" + fldName + ds[i].split('»')[0]); trOrig.html(ds[i].split('»')[1]); } } $('.tblM2MT' + fldName).append(trClone); $.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getnextYMM&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&rval=" + "" + "&ndx=" + -1 + "&YMMs=" + "", function (datas) { //$('.tblM2MT' + fldName).append(datas); }); SetSortables(); }); } function GetManyToManyTemplateGroupConnected(fldName, modId, relModId, modRefId, groupfield, skinid) { var vals = ""; $('.selMulti').each(function () { if ($(this).prop('checked')) { if (vals != "") { vals += ","; } vals += $(this).val(); $(this).removeAttr('checked'); } }); var trOrig = $('.tblM2MT' + fldName).find('.trAddNew'); var trClone = $('.tblM2MT' + fldName).find('.trAddNew').clone(); trClone.css('display', 'none'); trOrig.removeClass(); trOrig.html("Loading..."); $.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTGroup&modid=" + modId + "&sVals=" + vals + "&grpfield=" + groupfield + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&skin=" + skinid + "&x=" + (new Date).getTime(), function (data) { var ds = data.split('¹'); for (var i = 0; i < ds.length; i++) { if (ds[i] != "") { if (i > 0) { trOrig = trOrig.clone(); $('.tblM2MT' + fldName).append(trOrig); trOrig.removeClass(); } trOrig.addClass("Update tr" + fldName + ds[i].split('»')[0]); trOrig.html(ds[i].split('»')[1]); } } $('.tblM2MT' + fldName).append(trClone); $.get("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getnextYMM&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&rval=" + "" + "&ndx=" + -1 + "&YMMs=" + "", function (datas) { //$('.tblM2MT' + fldName).append(datas); }); SetSortables(); }); } function ToggleManyToManyTemplateEditOnly(fldName, modId, modRefId, relModId) { $('.spnM2MT' + fldName).show(); var isClone = $('.clonemsg').length > 0; $('.divM2MT' + fldName).html(""); //////$.ajax({ ////// url: "../Data/ManyToMany.ashx", ////// type: "GET", ////// async: true, ////// data: { ////// m2mtctrlid: fldName, ////// pageaction: "getM2MTEdit", ////// modid: modId, ////// modrefid: modRefId, ////// relmodid: relModId, ////// cln: isClone, ////// x: (new Date()).getTime() ////// }, ////// success: function (response) { ////// $('.divM2MT' + fldName).html(response); ////// $('.divM2MT' + fldName + ' .plisavebutton').hide(); ////// if (SetPLIPicsFiles != null) { ////// SetPLIPicsFiles(); ////// $('.divM2MT' + fldName + ' .imgHover').hover(function () { ////// $(this).find('.mainImg').fadeTo(200, 0.55).end().children('.hover').show(); ////// }, function () { ////// $(this).find('.mainImg').fadeTo(200, 1).end().children('.hover').hide(); ////// }); ////// } ////// var hasInserts = $('.divM2MT' + fldName + ' .Insert').length > 0; ////// if (isClone && hasInserts) { ////// var pliDiv = $('.divM2MT' + fldName).closest('.epoOnEdit'); ////// $(pliDiv).removeClass('epoOnEdit').addClass('apoOnEdit'); ////// } ////// SetEditables($('.divM2MT' + fldName).closest('.epoOnEdit')); ////// if (window.top.location.href.indexOf("profile.aspx") < 0) { ////// SetIframeHeight(); ////// } ////// }, ////// error: function (xhr, status, error) { ////// console.error("Error:", error); ////// } //////}); $('.divM2MT' + fldName).load("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTEdit&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&cln=" + isClone + "&x=" + (new Date).getTime(), function () { $(this).find('.plisavebutton').hide(); if (SetPLIPicsFiles != null) { SetPLIPicsFiles(); $('.imgHover').hover(function () { $(this).find('.mainImg').fadeTo(200, 0.55).end().children('.hover').show(); }, function () { $(this).find('.mainImg').fadeTo(200, 1).end().children('.hover').hide(); }); } var hasInserts = $(this).find('.Insert').length > 0; if (isClone && hasInserts) { var pliDiv = $(this).closest('.epoOnEdit'); $(pliDiv).removeClass('epoOnEdit'); $(pliDiv).addClass('apoOnEdit'); } SetEditables($(this).closest('.epoOnEdit')); if (window.top.location.href.indexOf("profile.aspx") < 0) { SetIframeHeight(); } }); } var curFldName = ''; function SaveManyToManyTemplate(fldName, modId, modRefId, relModId, sortField, sortValues, callBack, isOnParentAdd) { if (isOnParentAdd == null) { isOnParentAdd = false; } if ($('.tblM2MT' + fldName + ' tr').length == 2 && $('.tblM2MT' + fldName).find('.Insert').length == 0 && $('.tblM2MT' + fldName).find('.Update') == 0) { // Nothing to save, hide the table $('.tblM2MT' + fldName).css("display", "none"); $('.M2MTModRecs' + fldName).val('0'); if (window.location.href.indexOf('editfast.aspx') > -1 || window.location.href.indexOf('addnewfast.aspx') > -1) //its on an add/edit page and needs to save the whole page { $('.divM2MT' + fldName).html(''); if ($('.epoOnEdit').length == 0) { if ($('#btnSave').length > 0) { $('#btnSave').trigger('click'); } else { $('#btnSubmit').trigger('click'); } } } else { //just refresh the panel RefreshPanel($('.SelectedTab:first').attr('reallyuniqueid')); if (window.top.RefreshHtml != null) { RefreshHTML(); } } } else { // Iterate through the table and build the string for the handler to insert/update the controls var sVals = ""; var sVal; var iRowCnt = 0; var bWYS = false; var conctd = false; if ($('.tblM2MT' + fldName).length > 0) { if ($('.tblM2MT' + fldName).html().indexOf('GetManyToManyTemplateGroupConnected') > -1) { conctd = true; } } $('.tblM2MT' + fldName + ' tr').each(function () { sVal = ""; if ($(this).hasClass('Update')) { sVal = "U·"; } else if ($(this).hasClass('Insert')) { sVal = "I·"; } else if ($(this).hasClass('Delete')) { sVal = "D·"; } // This is a valid row if (sVal != "") { sVal += $(this).find('input:hidden').val() + '»'; if ($(this).html().indexOf('isWYSIWYG') > -1) { var hEc = $(this).find('#hidEditableControls').val().split(','); for (var k = 0; k < hEc.length; k++) { sVal += hEc[k].split('|')[0] + "·" + GetManyToManyEditControlTypeWYS($(this), hEc[k].split('|')[0], hEc[k].split('|')[1]) + "º"; } } else { $(this).find('td').each(function () { if ($(this).attr('editable') != null) { var field = $(this).attr('editable').split("·")[0]; sVal += $(this).attr('editable').split("·")[0] + "·" + GetManyToManyEditControlType($(this), field) + "º"; } }); } // Add this row to the array sVals += sVal + "¿"; } //check for additional/subitems for each row var hidParRowId = $(this).find('input:hidden').val(); if ($(this).find('.dvSIAR').length > 0) { $(this).find('.subItemRow').each(function () { if ($(this).attr('sisid') == '0') { sVal = 'SII·' + hidParRowId + '»'; //insert } else { sVal = 'SIU·' + $(this).attr('sisid') + '»' //update } $(this).find('td').each(function () { if ($(this).attr('editable') != null) { var field = $(this).attr('editable').split("·")[0]; sVal += $(this).attr('editable').split("·")[0] + "·" + GetManyToManyEditControlType($(this), field) + "º"; } }); sVals += sVal + "¿"; }); } iRowCnt++; }); $('.divM2MT' + fldName).html(""); if (modRefId == "0") { return sVals; } else { $.ajax({ url: "../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=saveM2MT&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId, method: "POST", async: false, data: { sVals: htmlEncode(sVals), conctd: conctd, isonparadd: isOnParentAdd } }) .done( function (data) { $.post('../handlers/HTMLCRUD.ashx?pageaction=postsavelisort', { s: sortField, v: sortValues, m: relModId, h: modId, r: modRefId }, function (data) { }); var finSaving = finishSaving; if (callBack == UpdateToEdit) { finSaving = finishSavingUpdateToEdit; } curFldName = fldName; //if (data.indexOf("tasks") == 0) { // window.top.ShowDialogURL2("../tools/schedulerupdatemsg.aspx?task=" + data, 400, 400, finSaving); //} //else { finSaving(); //} }); } } } function finishSavingUpdateToEdit() { if (window.location.href.indexOf('editfast.aspx') > -1) { //its on an edit page and needs to save the whole page $('.divM2MT' + curFldName).closest('.plidiv').remove(); if ($('.epoOnEdit').length == 0) { if ($('#btnSave').length > 0) { $('#btnSave').removeAttr('disabled'); $('#btnSave').trigger('click'); } else { $('#btnSubmit').removeAttr('disabled'); $('#btnSubmit').trigger('click'); } } } else { //just refresh the panel if (window.top.RefreshPanel != null) { RefreshPanel($('.SelectedTab:first').attr('reallyuniqueid')); if (window.top.RefreshHtml != null) { RefreshHTML(); } } } } function finishSaving() { if (window.location.href.indexOf('clone') > -1) { return; } if (window.location.href.indexOf('editfast.aspx') > -1) //its on an edit page and needs to save the whole page { $('.divM2MT' + curFldName).closest('.plidiv').remove(); var visiblePLIs = $('.epoOnEdit').parent().filter(function () { return $(this).is(':visible') && $(this).css('display') != 'none'; }).length; if (($('.epoOnEdit').length == 0 && $('.apoOnEdit').length == 0) || visiblePLIs == 0) { if ($('#btnSaveClose').length > 0) { $('#btnSaveClose').removeAttr('disabled'); $('#btnSaveClose').trigger('click'); } else { $('#btnSubmit').removeAttr('disabled'); $('#btnSubmit').trigger('click'); } } else { //another visible PLI on the page. if ($('#btnSaveClose').length > 0) { $('#btnSaveClose').removeAttr('disabled'); $('#btnSaveClose').trigger('click'); } else { $('#btnSubmit').removeAttr('disabled'); $('#btnSubmit').trigger('click'); } } } else if (window.location.href.toLowerCase().indexOf('addnewfast') > -1) { return; } else { //just refresh the panel if (window.top.RefreshPanel != null) { RefreshPanel($('.SelectedTab:first').attr('reallyuniqueid')); if (window.top.RefreshHtml != null) { RefreshHTML(); } } } } function AddNewSubLineItem(n) { var newRow = $('.subItemTemplateRow').clone(); $(newRow).addClass('subItemRow'); $(newRow).removeClass('subItemTemplateRow'); $(newRow).find('input[type="text"]').each(function () { if ($(this).attr('onchange') == null) { $(this).attr('onchange', 'LIEdit(this);MarkAsChanged()'); } }); $(newRow).find('textarea').each(function () { if ($(this).attr('onchange') == null) { $(this).attr('onchange', 'LIEdit(this);MarkAsChanged()'); } }); $(newRow).find('checkbox').each(function () { if ($(this).attr('onchange') == null) { $(this).attr('onchange', 'LIEdit(this);MarkAsChanged()'); } }); SetPLIPicsFiles(); $(newRow).find('.imgHover').hover(function () { $(this).find('.mainImg').fadeTo(200, 0.55).end().children('.hover').show(); }, function () { $(this).find('.mainImg').fadeTo(200, 1).end().children('.hover').hide(); }); $(n).closest('.tdSIAR').find('table').first().append($(newRow)); $(n).closest('.tdSIAR').find('table').first().find('.siHead').show(); } function DeleteSubLineItem(n) { $(n).closest('.subItemRow').remove(); } function DeleteSubLineItemExisting(n, sid, mid) { if(confirm('Are you sure you want to delete this Additional Line Item?')) { $.post('ManyToMany.ashx?pageaction=deletesublineitem', { sid: sid, relmodid: mid }, function (data) { if (data == '') { $(n).closest('.subItemRow').remove(); } else { alert("Error: The record was not deleted. Please try again or contact support."); } }); } } function ToggleManyToManyTemplate(ctrl, fldName, modId, modRefId, relModId) { if ($(ctrl).html().indexOf('Add/Edit') > -1) { $('.spnM2MT' + fldName).show(); $(ctrl).html('SAVE CHANGES'); var isClone = $('.clonemsg').length > 0; $('.divM2MT' + fldName).html(""); //////$.ajax({ ////// url: "../Data/ManyToMany.ashx", ////// type: "GET", ////// async: true, ////// data: { ////// m2mtctrlid: fldName, ////// pageaction: "getM2MTEdit", ////// modid: modId, ////// modrefid: modRefId, ////// relmodid: relModId, ////// cln: isClone, ////// x: (new Date()).getTime() ////// }, ////// success: function (response) { ////// $('.divM2MT' + fldName).html(response); ////// if (SetPLIPicsFiles != null) { ////// SetPLIPicsFiles(); ////// $('.imgHover').hover(function () { ////// $(this).find('.mainImg').fadeTo(200, 0.55).end().children('.hover').show(); ////// }, function () { ////// $(this).find('.mainImg').fadeTo(200, 1).end().children('.hover').hide(); ////// }); ////// } ////// if (window.top.location.href.indexOf("profile.aspx") < 0) { ////// SetIframeHeight(); ////// } ////// }, ////// error: function (xhr, status, error) { ////// console.error("Error:", error); ////// } //////}); $('.divM2MT' + fldName).load("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTEdit&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&cln=" + isClone + "&x=" + (new Date).getTime(), function () { if (SetPLIPicsFiles != null) { SetPLIPicsFiles(); $('.imgHover').hover(function () { $(this).find('.mainImg').fadeTo(200, 0.55).end().children('.hover').show(); }, function () { $(this).find('.mainImg').fadeTo(200, 1).end().children('.hover').hide(); }); } if (window.top.location.href.indexOf("profile.aspx") < 0) { SetIframeHeight(); } }); } // else if ($(ctrl).text() == 'auto fill') { // $('.spnM2MT' + fldName).show(); // var newctrl = ctrl.id.replace(/hypAuto/,'hypEdit'); // $('#' + newctrl).text('done'); // $(ctrl).remove(); // $('.divM2MT' + fldName).html(""); // $('.divM2MT' + fldName).load("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getM2MTAutoFillEdit&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&x=" + (new Date).getTime()); // } else if ($(ctrl).html().indexOf('CHANGES')>-1) { $('.PanelContentDiv').addClass('ShowLoading'); $('.spnM2MT' + fldName).hide(); $(ctrl).html(''); var srtF = ''; var vals = ''; var sortH = $(ctrl).closest('.plidiv').find('.sortHolder').val(); if (sortH != null && sortH != '') { sorts = sortH.split('·'); srtF = sorts[0]; vals = sorts[2]; var mod = sorts[1]; } SaveManyToManyTemplate(fldName, modId, modRefId, relModId, srtF, vals); } } function htmlEncode(value) { //create a in-memory div, set it's inner text(which jQuery automatically encodes) //then grab the encoded contents back out. The div never exists on the page. return $('
').text(value).html(); } function htmlDecode(value) { return $('
').html(value).text(); } function GetManyToManyEditControlType(edtCtrl, field) { var sVal = ""; switch (edtCtrl.attr('editable').split('·')[1]) { case "Check Box": if ($(edtCtrl).find('input:checkbox').prop('checked')) { sVal = "1"; } else { sVal = "0"; } break; case "Radio List Box": $(edtCtrl).find('#' + field).find('input[type="radio"]').each(function () { if ($(this).prop('checked')) { sVal = $(this).val(); } }); break; case "Check List Box": $(edtCtrl).find('table td').each(function () { if ($(this).find('input:checkbox').prop('checked')) { sVal += $(this).find('label').html() + ", "; } }); if (sVal.length > 3) { sVal = sVal.substring(0, sVal.length - 2); } break; case "Multi-Select List Box": $(edtCtrl).find('select').find('option').each(function () { if (this.selected) { sVal += this.text + ","; } }); if (sVal.length > 3) { sVal = sVal.substring(0, sVal.length - 1); } break; case "Drop Down": case "Owner": sVal = $(edtCtrl).find('select').val(); break; case "Text Area": sVal = $(edtCtrl).find('textarea').val(); break; case "Relationship": sVal = $(edtCtrl).find('select').val(); break; case "Reference": sVal = $(edtCtrl).find('select').val(); break; default: sVal = $(edtCtrl).find('input').val(); break; } return sVal; } function GetManyToManyEditControlTypeWYS(edtCtrl, field, ftype) { var sVal = ""; switch (ftype) { case "Check Box": if ($(edtCtrl).find('#' + field).prop('checked')) { sVal = "1"; } else { sVal = "0"; } break; case "Radio List Box": $(edtCtrl).find('#' + field).find('input[type="radio"]').each(function () { if ($(this).prop('checked')) { sVal = $(this).val(); } }); break; case "Check List Box": $(edtCtrl).find('table td').each(function () { if ($(this).find('input:checkbox').prop('checked')) { sVal += $(this).find('label').html() + ", "; } }); if (sVal.length > 3) { sVal = sVal.substring(0, sVal.length - 2); } break; case "Multi-Select List Box": $(edtCtrl).find('select').find('option').each(function () { if (this.selected) { sVal += this.text + ","; } }); if (sVal.length > 3) { sVal = sVal.substring(0, sVal.length - 1); } break; case "Drop Down": case "Owner": sVal = $(edtCtrl).find('#' + field).val(); break; case "Text Area": sVal = $(edtCtrl).find('#' + field).val(); break; case "Relationship": sVal = $(edtCtrl).find('#' + field).val(); break; default: sVal = $(edtCtrl).find('#' + field).val(); break; } return sVal; } function GetNextYMMField(fldName, n, i, modId, modRefId, relModId) { //n = the dropdown control, i = the current field in the list of fields var tCon = $('.divM2MT' + fldName); if (i == -1) { //reset the whole thing $(tCon).find('.hidYMMTrail').val(''); $(tCon).find('.hidYMMTrailVal').val(''); $.post("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getnextYMM&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&rval=" + "" + "&ndx=" + i + "&YMMs=" + "", function (data) { $(tCon).find('.trAddNew td').html(data); }); } else { var z = 0; $(tCon).find('.hidYMMTrail').val('') $(tCon).find('.hidYMMTrailVal').val(''); $(tCon).find('.crumby').each(function () { if (z <= i) { var nYT = $(tCon).find('.hidYMMTrail').val() + "|" + $(this).attr('sid'); //$(this).html().split(': ')[1]; $(tCon).find('.hidYMMTrail').val(nYT); } z++; }); var vlu = $(n).val(); //var vluV = n.selectedOptions[0].innerText; var vluV = n[n.selectedIndex].value; var nYMM = $(tCon).find('.hidYMMTrail').val() + "|" + vlu; var nYMMV = $(tCon).find('.hidYMMTrailVal').val() + "|" + vluV; $(tCon).find('.hidYMMTrail').val(nYMM); $(tCon).find('.hidYMMTrailVal').val(nYMMV); $.post("../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=getnextYMM&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId + "&rval=" + vlu + "&ndx=" + i + "&YMMs=" + nYMM + "&YMMVs=" + nYMMV, function (data) { $(tCon).find('.trAddNew td').html(data); }); } } function ClearMTMDrop(n) { $('.tblM2M' + n).find('img').each(function () { if ($(this).attr('src').indexOf('delete.png') > -1) { $(this).parent().trigger('click'); } }); } function LoadMTMDrop(specificOne) { if ($('.hypMTM').length > 0) { $('.hypMTM').each(function () { if (specificOne != null) { if (specificOne != $(this).attr("mtmdrop")) { return; } } //$(this).hide(); var dis = $(this); var md = $(this).attr("mtmdrop"); var modId = $(this).attr("modid"); var relModId = 0; if ($(md).length > 0) { $('.' + md).attr("relmod"); } else { relModId = $(this).closest('td').find('.hidRelatedModId').val(); } var uids = $('.' + md).attr("uids"); var refid = $(this).closest('td').find('.hidModRefId').val(); var dpndnt = $(this).closest('td').find('.hidDependentField').val(); if (relModId == '-10' || relModId == '-14') { //plugin field return; } var depVal = ''; if (dpndnt != null) { depVal = $('#' + dpndnt).attr('val'); } $.post('ManyToMany.ashx?pageaction=loadMTMDrop', { modid: modId, modrefid: refid, relmodid: relModId, relmodrefid: '0', uids: uids, fld: md, dep: depVal }, function (data) { $('.' + md).html(data); $(dis).show(); }); }); LoadMTM(); } else { LoadMTM(); } } function LoadMTM() { if ($('.divMTMT[activestatus="load"]').length > 0) { var dv = $('.divMTMT[activestatus="load"]').first(); var t = $(dv).html().replace('Loading ', '').replace('...', ''); $.post('../handlers/many2many.ashx?pageaction=loadem', { title: t, mid: $(dv).attr('modid'), cid: $(dv).attr('cid'), rmid: $(dv).attr('rmod'), sid: $(dv).attr('sid'), epo: $(dv).attr('epo') }, function (data) { var dv2 = $('.divMTMT[activestatus="load"]').first(); $(dv2).html(data); $(dv2).attr('activestatus', 'loaded'); if (parent.resizeIframe != null) { parent.resizeIframe('ifrm'); } //$(".QueueImage").thumbPopup({}); //GetManyToManyTemplate($(dv).attr('cid'), $(dv).attr('modid'), $(dv).attr('sid'), $(dv).attr('rmod')); $.post("../Data/ManyToMany.ashx?m2mtctrlid=" + $(dv2).attr('cid') + "&pageaction=getM2MTDisplay&modid=" + $(dv2).attr('modid') + "&modrefid=" + $(dv2).attr('sid') + "&relmodid=" + $(dv2).attr('rmod') + "&x=" + (new Date).getTime(), {}, function (data) { $('.divM2MT' + $(dv2).attr('cid')).html(data); $('.spnM2MT' + $(dv2).attr('cid')).hide(); LoadMTM(); }); }); } } function CancelGroup() { $('.trAddNew').hide(); } function SetSortables() { $('.tblSortable tbody').sortable({ placeholder: "sort-highlight", items: "tr.Update, tr.Insert", helper: fixWidthHelper, handle: ".sortHandle", scroll: true, //sort: function (event, ui) { // var currentScrollTop = $(window.top).scrollTop(), // topHelper = ui.position.top, // delta = topHelper - currentScrollTop; // setTimeout(function () { // $(window.top).scrollTop(currentScrollTop + (delta / 200)); // }, 5); //}, update: function (event, ui) { var tbl = $(ui.item).parent(); SaveOrder($(tbl)); } }); } function fixWidthHelper(e, ui) { ui.children().each(function () { $(this).width($(this).width()); }); return ui; } function SaveOrder(tbl) { var start = 0; var arr = []; $(tbl).find('tr.Update, tr.Insert').each(function () { if ($(this).hasClass('Update')) { arr.push($(this).find('input[type="hidden"]').first().val() + ':' + start.toString()); start++; } if ($(this).hasClass('Insert')) { arr.push('P' + $(this).find('input[type="hidden"]').first().val() + ':' + start.toString()); start++; } }); var srtF = $(tbl).closest('table').attr('sortField'); var vals = arr.join(','); var mod = $(tbl).closest('.plidiv').find('.hidRelatedModId').val(); if (mod == null) { mod = $(tbl).closest('.plidiv').closest('.divMTMT').attr('rmod'); } //console.log(vals); $(tbl).closest('.plidiv').find('.sortHolder').val(srtF + "·" + mod + "·" + vals); $('#hidPLIChanged').val('1'); if (window.top.sizeIFrame) { window.top.sizeIFrame(); } } function makeName(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for (var i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } function SetLabelListeners() { $('label').click(function (e) { if ($(this).attr('for') != '') { if ($(this).attr('for').indexOf('enHi_') < 0) { event.preventDefault(); $(this).prev().click(); } } }); }