var maconomyPriceListSelected; //Save the Form function PreSaveAction() { //Contract Description Box Character check if( $("DIV[id*=Description][role=textbox]").text().length > 254) { alert("Contract Description : Please enter characters below 255"); return false; } //Comment Box Character check if( $("DIV[id*=Comment][role=textbox]").text().length > 254) { alert("Comment Box : Please enter characters below 255"); return false; } //Customer Number Data var CustomerNumber = [] var AllCustomerNumber = $("textarea[title='AllCustomerNumbers']"); AllCustomerNumber.val(""); $("#ChosenCustomers").children().each(function () { var Customer = $(this); var SKI = (Customer.attr("data-ski") == "true") ? "true" : "false"; //New addition for SKI part CustomerNumber.push({ Number: Customer.attr("data-customernumber"), Name: Customer.attr("data-customername"), SKI: SKI }) }); //Customer Name Data var CustomerName = [] var AllCustomerName = $("textarea[title='AllCustomerNames']"); AllCustomerName.val(""); $("#ChosenCustomersNames").children().each(function () { var Customer = $(this); var SKI = (Customer.attr("data-ski") == "true") ? "true" : "false"; //New addition for SKI part CustomerName.push({ Number: Customer.attr("data-customernumber"), Name: Customer.attr("data-customername"), SKI: SKI }) }); var jsonCustomerName = JSON.stringify(CustomerName); var jsonCustomerNumber = JSON.stringify(CustomerNumber); if (CustomerName.length > 0 && CustomerNumber.length > 0) { AllCustomerNumber.val(JSON.stringify(CustomerNumber)); AllCustomerName.val(JSON.stringify(CustomerName)); } else if (CustomerName.length > 0 && CustomerNumber.length == 0) { AllCustomerName.val(JSON.stringify(CustomerName)); } else if (CustomerNumber.length > 0 && CustomerName.length == 0) { AllCustomerNumber.val(JSON.stringify(CustomerNumber)); } else { alert("Please enter Values for Customer Number or Customer Name"); return false; } //PriceList Data var PriceLists = [] var AllPriceList = $("textarea[title='AllPriceList']"); AllPriceList.val(""); $("#ChosenPriceList").children().each(function () { var PriceList = $(this); PriceLists.push({ Name: PriceList.text() }) }); var pricelistnumber = PriceLists.length; if (PriceLists.length > 0) { AllPriceList.val(JSON.stringify(PriceLists)); } else { if (maconomyPriceListSelected == "yes") { alert("Please enter Values for PriceList"); return false; } else { return true; } } return true; } function DeleteChosenPriceList(obj) { $(obj).parent().parent().remove(); } function DeleteChosenCustomer(obj) { $(obj).parent().parent().remove(); } function DeleteChosenCustomerName(obj) { $(obj).parent().parent().remove(); } //Rendering Customer Values chosen with Customer Number function RenderChosenCustomers() { var chosenCustomers = $("#ChosenCustomers"); var SelectedCustomers; SelectedCustomers = $("textarea[title='AllCustomerNumbers']").val(); var DisplayForm = false; if (SelectedCustomers === undefined) { DisplayForm = true; SelectedCustomers = $("#AllCustomerNumbers > div").text(); if(SelectedCustomers=='') { SelectedCustomers = null; return; } } else { if (SelectedCustomers.length == 0) { return; } } var SelectedCustomersJSON; SelectedCustomersJSON = JSON.parse(SelectedCustomers); $.each(SelectedCustomersJSON, function (i, o) { if (DisplayForm) { chosenCustomers.append("
" + o.Number + o.Name + "
"); return true; } chosenCustomers.append("
" + o.Number + o.Name + "
"); chosenCustomers.children().last().attr("data-customername", o.Name); chosenCustomers.children().last().attr("data-customernumber", o.Number); chosenCustomers.children().last().attr("data-ski", o.SKI); }); } //Rendering Customer Values chosen with Customer Name function RenderChosenCustomerName() { var chosenCustomersNames = $("#ChosenCustomersNames"); var SelectedCustomersNames; SelectedCustomersNames = $("textarea[title='AllCustomerNames']").val(); var DisplayFormNames = false; if (SelectedCustomersNames === undefined) { DisplayFormNames = true; SelectedCustomersNames = $("#AllCustomerNames > div").text(); if(SelectedCustomersNames=='') { SelectedCustomersNames = null; return; } } else { if (SelectedCustomersNames.length == 0) { return; } } var SelectedCustomersNamesJSON; SelectedCustomersNamesJSON = JSON.parse(SelectedCustomersNames); $.each(SelectedCustomersNamesJSON, function (i, o) { if (DisplayFormNames) { chosenCustomersNames.append("
" + o.Name + o.Number + "
"); return true; } chosenCustomersNames.append("
" + o.Number + o.Name + "
"); chosenCustomersNames.children().last().attr("data-customernumber", o.Number); chosenCustomersNames.children().last().attr("data-customername", o.Name); chosenCustomersNames.children().last().attr("data-ski", o.SKI); }); } //Rendering PriceList Values chosen function RenderChosenPriceLists() { var chosenPriceLists = $("#ChosenPriceList"); var SelectedPriceLists = $("textarea[title='AllPriceList']").val(); //var SelectedPriceLists1 = $("textarea[title='pricelist']").val(); var DisplayForm = false; if (SelectedPriceLists === undefined) { DisplayForm = true; SelectedPriceLists = $("#AllPriceList > div").text(); if(SelectedPriceLists=='') { SelectedPriceLists = null; return; } } else { if (SelectedPriceLists.length == 0) { maconomyPriceListSelected = "no"; return; } } var SelectedPriceListJSON; SelectedPriceListJSON = JSON.parse(SelectedPriceLists); $.each(SelectedPriceListJSON, function (i, o) { if (DisplayForm) { chosenPriceLists.append("
" + o.Name + "
"); return true; } chosenPriceLists.append("
" + o.Name + "
"); chosenPriceLists.children().last().attr("data-pricelist", o.Number); }); } //Customer Number Search function AddAutoComplete(selector) { $(selector).autocomplete({ autoFocus: true, minLength: 4, source: function (request, response) { var CAML = "" + request.term + "No"; $().SPServices({ operation: "GetListItems", async: false, listName: "Customers", CAMLViewFields: "", CAMLQuery: CAML, CAMLRowLimit: 10, completefunc: function (xData, Status) { response($.map($(xData.responseXML).SPFilterNode("z:row"), function (item) { return { label: $(item).attr("ows_CustomerNumber"), value: $(item).attr("ows_Name1") } })); } }); }, select: function (event, ui) { event.preventDefault(); var chosenCustomers = $("#ChosenCustomers"); chosenCustomers.append("
" + ui.item.label + " " + ui.item.value + "
"); //ive had to add the attribute this way as there seems to be a problem accessing an attribute added in the append function above chosenCustomers.children().last().attr("data-customernumber", ui.item.label); chosenCustomers.children().last().attr("data-customername", ui.item.value); //clear the search box this.value = ""; } }); } //Customer Name Search function AddAutoCompleteCustomerName(selector) { $(selector).autocomplete({ autoFocus: true, minLength: 4, source: function (request, response) { var CAML = "" + request.term + "No"; $().SPServices({ operation: "GetListItems", async: false, listName: "Customers", CAMLViewFields: "", CAMLQuery: CAML, CAMLRowLimit: 10, completefunc: function (xData, Status) { response($.map($(xData.responseXML).SPFilterNode("z:row"), function (item) { return { label: $(item).attr("ows_Name1"), value: $(item).attr("ows_CustomerNumber") } })); } }); }, select: function (event, ui) { event.preventDefault(); var chosenCustomers = $("#ChosenCustomersNames"); chosenCustomers.append("
" + ui.item.value + " " + ui.item.label + "
"); //ive had to add the attribute this way as there seems to be a problem accessing an attribute added in the append function above chosenCustomers.children().last().attr("data-customername", ui.item.label); chosenCustomers.children().last().attr("data-customernumber", ui.item.value); //clear the search box this.value = ""; } }); } //SKI customer Search function AttachGetSkiCustomers() { var SkiDropDown = $("select[title='Framework Contract is a part of SKI']"); SkiDropDown.change(function () { var IsSki = SkiDropDown.find("option:selected").val(); if (IsSki.toLowerCase() == "yes") { var CAML = "Public - International Financial Institutions (World Bank, UN)Denmark"; var SKICustomerLoadingIndicator = $("#SKICustomerLoadingIndicator"); SKICustomerLoadingIndicator.show().SPServices({ operation: "GetListItems", async: true, listName: "Customers", CAMLViewFields: "", CAMLQuery: CAML, CAMLRowLimit: 10, completefunc: function (xData, Status) { var chosenCustomers = $("#ChosenCustomersNames"); $(xData.responseXML).SPFilterNode("z:row").each(function () { chosenCustomers.append("
" + $(this).attr("ows_CustomerNumber") + " " + $(this).attr("ows_Name1") + "
"); //ive had to add the attribute this way as there seems to be a problem accessing an attribute added in the append function above chosenCustomers.children().last().attr("data-customernumber", $(this).attr("ows_CustomerNumber")).attr("data-ski", "true"); chosenCustomers.children().last().attr("data-customername", $(this).attr("ows_Name1")).attr("data-ski", "true"); }); SKICustomerLoadingIndicator.hide(); } }); } else { var chosenCustomers = $("#ChosenCustomersNames").find("[data-ski='true']").remove(); } }); } //Price List Search function AddAutoComplete1(selector) { var priceListDropDown = $("select[title='Maconomy Pricelist Created']"); priceListDropDown.change(function () { var IsPriceList = priceListDropDown.find("option:selected").val(); if (IsPriceList.toLowerCase() == "yes") { maconomyPriceListSelected = "yes"; } else { maconomyPriceListSelected = "no"; } }); $(selector).autocomplete({ autoFocus: true, minLength: 4, source: function (request, response) { var CAML = "" + request.term + ""; $().SPServices({ operation: "GetListItems", async: false, listName: "PriceList", CAMLViewFields: "", CAMLQuery: CAML, CAMLRowLimit: 10, completefunc: function (xData, Status) { response($.map($(xData.responseXML).SPFilterNode("z:row"), function (item) { return { label: $(item).attr("ows_JobPriceListName") } })); } }); }, select: function (event, ui) { event.preventDefault(); var chosenPriceLists = $("#ChosenPriceList"); chosenPriceLists.append("
" + ui.item.label + "
"); //ive had to add the attribute this way as there seems to be a problem accessing an attribute added in the append function above chosenPriceLists.children().last().attr("data-pricelist", ui.item.value); //clear the search box this.value = ""; } }); }