PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/baser/plugins/blog/views/blog_posts/admin/form.php

https://github.com/hashing/basercms
PHP | 260 lines | 225 code | 8 blank | 27 comment | 28 complexity | 7e73de3eafe4cbfdf2a79c20d8b6e6fb MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * [ADMIN] ブログ記事 フォーム
  5. *
  6. * PHP versions 5
  7. *
  8. * baserCMS : Based Website Development Project <http://basercms.net>
  9. * Copyright 2008 - 2012, baserCMS Users Community <http://sites.google.com/site/baserusers/>
  10. *
  11. * @copyright Copyright 2008 - 2012, baserCMS Users Community
  12. * @link http://basercms.net baserCMS Project
  13. * @package baser.plugins.blog.views
  14. * @since baserCMS v 0.1.0
  15. * @version $Revision$
  16. * @modifiedby $LastChangedBy$
  17. * @lastmodified $Date$
  18. * @license http://basercms.net/license/index.html
  19. */
  20. $bcBaser->css('ckeditor/editor', array('inline' => true));
  21. $statuses = array(0=>'非公開', 1=>'公開');
  22. $bcBaser->link('&nbsp;', array('controller' => 'blog', 'action' => 'preview', $blogContent['BlogContent']['id'], $previewId, 'view'), array('style' => 'display:none', 'id' => 'LinkPreview'));
  23. ?>
  24. <div id="CreatePreviewUrl" style="display:none"><?php echo $bcBaser->url(array('controller' => 'blog', 'action' => 'preview', $blogContent['BlogContent']['id'], $previewId, 'create')) ?></div>
  25. <div id="AddTagUrl" style="display:none"><?php echo $bcBaser->url(array('plugin' => 'blog', 'controller' => 'blog_tags', 'action' => 'ajax_add')) ?></div>
  26. <script type="text/javascript">
  27. $(window).load(function() {
  28. $("#BlogPostName").focus();
  29. });
  30. $(function(){
  31. /**
  32. * プレビューボタンクリック時イベント
  33. */
  34. $("#BtnPreview").click(function(){
  35. var content = $("#BlogPostContent").val();
  36. var detail = $("#BlogPostDetail").val();
  37. $("#BlogPostContent").val(editor_content_tmp.getData());
  38. $("#BlogPostDetail").val(editor_detail_tmp.getData());
  39. $.ajax({
  40. type: "POST",
  41. url: $("#CreatePreviewUrl").html(),
  42. data: $("#BlogPostForm").serialize(),
  43. success: function(result){
  44. if(result) {
  45. $("#LinkPreview").trigger("click");
  46. } else {
  47. alert('プレビューの読み込みに失敗しました。');
  48. }
  49. }
  50. });
  51. $("#BlogPostContent").val(content);
  52. $("#BlogPostDetail").val(detail);
  53. return false;
  54. });
  55. $("#LinkPreview").colorbox({width:"90%", height:"90%", iframe:true});
  56. /**
  57. * フォーム送信時イベント
  58. */
  59. $("#btnSave").click(function(){
  60. editor_content_tmp.execCommand('synchronize');
  61. editor_detail_tmp.execCommand('synchronize');
  62. $("#BlogPostMode").val('save');
  63. $("#BlogPostForm").submit();
  64. });
  65. /**
  66. * ブログタグ追加
  67. */
  68. $("#BlogTagName").keypress(function(ev) {
  69. if ((ev.which && ev.which === 13) || (ev.keyCode && ev.keyCode === 13)) {
  70. $("#BtnAddBlogTag").click();
  71. return false;
  72. } else {
  73. return true;
  74. }
  75. });
  76. $("#BtnAddBlogTag").click(function(){
  77. if(!$("#BlogTagName").val()) {
  78. return;
  79. }
  80. $.ajax({
  81. type: "POST",
  82. url: $("#AddTagUrl").html(),
  83. data: {'data[BlogTag][name]': $("#BlogTagName").val()},
  84. dataType: 'html',
  85. beforeSend: function() {
  86. $("#BtnAddBlogTag").attr('disabled', 'disabled');
  87. $("#TagLoader").show();
  88. },
  89. success: function(result){
  90. if(result) {
  91. $("#BlogTags").append(result);
  92. $("#BlogTagName").val('');
  93. } else {
  94. alert('ブログタグの追加に失敗しました。既に登録されていないか確認してください。');
  95. }
  96. },
  97. error: function(){
  98. alert('ブログタグの追加に失敗しました。');
  99. },
  100. complete: function(xhr, textStatus) {
  101. $("#BtnAddBlogTag").removeAttr('disabled');
  102. $("#TagLoader").hide();
  103. $("#BlogTags").effect("highlight",{},1500);
  104. }
  105. });
  106. });
  107. });
  108. </script>
  109. <?php if($this->action == 'admin_edit'): ?>
  110. <div class="em-box align-left">
  111. <?php if($bcForm->value('BlogPost.status')): ?>
  112. この記事のURL<?php $bcBaser->link(
  113. $bcBaser->getUri('/' . $blogContent['BlogContent']['name'] . '/archives/' . $bcForm->value('BlogPost.no')),
  114. '/' . $blogContent['BlogContent']['name'] . '/archives/' . $bcForm->value('BlogPost.no')) ?>
  115. <?php else: ?>
  116. この記事のURL<?php echo $bcBaser->getUri('/' . $blogContent['BlogContent']['name'] . '/archives/' . $bcForm->value('BlogPost.no')) ?>
  117. <?php endif ?>
  118. </div>
  119. <?php endif ?>
  120. <?php /* BlogContent.idを第一引数にしたいが為にURL直書き */ ?>
  121. <?php if($this->action=='admin_add'): ?>
  122. <?php echo $bcForm->create('BlogPost', array('url' => array('controller' => 'blog_posts', 'action' => 'add', $blogContent['BlogContent']['id']), 'id' => 'BlogPostForm')) ?>
  123. <?php elseif($this->action == 'admin_edit'): ?>
  124. <?php echo $bcForm->create('BlogPost', array('url' => array('controller' => 'blog_posts', 'action' => 'edit', $blogContent['BlogContent']['id'], $bcForm->value('BlogPost.id'), 'id' => false), 'id' => 'BlogPostForm')) ?>
  125. <?php endif; ?>
  126. <?php echo $bcForm->input('BlogPost.id', array('type' => 'hidden')) ?>
  127. <?php echo $bcForm->input('BlogPost.blog_content_id', array('type' => 'hidden', 'value' => $blogContent['BlogContent']['id'])) ?>
  128. <?php echo $bcForm->hidden('BlogPost.mode') ?>
  129. <!-- form -->
  130. <div class="section">
  131. <table cellpadding="0" cellspacing="0" id="FormTable" class="form-table">
  132. <?php if($this->action == 'admin_edit'): ?>
  133. <tr>
  134. <th class="col-head" style="width:53px"><?php echo $bcForm->label('BlogPost.no', 'NO') ?></th>
  135. <td class="col-input">
  136. <?php echo $bcForm->value('BlogPost.no') ?>
  137. <?php echo $bcForm->input('BlogPost.no', array('type' => 'hidden')) ?>
  138. </td>
  139. </tr>
  140. <?php endif; ?>
  141. <?php if($categories): ?>
  142. <tr>
  143. <th class="col-head"><?php echo $bcForm->label('BlogPost.blog_category_id', 'カテゴリー') ?></th>
  144. <td class="col-input">
  145. <?php echo $bcForm->input('BlogPost.blog_category_id', array('type' => 'select', 'options' => $categories, 'escape' => false)) ?>
  146. <?php echo $bcForm->error('BlogPost.blog_category_id') ?>
  147. </td>
  148. </tr>
  149. <?php endif ?>
  150. <tr>
  151. <th class="col-head"><?php echo $bcForm->label('BlogPost.name', 'タイトル') ?>&nbsp;<span class="required">*</span></th>
  152. <td class="col-input">
  153. <?php echo $bcForm->input('BlogPost.name', array('type' => 'text', 'size' => 40, 'maxlength' => 255, 'counter' => true)) ?>
  154. <?php echo $bcForm->error('BlogPost.name') ?>
  155. </td>
  156. </tr>
  157. <tr>
  158. <th class="col-head"><?php echo $bcForm->label('BlogPost.content', '本文') ?></th>
  159. <td class="col-input">
  160. <?php echo $bcForm->ckeditor('BlogPost.content',
  161. array('cols' => 60, 'rows' => 20),
  162. $ckEditorOptions1) ?>
  163. <?php echo $bcForm->error('BlogPost.content') ?>
  164. </td>
  165. </tr>
  166. <tr>
  167. <th class="col-head"><?php echo $bcForm->label('BlogPost.detail', '詳細') ?></th>
  168. <td class="col-input">
  169. <?php echo $bcForm->ckeditor('BlogPost.detail',
  170. array('cols' => 60, 'rows' => 20),
  171. $ckEditorOptions2) ?>
  172. <?php echo $bcForm->error('BlogPost.detail') ?>
  173. </td>
  174. </tr>
  175. <?php if(!empty($blogContent['BlogContent']['tag_use'])): ?>
  176. <tr>
  177. <th class="col-head"><?php echo $bcForm->label('BlogTag.BlogTag', 'タグ') ?></th>
  178. <td class="col-input">
  179. <div class="clearfix" id="BlogTags" style="padding:5px">
  180. <?php echo $bcForm->input('BlogTag.BlogTag',
  181. array('type' => 'select', 'multiple' => 'checkbox', 'options' => $bcForm->getControlSource('BlogPost.blog_tag_id'))) ?>
  182. </div>
  183. <?php echo $bcForm->error('BlogTag.BlogTag') ?>
  184. <?php echo $bcForm->input('BlogTag.name', array('type' => 'text')) ?>
  185. <?php echo $bcForm->button('新しいタグを追加', array('id' => 'BtnAddBlogTag')) ?>
  186. <?php $bcBaser->img('ajax-loader-s.gif', array('style' => 'vertical-align:middle;display:none', 'id' => 'TagLoader', 'class' => 'loader')) ?>
  187. </td>
  188. </tr>
  189. <?php endif ?>
  190. <tr>
  191. <th class="col-head"><?php echo $bcForm->label('BlogPost.status', '公開状態') ?>&nbsp;<span class="required">*</span></th>
  192. <td class="col-input">
  193. <?php echo $bcForm->input('BlogPost.status', array(
  194. 'type' => 'radio',
  195. 'options' => $statuses,
  196. 'legend' => false,
  197. 'separator' => '&nbsp;&nbsp;')) ?>
  198. <?php echo $bcForm->error('BlogPost.status') ?>
  199. &nbsp;&nbsp;
  200. <?php echo $bcForm->dateTimePicker('BlogPost.publish_begin', array('size' => 12, 'maxlength' => 10), true) ?>
  201. &nbsp;&nbsp;
  202. <?php echo $bcForm->dateTimePicker('BlogPost.publish_end', array('size' => 12, 'maxlength' => 10),true) ?><br />
  203. <?php echo $bcForm->input('BlogPost.exclude_search', array('type' => 'checkbox', 'label' => 'サイト内検索の検索結果より除外する')) ?>
  204. <?php echo $bcForm->error('BlogPost.publish_begin') ?>
  205. <?php echo $bcForm->error('BlogPost.publish_end') ?>
  206. </td>
  207. </tr>
  208. <tr>
  209. <th class="col-head"><?php echo $bcForm->label('BlogPost.user_id', '作成者') ?>&nbsp;<span class="required">*</span></th>
  210. <td class="col-input">
  211. <?php if(isset($user) && $user['user_group_id'] == 1): ?>
  212. <?php echo $bcForm->input('BlogPost.user_id', array(
  213. 'type' => 'select',
  214. 'options' => $users)) ?>
  215. <?php echo $bcForm->error('BlogPost.user_id') ?>
  216. <?php else: ?>
  217. <?php if(isset($users[$bcForm->value('BlogPost.user_id')])): ?>
  218. <?php echo $users[$bcForm->value('BlogPost.user_id')] ?>
  219. <?php endif ?>
  220. <?php echo $bcForm->hidden('BlogPost.user_id') ?>
  221. <?php endif ?>
  222. </td>
  223. </tr>
  224. <tr>
  225. <th class="col-head"><?php echo $bcForm->label('BlogPost.posts_date', '作成日') ?>&nbsp;<span class="required">*</span></th>
  226. <td class="col-input">
  227. <?php echo $bcForm->dateTimePicker('BlogPost.posts_date', array('size' => 12, 'maxlength' => 10), true) ?>
  228. <?php echo $bcForm->error('BlogPost.posts_date') ?>
  229. </td>
  230. </tr>
  231. </table>
  232. </div>
  233. <!-- button -->
  234. <div class="submit">
  235. <?php if($this->action == 'admin_add'): ?>
  236. <?php echo $bcForm->button('登録', array('div' => false, 'class' => 'btn-red button', 'id' => 'btnSave')) ?>
  237. <?php echo $bcForm->button('保存前確認', array('div' => false, 'class' => 'btn-green button', 'id' => 'BtnPreview')) ?>
  238. <?php elseif ($this->action == 'admin_edit'): ?>
  239. <?php if($editable): ?>
  240. <?php echo $bcForm->button('更新', array('div'=>false, 'class' => 'btn-orange button', 'id'=>'btnSave')) ?>
  241. <?php endif ?>
  242. <?php echo $bcForm->button('保存前確認', array('div' => false, 'class' => 'btn-green button', 'id' => 'BtnPreview')) ?>
  243. <?php if($editable): ?>
  244. <?php $bcBaser->link('削除',
  245. array('action' => 'delete', $blogContent['BlogContent']['id'], $bcForm->value('BlogPost.id')),
  246. array('class'=>'btn-gray button'),
  247. sprintf('%s を本当に削除してもいいですか?', $bcForm->value('BlogPost.name')),
  248. false); ?>
  249. <?php endif ?>
  250. <?php endif ?>
  251. </div>
  252. <?php echo $bcForm->end() ?>