BUG 0000 PMTables improving data edit UI

- data row editor improved, how for each type the field editor is diamic for date, numeric, and text
- hard coded labels completed
This commit is contained in:
Erik Amaru Ortiz
2011-09-20 09:34:53 -04:00
parent b0435a0890
commit 7efe72cf19
2 changed files with 79 additions and 28 deletions

View File

@@ -409,7 +409,6 @@ class pmTablesProxy extends HttpProxyController
if (count($row) > 0) { if (count($row) > 0) {
eval('$con = Propel::getConnection('.$this->classPeerName.'::DATABASE_NAME);'); eval('$con = Propel::getConnection('.$this->classPeerName.'::DATABASE_NAME);');
$con->begin();
$obj->fromArray($row, BasePeer::TYPE_FIELDNAME); $obj->fromArray($row, BasePeer::TYPE_FIELDNAME);
if ($obj->validate()) { if ($obj->validate()) {
@@ -423,6 +422,7 @@ class pmTablesProxy extends HttpProxyController
} }
} }
else { else {
$msg = '';
foreach($obj->getValidationFailures() as $objValidationFailure) { foreach($obj->getValidationFailures() as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage() . "\n"; $msg .= $objValidationFailure->getMessage() . "\n";
} }
@@ -460,6 +460,7 @@ class pmTablesProxy extends HttpProxyController
require_once 'classes/model/AdditionalTables.php'; require_once 'classes/model/AdditionalTables.php';
$oAdditionalTables = new AdditionalTables(); $oAdditionalTables = new AdditionalTables();
$table = $oAdditionalTables->load($httpData->id, true); $table = $oAdditionalTables->load($httpData->id, true);
$primaryKeys = $oAdditionalTables->getPrimaryKeys('keys');
$this->className = $table['ADD_TAB_CLASS_NAME']; $this->className = $table['ADD_TAB_CLASS_NAME'];
$this->classPeerName = $this->className . 'Peer'; $this->classPeerName = $this->className . 'Peer';
$sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP; $sPath = PATH_DB . SYS_SYS . PATH_SEP . 'classes' . PATH_SEP;
@@ -474,15 +475,17 @@ class pmTablesProxy extends HttpProxyController
if (is_array($rows)) { if (is_array($rows)) {
foreach($rows as $row) { foreach($rows as $row) {
$result = $this->_dataUpdate($row); $row = (array) $row;
$result = $this->_dataUpdate($row, $primaryKeys);
} }
} }
else { //then is object else { //then is object
$result = $this->_dataUpdate($rows); $row = (array) $rows;
$result = $this->_dataUpdate($row, $primaryKeys);
} }
$this->success = $result; $this->success = $result;
$this->message = $result ? 'Updated Successfully' : 'Error Updating record'; $this->message = $result ? G::loadTranslation('ID_UPDATED_SUCCESSFULLY') : G::loadTranslation('ID_UPDATE_FAILED');
} }
/** /**
@@ -505,7 +508,7 @@ class pmTablesProxy extends HttpProxyController
require_once $sPath . $this->className . '.php'; require_once $sPath . $this->className . '.php';
$this->success = $this->_dataDestroy($httpData->rows); $this->success = $this->_dataDestroy($httpData->rows);
$this->message = $this->success ? 'Deleted Successfully' : 'Error Deleting record'; $this->message = $this->success ? G::loadTranslation('ID_DELETED_SUCCESSFULLY') : G::loadTranslation('ID_DELETE_FAILED');
} }
/** /**
@@ -564,7 +567,7 @@ class pmTablesProxy extends HttpProxyController
$this->message = $sErrorMessages; $this->message = $sErrorMessages;
} else { } else {
$this->success = true; $this->success = true;
$this->message = 'File Imported "'.$filename.'" Successfully'; $this->message = G::loadTranslation('ID_FILE_IMPORTED_SUCCESSFULLY', array($filename));
} }
} }
else { else {
@@ -1035,11 +1038,11 @@ class pmTablesProxy extends HttpProxyController
* Update data from a addTable record * Update data from a addTable record
* @param $row * @param $row
*/ */
function _dataUpdate($row) function _dataUpdate($row, $primaryKeys)
{ {
$keys = G::decrypt($row->__index__, 'pmtable'); $keys = G::decrypt($row['__index__'], 'pmtable');
$keys = explode('-', $keys); $keys = explode('-', $keys);
unset($row->__index__); unset($row['__index__']);
$params = array(); $params = array();
@@ -1052,16 +1055,31 @@ class pmTablesProxy extends HttpProxyController
if (is_object($obj)) { if (is_object($obj)) {
foreach ($row as $key => $value) { foreach ($row as $key => $value) {
// validation, don't modify primary keys
if (in_array($key, $primaryKeys)) {
throw new Exception(G::loadTranslation('ID_DONT_MODIFY_PK_VALUE', array($key)));
}
$action = 'set' . AdditionalTables::getPHPName($key); $action = 'set' . AdditionalTables::getPHPName($key);
$obj->$action($value); $obj->$action($value);
} }
$obj->save(); if ($r = $obj->validate()) {
return true; $obj->save();
} else { $result = true;
return false; }
$this->success = false; else {
$this->message = 'Update Failed'; $msg = '';
foreach($obj->getValidationFailures() as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage() . "\n";
}
throw new Exception($msg);
}
} }
else {
$result = false;
}
return $result;
} }
/** /**

View File

@@ -82,17 +82,51 @@ Ext.onReady(function(){
_fields.push({name: _idProperty}); _fields.push({name: _idProperty});
for (i=0;i<tableDef.FIELDS.length; i++) { for (i=0;i<tableDef.FIELDS.length; i++) {
switch (tableDef.FIELDS[i].FLD_TYPE) {
case 'DATE':
columnRenderer = function (value) {
if (!value.dateFormat)
return value;
else
return value.dateFormat('Y-m-d');
}
columnAlign = 'left';
columnEditor = {
xtype : 'datefield',
format : 'Y-m-d',
allowBlank : true
};
break;
case 'INTEGER': case 'INT': case 'FLOAT': case 'DOUBLE' :
columnRenderer = {};
columnAlign = 'right';
columnEditor = {
xtype : 'numberfield',
format : 'Y-m-d',
allowBlank : true
};
break;
default:
columnRenderer = {};
columnAlign = 'left';
columnEditor = {
xtype : 'textfield',
allowBlank : true
};
}
column = { column = {
id : tableDef.FIELDS[i].FLD_NAME, id : tableDef.FIELDS[i].FLD_NAME,
header : tableDef.FIELDS[i].FLD_DESCRIPTION, header : tableDef.FIELDS[i].FLD_DESCRIPTION,
dataIndex : tableDef.FIELDS[i].FLD_NAME, dataIndex : tableDef.FIELDS[i].FLD_NAME,
width : 40 width : 40,
align : columnAlign,
renderer : columnRenderer
}; };
if (tableDef.FIELDS[i].FLD_AUTO_INCREMENT != 1) { if (tableDef.FIELDS[i].FLD_AUTO_INCREMENT != 1) {
column.editor = { column.editor = columnEditor
xtype : 'textfield',
allowBlank : true
}
} }
else { else {
column.editor = { column.editor = {
@@ -156,15 +190,14 @@ Ext.onReady(function(){
// all exception events // all exception events
Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) { Ext.data.DataProxy.addListener('exception', function(proxy, type, action, options, res) {
try{ if (res.raw.success) {
response = Ext.util.JSON.decode(res.responseText); if(res.raw.message != 'nothing to do') {
PMExt.notify(_('ID_INFO'), response.raw.message);
if(response.message != 'nothing to do') {
PMExt.notify(_('ID_ERROR'), response.msg);
} }
} }
catch(e) { else {
PMExt.notify(_('ID_ERROR'), res.responseText); PMExt.error(_('ID_ERROR'), res.raw.message);
infoGrid.store.reload();
} }
}); });