Dear Rajesh ,
i Apply but i am getting error i am attaching error screen shot and my controller functionality please help me
onInit: function() {
var oModel = new sap.ui.model.odata.ODataModel("proxy/XXXXXXX:8000/sap/opu/odata/sap/ZCRUD3_SRV_01/",true);
this.getView().setModel(oModel,"empModel");
var oGrid = this.getView().byId("gridId");
oGrid.setVisible(false);
},
myDateFormatter:function(someDate){
jQuery.sap.require("sap.ui.core.format.DateFormat");
var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: "yyyy/MM/dd"});
formattedDate = oDateFormat.format(new Date(someDate));
return formattedDate;
},
onDisplay: function(){
var oTable = this.getView().byId("idProductsTable");
var contexts = oTable.getSelectedContexts();
if(contexts.length == 0){
alert("please select a row");
}else
{
var oGrid = this.getView().byId("gridId");
oGrid.setVisible(true);
var oSave = this.getView().byId("saveBtnId");
oSave.setVisible(true);
var items = contexts.map(function(c){
return c.getObject();
});
var oId = this.getView().byId("lm");
oId.setEditable(false);
oId.setValue(items[0].Amount);
var oId = this.getView().byId("lr");
oId.setEditable(false);
oId.setValue(items[0].Dates);
}
},
mode : 0,
onUpdate: function(){
var oTable = this.getView().byId("idProductsTable");
var contexts = oTable.getSelectedContexts();
if(contexts.length == 0){
alert("please select a row");
}else
{
var oGrid = this.getView().byId("gridId");
oGrid.setVisible(true);
var oSave = this.getView().byId("saveBtnId");
oSave.setVisible(true);
var items = contexts.map(function(c){
return c.getObject();
});
var oId = this.getView().byId("lm");
oId.setEditable(true);
oId.setValue(items[0].Amount);
var oId = this.getView().byId("lr");
oId.setEditable(true);
oId.setValue(items[0].Dates);
this.mode = "update";
}
},
onCreate: function(){
var oGrid = this.getView().byId("gridId");
oGrid.setVisible(true);
var oSave = this.getView().byId("saveBtnId");
oSave.setVisible(true);
var oId = this.getView().byId("lm");
oId.setEditable(true);
oId.setValue("");
var oId = this.getView().byId("lr");
oId.setEditable(true);
oId.setValue("");
this.mode = "create";
},
deleteId : 0,
onDelete: function(){
var oGrid = this.getView().byId("gridId");
oGrid.setVisible(false);
var oTable = this.getView().byId("idProductsTable");
var contexts = oTable.getSelectedContexts();
if(contexts.length == 0){
alert("please select a row");
}else
{
var items = contexts.map(function(c){
return c.getObject();
});
deleteId = items[0].Amount;
this.mode = "delete";
this.onSave();
}
},
onSave: function(){
view = this.getView();
var oTable = this.getView().byId("idProductsTable");
if(this.mode == "update"){
var oId = this.getView().byId("lm").getValue();
var Dates = this.getView().byId("lr").getValue();
OData.request({
requestUri:"proxy/XXXXXXX:8000/sap/opu/odata/sap/ZCRUD3_SRV_01/",
method:"GET",
headers:{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" :"application/atom+xml",
"DataServiceVersion" : "2.0",
"X-CSRF-Token" : "Fetch"
}},
function(data,response){
header_xcsrf_token = response.headers['x-csrf-token'];
OData.request({
requestUri:"proxy/http/XXXXXX:8000/sap/opu/odata/sap/ZCRUD3_SRV_01/crudSet('"+oId+"')",
method:"PUT",
headers:{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" :"application/atom+xml",
"DataServiceVersion" : "2.0",
"Accept" : "applicaton/atom+xml,application/atomsvc+xml,application/xml",
"X-CSRF-Token" : header_xcsrf_token
},
data:
{
Amount : oId,
Dates : Dates,
}},
function(data,response)
{
var oSubDialog = new sap.ui.commons.Dialog({
title: "Updated",
content:[
new sap.ui.commons.Label({
text : "Data Updated Successfully"
})
]
}
);
oTable.setBusy(true);
oSubDialog.open();
oSubDialog.addButton(new sap.ui.commons.Button({
text: "Ok",
press: function()
{
oSubDialog.close();
oTable.setBusy(false);
}
}));
view.getModel("empModel").refresh();
view.byId("gridId").setvisible(false);
},
function(err)
{
alert("Update error");
}
);
},
function(err)
{
var request = err.request;
var response = err.response;
alert("Error in Get -- Request"+request+"Response"+response);
}
);
}
else if(this.mode == "create"){
var oId = this.getView().byId("lm").getValue();
var Dates = this.getView().byId("lr").getValue();
OData.request({
requestUri:"proxy/http/XXXXXX:8000/sap/opu/odata/sap/ZCRUD3_SRV_01/",
method:"GET",
headers:{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" :"application/atom+xml",
"DataServiceVersion" : "2.0",
"X-CSRF-Token" : "Fetch"
}},
function(data,response){
header_xcsrf_token = response.headers['x-csrf-token'];
OData.request({
requestUri:"proxy/http/xxxxxx:8000/sap/opu/odata/sap/ZCRUD3_SRV_01/crudSet",
method:"POST",
headers:{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" :"application/atom+xml",
"DataServiceVersion" : "2.0",
"Accept" : "applicaton/atom+xml,application/atomsvc+xml,application/xml,application/json",
"X-CSRF-Token" : header_xcsrf_token
},
data:
{
Amount : oId,
Dates : Dates,
}
}
,
function(data,response)
{
var oSubDialog = new sap.ui.commons.Dialog({
title: "create",
content:[
new sap.ui.commons.Label({
text : "Data Created Successfully"
})
]
}
);
oTable.setBusy(true);
oSubDialog.open();
oSubDialog.addButton(new sap.ui.commons.Button({
text: "Ok",
press: function()
{
oSubDialog.close();
oTable.setBusy(false);
}
}));
view.getModel("empModel").refresh();
view.byId("gridId").setVisible(false);
},
function(err)
{
alert("Create error");
});
},
function(err)
{
var request = err.request;
var response = err.response;
alert("Error in Get -- Request"+request+"Response"+response);
});
}else if(this.mode == "delete")
{
var oId = this.getView().byId("lm").getValue();
var Dates = this.getView().byId("lr").getValue();
OData.request({
requestUri:"proxy/http/XXXXXX:8000/sap/opu/odata/sap/ZCRUD3_SRV_01/",
method:"GET",
headers:{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" :"application/atom+xml",
"DataServiceVersion" : "2.0",
"X-CSRF-Token" : "Fetch"
}},
function(data,response){
header_xcsrf_token = response.headers['x-csrf-token'];
OData.request({
requestUri:"proxy/http/xxxxxx:8000/sap/opu/odata/sap/ZCRUD3_SRV_01/crudSet('"+deleteId+"')",
method:"DELETE",
headers:{
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" :"application/atom+xml",
"DataServiceVersion" : "2.0",
"Accept" : "applicaton/atom+xml,application/atomsvc+xml,application/xml",
"X-CSRF-Token" : header_xcsrf_token
},
data:
{
Amount : oId,
Dates : Dates,
}
}
,
function(data,response)
{
var oSubDialog = new sap.ui.commons.Dialog({
title: "Deleted",
content:[
new sap.ui.commons.Label({
text : "Data Deleted Successfully"
})
]
}
);
oTable.setBusy(true);
oSubDialog.open();
oSubDialog.addButton(new sap.ui.commons.Button({
text: "Ok",
press: function()
{
oSubDialog.close();
oTable.setBusy(false);
}
}));
view.getModel("empModel").refresh();
view.byId("gridId").setVisible(false);
},
function(err)
{
alert("Deleted error");
}
);
},
function(err)
{
var request = err.request;
var response = err.response;
alert("Error in Get -- Request"+request+"Response"+response);
}
);
}