From bb9b85bf6a0be5de8cfd4112f129923b70f8efe5 Mon Sep 17 00:00:00 2001 From: Luis Fernando Saisa Lopez Date: Thu, 30 Jun 2016 11:44:24 -0400 Subject: [PATCH] HOR-264-B-31 "Request an option to rename..." SOLVED --- workflow/engine/controllers/pmTables.php | 4 ++ .../BusinessModel/ReportTable.php | 46 +++++++++++++++++++ .../engine/templates/pmTables/editReport.js | 43 ++++++++++++++++- 3 files changed, 91 insertions(+), 2 deletions(-) diff --git a/workflow/engine/controllers/pmTables.php b/workflow/engine/controllers/pmTables.php index c86b3bb72..57672499c 100755 --- a/workflow/engine/controllers/pmTables.php +++ b/workflow/engine/controllers/pmTables.php @@ -101,6 +101,10 @@ class pmTables extends Controller } } + if (preg_match("/^PMT_(.*)$/", $table['ADD_TAB_NAME'], $match)) { + $table['ADD_TAB_NAME'] = $match[1]; + } + $this->includeExtJS( 'pmTables/' . $jsFile ); $this->setJSVar( 'flagProcessmap', (isset($_REQUEST['flagProcessmap'])) ? $_REQUEST['flagProcessmap'] : 0); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/ReportTable.php b/workflow/engine/src/ProcessMaker/BusinessModel/ReportTable.php index 2cd8b52ac..82f459362 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/ReportTable.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/ReportTable.php @@ -348,11 +348,45 @@ class ReportTable $result = new \stdClass(); try { + $additionalTableUid = $arrayData['REP_TAB_UID']; + $flagNew = 0; + + $additionalTables = \AdditionalTablesPeer::retrieveByPK($arrayData['REP_TAB_UID']); + + if (!is_null($additionalTables)){ + $arrayData['REP_TAB_NAME'] = 'PMT_' . trim($arrayData['REP_TAB_NAME']); + + if ($additionalTables->getAddTabName() != $arrayData['REP_TAB_NAME']) { + $arrayData['REP_TAB_UID'] = ''; + $flagNew = 1; + } + } + ob_start(); $arrayData['PRO_UID'] = trim($arrayData['PRO_UID']); $arrayData['columns'] = \G::json_decode(stripslashes($arrayData['columns'])); //Decofing data columns + if ($flagNew == 1) { + $arrayNewColumn = []; + $counter = 0; + + foreach ($arrayData['columns'] as $value) { + $column = $value; + + if (!preg_match('/^(?:APP_UID|APP_NUMBER|APP_STATUS|ROW)$/', $column->field_name)) { + $column->uid = ''; + $column->_index = $counter; + + $arrayNewColumn[] = $column; + + $counter++; + } + } + + $arrayData['columns'] = $arrayNewColumn; + } + $additionalTable = new \AdditionalTables(); $repTabClassName = $additionalTable->getPHPName($arrayData['REP_TAB_NAME']); @@ -531,6 +565,18 @@ class ReportTable $result->success = true; $result->message = $result->msg = $buildResult; + + require_once(PATH_CORE . 'controllers/pmTablesProxy.php'); + + if ($flagNew == 1) { + $pmTablesProxy = new \pmTablesProxy(); + + $obj = new \stdClass(); + $obj->rows = \G::json_encode([['id' => $additionalTableUid, 'type' => '']]); + + //Delete Report Table + $resultDeleteReportTable = $pmTablesProxy->delete($obj); + } } catch (\Exception $e) { $buildResult = ob_get_contents(); diff --git a/workflow/engine/templates/pmTables/editReport.js b/workflow/engine/templates/pmTables/editReport.js index b4999a146..ea249268e 100755 --- a/workflow/engine/templates/pmTables/editReport.js +++ b/workflow/engine/templates/pmTables/editReport.js @@ -923,7 +923,7 @@ function validateFieldSizeAutoincrement(valueType, defaultValue) { } // setting table attributes for current editing process Ext.getCmp('REP_TAB_NAME').setValue(TABLE.ADD_TAB_NAME); - Ext.getCmp('REP_TAB_NAME').setDisabled(true); + Ext.getCmp('REP_TAB_NAME').setDisabled(false); Ext.getCmp('REP_TAB_DSC').setValue(TABLE.ADD_TAB_DESCRIPTION); // grid @@ -1052,7 +1052,46 @@ function validateFieldSizeAutoincrement(valueType, defaultValue) { buttons:[ { id: 'southPanelCreateUpdate', text: TABLE === false ? _("ID_CREATE") : _("ID_UPDATE"), - handler: createReportTable + handler: function() + { + if (TABLE === false) { + createReportTable(); + } else { + var oldRepTabName = TABLE.ADD_TAB_NAME; + var newRepTabName = Ext.getCmp("REP_TAB_NAME").getValue().trim(); + + if (newRepTabName != "") { + if (oldRepTabName != newRepTabName) { + Ext.MessageBox.show({ + title: _("ID_CONFIRM"), + msg: _("ID_RT_RENAME_NAME_TABLE"), + icon: Ext.MessageBox.QUESTION, + buttons: { + yes: _("ID_RT_CONTINUE_TABLE_RENAME"), + no: _("ID_RT_NOT_CHANGE_NAME") + }, + fn: function (buttonId, text, opt) + { + if (buttonId == "yes") { + createReportTable(); + } + } + }); + } else { + createReportTable(); + } + } else { + PMExt.error( + _("ID_ERROR"), + _("ID_TABLE_NAME_IS_REQUIRED"), + function() + { + Ext.getCmp("REP_TAB_NAME").focus(); + } + ); + } + } + } }, { id: 'southPanelCancel', text:_("ID_CANCEL"),