Comment posted by
SRIRAM
on Monday, June 30, 2014 12:43 PM
|
|
I have serious issue with the Knockout script as follows.
My function are not executing in sequence manner. my objective is to set the drop-down values in the EDIT mode. so some times its showing pointing it to right data some times its setting 0 vales. here is my code.
function tblUBRAMDetails(data) {
this.BURAMIdPK = ko.observable(data.BURAMIdPK)
this.BUIDFK = ko.observable(data.BUIDFK)
this.Asof = ko.observable(data.Asof)
this.CRMP = ko.observable(data.CRMP)
this.Underwriting = ko.observable(data.Underwriting)
this.RiskMonitoring = ko.observable(data.RiskMonitoring)
this.RiskIdentification = ko.observable(data.RiskIdentification)
this.Criticizedassetsmgmt = ko.observable(data.Criticizedassetsmgmt)
this.LevelofRisk = ko.observable(data.LevelofRisk)
this.TrendofRisk = ko.observable(data.TrendofRisk)
this.Processdesing = ko.observable(data.Processdesing)
this.ProcessEffective = ko.observable(data.ProcessEffective)
this.QAComments = ko.observable(data.QAComments)
this.EPMID = ko.observable(data.EPMID)
this.EPMStatus = ko.observable(data.EPMStatus)
this.CCEID = ko.observable(data.CCEID)
this.CCEStatus = ko.observable(data.CCEStatus)
this.CCEComments = ko.observable(data.CCEComments)
this.IsProcessStart = ko.observable(data.IsProcessStart)
}
function BURAMVIEW() {
var tabs = $("#tabs").tabs({
select: function (e, i) {
selected_tab = i.index;
}
});
var self = this;
self.BuRAMs = ko.observableArray([]);
self.CRMP = ko.observableArray();
self.UNDER = ko.observableArray();
self.RM = ko.observableArray();
self.RID = ko.observableArray();
self.CRTICIZED = ko.observableArray();
self.PROCESSDESIGN = ko.observableArray();
self.PROCESSEFFECT = ko.observableArray();
self.GETUBRAMDTLS = ko.observableArray([]);
self.LEVELOFRISK = ko.observableArray();
self.TRENDOFRISK = ko.observableArray();
self.EPMSTATUS = ko.observableArray();
self.CCESTATUS = ko.observableArray();
self.TRENDOFRISK = ko.observableArray();
self.LEVELOFRISK = ko.observableArray();
self.MANGERS = ko.observableArray();
//For control flow.
self.LOGINID = ko.observable();
self.LOGINROLEID = ko.observable();
self.vv = ko.observable();
$.ajax({
type: "POST",
data: {},
url: "../BURAMPages/CreateEditUBBURAM.aspx/GetAllBusinessUnit",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response != "") {
// var vResults = $.map(response.d, function (item) { return new tblBu(item) });
// self.BuRAMs(vResults);
self.BuRAMs(response.d);
}
}
});
$.ajax({
type: "POST",
data: ko.toJSON({ scode: "CH6" }),
url: "../AQReviewPages/LineCard.aspx/GetAllDivisions",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response != "") {
self.CRMP(response.d);
self.UNDER(response.d);
self.RM(response.d);
self.RID(response.d);
self.CRTICIZED(response.d);
self.PROCESSDESIGN(response.d);
self.PROCESSEFFECT(response.d);
//end Disable fields..
}
}
}); self.LoginDetails = function () {
$.ajax({
type: "POST",
data: {},
url: "../BURAMPages/CreateEditUBBURAM.aspx/GetLoginDetails",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response != "") {
self.LOGINID(response.d[0].UserPK);
self.LOGINROLEID(response.d[0].LoginUserRoleId);
self.GetControlFlow(0);
}
}
});
}
//Adding empty values for the first time
self.LoginDetails();
self.GETUBRAMDTLS(GetEmptyUBRAM());
self.EditUBDetails = function () {
$.ajax({
type: "POST",
data: ko.toJSON({ ipBuidPK: vBuidPK }),
url: "../BURAMPages/CreateEditUBBURAM.aspx/GetBUDetailsByID",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (results) {
if (results.d.length > 0) {
var vResults = $.map(results.d, function (item) { return new tblUBRAMDetails(item) });
self.GETUBRAMDTLS(vResults);
self.GetControlFlow(self.GETUBRAMDTLS()[0].EPMID())
}
else { self.GETUBRAMDTLS(GetEmptyUBRAM()); }
},
error: function (err) {
alert(err.responseText + " - " + err.statusText);
}
});
}
self.GetControlFlow = function (vEMPID) {
//For Exminers...
if (self.LOGINROLEID() == 6 && self.LOGINID() != vEMPID) {
$("#ddlepm").prop("disabled", true);
$("#ddlepmstatus").prop("disabled", true);
$("#ddlccestatus").prop("disabled", true);
}
//For CCE
else if (self.LOGINROLEID() == 5) {
$("#ddlepm").prop("disabled", true);
$("#ddlepmstatus").prop("disabled", true);
$("#ddlccestatus").prop("disabled", false);
}
//For Admin
else if (self.LOGINROLEID() == 1) {
$("#ddlepm").prop("disabled", false);
$("#ddlepmstatus").prop("disabled", false);
$("#ddlccestatus").prop("disabled", false);
}
else if (vEMPID > 0 && LOGINROLEID == vEMPID) {
$("#ddlepm").prop("disabled", true);
$("#ddlepmstatus").prop("disabled", false);
$("#ddlccestatus").prop("disabled", true);
}
else if (self.LOGINROLEID() == 3) {
$("#ddlepm").prop("disabled", true);
$("#ddlepmstatus").prop("disabled", false);
$("#ddlccestatus").prop("disabled", true);
}
}
}; //End View..
$(document).ready(function () {
$("#txtasof").datepicker();
var vBURAMView = new BURAMVIEW();
vBuidPK = 1;
vBURAMView.EditUBDetails();
ko.applyBindings(vBURAMView);
});
I am really frustrated.Please help me out.
Thanks,
Sriram