week 4, unit 5

master
Stefan Haslinger 2022-04-29 13:15:05 +00:00
parent 102a4c2e47
commit e7ecee9f4a
4 changed files with 96 additions and 10 deletions

View File

@ -0,0 +1,72 @@
sap.ui.define([
"sap/ui/core/Control",
"sap/m/RatingIndicator",
"sap/m/Button"
], function(Control, RatingIndicator, Button) {
"use strict";
return Control.extend("opensap.manageproducts.control.ProductRate", {
metadata: {
properties: {
value: {
type: "float",
defaultValue: 0}
},
aggregations: {
_rating: {
type: "sap.m.RatingIndicator",
multiple: false,
visibility: "hidden"
},
_button : {
type: "sap.m.Button",
multiple: false,
visibility: "hidden"}
},
events : {}
},
init : function() {
this.setAggregation("_rating", new RatingIndicator({
value : this.getValue(),
maxValue : 5,
liveChange : this._onRate.bind(this)
}).addStyleClass("sapUiTinyMarginEnd"));
this.setAggregation("_button", new Button({
text : "{i18n>productRatingButtonText}",
press : this._onSubmit.bind(this),
enabled : false
}));
},
_onSubmit : function() {
this.fireEvent("valueSubmit", {
value : this.getValue()
});
this.getAggregation("_button").setEnabled(false);
},
_onRate : function(oEvent) {
this.setValue(oEvent.getParameter("value"));
this.getAggregation("_button").setEnabled(true);
},
renderer : function(oRm, oControl) {
oRm.write("<div");
oRm.writeControlData(oControl);
oRm.addClass("sapUiSmallMarginBeginEnd");
oRm.writeClasses();
oRm.write(">");
oRm.renderControl(oControl.getAggregation("_rating"));
oRm.renderControl(oControl.getAggregation("_button"));
oRm.write("</div>");
}
});
});

View File

@ -2,8 +2,9 @@ sap.ui.define([
"./BaseController",
"sap/ui/model/json/JSONModel",
"sap/ui/core/routing/History",
"../model/formatter"
], function (BaseController, JSONModel, History, formatter) {
"../model/formatter",
"sap/m/MessageToast"
], function (BaseController, JSONModel, History, formatter, MessageToast) {
"use strict";
return BaseController.extend("opensap.manageproducts.controller.Object", {
@ -33,7 +34,12 @@ sap.ui.define([
/* event handlers */
/* =========================================================== */
onRatingChanged: function(oEvent) {
var iValue = oEvent.getParameter("value"),
sMessage = this.getResourceBundle().getText("productRatingSuccess", [iValue]);
MessageToast.show(sMessage);
},
/**
* Event handler for navigating back.
* It there is a history entry we go one step back in the browser history

View File

@ -96,6 +96,12 @@ supplierTitle=Supplier
#XGRP: Map panel title
mapTitle=Map
#XTIT: Submit Rating Button text
productRatingButtonText=Submit
#YMSG: Submit Rating Success Message
productRatingSuccess=Your new rating value is {0}
#~~~ Share Menu Options ~~~~~~~~~~~~~~~~~~~~~~~
#XTIT: Send E-Mail subject

View File

@ -1,23 +1,25 @@
<mvc:View
controllerName="opensap.manageproducts.controller.ProductDetails"
controllerName="opensap.manageproducts.controller.Object"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:form="sap.ui.layout.form">
<Panel
xmlns:form="sap.ui.layout.form"
xmlns:course="opensap.manageproducts.control">
<Panel id="_IDGenPanel1"
class="sapUiResponsiveMargin"
width="auto"
headerText="{i18n>productTitle}"
expandable="{device>/system/phone}"
expanded="true">
<content>
<course:ProductRate id="_IDGenProductRate1" valueSubmit="onRatingChanged"/>
<form:SimpleForm id="objectForm">
<form:content>
<Label id="categoryLabel" text="{i18n>productCategoryLabel}"/>
<Text id="category" text="{Category}"/>
<Label text="{i18n>productNameLabel}"/>
<Text text="{Name}"/>
<Label text="{i18n>productWeightLabel}"/>
<Text text="{= ${WeightMeasure} + ' ' + ${WeightUnit}}"/>
<Label id="_IDGenLabel1" text="{i18n>productNameLabel}"/>
<Text id="_IDGenText1" text="{Name}"/>
<Label id="_IDGenLabel2" text="{i18n>productWeightLabel}"/>
<Text id="_IDGenText2" text="{= ${WeightMeasure} + ' ' + ${WeightUnit}}"/>
</form:content>
</form:SimpleForm>
</content>