Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YOSHIDA Hiroki
committed
Jun 27, 2015
1 parent
cdf963d
commit 20496ce
Showing
2 changed files
with
62 additions
and
70 deletions.
There are no files selected for viewing
123 changes: 56 additions & 67 deletions
123
backend/app/assets/javascripts/comable/admin/pages.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,69 @@ | ||
$(document).ready( -> | ||
# 公開/非公開の制御 | ||
disp_published_at_by_published() | ||
class @Page | ||
constructor: -> | ||
$(document).ready(@ready) | ||
|
||
# 日付を空にされたら非公開にする | ||
swicth_unpublished_by_page_published_at() | ||
ready: => | ||
@radio_published = $('#page_published_at_published') | ||
@radio_unpublished = $('#page_published_at_unpublished') | ||
@published_at = $('#page_published_at') | ||
|
||
# ページタイトルの制御 | ||
set_page_title() | ||
@initialize_visibility() | ||
@add_event_to_set_visibility() | ||
@add_event_to_set_page_title() | ||
@add_event_to_set_meta_description() | ||
|
||
# メタディスクリプションの制御 | ||
set_meta_description() | ||
) | ||
# 公開/非公開の制御 | ||
initialize_visibility: -> | ||
if @radio_published.is(':checked') | ||
@published() | ||
if @radio_unpublished.is(':checked') | ||
@unpublished() | ||
|
||
# 公開/非公開の制御 | ||
disp_published_at_by_published = -> | ||
# 初期状態 | ||
if $('#published_true').prop('checked') is true | ||
published_action() | ||
if $('#published_false').prop('checked') is true | ||
unpublished_action() | ||
# 公開の際の制御 | ||
published: => | ||
@published_at.show() | ||
@published_at.val(moment().format('YYYY-MM-DD HH:mm')) unless @published_at.val() | ||
|
||
# 公開がチェックされた時 | ||
$('#published_true').click( -> | ||
published_action() | ||
) | ||
# 非公開の際の制御 | ||
unpublished: => | ||
@published_at.hide() | ||
@published_at.val('') | ||
|
||
# 非公開がチェックされた時 | ||
$('#published_false').click( -> | ||
unpublished_action() | ||
) | ||
add_event_to_set_visibility: -> | ||
@radio_published.click(@published) | ||
@radio_unpublished.click(@unpublished) | ||
|
||
# 公開の際の制御 | ||
published_action = -> | ||
$('#page_published_at').show() | ||
if $('#page_published_at').val() == '' | ||
$('#page_published_at').val(moment().format("YYYY-MM-DD HH:mm")) | ||
# 日付を空にされたら非公開にする | ||
@published_at.blur( => | ||
@radio_unpublished.click() unless @published_at.val() | ||
) | ||
|
||
# 非公開の際の制御 | ||
unpublished_action = -> | ||
$('#page_published_at').hide() | ||
$('#page_published_at').val('') | ||
# ページタイトルの制御 | ||
add_event_to_set_page_title: -> | ||
$title = $('#page_title') | ||
$page_title = $('#page_page_title') | ||
|
||
# 日付を空にされたら非公開にする | ||
swicth_unpublished_by_page_published_at = -> | ||
$('#page_published_at').blur( -> | ||
if $(this).val() == '' | ||
$('#published_false').click() | ||
$(this).hide() | ||
$(this).val('') | ||
) | ||
# タイトルを入力した時にページタイトルが空だったらタイトルの値を入れる | ||
$title.blur( -> | ||
$page_title.val($(this).val()) unless $page_title.val() | ||
) | ||
|
||
# ページタイトルの制御 | ||
set_page_title = -> | ||
# タイトルを入力した時にページタイトルが空だったらタイトルの値を入れる | ||
$('#page_title').blur( -> | ||
if $('#page_page_title').val() == '' | ||
$('#page_page_title').val($(this).val()) | ||
) | ||
# ページタイトルが空にされたらタイトルの値を入れる | ||
$page_title.blur( -> | ||
$(this).val($title.val()) unless $(this).val() | ||
) | ||
|
||
# ページタイトルが空にされたらタイトルの値を入れる | ||
$('#page_page_title').blur( -> | ||
if $(this).val() == '' | ||
$(this).val($('#page_title').val()) | ||
) | ||
# メタディスクリプションの制御 | ||
add_event_to_set_meta_description: -> | ||
$content = $('#page_content') | ||
$meta_description = $('#page_meta_description') | ||
|
||
# メタディスクリプションの制御 | ||
set_meta_description = -> | ||
# 内容を入力した時にページタイトルが空だったら内容の値を入れる | ||
$('#page_content').blur( -> | ||
if $('#page_meta_description').val() == '' | ||
$('#page_meta_description').val($($(this).val()).text()) | ||
) | ||
# 内容を入力した時にメタディスクリプションが空だったら内容の値を入れる | ||
$content.blur( -> | ||
$meta_description.val($($(this).val()).text()) unless $meta_description.val() | ||
) | ||
|
||
# メタディスクリプションが空にされたら内容の値を入れる | ||
$('#page_meta_description').blur( -> | ||
if $(this).val() == '' | ||
$html = $($('#page_content').val()) | ||
$(this).val($html.text()) | ||
) | ||
# メタディスクリプションが空にされたら内容の値を入れる | ||
$meta_description.blur( -> | ||
$(this).val($($content.val()).text()) unless $(this).val() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters