dojo._xdResourceLoaded(function(dojo, dijit, dojox){
return {depends: [["provide", "kfc.kwo.LookupValuesGrid"],
["require", "dojox.grid.DataGrid"],
["require", "dojo.data.ItemFileWriteStore"],
["require", "kfc._KFC"],
["require", "dojox.grid.cells.dijit"]],
defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["kfc.kwo.LookupValuesGrid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["kfc.kwo.LookupValuesGrid"] = true;
dojo.provide("kfc.kwo.LookupValuesGrid");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileWriteStore");
//dojo.require("kfc.kwo._LookupValues");
dojo.require("kfc._KFC");
dojo.require("dojox.grid.cells.dijit");
dojo.declare("kfc.kwo.LookupValuesGrid", [/*kfc.kwo._LookupValues*/kfc._KFC], {
/*templateString:"
\n \n
\n Values\n \n
\n
\n
\n"*/
templateString: dojo.cache("kfc.kwo", "templates/LookupValuesGrid.html", "\n \n
\n Values\n \n
\n
\n
\n")
,widgetsInTemplate: true
,store: null
,isDirty: false
,saveFile: "server/save.php"
,loadFile: "server/load.php"
,seedFile: "server/getTypes.php"
,db_schema: "KFC"
,db_table_name: "KWO_LOOKUP_VALUES"
,_getGridStructure: function () {
return [
{ name: " ", formatter: function () { return " "; }, editable: false, width: "1em" }
,{ name: "Code", field: "P_CODE", editable: true, width: "15em" }
,{ name: "Description", field: "P_DESCRIPTION", editable: true, width: "auto" }
,{ name: "Value", field: "P_VALUE", editable: true, width: "20em" }
,{ name: "Enabled", field: "P_ENABLED_FLAG", editable: true, width: "8em"
,type: dojox.grid.cells.Select, options: ["Y", "N"] }
];
}
,_setGridStore: function () {
this.grid.setStore(this.store);
}
,_setTitle: function (p_title) {
p_title = (typeof p_title != "undefined") ? p_title : "";
this.title.innerHTML = "Values" + ((p_title) ? (" for " + p_title) : (""));
}
,_getDataStructure: function () {
return {
P_ID: null
,P_LOOKUP_ID: null
,P_CODE: ""
,P_DESCRIPTION: ""
,P_VALUE: ""
,P_ENABLED_FLAG: "Y"
,P_DELETED_FLAG: "N"
};
}
,_createStore: function () {
var s = (this.store_path.length)
? new dojo.data.ItemFileWriteStore({ url: this.store_path })
: new dojo.data.ItemFileWriteStore({ data: { identifier: 'P_ID', items: [] }});
this.setStore(s);
}
,setStore: function (p_store) {
this.store = p_store;
}
,_setEmptyStore: function () {
var s = new dojo.data.ItemFileWriteStore({ data: { items: [] } });
this.setStore(s);
}
,refresh: function () {
this._setTitle();
this.grid.selection.clear();
this.load();
}
/**
* Load the lookup values for the corresponding lookup id. If no ID is
* passed in, use an empty store.
*/
,load: function (p_id) {
p_id = (typeof p_id != "undefined") ? p_id : null;
var _this = this;
_this.setStatus({ MSG: "Fetching lookup values...", DETAILS: "load("+p_id+")", TYPE: "INFO", ACTIVITY: true });
//if no id was passed in, use an empty store and exit
if (!p_id) {
this._setEmptyStore();
this.setStatus({ MSG: "Done", TYPE: "INFO", ACTIVITY: false });
return;
}
this.grid.selection.clear();
dojo.xhrPost({
sync: true
,url: _this.loadFile
,handleAs: "json"
,content: {
P_REQ_NAME: "LOOKUP_VALUES"
,P_REQ_TYPE: "LOAD"
,P_SCHEMA: _this.db_schema
,P_TABLE_NAME: _this.db_table_name
,P_VALUES: dojo.toJson({ "P_LOOKUP_ID": p_id })
}
,load: function (p_response) {
_this.setStatus({ MSG: "Done", TYPE: "INFO", ACTIVITY: false });
var s = new dojo.data.ItemFileWriteStore({ data: p_response });
_this.setStore(s);
}
,error: function (p_error) {
_this.setStatus({ MSG: "Failed to retrieve lookup values...", TYPE: "ERROR", ACTIVITY: false });
}
});
}
/** When adding a new row, be sure that a lookup (parent) id is passed in. */
,addRow: function (p_lookup_id) {
if (typeof p_lookup_id == "undefined" || !p_lookup_id) {
this.setStatus({ MSG: "Invalid parent lookup", TYPE: "ERROR", ACTIVITY: false });
return;
}
var row = this._getDataStructure();
row.P_ID = new Date().getTime();
row.P_LOOKUP_ID = p_lookup_id;
this.store.newItem(row);
}
,deleteRow: function () {
var grid = this.grid;
var selected = grid.selection.getSelected();
for (var i in selected) {
this.store.deleteItem(selected[i]);
}
}
,save: function () {
this.setStatus({ MSG: "Saving lookup values...", TYPE: "INFO", ACTIVITY: true });
var _this = this;
var values = {
"NEW": KfcStoreFunctions.getNewItems(this.store, true)
,"UPD": KfcStoreFunctions.getModifiedItems(this.store, true)
,"DEL": KfcStoreFunctions.getDeletedItems(this.store, true)
};
dojo.xhrPost({
sync: true
,url: _this.saveFile
,handleAs: "text"
,content: {
P_REQ_NAME: "LOOKUP_VALUES"
,P_REQ_TYPE: "SAVE"
,P_SCHEMA: _this.db_schema
,P_TABLE_NAME: _this.db_table_name
,P_VALUES: dojo.toJson(values)
}
,load: function (p_response) {
console.log(p_response);
//this.isDirty = false;
_this.setStatus({ MSG: "Lookup values saved", TYPE: "INFO", ACTIVITY: false });
}
,error: function (p_error) {
console.log(p_error);
_this.setStatus({ MSG: "Failed to save lookup values...", DETAILS: p_error, TYPE: "ERROR", ACTIVITY: false });
}
});
}
/*** END _Lookups.js ***/
,setStatus: function (params) {}
,postCreate: function () {
this.grid.attr("structure", this._getGridStructure());
this.grid.startup();
dojo.connect(this, "setStore", this, "_setGridStore");
}
});
}
}};});