mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
haciendo formulario de editar tarifa envio
This commit is contained in:
@ -32,6 +32,20 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
|
||||
$this->viewData['pageTitle'] = lang('TarifasEnvios.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
|
||||
|
||||
// Breadcrumbs
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => lang("App.menu_tarifas"), 'route' => "javascript:void(0);", 'active' => false],
|
||||
['title' => lang("App.menu_tarifasenvios"), 'route' => site_url('tarifas/tarifasenvios'), 'active' => true]
|
||||
];
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
|
||||
@ -54,7 +68,8 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
public function add() {
|
||||
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
@ -66,6 +81,10 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if (isset($this->model->user_updated_id)) {
|
||||
$sanitizedData['user_created_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
@ -95,7 +114,8 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
return redirect()->to(site_url('tarifas/tarifasenvios/edit/' . $id))->with('sweet-success', $message);
|
||||
//return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message);
|
||||
else:
|
||||
return $this->redirect2listView('sweet-success', $message);
|
||||
endif;
|
||||
@ -119,6 +139,9 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
} // end function add()
|
||||
|
||||
public function edit($requestedId = null) {
|
||||
|
||||
// JJO
|
||||
$session = session();
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
@ -139,9 +162,12 @@ class Tarifasenvios extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
|
||||
|
||||
// JJO
|
||||
if (isset($this->model->user_updated_id)) {
|
||||
$sanitizedData['user_updated_id'] = $session->id_user;
|
||||
}
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
@ -11,6 +11,10 @@ use App\Models\Tarifas\TarifaEnvioModel;
|
||||
|
||||
use App\Models\Tarifas\TarifaEnvioZonaModel;
|
||||
|
||||
use
|
||||
DataTables\Editor,
|
||||
DataTables\Editor\Field;
|
||||
|
||||
class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
|
||||
|
||||
protected $modelName = TarifaEnvioZonaModel::class;
|
||||
@ -196,6 +200,90 @@ class Tarifasenvioszonas extends \App\Controllers\GoBaseResourceController {
|
||||
} // end function edit(...)
|
||||
|
||||
|
||||
public function datatable_editor()
|
||||
{
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
|
||||
|
||||
// Build our Editor instance and process the data coming from _POST
|
||||
$response = Editor::inst($db, 'tarifas_envios_zonas')
|
||||
->fields(
|
||||
Field::inst('cp_inicial')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.required'))
|
||||
)
|
||||
->validator('Validate::maxLen(10)', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_inicial.max_length'))
|
||||
),
|
||||
Field::inst('cp_final')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_final.required'))
|
||||
)
|
||||
->validator('Validate::maxLen(10)', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.cp_final.max_length'))
|
||||
),
|
||||
Field::inst('importe_fijo')
|
||||
->validator('Validate::required', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.importe_fijo.required'))
|
||||
)
|
||||
->validator('Validate::numeric', array(
|
||||
'message' => lang('TarifasEnviosZonas.validation.importe_fijo.integer'))
|
||||
),
|
||||
Field::inst('tarifa_envio_id'),
|
||||
Field::inst('user_created_id'),
|
||||
Field::inst('created_at'),
|
||||
Field::inst('user_updated_id'),
|
||||
Field::inst('updated_at'),
|
||||
Field::inst('is_deleted'),
|
||||
Field::inst('deleted_at'),
|
||||
|
||||
)
|
||||
->validator(function ($editor, $action, $data) {
|
||||
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
|
||||
foreach ($data['data'] as $pkey => $values) {
|
||||
// Si no se quiere borrar...
|
||||
if ($data['data'][$pkey]['is_deleted'] != 1) {
|
||||
/*Los CP son string... consultar si checkear*/
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
->on('preCreate', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_created_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('created_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->on('preEdit', function ($editor, &$values) {
|
||||
$session = session();
|
||||
$datetime = (new \CodeIgniter\I18n\Time("now"));
|
||||
$editor
|
||||
->field('user_updated_id')
|
||||
->setValue($session->id_user);
|
||||
$editor
|
||||
->field('updated_at')
|
||||
->setValue($datetime->format('Y-m-d H:i:s'));
|
||||
})
|
||||
->debug(true)
|
||||
->process($_POST)
|
||||
->data();
|
||||
|
||||
$newTokenHash = csrf_hash();
|
||||
$csrfTokenName = csrf_token();
|
||||
|
||||
$response[$csrfTokenName] = $newTokenHash;
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
} else {
|
||||
return $this->failUnauthorized('Invalid request', 403);
|
||||
}
|
||||
}
|
||||
|
||||
public function datatable() {
|
||||
if ($this->request->isAJAX()) {
|
||||
|
||||
Reference in New Issue
Block a user