sap.ui.controller("singledynamicfragment.dynamicFrag", {
onInit : function (oEvent) {
var oModel=new sap.ui.model.json.JSONModel("model/products.json");
this.getView().setModel(oModel);
},
handleValueHelp1 : function(oEvent) {
this.aa=oEvent.getSource().sId;
//this.click="idClick";
if(this.aa=="iddynamicFrag1--productInput1"){
FTitle="Product_Id";
title="{ProductId}";
this.CommonMethod(FTitle,title);
}
if(this.aa=="iddynamicFrag1--productInput2"){
FTitle="Product_Name";
title="{Name}";
this.CommonMethod(FTitle,title);
}
if(this.aa=="iddynamicFrag1--productInput3"){
FTitle="Product_Category";
title="{Category}";
this.CommonMethod(FTitle,title);
}
},
CommonMethod:function(Dtitle,title){
var template= new sap.m.StandardListItem({
title:title,
// id:listid
});
if (!this._oValueHelpDialog) {
this._oValueHelpDialog = sap.ui.xmlfragment("singledynamicfragment.ValueHelp",this);
this.getView().addDependent(this._oValueHelpDialog);
}
this._oValueHelpDialog.setTitle(Dtitle);
var oModel=new sap.ui.model.json.JSONModel("model/products.json");
this._oValueHelpDialog.setModel(oModel);
this._oValueHelpDialog.bindAggregation("items","/ProductCollection",template);
this._oValueHelpDialog.open();
},
handleValueHelpClose : function (oEvent) {
if(this.aa=="iddynamicFrag1--productInput1"){
var oSelectedItem1 = oEvent.getParameter("selectedItem"),
oInput = this.byId("productInput1");
if (oSelectedItem1) {
this.byId("productInput1").setValue(oSelectedItem1.getTitle());
}
if (!oSelectedItem1) {
oInput.resetProperty("");
}
}
else if(this.aa=="iddynamicFrag1--productInput2"){
var oSelectedItem2 = oEvent.getParameter("selectedItem"),
oInput = this.byId("productInput2");
if (oSelectedItem2) {
this.byId("productInput2").setValue(oSelectedItem2.getTitle());
}
if (!oSelectedItem2) {
oInput.resetProperty("");
}
}
else if(this.aa=="iddynamicFrag1--productInput3"){
var oSelectedItem3 = oEvent.getParameter("selectedItem"),
oInput = this.byId("productInput3");
if (oSelectedItem3) {
this.byId("productInput3").setValue(oSelectedItem3.getTitle());
}
if (!oSelectedItem3) {
oInput.resetProperty("");
}
}
},
//if(this.aa=="iddynamicFrag1--productInput3"){
handleSearch : function (oEvent) {
if(this.aa=="iddynamicFrag1--productInput1"){
var aFilters = [];
var sQuery = oEvent.getParameter('value');
if (sQuery && sQuery.length > 0) {
var filter = new sap.ui.model.Filter("ProductId", sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
// update list binding
this._oValueHelpDialog.getBinding('items').filter(aFilters);
}
else if(this.aa=="iddynamicFrag1--productInput2"){
var aFilters = [];
var sQuery = oEvent.getParameter('value');
if (sQuery && sQuery.length > 0) {
var filter = new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
this._oValueHelpDialog.getBinding('items').filter(aFilters);
}
else if(this.aa=="iddynamicFrag1--productInput3"){
var aFilters = [];
var sQuery = oEvent.getParameter('value');
if (sQuery && sQuery.length > 0) {
var filter = new sap.ui.model.Filter("Category", sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
this._oValueHelpDialog.getBinding('items').filter(aFilters);
}
},
});
onInit : function (oEvent) {
var oModel=new sap.ui.model.json.JSONModel("model/products.json");
this.getView().setModel(oModel);
},
handleValueHelp1 : function(oEvent) {
this.aa=oEvent.getSource().sId;
//this.click="idClick";
if(this.aa=="iddynamicFrag1--productInput1"){
FTitle="Product_Id";
title="{ProductId}";
this.CommonMethod(FTitle,title);
}
if(this.aa=="iddynamicFrag1--productInput2"){
FTitle="Product_Name";
title="{Name}";
this.CommonMethod(FTitle,title);
}
if(this.aa=="iddynamicFrag1--productInput3"){
FTitle="Product_Category";
title="{Category}";
this.CommonMethod(FTitle,title);
}
},
CommonMethod:function(Dtitle,title){
var template= new sap.m.StandardListItem({
title:title,
// id:listid
});
if (!this._oValueHelpDialog) {
this._oValueHelpDialog = sap.ui.xmlfragment("singledynamicfragment.ValueHelp",this);
this.getView().addDependent(this._oValueHelpDialog);
}
this._oValueHelpDialog.setTitle(Dtitle);
var oModel=new sap.ui.model.json.JSONModel("model/products.json");
this._oValueHelpDialog.setModel(oModel);
this._oValueHelpDialog.bindAggregation("items","/ProductCollection",template);
this._oValueHelpDialog.open();
},
handleValueHelpClose : function (oEvent) {
if(this.aa=="iddynamicFrag1--productInput1"){
var oSelectedItem1 = oEvent.getParameter("selectedItem"),
oInput = this.byId("productInput1");
if (oSelectedItem1) {
this.byId("productInput1").setValue(oSelectedItem1.getTitle());
}
if (!oSelectedItem1) {
oInput.resetProperty("");
}
}
else if(this.aa=="iddynamicFrag1--productInput2"){
var oSelectedItem2 = oEvent.getParameter("selectedItem"),
oInput = this.byId("productInput2");
if (oSelectedItem2) {
this.byId("productInput2").setValue(oSelectedItem2.getTitle());
}
if (!oSelectedItem2) {
oInput.resetProperty("");
}
}
else if(this.aa=="iddynamicFrag1--productInput3"){
var oSelectedItem3 = oEvent.getParameter("selectedItem"),
oInput = this.byId("productInput3");
if (oSelectedItem3) {
this.byId("productInput3").setValue(oSelectedItem3.getTitle());
}
if (!oSelectedItem3) {
oInput.resetProperty("");
}
}
},
//if(this.aa=="iddynamicFrag1--productInput3"){
handleSearch : function (oEvent) {
if(this.aa=="iddynamicFrag1--productInput1"){
var aFilters = [];
var sQuery = oEvent.getParameter('value');
if (sQuery && sQuery.length > 0) {
var filter = new sap.ui.model.Filter("ProductId", sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
// update list binding
this._oValueHelpDialog.getBinding('items').filter(aFilters);
}
else if(this.aa=="iddynamicFrag1--productInput2"){
var aFilters = [];
var sQuery = oEvent.getParameter('value');
if (sQuery && sQuery.length > 0) {
var filter = new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
this._oValueHelpDialog.getBinding('items').filter(aFilters);
}
else if(this.aa=="iddynamicFrag1--productInput3"){
var aFilters = [];
var sQuery = oEvent.getParameter('value');
if (sQuery && sQuery.length > 0) {
var filter = new sap.ui.model.Filter("Category", sap.ui.model.FilterOperator.Contains, sQuery);
aFilters.push(filter);
}
this._oValueHelpDialog.getBinding('items').filter(aFilters);
}
},
});