-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBackToHelper.php
More file actions
172 lines (156 loc) · 5.14 KB
/
BackToHelper.php
File metadata and controls
172 lines (156 loc) · 5.14 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
* BackTo Helper
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('AppHelper', 'View/Helper');
/**
* BackTo Helper
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\NetCommons\View\Helper
*/
class BackToHelper extends AppHelper {
/**
* Other helpers used by HtmlHelper
*
* @var array
*/
public $helpers = array(
'Html',
'Form',
'NetCommons.Button',
);
/**
* Creates a `<button>` tag. The type attribute defaults to `type="submit"`
* You can change it to a different value by using `$options['type']`.
*
* ### Options:
*
* `escape` - HTML entity encode the $title of the button. Defaults to false.
*
* ### Original options
* `url` - The url in onclick attribute
* `icon` - Icon to be displayed on the button (only to specify the last keyword of gliphs of bootstrap components)
* `iconSize` - '' is the default size : lg / sm / xs
*
* @param string $title The button's caption. Not automatically HTML encoded
* @param string $url The url in onclick attribute
* @param array $options Array of options and HTML attributes.
* @return string A HTML button tag.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::button
*/
public function button($title, $url, $options = array()) {
//iconの有無
$iconElement = '';
if (! isset($options['icon'])) {
$options['icon'] = 'remove';
}
if ($options['icon'] !== '') {
$iconElement = '<span class="glyphicon glyphicon-' . h($options['icon']) .
'" aria-hidden="true"></span> ';
unset($options['icon']);
$title = h($title);
$options['escape'] = false;
}
//ボタンサイズ
if (Hash::get($options, 'iconSize')) {
$sizeAttr = h(' btn-' . $options['iconSize']);
} else {
$sizeAttr = $this->Button->getButtonSize();
}
$options = Hash::remove($options, 'iconSize');
if ($url) {
$inputOptions = Hash::merge(array(
'class' => 'btn btn-default btn-workflow' . $sizeAttr,
'ng-class' => '{disabled: sending}',
'ng-click' => 'sending=true',
), $options);
return $this->Html->link($iconElement . $title, $url, $inputOptions);
} else {
$inputOptions = Hash::merge(array(
'type' => 'button',
'class' => 'btn btn-default btn-workflow' . $sizeAttr,
'ng-class' => '{disabled: sending}',
), $options);
return $this->Form->button($iconElement . $title, $inputOptions);
}
}
/**
* backToPageButton Go back to the page where the plugin has been first displayed
* #### Original options
* `icon` - Icon to be displayed on the button (only to specify the last keyword of gliphs of bootstrap components)
* `iconSize` - '' is the default size : lg / sm / xs
*
* @param string $title Title string to be displayed on the button
* @param mixed $url Link url
* @param array $options Array of options and HTML arguments.
* @return string
*/
public function linkButton($title, $url, $options = array()) {
//iconの有無
$iconElement = '';
//アイコン
$icon = Hash::get($options, 'icon', 'remove');
$options = Hash::remove($options, 'icon');
if ($icon) {
$iconElement = '<span class="glyphicon glyphicon-' . h($icon) .
'" aria-hidden="true"></span> ';
}
//ボタンサイズ
if (Hash::get($options, 'iconSize')) {
$sizeAttr = h('btn-' . $options['iconSize']);
} else {
$sizeAttr = trim($this->Button->getButtonSize());
}
$options = Hash::remove($options, 'iconSize');
//class属性
$class = Hash::get($options, 'class', array());
if (is_string($class)) {
$class = explode(' ', $class);
}
if ($sizeAttr) {
$class = array_merge(['btn', 'btn-default', $sizeAttr], $class);
} else {
$class = array_merge(['btn', 'btn-default'], $class);
}
$options = Hash::remove($options, 'class');
$inputOptions = Hash::merge(
array('class' => $class),
$options,
array('escapeTitle' => false)
);
if (Hash::get($options, 'escapeTitle', true)) {
$title = h($title);
}
return $this->Html->link($iconElement . $title, $url, $inputOptions);
}
/**
* backToPageButton Go back to the page where the plugin has been first displayed
*
* @param string $title Title string to be displayed on the button
* @param array $options Array of options and HTML arguments.
* @return string
*/
public function pageLinkButton($title, $options = array()) {
$url = NetCommonsUrl::backToPageUrl(null);
return $this->linkButton($title, $url, $options);
}
/**
* backToPageButton Go back to the page where the plugin has been first displayed
*
* @param string $title Title string to be displayed on the button
* @param string $defaultField Plugin table's default action field. The value is "default_action" or "default_setting_action"
* @param array $options Array of options and HTML attributes.
* @return string
*/
public function indexLinkButton($title, $defaultField = 'default_action', $options = array()) {
$url = NetCommonsUrl::backToIndexUrl($defaultField);
return $this->linkButton($title, $url, $options);
}
}