Skip to content

Commit

Permalink
Input suggestion backend search
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerem Kayacan committed Jun 2, 2023
1 parent fd66833 commit 6d1d8ed
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 0 deletions.
189 changes: 189 additions & 0 deletions src/new/input-suggestion-backend-search/Main.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*global location history */
sap.ui.define([
"co/bim/zfio_cashsheet/controller/BaseController",
"sap/ui/model/json/JSONModel",
"sap/ui/core/routing/History",
"co/bim/zfio_cashsheet/model/formatter",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator",
"sap/m/Dialog",
"sap/m/Button",
"sap/m/Label",
"sap/m/library",
"sap/m/MessageToast",
"sap/m/MessageBox",
"sap/m/Text",
"sap/m/TextArea",
"sap/m/Input",
"sap/ui/core/Core",
"sap/ui/core/Fragment"
], function(BaseController, JSONModel, History, formatter, Filter, FilterOperator, Dialog, Button, Label, mobileLibrary, MessageToast,
MessageBox, Text, TextArea, Input, Core, Fragment) {
"use strict";

var ButtonType = mobileLibrary.ButtonType;
var DialogType = mobileLibrary.DialogType;

var oBundle = jQuery.sap.resources({
url: jQuery.sap.getModulePath("co.bim.zfio_cashsheet") + "/i18n/i18n.properties",
locale: sap.ui.getCore().getConfiguration().getLanguage()
});

return BaseController.extend("co.bim.zfio_cashsheet.controller.Worklist", {

formatter: formatter,

/* =========================================================== */
/* lifecycle methods */
/* =========================================================== */

/**
* Called when the worklist controller is instantiated.
* @public
*/
onInit: function() {
var oViewModel,
iOriginalBusyDelay,
oTable = this.byId("dailySalesTable");

// Put down worklist table's original value for busy indicator delay,
// so it can be restored later on. Busy handling on the table is
// taken care of by the table itself.
iOriginalBusyDelay = oTable.getBusyIndicatorDelay();
// keeps the search state
this._aTableSearchState = [];

this._screenState = {
blank: "BLANK",
unsaved: "NEW",
saved: "SAVED",
create: "CREATE",
edit: "EDIT",
approved: "APPROVED"
};

this._authenticated = false;

// Model used to manipulate control states
oViewModel = new JSONModel({
worklistTableTitle: this.getResourceBundle().getText("worklistTableTitle"),
saveAsTileTitle: this.getResourceBundle().getText("saveAsTileTitle", this.getResourceBundle().getText("worklistViewTitle")),
shareOnJamTitle: this.getResourceBundle().getText("worklistTitle"),
shareSendEmailSubject: this.getResourceBundle().getText("shareSendEmailWorklistSubject"),
shareSendEmailMessage: this.getResourceBundle().getText("shareSendEmailWorklistMessage", [location.href]),
tableNoDataText: this.getResourceBundle().getText("tableNoDataText"),
tableBusyDelay: 0,
state: {
dailySalesBusy: false,
incomeBusy: false,
expensesBusy: false,
bankBusy: false,
banknotesBusy: false,
screen: this._screenState.blank,
editButton: false,
printButton: false,
authenticated: false
},
data: {
tarih: new Date(),
kasaTarihi: new Date(),
snote: "",
magazaNo: "",
magazaAdi: "",
cashGrandTotal: "",
safeDifference: "",
openingbalexists: true,
dailySales: [],
income: [],
expenses: [],
bank: [],
bankNotes: [],
storeInputSuggestions: []
}
//, checkuser: {
// EAuth: "X"
// }
});
this.setModel(oViewModel, "worklistView");
oViewModel.setSizeLimit(25000);
this.getOwnerComponent().getModel().setSizeLimit(25000);

// Make sure, busy indication is showing immediately so there is no
// break after the busy indication for loading the view's meta data is
// ended (see promise 'oWhenMetadataIsLoaded' in AppController)
oTable.attachEventOnce("updateFinished", function() {
// Restore original busy indicator delay for worklist's table
oViewModel.setProperty("/tableBusyDelay", iOriginalBusyDelay);
});

// Add the worklist page to the flp routing history
this.addHistoryEntry({
title: this.getResourceBundle().getText("worklistViewTitle"),
icon: "sap-icon://table-view",
intent: "#KasaDefteri-display"
}, true);

this.getRouter().getRoute("worklist").attachPatternMatched(this._onMasterMatched, this);
},

/* =========================================================== */
/* event handlers */
/* =========================================================== */

onStoreSuggest: function(oEvent) {
var query = oEvent.getParameter("suggestValue");
// Call OData service with the search query
this._callStoreSearch(query);
},

onMagazaChange: function(oEvent) {
this.getModel("worklistView").setProperty("/data/magazaAdi", "");
this._initTables();
var sMagazaNo = oEvent.getParameter("newValue");
var sRetailStoreName = this.getModel().getProperty("/EtStoresSet('" + sMagazaNo + "')").Retailstorename;
if (sRetailStoreName) {
this.getModel("worklistView").setProperty("/data/magazaAdi", sRetailStoreName);
var dKasaTarihi = this.byId("kasaTarihiDP").getDateValue();
if (dKasaTarihi) {
this._fetchData(sMagazaNo, dKasaTarihi);
}
}
},

_callStoreSearch: function(query) {
var oDataModel = this.getView().getModel();
var entitySet = "/EtStoresSet";
var filters = [];

// Create a filter for searching TextField containing the query
var filter = new sap.ui.model.Filter("Retailstorename", sap.ui.model.FilterOperator.EQ, query);
filters.push(filter);

oDataModel.read(entitySet, {
filters: filters,
success: function(data) {
var suggestions = [];

// Extract the relevant data from the OData response
data.results.forEach(function(result) {
suggestions.push({
Retailstoreid: result.Retailstoreid,
Retailstorename: result.Retailstorename
});
});

// var suggestionModel = new sap.ui.model.json.JSONModel();
// suggestionModel.setData({
// Suggestions: suggestions
// });
// this.getView().setModel(suggestionModel, "suggestionModel");
this.getModel("worklistView").setProperty("/data/storeInputSuggestions", suggestions);
}.bind(this),
error: function(error) {
// Handle error
}
});
},

});
});
33 changes: 33 additions & 0 deletions src/new/input-suggestion-backend-search/Main.view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<mvc:View controllerName="co.bim.zfio_cashsheet.controller.Worklist" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc"
xmlns:semantic="sap.f.semantic" xmlns:footerbar="sap.ushell.ui.footerbar" xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core"
xmlns:l="sap.ui.layout">
<semantic:SemanticPage id="page" headerPinnable="false" toggleHeaderOnTitleClick="false" showFooter="true">
<semantic:titleHeading>
<Title text="{i18n>worklistTitle}"/>
</semantic:titleHeading>
<semantic:content>
<Panel>
<Label text="{i18n>magazaNo}"/>
<Input id="magazaInput" type="Text" placeholder="{i18n>magazaAra}" showSuggestion="true" suggestionRows="{worklistView>/data/storeInputSuggestions}" suggest=".onStoreSuggest"
startSuggestion="2" maxLength="4" change=".onMagazaChange">
<suggestionColumns>
<Column>
<Label text="{i18n>magazaNo}"/>
</Column>
<Column>
<Label text="{i18n>magazaAdi}"/>
</Column>
</suggestionColumns>
<suggestionRows>
<ColumnListItem>
<cells>
<Text text="{worklistView>Retailstoreid}"/>
<Text text="{worklistView>Retailstorename}"/>
</cells>
</ColumnListItem>
</suggestionRows>
</Input>
</Panel>
</semantic:content>
</semantic:SemanticPage>
</mvc:View>

0 comments on commit 6d1d8ed

Please sign in to comment.