/
admin_edit.ctp
208 lines (181 loc) · 6.17 KB
/
admin_edit.ctp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php echo $this->element('admin_menu');?>
<?php $this->start('css-embedded'); ?>
<?php echo $this->Html->css('summernote.css');?>
<style type='text/css'>
.form-control-upload
{
display : inline-block !important;
margin-right : 10px !important;
widht : 85%;
}
.form-control-filename
{
border : none !important;
box-shadow : none !important;
}
label span
{
font-weight: normal;
}
</style>
<?php $this->end(); ?>
<?php $this->start('script-embedded'); ?>
<?php echo $this->Html->script('summernote.min.js');?>
<?php echo $this->Html->script('lang/summernote-ja-JP.js');?>
<script>
$(document).ready(function()
{
$url = $('.form-control-upload');
$url.after('<input id="btnUpload" type="button" value="アップロード">');
$("#btnUpload").click(function(){
var val = $('input[name="data[Content][kind]"]:checked').val();
if(!val)
return false;
if(
(val=='text')||
(val=='test')
)
return false;
if(val=='url')
val = 'file';
window.open('<?php echo Router::url(array('controller' => 'contents', 'action' => 'upload'))?>/'+val, '_upload', 'width=650,height=500,resizable=no');
return false;
});
$('input[name="data[Content][kind]"]:radio').change( function() {
render();
});
// 保存時、コード表示モードの場合、解除する(編集中の内容を反映するため)
$('#ContentAdminEditForm').submit( function() {
var val = $('input[name="data[Content][kind]"]:checked').val();
if(val=='html')
{
if ($('#ContentBody').summernote('codeview.isActivated')) {
$('#ContentBody').summernote('codeview.deactivate')
}
}
});
render();
});
function render()
{
var content_kind = $('input[name="data[Content][kind]"]:checked').val();
$(".kind").hide();
$(".kind-"+content_kind).show();
$("#btnPreview").hide();
switch(content_kind)
{
case 'text': // テキスト
$("#ContentBody").summernote('destroy');
// テキストが存在しない場合、空文字にする。
if($('<span>').html($("#ContentBody").val()).text()=="")
$("#ContentBody").val("");
$("#btnPreview").show();
break;
case 'html': // リッチテキスト
// リッチテキストエディタを起動
CommonUtil.setRichTextEditor('#ContentBody', <?php echo (Configure::read('use_upload_image') ? 'true' : 'false')?>, '<?php echo $this->webroot ?>');
$("#btnPreview").show();
break;
case 'movie': // 動画
$(".form-control-upload").css('width', '85%');
$("#btnUpload").show();
$("#btnPreview").show();
break;
case 'url':
$(".form-control-upload").css('width', '100%');
$("#btnUpload").hide();
$("#btnPreview").show();
break;
case 'file':
$(".form-control-upload").css('width', '85%');
$("#btnUpload").show();
break;
case 'test':
break;
}
}
function preview()
{
var content_kind = $('input[name="data[Content][kind]"]:checked').val();
$.ajax({
url: "<?php echo Router::url(array('action' => 'preview')) ?>",
type: "POST",
data: {
content_title : $("#ContentTitle").val(),
content_kind : $('input[name="data[Content][kind]"]:checked').val(),
content_url : $("#ContentUrl").val(),
content_body : $("#ContentBody").val(),
},
dataType: "text",
success : function(response){
//通信成功時の処理
//alert(response);
var url = '<?php echo Router::url(array('controller' => 'contents', 'action' => 'preview'))?>'.replace('admin/', '');
window.open(url, '_preview', 'width=1000,height=700,resizable=no');
},
error: function(){
//通信失敗時の処理
//alert('通信失敗');
}
});
}
function setURL(url, file_name)
{
$('.form-control-upload').val(url);
if(file_name)
$('.form-control-filename').val(file_name);
}
</script>
<?php $this->end(); ?>
<div class="contents form">
<?php
$this->Html->addCrumb('コース一覧', array('controller' => 'courses', 'action' => 'index'));
$this->Html->addCrumb($course['Course']['title'], array('controller' => 'contents', 'action' => 'index', $course['Course']['id']));
echo $this->Html->getCrumbs(' / ');
?>
<div class="panel panel-default">
<div class="panel-heading">
<?php echo ($this->action == 'admin_edit') ? __('編集') : __('新規コンテンツ'); ?>
</div>
<div class="panel-body">
<?php echo $this->Form->create('Content', Configure::read('form_defaults')); ?>
<?php
echo $this->Form->input('id');
echo $this->Form->input('title', array('label' => 'コンテンツタイトル'));
echo $this->Form->input('kind', array(
'type' => 'radio',
'before' => '<label class="col col-md-3 control-label">コンテンツ種別</label>',
'separator'=>"<br>",
'disabled'=>false,
'legend' => false,
'class' => false,
'options' => Configure::read('content_kind_comment')
)
);
echo "<div class='kind kind-movie kind-url kind-file'>";
echo $this->Form->input('url', array('label' => 'URL', 'class' => 'form-control form-control-upload'));
echo "</div>";
echo "<div class='kind kind-file'>";
echo $this->Form->input('file_name', array('label' => 'ファイル名', 'class' => 'form-control-filename', 'readonly' => 'readonly'));
echo "</div>";
echo "<div class='kind kind-text kind-html'>";
echo $this->Form->input('body', array('label' => '内容'));
echo "</div>";
echo "<span class='kind kind-test'>";
echo $this->Form->input('timelimit', array('label' => '制限時間 (0-100分)'));
echo $this->Form->input('pass_rate', array('label' => '合格とする得点率 (0-100%)'));
echo "</span>";
echo "<span class='kind kind-text kind-html kind-movie kind-url kind-file kind-test'>";
echo $this->Form->input('comment', array('label' => '備考'));
echo "</span>";
?>
<div class="form-group">
<div class="col col-md-9 col-md-offset-3">
<button id="btnPreview" class="btn btn-default" value="プレビュー" onclick="preview(); return false;" type="submit">プレビュー</button>
<?php echo $this->Form->submit('保存', Configure::read('form_submit_defaults')); ?>
</div>
</div>
<?php echo $this->Form->end(); ?>
</div>
</div>
</div>