Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sap.ui.define([
- "sap/ui/core/mvc/Controller",
- "sap/m/MessageBox",
- "../utilities",
- "sap/ui/core/routing/History",
- "../Formatter"
- ], function(BaseController, MessageBox, Utilities, History, Formatter) {
- "use strict";
- return BaseController.extend("com.techedge.entitydemo.controller.Loading.LoadSuppliesMaterialsList", {
- /* Starting the formatter for dynamic translations*/
- formatter: Formatter,
- onInit: function() {
- this.list = this.byId('AddedMcList');
- this.mBindingOptions = {};
- this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
- this.oRouter.getTarget("LoadSuppliesMaterialsList").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
- /* this.oRouter.getRoute("EntityList").attachPatternMatched(this.onGroupSelected, this);*/
- this.oRouter.getTarget("LoadSuppliesMaterialsListNewRow").attachDisplay(jQuery.proxy(this.handleRouteMatchedNewRow, this));
- this._arrayMastercode = [];
- },
- handleRouteMatched: function(oEvent) {
- this.byId('objectHeaderSummary').setTitle(window.currentSupplier.DS_ENTITY_DESCRIPTION);
- var oBundle = this.getView().getModel("i18n").getResourceBundle();
- var newText = oBundle.getText("erpCode");
- this.byId('objectAttributeErp').setText(newText + ': ' + window.currentSupplier.CD_ERP_SHIPMENT.replace(/^0+/, ''))
- this.list.removeAllItems();
- var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
- this.byId('objectAttributeSummary').setText(subtitle + ': 0');
- },
- handleRouteMatchedNewRow: function(oEvent) {
- var titleNewRow = window.currentMastercode.CD + ' - ' + window.currentMastercode.TX;
- var numberNewRow = window.currentMastercode.QTY;
- var umNewRow = window.currentMastercode.CD_UM;
- var object = new sap.m.ObjectListItem({
- title: titleNewRow,
- number: numberNewRow,
- numberUnit: umNewRow
- });
- this.list.addItem(object);
- var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
- var previousQty = parseInt(this.byId('objectAttributeSummary').getText().split(':')[1]);
- var items = this.list.getItems();
- var qty = 0;
- for (var i = 0; i < items.length; i++) {
- qty += parseInt(items[i].getNumber());
- }
- var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
- this.byId('objectAttributeSummary').setText(subtitle + ': ' + qty);
- //var newQty = previousQty + parseInt(numberNewRow);
- //this.byId('objectAttributeSummary').setText(subtitle + ': ' + newQty);
- this._arrayMastercode.push(window.currentMastercode);
- debugger;
- window.currentMastercode = {};
- },
- //------------------------------------
- //---------- Button functions ----------
- //----------------------------------------
- onAddMC: function() {
- if (this.list.getSelectedItems().length === 0) {
- this.doNavigate("LoadSuppliesAddMaterial", "", "", "");
- } else if (this.list.getSelectedItems().length === 1) {
- var that = this;
- var query = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri +
- "/MasterCodesView?$filter=CD eq '" + this.list.getSelectedItems()[0].getTitle().split(' -')[0] + "'");
- var success = function(data) {
- if (data.results.length > 0) {
- window.currentMastercode = data.results[0];
- var context = {};
- context.sPath = '/' + data.results[0].__metadata.uri.split('/')[data.results[0].__metadata.uri.split('/').length - 1];
- that.doNavigate("LoadSuppliesMaterialQty", context, "", "", true);
- }
- };
- Utilities._makeOfflineQuery(query, success, function() {});
- this.list.getSelectedItems()[0].destroy();
- }
- },
- onRemoveMC: function(event) {
- console.log('Remove MC');
- if (this.list.getItems().length > 0) {
- var selected = this.list.getSelectedItems();
- for (var i = 0; i < selected.length; i++) {
- selected[i].destroy();
- }
- } else {
- //list is empty
- }
- var items = this.list.getItems();
- var qty = 0;
- for (var i = 0; i < items.length; i++) {
- qty += parseInt(items[i].getNumber());
- }
- var subtitle = this.byId('objectAttributeSummary').getText().split(':')[0];
- this.byId('objectAttributeSummary').setText(subtitle + ': ' + qty);
- },
- onClearMC: function() {
- console.log('Clear');
- if (this.list.getItems().length > 0) {
- this.list.selectAll();
- } else {
- //list is empty
- }
- },
- //----------------------------------------
- //--------------------------------------
- //------------------------------------
- _onPageNavButtonPress: function() {
- this.doNavigate("LoadingList", "", "", "");
- },
- getQueryParameters: function(oLocation) {
- var oQuery = {};
- var aParams = oLocation.search.substring(1).split("&");
- for (var i = 0; i < aParams.length; i++) {
- var aPair = aParams[i].split("=");
- oQuery[aPair[0]] = decodeURIComponent(aPair[1]);
- }
- return oQuery;
- },
- doNavigate: function(sRouteName, oBindingContext, fnPromiseResolve, sViaRelation, viaAdd) {
- if (viaAdd === true) {
- var sPath = oBindingContext.sPath;
- var oModel = null;
- } else {
- var sPath = oBindingContext ? oBindingContext.getPath() : null;
- var oModel = oBindingContext ? oBindingContext.getModel() : null;
- }
- var sEntityNameSet;
- if (sPath !== null && sPath !== "") {
- if (sPath.substring(0, 1) === "/") {
- sPath = sPath.substring(1);
- }
- sEntityNameSet = sPath.split("(")[0];
- }
- var sNavigationPropertyName;
- var sMasterContext = this.sMasterContext ? this.sMasterContext : sPath;
- if (sEntityNameSet !== null) {
- sNavigationPropertyName = sViaRelation || this.getOwnerComponent().getNavigationPropertyForNavigationWithContext(sEntityNameSet,
- sRouteName);
- }
- if (sNavigationPropertyName !== null && sNavigationPropertyName !== undefined) {
- if (sNavigationPropertyName === "") {
- this.oRouter.navTo(sRouteName, {
- context: sPath,
- masterContext: sMasterContext
- }, false);
- } else {
- oModel.createBindingContext(sNavigationPropertyName, oBindingContext, null, function(bindingContext) {
- if (bindingContext) {
- sPath = bindingContext.getPath();
- if (sPath.substring(0, 1) === "/") {
- sPath = sPath.substring(1);
- }
- } else {
- sPath = "undefined";
- }
- // If the navigation is a 1-n, sPath would be "undefined" as this is not supported in Build
- if (sPath === "undefined") {
- this.oRouter.navTo(sRouteName);
- } else {
- this.oRouter.navTo(sRouteName, {
- context: sPath,
- masterContext: sMasterContext
- }, false);
- }
- }.bind(this));
- }
- } else {
- this.oRouter.navTo(sRouteName, {
- context: sPath
- });
- }
- if (typeof fnPromiseResolve === "function") {
- fnPromiseResolve();
- }
- },
- onContinuePress: function(oEvent) {
- //CREATE + FLUSH
- debugger;
- var that = this;
- var success = function(results){
- if (that._arrayMastercode && that._arrayMastercode.length !== 0) {
- var urlMovementsConfig = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri + "MovementsConfig");
- var oHeaders = {};
- oHeaders['Content-Type'] = "application/json";
- oHeaders['accept'] = "application/json";
- // Iterate over all objects and update offlineStore
- for (var i = 0; i < that._arrayMastercode.length; i++) {
- var currObj = that._arrayMastercode[i];
- var newUpdateObjMovementsConfig = [];
- newUpdateObjMovementsConfig = {
- "CD_MOVEMENT_TYPE": "SUP",
- "CD_ITEM_TYPE": "PRO",
- "ID_ITEM": currObj.ID,
- "ID_CENTER": 2080,
- "CD_LOC_TYPE": "T001",
- "IS_FINAL_QTY": "1",
- "DT_MOVEMENT": "/Date(1496016000000)/"
- };
- var requestMovementsConfig = {
- headers: oHeaders,
- requestUri: urlMovementsConfig,
- method: "POST",
- data: newUpdateObjMovementsConfig
- };
- var match = results.results.find(function(el){
- return el.ID_ITEM === currObj.ID;
- });
- if(typeof (match) !== 'undefined'){
- requestMovementsConfig.requestUri = match.__metadata.uri;
- requestMovementsConfig.method = 'PUT';
- }
- //Database write
- OData.request(requestMovementsConfig, function(res) {
- console.log("success", res)
- // window.somethingToSync = true;
- jQuery.sap.require("jquery.sap.storage");
- var locStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);
- locStorage.remove('somethingToSync');
- locStorage.put("somethingToSync", 1);
- that._arrayMastercode = [];
- that.doNavigate("Launchpad", "", "", "");
- }, function(res) {
- console.log("failure", res)
- });
- // STO14
- var urlStockWarehouseView = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri + "StockWarehouseView");
- // Iterate over all objects and update offlineStore
- for (var i = 0; i < that._arrayMastercode.length; i++) {
- var currObj = that._arrayMastercode[i];
- var newUpdateObjStockWarehouseView = [];
- newUpdateObjStockWarehouseView = {
- "CD_LOC_TYPE": "SUP",
- "ID_LOCATION": 3093,
- "ID_ITEM": currObj.ID,
- "ID_CENTER": 2080,
- "FL_QTY": "22222222222222",
- "CD_ITEM_TYPE": "PRO",
- "CD_ITEM_BATCH": "000-1012-0920-I"
- };
- var requestStockWarehouseView = {
- headers: oHeaders,
- requestUri: urlStockWarehouseView,
- method: "POST",
- data: newUpdateObjStockWarehouseView
- };
- /* var match = results.results.find(function(el){
- return el.ID_ITEM === currObj.ID;
- });
- if(typeof (match) !== 'undefined'){
- requestMovementsConfig.requestUri = match.__metadata.uri;
- requestMovementsConfig.method = 'PUT';
- } */
- //Database write
- OData.request(requestStockWarehouseView, function(res) {
- console.log("success", res)
- // window.somethingToSync = true;
- jQuery.sap.require("jquery.sap.storage");
- var locStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);
- locStorage.remove('somethingToSync');
- locStorage.put("somethingToSync", 1);
- that._arrayMastercode = [];
- that.doNavigate("Launchpad", "", "", "");
- }, function(res) {
- console.log("failure", res)
- });
- }
- }
- };
- var fail = function(){};
- var query = encodeURI(sap.hybrid.OData.offlineStore.appOfflineStore.storeAll.serviceUri + "MovementsConfig");
- Utilities._makeOfflineQuery(query, success, fail);
- // this._arrayMastercode = [];
- // window.hasLocalChange = true;
- //this.doNavigate("Launchpad", "", "", "");
- }
- });
- }, /* bExport= */
- true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement