From: Andrey Kutejko Date: Sun, 4 Jan 2015 16:07:37 +0000 (+0200) Subject: rework change referrer feature X-Git-Tag: 0.6~96 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=d0259838d2afd9b7b60cc73c88f977e3c1939784;p=ipf.git rework change referrer feature --- diff --git a/ipf/admin/component.php b/ipf/admin/component.php index 69fcd19..f07523c 100644 --- a/ipf/admin/component.php +++ b/ipf/admin/component.php @@ -154,7 +154,22 @@ abstract class IPF_Admin_Component return array(); } - // Views Function + protected function referrerOfChangeAction() + { + return + \PFF\Arr::get($this->request->REQUEST, 'ipf_referrer', + \PFF\Arr::get($this->request->SERVER, 'HTTP_REFERER', + '')); + } + + protected function changeSucceed() + { + $url = @$this->request->POST['ipf_referrer']; + if (!$url) + $url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'listItems'), array($this->app->slug(), $this->slug())); + return new IPF_HTTP_Response_Redirect($url); + } + public function addItem() { $errors = false; @@ -164,13 +179,8 @@ abstract class IPF_Admin_Component if ($form->isValid()) { list($id, $object) = $this->saveObject($form, null); - IPF_Admin_Log::logObject($this, 'add', $object, $id); - - $url = @$this->request->POST['ipf_referrer']; - if (!$url) - $url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'listItems'), array($this->app->slug(), $this->slug())); - return new IPF_HTTP_Response_Redirect($url); + return $this->changeSucceed(); } $errors = true; } else { @@ -190,6 +200,7 @@ abstract class IPF_Admin_Component 'extra_css' => $extraMedia['css'], 'errors' => $errors, 'objecttools' => array(), + 'ipf_referrer' => $this->referrerOfChangeAction(), )); } @@ -201,13 +212,8 @@ abstract class IPF_Admin_Component if ($this->request->method == 'POST') { IPF_Admin_Log::logObject($this, 'delete', $object); - $this->deleteObject($object); - - $url = @$this->request->POST['ipf_referrer']; - if (!$url) - $url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'listItems'), array($this->app->slug(), $this->slug())); - return new IPF_HTTP_Response_Redirect($url); + return $this->changeSucceed(); } return $this->fullContext(array( @@ -215,7 +221,7 @@ abstract class IPF_Admin_Component 'classname' => $this->verbose_name(), 'object' => $object, 'object_id' => $id, - 'ipf_referrer' => @$this->request->GET['ipf_referrer'], + 'ipf_referrer' => $this->referrerOfChangeAction(), )); } @@ -232,14 +238,8 @@ abstract class IPF_Admin_Component if ($form->isValid()) { list($id, $object) = $this->saveObject($form, $object); - IPF_Admin_Log::logObject($this, 'change', $object, $id); - - $url = @$this->request->POST['ipf_referrer']; - if (!$url) - $url = IPF_HTTP_URL::urlForView(array('IPF_Admin_Controller', 'listItems'), array($this->app->slug(), $this->slug())); - - return new IPF_HTTP_Response_Redirect($url); + return $this->changeSucceed(); } $errors = true; } else { @@ -262,6 +262,7 @@ abstract class IPF_Admin_Component 'extra_css' => $extraMedia['css'], 'errors' => $errors, 'objecttools' => $objecttools, + 'ipf_referrer' => $this->referrerOfChangeAction(), )); } diff --git a/ipf/admin/templates/admin/change.html b/ipf/admin/templates/admin/change.html index d884d88..910df4f 100644 --- a/ipf/admin/templates/admin/change.html +++ b/ipf/admin/templates/admin/change.html @@ -27,7 +27,7 @@ {/block}
- +
{if $errors}

Please correct the error below.

@@ -38,7 +38,7 @@ {/block}
- {if ($mode=='change') && $component->isAccessible(array('delete'))}

{trans 'Delete'}

{/if} + {if ($mode=='change') && $component->isAccessible(array('delete'))}

{trans 'Delete'}

{/if} {if ($mode=='change') && $component->isAccessible(array('change'))}{/if} {if ($mode=='add') && $component->isAccessible(array('add'))}{/if} @@ -51,13 +51,6 @@ {/block} {block scripts} - {foreach $extra_js as $js} {$js|safe} {/foreach} diff --git a/ipf/admin/templates/admin/delete.html b/ipf/admin/templates/admin/delete.html index d346a16..7b991b2 100644 --- a/ipf/admin/templates/admin/delete.html +++ b/ipf/admin/templates/admin/delete.html @@ -13,7 +13,7 @@

{$page_title}

- +

Are you sure you want to delete {$object}?