-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRegistrationEditHelper.php
More file actions
154 lines (145 loc) · 4.71 KB
/
RegistrationEditHelper.php
File metadata and controls
154 lines (145 loc) · 4.71 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
<?php
/**
* Registration Edit Helper
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @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');
/**
* Question edit Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Registrations\View\Helper
*/
class RegistrationEditHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'NetCommons.NetCommonsForm',
'NetCommons.NetCommonsHtml',
'Form'
);
/**
* 項目属性設定作成
*
* @param string $fieldName フィールド名
* @param string $title 見出しラベル
* @param array $options INPUT要素に与えるオプション属性
* @param string $label checkboxの時のラベル
* @return string HTML
*/
public function questionInput($fieldName, $title, $options, $label = '') {
if (isset($options['ng-model'])) {
$ngModel = $options['ng-model'];
$modelNames = explode('.', $ngModel);
$errorMsgModelName = $modelNames[0] . '.errorMessages.' . $modelNames[1];
$ret = '<div class="row form-group" ng-class="{\'has-error\': ' . $errorMsgModelName . '}">';
} else {
$ret = '<div class="row form-group">';
}
$ret .= '<label class="col-xs-2 control-label">' . $title;
if (isset($options['required']) && $options['required'] == true) {
$ret .= $this->_View->element('NetCommons.required');
}
$ret .= '</label><div class="col-xs-10">';
$type = $options['type'];
if ($this->_View->viewVars['isPublished']) {
$options = Hash::merge($options, array('disabled' => true));
}
$options = Hash::merge($options, array('div' => false, 'label' => false));
if ($type == 'wysiwyg') {
if ($this->_View->viewVars['isPublished']) {
$ret .= '<div class="well well-sm" ng-bind-html="' . $ngModel . ' | ncHtmlContent"></div>';
} else {
$ret .= $this->NetCommonsForm->wysiwyg($fieldName, $options);
}
} elseif ($type == 'checkbox') {
$options = Hash::merge($options, array('label' => $label));
$ret .= $this->NetCommonsForm->checkbox($fieldName, $options);
} else {
$ret .= $this->NetCommonsForm->input($fieldName, $options);
}
if (isset($options['ng-model'])) {
$ret .= '<div class="has-error" ng-if="' . $errorMsgModelName . '">';
$ret .= '<div class="help-block" ng-repeat="errorMessage in ' . $errorMsgModelName . '">';
$ret .= '{{errorMessage}}</div></div>';
$ret .= '</div></div>';
}
return $ret;
}
/**
* 登録フォーム属性設定作成
*
* @param string $fieldName フィールド名
* @param string $label checkboxの時のラベル
* @param array $options INPUT要素に与えるオプション属性
* @param string $help 追加説明文
* @return string HTML
*/
public function registrationAttributeCheckbox(
$fieldName, $label, $options = array(), $help = '') {
$ngModel = 'registration.registration.' . Inflector::variable($fieldName);
$ret = '<div class=" checkbox"><label>';
$options = Hash::merge(array(
'type' => 'checkbox',
'div' => false,
'label' => false,
'class' => '',
'error' => false,
'ng-model' => $ngModel,
//'ng-checked' => $ngModel . '==' . RegistrationsComponent::USES_USE,
// この記述でないと チェックON,OFFが正常に動作しない。
'ng-false-value' => '"0"',
'ng-true-value' => '"1"'
),
$options
);
$ret .= $this->NetCommonsForm->input($fieldName, $options);
$ret .= $label;
if (!empty($help)) {
$ret .= '<span class="help-block">' . $help . '</span>';
}
$ret .= '</label>';
$ret .= '<div class="has-error">';
$ret .= $this->NetCommonsForm->error($fieldName, null, array('class' => 'help-block'));
$ret .= '</div>';
$ret .= '</div>';
return $ret;
}
/**
* 登録フォーム期間設定作成
*
* @param string $fieldName フィールド名
* @param array $options オプション
* @return string HTML
*/
public function registrationAttributeDatetime($fieldName, $options) {
$ngModel = 'registration.registration.' . Inflector::variable($fieldName);
$defaultOptions = array(
'type' => 'datetime',
'id' => $fieldName,
'ng-model' => $ngModel,
);
$options = Hash::merge($defaultOptions, $options);
if (isset($options['min']) && isset($options['max'])) {
$min = $options['min'];
$max = $options['max'];
$options = Hash::merge($options, array(
'ng-focus' => 'setMinMaxDate($event, \'' . $min . '\', \'' . $max . '\')',
));
}
$ret = '';
$ret .= $this->NetCommonsForm->input($fieldName, $options);
if (!empty($help)) {
$ret .= '<span class="help-block">' . $help . '</span>';
}
return $ret;
}
}