Thanks for your repy.
The same code is working in local webide without any errors.
Detail.controller.js
jQuery.sap.require("Bday.utils.Helper");
jQuery.sap.require("sap.m.MessageBox");
sap.ui.core.mvc.Controller.extend("Bday.view.Detail", {
onInit: function() {
alert("I am in details controller");
var view = this.getView();
sap.ui.core.UIComponent.getRouterFor(this).attachRouteMatched(function(oEvent) {
// when detail navigation occurs, update the binding context
console.log(oEvent.getParameter("name"));
if (oEvent.getParameter("name") === "Detail") {
var context = new sap.ui.model.Context(view.getModel(), '/' + oEvent.getParameter("arguments").contextPath);
view.setBindingContext(context);
// Make sure the master is here
}
}, this);
this._getFormFragment("DetailFragment");
},
onAfterRendering: function() {
/* this.getView().byId("dob1").setSelectedKey(Mon);
this.getView().byId("dob2").setSelectedKey(Dat);
this.getView().byId("add").setSelectedKey(Add);*/
},
onExit: function() {
if (this._oActionSheet) {
this._oActionSheet.destroy();
this._oActionSheet = null;
}
},
handleNavButtonPress: function(oEvent) {
/*var history = sap.ui.core.routing.History.getInstance();
var url = sap.ui.core.UIComponent.getRouterFor(this).getURL("master", {});
var direction = history.getDirection(url);
if ("Backwards" === direction) {
window.history.go(-1);
} else {
var replace = true; // otherwise we go backwards with a forward history
this.navTo(route, data, replace);
}*/
sap.ui.core.UIComponent.getRouterFor(this).myNavBack("master");
},
openDeleteMessageBox: function(oEvent) {
// this is required since there is no direct access to the box's icons like MessageBox.Icon.WARNING
// open a fully configured message box
var oModel = this.getView().getModel();
var sPath = oEvent.getSource().getBindingContext().sPath;
var _router = sap.ui.core.UIComponent.getRouterFor(this);
sap.m.MessageBox.confirm("Are you sure you wish to delete Employee?" + sPath.substring(17, 25), {
icon: sap.m.MessageBox.Icon.SUCCESS,
title: "Employee Details Deleting...",
// actions: [sap.m.MessageBox.Action.OK, sap.m.MessageBox.Action.CANCEL],
onClose: function(oResult) {
// var sPath = oEvent.getSource().getBindingContext().sPath;
if (oResult === "OK") {
sap.ui.controller("Bday.view.Detail")._removeEmployee(sPath, oModel, _router);
// this._removeEmployee(sPath);
}
}
});
},
_removeEmployee: function(sPath, oModel, _router) {
// var oModel = sap.ui.controller("Bday.view.Detail").getView().getModel();
oModel.remove(sPath, {
success: jQuery.proxy(function(mResponse) {
sap.m.MessageBox.show("Employee Details successfully deleted for Employee ID:", {
icon: sap.m.MessageBox.Icon.SUCCESS,
title: "Employee Details Deleting...",
actions: [sap.m.MessageBox.Action.OK],
onClose: function() {
sap.ui.controller("Bday.view.Detail")._routeToViewAll(oModel, _router);
}
});
}, this),
error: jQuery.proxy(function() {
// this.oBusyDialog.close();
jQuery.sap.require("sap.m.MessageBox");
// ID of newly inserted product is available in mResponse.ID
// this.oBusyDialog.close();
sap.m.MessageBox.show("Error in Deleting Details for Employee ID:", {
icon: sap.m.MessageBox.Icon.ERROR,
title: "ERROR"
});
}, this)
});
},
onDeleteEmployee: function(oEvent) {
this.openDeleteMessageBox(oEvent);
// this.oBusyDialog.open();
},
_getFormFragment: function(sFragmentName) {
var oPage = this.getView().byId("detailsPage");
oPage.removeAllContent();
this.flag = false;
if (sFragmentName === "DetailFragment") {
if (!this._oDetailFragment) {
this._oDetailFragment = sap.ui.xmlfragment("Bday.view." + sFragmentName, this);
// this.getView().addDependent(this._oFragment);
oPage.insertContent(this._oDetailFragment);
} else {
oPage.insertContent(this._oDetailFragment);
}
}
if (sFragmentName === "EditFragment") {
this.flag = true;
if (!this._oEditFragment) {
this._oEditFragment = sap.ui.xmlfragment("Bday.view." + sFragmentName, this);
// this.getView().addDependent(this._oFragment);
oPage.insertContent(this._oEditFragment);
} else {
oPage.insertContent(this._oEditFragment);
}
}
},
_toggleButtonsAndView: function(bEdit) {
var oView = this.getView();
// Show the appropriate action buttons
oView.byId("editButton").setVisible(bEdit);
oView.byId("saveButton").setVisible(!bEdit);
// oView.byId("cancelButton").setVisible(!bEdit);
oView.byId("calendarButton").setVisible(bEdit);
oView.byId("deleteButton").setVisible(bEdit);
// Set the right form type
// this._getFormFragment(bEdit ? "DetailFragment" : "EditFragment");
},
onCancelFromDetail: function(oEvent) {
if (this.flag) {
this._getFormFragment("DetailFragment");
this._toggleButtonsAndView(true);
} else {
sap.ui.core.UIComponent.getRouterFor(this).navTo("_viewAll");
}
// this._toggleButtonsAndView(false);
},
dateFromString: function(sDate) {
// Try to create date directly, otherwise assume dd/mm/yyyy
// var sValue = oEvent.getParameter("value");
var a = sDate.split("/")[0];
var b = sDate.split("/")[1];
if (a < 10)
{
a = '0' + a;
}
if (b < 10)
{
b = '0' + b;
}
var oDate = b + "/" + a;
return oDate;
},
onSaveFromDetail: function(oEvent) {
var flag = false;
if (!sap.ui.getCore().byId("fname").getValue()) {
sap.ui.getCore().byId("fname").setValueState(sap.ui.core.ValueState.Error);
flag = true;
} else {
sap.ui.getCore().byId("fname").setValueState(sap.ui.core.ValueState.None);
}
if (!sap.ui.getCore().byId("lname").getValue()) {
sap.ui.getCore().byId("lname").setValueState(sap.ui.core.ValueState.Error);
flag = true;
} else {
sap.ui.getCore().byId("lname").setValueState(sap.ui.core.ValueState.None);
}
var month = sap.ui.getCore().byId("dob1").getSelectedKey();
var date = sap.ui.getCore().byId("dob2").getSelectedKey();
if (month === "4" || month === "6" || month === "9" || month === "11") {
if (date === "31") {
sap.m.MessageBox.show("Please select the correct Date of Birth.", {
icon: sap.m.MessageBox.Icon.ERROR,
title: "ERROR"
});
flag = true;
}
}
if (month === "2") {
if (date === "30" || date === "31") {
sap.m.MessageBox.show("Please select the correct Date of Birth.", {
icon: sap.m.MessageBox.Icon.ERROR,
title: "ERROR"
});
flag = true;
}
}
if (!sap.ui.getCore().byId("email").getValue()) {
sap.ui.getCore().byId("email").setValueState(sap.ui.core.ValueState.Error);
flag = true;
} else {
sap.ui.getCore().byId("email").setValueState(sap.ui.core.ValueState.None);
var Emailid2 = sap.ui.getCore().byId("email").getValue();
var email = Emailid2.split("@");
if (email.length === 2 || email.length === 1) {
Emailid2 = email[0] + "@accenture.com";
} else {
sap.ui.getCore().byId("email").setValueState(sap.ui.core.ValueState.Error);
flag = true;
}
}
//to check for URL
var ProfilePic_URL = null;
ProfilePic_URL = sap.ui.getCore().byId("ppicture").getValue();
var ProfilePic_regex = /http?:\/\/(thumbnail\.)?(accenture\.)?(com)\/([0-9]{6,7}\.)(jpg)/;
if (ProfilePic_URL === "undefined" || ProfilePic_URL === "")
{
sap.ui.getCore().byId("ppicture").setValueState(sap.ui.core.ValueState.None);
}
else if (ProfilePic_URL.length !== null) {
if (!ProfilePic_URL.match(ProfilePic_regex)) {
sap.m.MessageBox.show("Please enter valid URL", {
icon: sap.m.MessageBox.Icon.ERROR,
title: "ERROR"
});
flag = true;
}
}
var mobno_regex = /^[0-9]+$/;
var mobno = sap.ui.getCore().byId("phone").getValue();
if (!mobno || mobno.length != 10 || !mobno.match(mobno_regex)) {
sap.ui.getCore().byId("phone").setValueState(sap.ui.core.ValueState.Error);
flag = true;
} else {
sap.ui.getCore().byId("phone").setValueState(sap.ui.core.ValueState.None);
}
if (!flag) {
var Employeeid1 = sap.ui.getCore().byId("empid").getValue();
var Firstname1 = sap.ui.getCore().byId("fname").getValue();
var Lastname1 = sap.ui.getCore().byId("lname").getValue();
var Emailid1 = Emailid2;
var Phone1 = sap.ui.getCore().byId("phone").getValue();
var month1 = sap.ui.getCore().byId("dob1").getSelectedKey();
var date1 = sap.ui.getCore().byId("dob2").getSelectedKey();
var Address1 = sap.ui.getCore().byId("add").getSelectedKey();
var ProfilePic_URL1 = sap.ui.getCore().byId("ppicture").getValue();
var Dob1 = month1 + "/" + date1;
var mPayload = {
Employeeid: Employeeid1,
Firstname: Firstname1,
Lastname: Lastname1,
Dob: this.dateFromString(Dob1),
Emailid: Emailid1,
Phone: Phone1,
Address: Address1,
ProfilePic_URL: ProfilePic_URL1
};
var sPath = "/TeamDetailsSet(Employeeid='" + Employeeid1 + "')";
//console.log(this.getView());
//console.log(sap.ui.core.UIComponent.getRouterFor(this));
/*var router=sap.ui.core.UIComponent.getRouterFor(this);
// var oModel= sap.ui.getCore().getModel("ABCD");
var listId=sap.ui.getCore().getModel("listId");
console.log(listId);*/
var oView = this.getView();
var router = sap.ui.core.UIComponent.getRouterFor(this);
var oModel = this.getView().getModel();
oModel.update(sPath, mPayload, {
success: jQuery.proxy(function(mResponse) {
jQuery.sap.require("sap.m.MessageBox");
sap.m.MessageBox.show("Employee Details successfully updated for Employee ID:" + mPayload.Employeeid, {
icon: sap.m.MessageBox.Icon.SUCCESS,
title: "Details Updated",
actions: [sap.m.MessageBox.Action.OK],
onClose: this._routeToDetail(oEvent)
});
}, this),
error: jQuery.proxy(function() {
// this.oBusyDialog.close();
jQuery.sap.require("sap.m.MessageBox");
// ID of newly inserted product is available in mResponse.ID
// this.oBusyDialog.close();
sap.m.MessageBox.show("Error in Updating Details for Employee ID:" + mPayload.Employeeid, {
icon: sap.m.MessageBox.Icon.ERROR,
title: "ERROR"
});
}, this)
});
}
},
_routeToDetail: function(oEvent) {
this.getView().getModel().refresh();
this._getFormFragment("DetailFragment");
this._toggleButtonsAndView(true);
},
_routeToViewAll: function(oModel, _router) {
oModel.refresh();
// sap.ui.core.UIComponent.getRouterFor(this).navTo("_viewAll");
// sap.ui.controller("Bday.view.Detail")._router().navTo("_viewAll");
_router.navTo("_viewAll");
},
onEditEmployee: function(oEvent) {
this._getFormFragment("EditFragment");
this._toggleButtonsAndView(false);
},
addToCalendar: function(oEvent) {
this.dob = this.getView().getModel().getProperty(oEvent.getSource().getBindingContext().sPath + "/Dob");
//alert(this.dob);
if (this.dob !== null) {
var a = this.dob.substring(4, 6);
if (a < 10) {
a = a % 10;
}
switch (parseInt(a)) {
case 1:
a = "January";
break;
case 2:
a = "February";
break;
case 3:
a = "March";
break;
case 4:
a = "April";
break;
case 5:
a = "May";
break;
case 6:
a = "June";
break;
case 7:
a = "July";
break;
case 8:
a = "August";
break;
case 9:
a = "September";
break;
case 10:
a = "October";
break;
case 11:
a = "November";
break;
case 12:
a = "December";
break;
}
var date = this.dob.substring(6, 8);
var oDate = a + " " + date;
}
// alert(oDate);
this.firstname = this.getView().getModel().getProperty(oEvent.getSource().getBindingContext().sPath + "/Firstname");
// alert(this.firstname);
this.lastname = this.getView().getModel().getProperty(oEvent.getSource().getBindingContext().sPath + "/Lastname");
// alert(this.lastname);
this.loc = this.getView().getModel().getProperty(oEvent.getSource().getBindingContext().sPath + "/Address");
// alert(this.loc);
/*var currentDate = new Date();
var currentDay = currentDate.getDate();
var currentMonth = currentDate.getMonth() + 1;
if (currentDay < 10) {
currentDay = "0" + currentDay;
}
if (currentMonth < 10) {
currentMonth = "0" + currentMonth;
}
var today ="'"+ "9999" +currentMonth+currentDay+"'";
alert(today);
var startDate;
{
alert("hello" + this.dob);
if(this.dob>today)
startDate = new Date(oDate + ", 2015 8:00:00");
else
startDate = new Date(oDate + ", 2016 8:00:00");
//alert(startDate);
alert(startDate);
return(startDate);
}
var endDate;
if(this.dob>today)
{
endDate = new Date(oDate + ", 2015 8:00:00");
alert(endDate);
}
else
{
endDate = new Date(oDate + ", 2016 8:00:00");
}
return(endDate);*/
// alert(endDate);
var startDate =new Date(oDate + ", 2015 8:00:00");
var endDate=new Date(oDate + ", 2015 8:00:00");
// alert(startDate);
// var endDate = new Date(oDate + ", 2015 18:00:00");
var
notes = "Arrive on time, don't want to miss out (from Android)";
var
title = this.firstname + " " + this.lastname;
// alert(this.firstname + " " + this.lastname);
var
location = this.loc;
var
notes = "Happy Birthday !!";
var success = function() {
jQuery.sap.require("sap.m.MessageBox");
sap.m.MessageBox.show("Birthday Reminder is created in your calendar for " + title, {
icon: sap.m.MessageBox.Icon.SUCCESS,
title: "Calendar Event Created ",
actions: [sap.m.MessageBox.Action.OK]
});
// alert("Success");
};
var error = function(message) {
jQuery.sap.require("sap.m.MessageBox");
sap.m.MessageBox.show("Error in adding event in Calendar:", {
icon: sap.m.MessageBox.Icon.ERROR,
title: "ERROR",
actions: [sap.m.MessageBox.Action.OK]
});
};
window.plugins.calendar.createEvent(title, location, notes, startDate, endDate, success, error);
}