-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthKeyPopupButtonHelper.php
More file actions
110 lines (105 loc) · 3.74 KB
/
AuthKeyPopupButtonHelper.php
File metadata and controls
110 lines (105 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* PopupButtonHelper
*
* @copyright Copyright 2014, NetCommons Project
* @author Allcreator <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('AppHelper', 'View/Helper');
/**
* Authorization key poup button Helper
*
* @package NetCommons\AuthorizationKeys\View\Helper
*/
class AuthKeyPopupButtonHelper extends AppHelper {
/**
* 概要
*
* ダウンロードパスワードを求めるなど
* なんらかのアクション実行前にどうしてもキーとなるワードの入力を求めたいときに
* 表示するキーワード入力専用POPUPを出せるボタンを提供します
*
* 利用方法
* 通常のHelper利用と同様です AuthorizationKeys.AuthKeyPopupButtonをHelperとして組み込んでください。
* Viewでは、popupButtonメソッドを呼び出します。
* popupButtonでは最低限、以下の要素をオプション配列の形式で引数として与える必要があります。
* url: キーワード入力後に遷移する先のURL
*
* 必要に応じて以下の指定をすることができます
* icon: ボタンに表示するアイコン(default:glyphicon-download)
* btn-label: ボタンに表示するラベル(default:なし)
* class: ボタンのclass(default:btn btn-success)
* popup-title: POPUPダイアログに表示するタイトル(default:__d('authorization_keys', 'Authorization key confirm dialog')
* popup-label: POPUPダイアログに表示する入力エリアラベル(default:__d('authorization_keys', 'Authorization key')
* popup-placeholder: POPUPダイアログに表示するplaceholder(default:__d('authorization_keys', 'Please input authorization key')
*
* #### サンプルコード
* ```
* public $helpers = array(
* 'AuthorizationKeys.AuthKeyPopupButton',
* );
* <?php echo $this->AuthKeyPopupButton->popupButton(array(
* 'url' => NetCommonsUrl::actionUrl(.......),
* 'popup-label' => __d('questionnaires', 'Title'),
* 'popup-title' => __d('questionnaires', 'Download password'),
* ));?>
* ```
*/
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'Form',
'Html'
);
/**
* Before render callback. beforeRender is called before the view file is rendered.
*
* Overridden in subclasses.
*
* @param string $viewFile The view file that is going to be rendered
* @return void
*/
public function beforeRender($viewFile) {
$this->NetCommonsHtml->script('/authorization_keys/js/authorization_keys.js');
parent::beforeRender($viewFile);
}
/**
* Get button for popup dialog
*
* @param array $options option for input
* @return string button tag
*/
public function popupButton($options) {
$defaults = array(
'class' => 'btn btn-success',
'icon' => 'glyphicon-download',
'label' => '',
'popup-title' => __d('authorization_keys', 'Authorization key confirm dialog'),
'popup-label' => __d('authorization_keys', 'Authorization key'),
'popup-placeholder' => __d('authorization_keys', 'Please input authorization key')
);
$options = Hash::merge($defaults, $options);
if (! empty($options['icon'])) {
$icon = '<span class="glyphicon ' . $options['icon'] . '" ></span>';
} else {
$icon = '';
}
$html = '<a authorization-keys-popup-link frame-id="' . Current::read('Frame.id') . '" ' .
'class="' . $options['class'] . '" ' .
'url="' . $options['url'] . '" ' .
'popup-title="' . $options['popup-title'] . '" ' .
'popup-label="' . $options['popup-label'] . '" ' .
'popup-placeholder="' . $options['popup-placeholder'] . '">' .
$icon .
$options['label'] .
'</a>';
return $html;
}
}