<commit_before>/*!
 * ${copyright}
 */
sap.ui.define([
	"sap/base/Log",
	"sap/base/security/encodeURL",
	"sap/m/MessageBox",
	"sap/m/MessageToast",
	"sap/ui/core/library",
	"sap/ui/core/Core",
	"sap/ui/core/Element",
	"sap/ui/core/message/Message",
	"sap/ui/core/mvc/Controller",
	"sap/ui/model/Filter",
	"sap/ui/model/FilterOperator",
	"sap/ui/model/Sorter",
	"sap/ui/model/odata/ODataUtils"
], function (Log, encodeURL, MessageBox, MessageToast, coreLibrary, Core, Element, Message,
		Controller, Filter, FilterOperator, Sorter, ODataUtils) {
	"use strict";
	var sClassname = "sap.ui.core.internal.samples.odata.v2.SalesOrders.Main.controller",
		MessageType = coreLibrary.MessageType;

	return Controller.extend("sap.ui.core.internal.samples.odata.v2.SalesOrders.Main", {
		/**
		 * Clears persistent or technical messages from the message model.
		 *
		 * @param {boolean} bUnboundOnly Whether only unbound messages are removed
		 */
		clearPersistentMessages : function (bUnboundOnly) {
			var aMessages = this.getView().getModel("messages").getObject("/");

			Core.getMessageManager().removeMessages(aMessages.filter(function (oMessage) {
				return (oMessage.technical || oMessage.persistent)
					&& (!bUnboundOnly || !oMessage.target);
			}));
		},

		handleMessageChange : function (oEvent) {
			var aMessages = oEvent.getParameter("newMessages"),
				sMessageText,
				aPersistentMessages = aMessages.filter(function (oMessage) {
					return oMessage.getPersistent()
						// don't show success messages in a popup dialog
						&& oMessage.getType() !== MessageType.Success;
				}).sort(Message.compare);

			if (!aPersistentMessages.length) {
				return;
			}

			sMessageText = aPersistentMessages.map(function (oMessage) {
				return oMessage.getMessage();
			}).join(";\n");
			MessageBox[aPersistentMessages[0].getType().toLowerCase()](sMessageText);
		},

		onCloneItem : function (oEvent) {
			var oView = this.getView(),
				oModel = oView.getModel(),
				oTable = oView.byId("ToLineItems"),
				oSelectedItem = oTable.getContextByIndex(oTable.getSelectedIndex()).getObject(),
				sSalesOrderID = oSelectedItem.SalesOrderID,
				sSalesOrderItemPosition = oSelectedItem.ItemPosition,
				sItem = "\"" + sSalesOrderID + " / " + sSalesOrderItemPosition + "\"";

			oModel.callFunction("/SalesOrderItem_Clone", {
				adjustDeepPath : function (mParameters) {
					var aPathSegments = mParameters.response.headers.location.split("/"),
						sEntityKey = aPathSegments[aPathSegments.length - 1],
						sKeyPredicate = sEntityKey.slice(sEntityKey.indexOf("("));

					return "/SalesOrderSet('" + sSalesOrderID + "')/ToLineItems" + sKeyPredicate;
				},
				expand : "ToProduct,ToHeader",
				method : "POST",
				success : MessageToast.show.bind(null, "Successfully cloned item " + sItem),
				urlParameters : {
					ItemPosition : encodeURL(sSalesOrderItemPosition),
					SalesOrderID : encodeURL(sSalesOrderID)
				}
			});
		},

		onCloseCreatedItemDialog : function () {
			this.byId("createSalesOrderItemDialog").close();
		},

		onCloseMessageDetails : function (oEvent) {
			var oMessageDetails = this.byId("messageDetails");

			oMessageDetails.setBindingContext(null);
			oMessageDetails.close();
		},

		onCloseProductDetails : function () {
			this.byId("productDetailsDialog").close();
		},

		onCreateItem : function () {
			var oBindingContext = this.byId("objectPage").getBindingContext(),
				oCreatedContext,
				oCreateDialog = this.byId("createSalesOrderItemDialog");

			oCreatedContext = this.byId("ToLineItems").getBinding("rows").create({
				DeliveryDate : new Date(Date.now() + 14 * 24 * 3600000),
				Note : "Created by OData V2 Sales Orders App",
				ProductID : "HT-1000",
				Quantity : "1",
				QuantityUnit : "EA",
				SalesOrderID : oBindingContext.getProperty("SalesOrderID")
			}, /*bAtEnd*/true, {
				error : function (oError) {
					Log.info("Error Handler: Failed to created sales order item",
						JSON.stringify(oError), sClassname);
				},
				expand : "ToProduct,ToHeader",
				success : function (/*oData, oResponse*/) {
					Log.info("Success Handler: Sales order item creation was successful",
						oCreatedContext.getPath(), sClassname);
				}
			});

			oCreatedContext.created().then(function () {
				var sMessage = "Created sales order item '"
						+ oCreatedContext.getProperty("ItemPosition") + "'";

				Log.info(sMessage, oCreatedContext.getPath(), sClassname);
				MessageBox.success(sMessage);
			}, function () {
				var sMessage = "Discarded sales order item creation";

				Log.info(sMessage, oCreatedContext.getPath(), sClassname);
				MessageToast.show(sMessage);
			}).finally(function () {
				oCreateDialog.close();
			});
			oCreateDialog.setBindingContext(oCreatedContext);
			oCreateDialog.open();
		},

		onCreateSalesOrder : function () {
			var oListBinding = this.byId("SalesOrderSet").getBinding("items"),
				oCreatedContext = oListBinding.create({
					CustomerID : "0100000000",
					LifecycleStatus : "N"
				}, /*bAtEnd*/oListBinding.isCreationAreaAtEnd() !== undefined);

			oCreatedContext.created().then(function () {
				MessageToast.show("Created sales order "
					+ oCreatedContext.getProperty("SalesOrderID"));
			}, function (oError) {<commit_msg>[INTERNAL] sap.ui.core.internal.samples.odata.v2.SalesOrders: Do not use private list binding method<commit_after>/*!
 * ${copyright}
 */
sap.ui.define([
	"sap/base/Log",
	"sap/base/security/encodeURL",
	"sap/m/MessageBox",
	"sap/m/MessageToast",
	"sap/ui/core/library",
	"sap/ui/core/Core",
	"sap/ui/core/Element",
	"sap/ui/core/message/Message",
	"sap/ui/core/mvc/Controller",
	"sap/ui/model/Filter",
	"sap/ui/model/FilterOperator",
	"sap/ui/model/Sorter",
	"sap/ui/model/odata/ODataUtils"
], function (Log, encodeURL, MessageBox, MessageToast, coreLibrary, Core, Element, Message,
		Controller, Filter, FilterOperator, Sorter, ODataUtils) {
	"use strict";
	var sClassname = "sap.ui.core.internal.samples.odata.v2.SalesOrders.Main.controller",
		MessageType = coreLibrary.MessageType;

	return Controller.extend("sap.ui.core.internal.samples.odata.v2.SalesOrders.Main", {
		/**
		 * Clears persistent or technical messages from the message model.
		 *
		 * @param {boolean} bUnboundOnly Whether only unbound messages are removed
		 */
		clearPersistentMessages : function (bUnboundOnly) {
			var aMessages = this.getView().getModel("messages").getObject("/");

			Core.getMessageManager().removeMessages(aMessages.filter(function (oMessage) {
				return (oMessage.technical || oMessage.persistent)
					&& (!bUnboundOnly || !oMessage.target);
			}));
		},

		handleMessageChange : function (oEvent) {
			var aMessages = oEvent.getParameter("newMessages"),
				sMessageText,
				aPersistentMessages = aMessages.filter(function (oMessage) {
					return oMessage.getPersistent()
						// don't show success messages in a popup dialog
						&& oMessage.getType() !== MessageType.Success;
				}).sort(Message.compare);

			if (!aPersistentMessages.length) {
				return;
			}

			sMessageText = aPersistentMessages.map(function (oMessage) {
				return oMessage.getMessage();
			}).join(";\n");
			MessageBox[aPersistentMessages[0].getType().toLowerCase()](sMessageText);
		},

		onCloneItem : function (oEvent) {
			var oView = this.getView(),
				oModel = oView.getModel(),
				oTable = oView.byId("ToLineItems"),
				oSelectedItem = oTable.getContextByIndex(oTable.getSelectedIndex()).getObject(),
				sSalesOrderID = oSelectedItem.SalesOrderID,
				sSalesOrderItemPosition = oSelectedItem.ItemPosition,
				sItem = "\"" + sSalesOrderID + " / " + sSalesOrderItemPosition + "\"";

			oModel.callFunction("/SalesOrderItem_Clone", {
				adjustDeepPath : function (mParameters) {
					var aPathSegments = mParameters.response.headers.location.split("/"),
						sEntityKey = aPathSegments[aPathSegments.length - 1],
						sKeyPredicate = sEntityKey.slice(sEntityKey.indexOf("("));

					return "/SalesOrderSet('" + sSalesOrderID + "')/ToLineItems" + sKeyPredicate;
				},
				expand : "ToProduct,ToHeader",
				method : "POST",
				success : MessageToast.show.bind(null, "Successfully cloned item " + sItem),
				urlParameters : {
					ItemPosition : encodeURL(sSalesOrderItemPosition),
					SalesOrderID : encodeURL(sSalesOrderID)
				}
			});
		},

		onCloseCreatedItemDialog : function () {
			this.byId("createSalesOrderItemDialog").close();
		},

		onCloseMessageDetails : function (oEvent) {
			var oMessageDetails = this.byId("messageDetails");

			oMessageDetails.setBindingContext(null);
			oMessageDetails.close();
		},

		onCloseProductDetails : function () {
			this.byId("productDetailsDialog").close();
		},

		onCreateItem : function () {
			var oBindingContext = this.byId("objectPage").getBindingContext(),
				oCreatedContext,
				oCreateDialog = this.byId("createSalesOrderItemDialog");

			oCreatedContext = this.byId("ToLineItems").getBinding("rows").create({
				DeliveryDate : new Date(Date.now() + 14 * 24 * 3600000),
				Note : "Created by OData V2 Sales Orders App",
				ProductID : "HT-1000",
				Quantity : "1",
				QuantityUnit : "EA",
				SalesOrderID : oBindingContext.getProperty("SalesOrderID")
			}, /*bAtEnd*/true, {
				error : function (oError) {
					Log.info("Error Handler: Failed to created sales order item",
						JSON.stringify(oError), sClassname);
				},
				expand : "ToProduct,ToHeader",
				success : function (/*oData, oResponse*/) {
					Log.info("Success Handler: Sales order item creation was successful",
						oCreatedContext.getPath(), sClassname);
				}
			});

			oCreatedContext.created().then(function () {
				var sMessage = "Created sales order item '"
						+ oCreatedContext.getProperty("ItemPosition") + "'";

				Log.info(sMessage, oCreatedContext.getPath(), sClassname);
				MessageBox.success(sMessage);
			}, function () {
				var sMessage = "Discarded sales order item creation";

				Log.info(sMessage, oCreatedContext.getPath(), sClassname);
				MessageToast.show(sMessage);
			}).finally(function () {
				oCreateDialog.close();
			});
			oCreateDialog.setBindingContext(oCreatedContext);
			oCreateDialog.open();
		},

		onCreateSalesOrder : function () {
			var oTable = this.byId("SalesOrderSet"),
				bAtEnd = oTable.getItems()[0]
					&& oTable.getItems()[0].getBindingContext("SalesOrders").isTransient()
						!== undefined,
				oListBinding = oTable.getBinding("items"),
				oCreatedContext = oListBinding.create({
					CustomerID : "0100000000",
					LifecycleStatus : "N"
				}, bAtEnd);

			oCreatedContext.created().then(function () {
				MessageToast.show("Created sales order "
					+ oCreatedContext.getProperty("SalesOrderID"));
			}, function (oError) {
{'fraction_non_alphanumeric': 0.1444080486663547, 'fraction_numerical': 0.006083294337856809, 'mean_word_length': 4.1129186602870815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4234835', 'n_tokens_mistral': 4009, 'n_tokens_neox': 3318, 'n_words': 569}