// ------------------------------------------------------------------------------------------------------------------
// 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("





");
//////$.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 aVals = [];
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 + "¿";
aVals.push(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 + "¿";
aVals.push(sVal);
});
}
iRowCnt++;
});
$('.divM2MT' + fldName).html("
");
if (modRefId == "0") {
return sVals;
}
else {
var bCool = true;
for (var i = 0; i < aVals.length; i++) {
$.ajax({
url: "../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=saveM2MT&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId,
method: "POST",
async: true,
data: { sVals: htmlEncode(aVals[i]), conctd: conctd, isonparadd: isOnParentAdd }
})
.done(
function (data) {
bCool = true;
}
);
}
if (bCool) {
$.post(
'../Data/ManyToMany.ashx?m2mtctrlid=' + fldName +
'&pageaction=saveParentM2MT' +
'&modid=' + modId +
'&modrefid=' + modRefId +
'&relmodid=' + relModId,
{}
).always(function () {
$.post(
'../handlers/HTMLCRUD.ashx?pageaction=postsavelisort',
{ s: sortField, v: sortValues, m: relModId, h: modId, r: modRefId }
);
});
var finSaving = finishSaving;
if (callBack == UpdateToEdit) {
finSaving = finishSavingUpdateToEdit;
}
curFldName = fldName;
finSaving();
}
//$.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;
// finSaving();
// });
}
}
}
function SaveHVAdditionalLineItems(parentId, fldName, modId, modRefId, relModId, callBack) {
var isOnParentAdd = false;
var conctd = false;
var aVals = [];
var sVal;
$('.addlis').find('.subItemRow').each(function () {
if ($(this).attr('sisid') == '0') {
sVal = 'SII·' + parentId + '»'; //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 + "¿";
aVals.push(sVal);
});
var bCool = true;
for (var i = 0; i < aVals.length; i++) {
$.ajax({
url: "../Data/ManyToMany.ashx?m2mtctrlid=" + fldName + "&pageaction=saveM2MT&modid=" + modId + "&modrefid=" + modRefId + "&relmodid=" + relModId,
method: "POST",
async: true,
data: { sVals: htmlEncode(aVals[i]), conctd: conctd, isonparadd: isOnParentAdd }
})
.done(
function (data) {
bCool = true;
}
);
}
if (bCool) {
var finSaving = finishSaving;
if (callBack == UpdateToEdit) {
finSaving = finishSavingUpdateToEdit;
}
curFldName = fldName;
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();
$('.addlis').remove(); //for high volume with additional line items.
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();
$('.addlis').remove(); //for high volume with additional line items.
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('');
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) {
$(ctrl).html('');
$('.plisavebutton.point').html('SAVING CHANGES...');
$('.plisavebutton.point').css('backgroundColor','grey');
setTimeout(function () {
$('.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);
}, 100);
}
}
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);
if ($(dv2).attr('ihv') != 'True') {
$('.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();
}
}
});
}