BUG 0000 PM Tables + Report Tables ver. 2

(fixes in list an data handling)
This commit is contained in:
Erik Amaru Ortiz
2011-07-11 20:08:59 -04:00
parent 9f35a8aa01
commit f8666d3289
4 changed files with 183 additions and 63 deletions

View File

@@ -116,6 +116,9 @@ class pmTables extends Controller
$this->includeExtJS('pmTables/' . $jsFile, $this->debug);
//fix for backware compatibility
$table['DBS_UID'] = $table['DBS_UID'] == null || $table['DBS_UID'] == '' ? 'workflow': $table['DBS_UID'];
$this->setJSVar('ADD_TAB_UID', $addTabUid);
$this->setJSVar('PRO_UID', isset($_GET['PRO_UID'])? $_GET['PRO_UID'] : false);
$this->setJSVar('TABLE', $table);

View File

@@ -11,6 +11,9 @@ require_once 'classes/model/AdditionalTables.php';
class pmTablesProxy extends HttpProxyController
{
protected $className;
protected $classPeerName;
/**
* get pmtables list
* @param string $httpData->start
@@ -381,18 +384,42 @@ class pmTablesProxy extends HttpProxyController
require_once 'classes/model/AdditionalTables.php';
$oAdditionalTables = new AdditionalTables();
$table = $oAdditionalTables->load($httpData->id, true);
$className = $table['ADD_TAB_CLASS_NAME'];
$sClassPeerName = $className . 'Peer';
$this->className = $table['ADD_TAB_CLASS_NAME'];
$this->classPeerName = $this->className . 'Peer';
$sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
if (!file_exists ($sPath . $this->className . '.php') ) {
throw new Exception("ERROR: $className class file doesn't exit!");
}
require_once $sPath . $this->className . '.php';
$rows = G::json_decode($httpData->rows);
eval('$obj = new ' .$this->className. '();');
if (is_array($rows)) {
foreach ($rows as $row) {
foreach ($row as $key => $value) {
$action = 'set' . AdditionalTables::getPHPName($key);
$res = $obj->$action($value);
}
$this->success = $res ? true: false;
}
}
else {
foreach ($rows as $key => $value) {
$action = 'set' . AdditionalTables::getPHPName($key);
$obj->$action($value);
}
if ($obj->save() >0) {
$this->success = true;
}
else {
$this->success = false;
}
}
else { //then is object
}
print_R($row);
//$sClassPeerName::retrieveByPk();
$this->message = $this->success ? 'Saved Successfully' : 'Error Updating record';
}
/**
@@ -406,27 +433,48 @@ class pmTablesProxy extends HttpProxyController
require_once 'classes/model/AdditionalTables.php';
$oAdditionalTables = new AdditionalTables();
$table = $oAdditionalTables->load($httpData->id, true);
$className = $table['ADD_TAB_CLASS_NAME'];
$slassPeerName = $className . 'Peer';
$this->className = $table['ADD_TAB_CLASS_NAME'];
$this->classPeerName = $this->className . 'Peer';
$sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
if (!file_exists ($sPath . $this->className . '.php') ) {
throw new Exception("ERROR: $className class file doesn't exit!");
}
require_once $sPath . $this->className . '.php';
$rows = G::json_decode($httpData->rows);
print_R($rows);
if (is_array($rows)) {
foreach($rows as $row) {
$result = $this->_dataUpdate($row);
}
}
else { //then is object
$keys = explode('-', $rows->__index__);
foreach ($keys as $key) {
$params .= is_numeric($key) ? $key : "'$key'";
}
$obj = null;
var_dump('$obj = $classPeerName::retrieveByPk('.implode(',', $params).')');
eval('$obj = $classPeerName::retrieveByPk('.implode(',', $params).')');
var_dump($obj);
$result = $this->_dataUpdate($rows);
}
//$sClassPeerName::retrieveByPk();
$this->success = $result;
$this->message = $result ? 'Updated Successfully' : 'Error Updating record';
}
public function dataDestroy($httpData)
{
require_once 'classes/model/AdditionalTables.php';
$oAdditionalTables = new AdditionalTables();
$table = $oAdditionalTables->load($httpData->id, true);
$this->className = $table['ADD_TAB_CLASS_NAME'];
$this->classPeerName = $this->className . 'Peer';
$sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
if (!file_exists ($sPath . $this->className . '.php') ) {
throw new Exception("ERROR: $className class file doesn't exit!");
}
require_once $sPath . $this->className . '.php';
$this->success = $this->_dataDestroy($httpData->rows);
$this->message = $this->success ? 'Deleted Successfully' : 'Error Deleting record';
}
@@ -434,6 +482,62 @@ class pmTablesProxy extends HttpProxyController
* - protected functions (non callable from controller outside) -
*/
/**
* Update data from a addTable record
* @param $row
*/
function _dataUpdate($row)
{
$keys = explode('-', $row->__index__);
unset($row->__index__);
$params = array();
foreach ($keys as $key) {
$params[] = is_numeric($key) ? $key : "'$key'";
}
$obj = null;
eval('$obj = '.$this->classPeerName.'::retrieveByPk('.implode(',', $params).');');
if (is_object($obj)) {
foreach ($row as $key => $value) {
$action = 'set' . AdditionalTables::getPHPName($key);
$obj->$action($value);
}
$obj->save();
return true;
} else {
return false;
$this->success = false;
$this->message = 'Update Failed';
}
}
/**
* Update data from a addTable record
* @param $row
*/
function _dataDestroy($row)
{
$row = str_replace('"', '', $row);
$keys = explode('-', $row);
$params = array();
foreach ($keys as $key) {
$params[] = is_numeric($key) ? $key : "'$key'";
}
$obj = null;
eval('$obj = '.$this->classPeerName.'::retrieveByPk('.implode(',', $params).');');
if (is_object($obj)) {
$obj->delete();
return true;
} else {
return false;
$this->success = false;
$this->message = 'Update Failed';
}
}
/**
* Get report table default columns
* @param $type

View File

@@ -13,6 +13,7 @@ var store;
var cmodel;
var smodel;
var infoGrid;
var _fields;
Ext.onReady(function(){
@@ -89,27 +90,27 @@ Ext.onReady(function(){
}
}
// smodel = new Ext.grid.CheckboxSelectionModel({
// listeners:{
// selectionchange: function(sm){
// var count_rows = sm.getCount();
// switch(count_rows){
// case 0:
// editButton.disable();
// deleteButton.disable();
// break;
// case 1:
// editButton.enable();
// deleteButton.enable();
// break;
// default:
// editButton.disable();
// deleteButton.disable();
// break;
// }
// }
// }
// });
smodel = new Ext.grid.CheckboxSelectionModel({
listeners:{
selectionchange: function(sm){
var count_rows = sm.getCount();
switch(count_rows){
case 0:
editButton.disable();
deleteButton.disable();
break;
case 1:
editButton.enable();
deleteButton.enable();
break;
default:
editButton.disable();
//deleteButton.disable();
break;
}
}
}
});
//row editor for table columns grid
editor = new Ext.ux.grid.RowEditor({
@@ -148,6 +149,10 @@ Ext.onReady(function(){
autoSave: true // <-- false would delay executing create, update, destroy requests until specifically told to do so with some [save] buton.
});
Ext.data.DataProxy.addListener('write', function(proxy, action, result, res, rs) {
PMExt.notify('UPDATE', 'the record was updated successfully.');
});
// load the store immeditately
//store.load();
@@ -217,7 +222,7 @@ Ext.onReady(function(){
store: store,
cm: cmodel,
plugins: [editor],
//sm: smodel,
sm: smodel,
tbar:[newButton,'-',editButton, deleteButton,'-',importButton,{xtype: 'tbfill' }, backButton],
bbar: bbarpaging,
listeners: {
@@ -273,8 +278,24 @@ capitalize = function(s){
DoNothing = function(){};
//Load New PM Table Row Forms
var props = function(){};
NewPMTableRow = function(){
location.href = 'additionalTablesDataNew?sUID=' + TABLES.UID;
var PMRow = infoGrid.getStore().recordType;
//var meta = mapPMFieldType(records[i].data['FIELD_UID']);
for(i=0; i<_fields.length; i++) {
props.prototype[_fields[i].name] = '';
}
var row = new PMRow(new props);
length = infoGrid.getStore().data.length;
editor.stopEditing();
store.insert(length, row);
infoGrid.getView().refresh();
infoGrid.getSelectionModel().selectRow(length);
editor.startEditing(length);
};
//Load PM Table Edition Row Form
@@ -292,20 +313,12 @@ EditPMTableRow = function(){
//Confirm PM Table Row Deletion Tasks
DeletePMTableRow = function(){
iGrid = Ext.getCmp('infoGrid');
rowsSelected = iGrid.getSelectionModel().getSelections();
Ext.Msg.confirm(_('ID_CONFIRM'), _('ID_MSG_CONFIRM_DELETE_ROW'),
function(btn, text){
if (btn=="yes"){
var aRowsSeleted = (RetrieveRowsID(rowsSelected)).split(",") ;
var aTablesPKF = (TABLES.PKF).split(","); ;
var sParam = '';
for(var i=0;i<aTablesPKF.length; i++){
sParam += '&' + aTablesPKF[i] + '=' + aRowsSeleted[i];
}
location.href = 'additionalTablesDataDelete?sUID='+TABLES.UID+sParam;
}
PMExt.confirm(_('ID_CONFIRM'), _('ID_CONFIRM_REMOVE_FIELD'), function(){
var records = Ext.getCmp('infoGrid').getSelectionModel().getSelections();
Ext.each(records, Ext.getCmp('infoGrid').store.remove, Ext.getCmp('infoGrid').store);
});
};
//Load Import PM Table From CSV Source

View File

@@ -222,8 +222,8 @@ Ext.onReady(function(){
}});
cmodelColumns.push({header: 'Table Type', dataIndex: 'PRO_UID', width: 120, align:'left', renderer: function(v,p,r){
color = r.get('PRO_UID') == '' ? 'green' : 'blue';
value = r.get('PRO_UID') == '' ? 'Table' : 'Report';
color = r.get('PRO_UID') ? 'green' : 'blue';
value = r.get('PRO_UID') ? 'Table' : 'Report';
return '<span style="color:'+color+'">'+value+'</span> ';
}});
@@ -346,7 +346,7 @@ EditPMTable = function(){
var row = Ext.getCmp('infoGrid').getSelectionModel().getSelected();
if (row.data.TYPE != 'CLASSIC') {
tableType = row.data.PRO_UID !== '' ? 'report' : 'table';
tableType = row.data.PRO_UID ? 'report' : 'table';
proParam = PRO_UID !== false ? '&PRO_UID='+PRO_UID : '';
location.href = 'pmTables/edit?id='+row.data.ADD_TAB_UID+'&tableType=' + tableType + proParam;
}