Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private function __assertButtons($result, $cancelUrl, $backUrl, $disapproval, $a

//戻るのチェック
if ($backUrl) {
$expected = '<a href="' . $backUrl . '" class="btn btn-default btn-workflow">' .
$expected = '<a href="' . $backUrl . '" class="btn btn-default btn-workflow" ng-class="{disabled: sending}">' .
'<span class="glyphicon glyphicon-chevron-left"></span> ' . __d('net_commons', 'BACK') .
'</a>';
$this->assertTextContains($expected, $result);
Expand Down
6 changes: 4 additions & 2 deletions View/Helper/ButtonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ public function cancelAndSaveAndSaveTemp($cancelUrl = null, $cancelOptions = [],
$cancelOptions
);

//戻るボタン
//前へボタン
if (isset($backUrl)) {
$output .= $this->Html->link(
'<span class="glyphicon glyphicon-chevron-left"></span> ' . __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}'
)
);
}
Expand Down
149 changes: 125 additions & 24 deletions View/Helper/WizardHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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ファイルのボタンサンプル
* (ワークフローなし)<br>
* 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 {
Expand All @@ -26,6 +77,7 @@ class WizardHelper extends AppHelper {
public $helpers = array(
'NetCommons.Button',
'NetCommons.NetCommonsHtml',
'Workflow.Workflow',
);

/**
Expand Down Expand Up @@ -124,24 +176,88 @@ 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
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
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) {
Expand All @@ -160,22 +276,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);
}

}