From 68a96ecccbe9943b7d7e86af976f2c5cf5010dc2 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 14 May 2016 18:48:58 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E3=82=A6=E3=82=A3=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=83=98=E3=83=AB=E3=83=91=E3=83=BC=E3=82=92=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=83=95=E3=83=AD=E3=83=BC=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CancelAndSaveAndSaveTempTest.php | 2 +- View/Helper/ButtonHelper.php | 6 +- View/Helper/WizardHelper.php | 148 +++++++++++++++--- 3 files changed, 129 insertions(+), 27 deletions(-) diff --git a/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php b/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php index 90417360..a37844bd 100644 --- a/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php +++ b/Test/Case/View/Helper/ButtonHelper/CancelAndSaveAndSaveTempTest.php @@ -146,7 +146,7 @@ private function __assertButtons($result, $cancelUrl, $backUrl, $disapproval, $a //戻るのチェック if ($backUrl) { - $expected = '' . + $expected = '' . ' ' . __d('net_commons', 'BACK') . ''; $this->assertTextContains($expected, $result); diff --git a/View/Helper/ButtonHelper.php b/View/Helper/ButtonHelper.php index 3c4b8291..e6831bbd 100644 --- a/View/Helper/ButtonHelper.php +++ b/View/Helper/ButtonHelper.php @@ -270,13 +270,15 @@ public function cancelAndSaveAndSaveTemp($cancelUrl = null, $cancelOptions = [], $cancelOptions ); - //戻るボタン + //前へボタン if (isset($backUrl)) { $output .= $this->Html->link( ' ' . __d('net_commons', 'BACK'), $backUrl, array( - 'class' => 'btn btn-default' . $this->getButtonSize() . ' btn-workflow', 'escape' => false + 'class' => 'btn btn-default' . $this->getButtonSize() . ' btn-workflow', + 'escape' => false, + 'ng-class' => '{disabled: sending}' ) ); } diff --git a/View/Helper/WizardHelper.php b/View/Helper/WizardHelper.php index f91eab43..10bcb9cc 100644 --- a/View/Helper/WizardHelper.php +++ b/View/Helper/WizardHelper.php @@ -14,6 +14,57 @@ /** * ウィザードHelper * + * #### コントローラの定義(helpersのサンプル) + * https://github.com/NetCommons3/Rooms/blob/master/Controller/RoomsAppController.php#L73-L98 + * ``` + * public $helpers = array( + * 'NetCommons.Wizard' => array( + * 'navibar' => array( + * self::WIZARD_ROOMS => array( + * 'url' => array( + * 'controller' => 'rooms', + * 'action' => 'add', + * ), + * 'label' => array('rooms', 'General setting'), + * ), + * self::WIZARD_ROOMS_ROLES_USERS => array( + * 'url' => array( + * 'controller' => 'rooms_roles_users', + * 'action' => 'edit', + * ), + * 'label' => array('rooms', 'Edit the members to join'), + * ), + * self::WIZARD_PLUGINS_ROOMS => array( + * 'url' => array( + * 'controller' => 'plugins_rooms', + * 'action' => 'edit', + * ), + * 'label' => array('rooms', 'Select the plugins to join'), + * ), + * ), + * 'cancelUrl' => null + * ), + * ); + * ``` + * + * #### viewファイルのWizardバーサンプル + * https://github.com/NetCommons3/Rooms/blob/master/View/PluginsRooms/edit.ctp#L17 + * ``` + * echo $this->Wizard->navibar(RoomsAppController::WIZARD_PLUGINS_ROOMS); + * ``` + * + * ##### viewファイルのボタンサンプル + * (ワークフローなし)
+ * https://github.com/NetCommons3/Rooms/blob/master/View/PluginsRooms/edit.ctp#L17 + * ``` + * echo $this->Wizard->buttons(RoomsAppController::WIZARD_PLUGINS_ROOMS); + * ``` + * (ワークフローあり) + * ``` + * echo $this->Wizard->workflowButtons('Questionnaire.status'); + * ``` + * + * * @package NetCommons\NetCommons\View\Helper */ class WizardHelper extends AppHelper { @@ -26,6 +77,7 @@ class WizardHelper extends AppHelper { public $helpers = array( 'NetCommons.Button', 'NetCommons.NetCommonsHtml', + 'Workflow.Workflow', ); /** @@ -124,24 +176,87 @@ public function naviUrl($activeKey) { * ウィザードボタン * * @param string $activeKey アクティブのキー - * @param array $cancelOptions キャンセルボタンのオプション - * @param array $prevOptions 戻るボタンのオプション - * @param array $nextOptions 次へ、決定ボタンのオプション + * @param array $cancelOpt キャンセルボタンのオプション + * @param array $prevOpt 前へボタンのオプション + * @param array $nextOpt 次へ、決定ボタンのオプション * @return string HTML */ - public function buttons($activeKey, $cancelOptions = [], $prevOptions = [], $nextOptions = []) { + public function buttons($activeKey, $cancelOpt = [], $prevOpt = [], $nextOpt = []) { $output = ''; + //ウィザードの状態取得 + list($prev, $next) = $this->__wizardStep($activeKey); + //キャンセルボタン $cancelUrl = $this->NetCommonsHtml->url( - Hash::get($cancelOptions, 'url', $this->settings['cancelUrl']) + Hash::get($cancelOpt, 'url', $this->settings['cancelUrl']) ); - $cancelTitle = Hash::get($cancelOptions, 'title', __d('net_commons', 'Cancel')); - $output .= $this->Button->cancel($cancelTitle, $cancelUrl, $cancelOptions); + $cancelTitle = Hash::get($cancelOpt, 'title', __d('net_commons', 'Cancel')); + $output .= $this->Button->cancel($cancelTitle, $cancelUrl, $cancelOpt); + + //前へボタン + if ($prev) { + $prevUrl = $this->NetCommonsHtml->url(Hash::get($prevOpt, 'url', $prev['url'])); + $prevlTitle = Hash::get($prevOpt, 'title', __d('net_commons', 'BACK')); + $prevOpt['icon'] = Hash::get($prevOpt, 'icon', 'chevron-left'); + $output .= $this->Button->cancel($prevlTitle, $prevUrl, $prevOpt); + } + + //次へ・決定ボタン + if ($next) { + $nextTitle = Hash::get($nextOpt, 'title', __d('net_commons', 'NEXT')); + $nextOpt['icon'] = Hash::get($nextOpt, 'icon', 'chevron-right'); + } else { + $nextTitle = Hash::get($nextOpt, 'title', __d('net_commons', 'OK')); + } + $output .= $this->Button->save($nextTitle, $nextOpt); + + return $output; + } + +/** + * ウィザードボタン + * + * @param string $statusName ステータスのフィールド名("Modelname.fieldname") + * @param array $cancelUrl キャンセルURL + * @param array $prevUrl 前へURL + * @param array $panel panel-footerを表示するかどうか + * @return string HTML + */ + public function workflowButtons($statusName, $cancelUrl = null, $prevUrl = null, $panel = false) { + $output = ''; + + $keys = array_keys($this->settings['navibar']); + $activeKey = array_pop($keys); //ウィザードの状態取得 - $prev = null; + list($prev, ) = $this->__wizardStep($activeKey); + + //キャンセルURL + if (! $cancelUrl) { + $cancelUrl = $this->settings['cancelUrl']; + } + + //前へURL + if (! $prevUrl && $prev) { + $prevUrl = $this->NetCommonsHtml->url($prev['url']); + } + + $output .= $this->Workflow->buttons($statusName, $cancelUrl, $panel, $prevUrl); + + return $output; + } + +/** + * ウィザードの状態取得 + * + * @param string $activeKey アクティブのキー + * @return array $activeKeyがnullの場合、$nextは最後の + */ + private function __wizardStep($activeKey) { + //ウィザードの状態取得 $current = null; + $prev = null; $next = null; $step = null; foreach ($this->settings['navibar'] as $key => $navibar) { @@ -160,22 +275,7 @@ public function buttons($activeKey, $cancelOptions = [], $prevOptions = [], $nex $step = $navibar; } - if ($prev) { - $prevUrl = $this->NetCommonsHtml->url(Hash::get($prevOptions, 'url', $prev['url'])); - $prevlTitle = Hash::get($prevOptions, 'title', __d('net_commons', 'BACK')); - $prevOptions['icon'] = Hash::get($prevOptions, 'icon', 'chevron-left'); - $output .= $this->Button->cancel($prevlTitle, $prevUrl, $prevOptions); - } - - if ($next) { - $nextTitle = Hash::get($nextOptions, 'title', __d('net_commons', 'NEXT')); - $nextOptions['icon'] = Hash::get($nextOptions, 'icon', 'chevron-right'); - } else { - $nextTitle = Hash::get($nextOptions, 'title', __d('net_commons', 'OK')); - } - $output .= $this->Button->save($nextTitle, $nextOptions); - - return $output; + return array($prev, $next); } } From c1231c844e5d19fd486a2348fc07cc17ff5d4973 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Sat, 14 May 2016 21:30:45 +0900 Subject: [PATCH 2/2] =?UTF-8?q?phpmd=E3=82=A8=E3=83=A9=E3=83=BC=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- View/Helper/WizardHelper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/View/Helper/WizardHelper.php b/View/Helper/WizardHelper.php index 10bcb9cc..401cb12b 100644 --- a/View/Helper/WizardHelper.php +++ b/View/Helper/WizardHelper.php @@ -222,6 +222,7 @@ public function buttons($activeKey, $cancelOpt = [], $prevOpt = [], $nextOpt = [ * @param array $prevUrl 前へURL * @param array $panel panel-footerを表示するかどうか * @return string HTML + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ public function workflowButtons($statusName, $cancelUrl = null, $prevUrl = null, $panel = false) { $output = '';