Commit ccd51f2d by tady

mod-confirm-unload

parent b944d9c9
......@@ -18,3 +18,4 @@
//= require_tree .
_.mixin(_.string.exports());
$ ->
# search form animation
# 上部の検索フォームのアニメーション
$('#app-search-form input')
.on 'focus', ->
$(this).parents('#app-search-form').animate({width: '400px'})
.on 'blur', ->
$(this).parents('#app-search-form').animate({width: '200px'})
# コードハイライト
# TODO
prettyPrint()
# Desc
# ページから離脱するときに確認画面を出す
# `.js-disable-confirm-unload`クラスのついた要素をクリックした時に無効にする
# Usage:
# $.setConfirmUnload()
$.extend
setConfirmUnload: ->
confirmUnload = ->
return 'このページを離れますか?'
$(window).on('beforeunload', confirmUnload)
$('.js-disable-confirm-unload').on 'click', ->
$(window).off('beforeunload', confirmUnload)
return @
......@@ -5,6 +5,7 @@ class PostsController < ApplicationController
before_action :require_login
layout 'app'
# TODO: not to use
include ApplicationHelper
include RV::Mailer
......@@ -19,6 +20,7 @@ class PostsController < ApplicationController
end
def preview
# TODO: not to use
render text: h_application_format_markdown(params[:text])
end
......
class TagsController < ApplicationController
before_action :set_tag, only: [:show, :edit, :update, :destroy]
layout 'app'
def index
end
def show
@tag = Tag.find_by(tag_params)
@posts = @tag.posts
end
def new
@tag = Tag.new
end
def edit
end
def create
@tag = Tag.new(tag_params)
@tag.author = current_user
respond_to do |format|
if @tag.save
format.html { redirect_to root_path(id: @tag.id), flash: { notice: 'Tag was successfully created.' } }
format.json { render action: 'show', status: :created, location: @tag }
else
format.html { render action: 'new' }
format.json { render json: @tag.errors, status: :unprocessable_entity }
end
end
end
def update
@tag.author = current_user
respond_to do |format|
if @tag.update(tag_params)
format.html { redirect_to root_path(id: @tag.id), flash: { notice: 'Tag was successfully updated.' } }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @tag.errors, status: :unprocessable_entity }
end
end
end
def destroy
@tag.destroy
respond_to do |format|
format.html { redirect_to posts_url, flash: { success: 'Tag successfully deleted.' } }
format.json { head :no_content }
end
end
def merge_to
@tag = Tag.find_by(tag_params) or raise ActiveRecord::RecordNotFound
@merge_to_tag = Tag.find_by(name: params[:merge_to_name]) or raise ActiveRecord::RecordNotFound
@tag.move_all_posts_to!(@merge_to_tag)
......@@ -18,8 +64,10 @@ class TagsController < ApplicationController
private
def tag_params
params.permit(:name).to_hash
def set_tag
tag = Tag.find_by(name: params[:name]) or raise ActiveRecord::RecordNotFound
@tag = tag.decorate
end
end
......@@ -13,7 +13,11 @@ class TagDecorator < Draper::Decorator
# tagページのURL
# urlエンコードを施す
def show_path
h.show_tag_path(name: h.url_encode(model.name))
h.tag_path(name: h.url_encode(model.name))
end
def edit_path
h.edit_tag_path(name: h.url_encode(model.name))
end
# tagをtree viewで表示する
......
......@@ -32,7 +32,7 @@
<div class="col-md-2">
<div class="actions">
<%= f.submit class: 'btn btn-primary', id: 'save_button' %>
<%= f.submit class: 'btn btn-primary js-disable-confirm-unload', id: 'save_button' %>
</div>
</div>
......@@ -55,7 +55,6 @@
<div class="box-text">
<div id="post_preview" class="text-box body viewer github">
<%#= h_application_format_markdown(sample_body).html_safe %>
</div>
</div>
......@@ -67,7 +66,6 @@
<% content_for :footer_js do %>
<script type="text/javascript">
$.setConfirmUnload()
</script>
<% end %>
<h1>新しい投稿</h1>
<h1>編集</h1>
<%= render 'form' %>
<%= form_for(@tag) do |f| %>
<% if @tag.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tag.errors.count, "error") %> prohibited this tag from being saved:</h2>
<ul>
<% @tag.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="row">
<div class="col-md-10">
<div class="field">
<div class="input-group">
<span class="input-group-addon"><%= f.label :name %></span>
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
</div>
<div class="col-md-2">
<div class="actions">
<%= f.submit class: 'btn btn-primary', id: 'save_button' %>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-6 col-md-6">
<div class="field">
<!-- <%= f.label :body %><br> -->
<%= f.text_area :body, class: 'autosize editor disable-tab' %>
</div>
</div><!--/span-->
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="box-text">
<div id="tag_preview" class="text-box body viewer github">
</div>
</div>
</div><!--/span-->
</div><!--/row-->
<% end %>
<% content_for :footer_js do %>
<script type="text/javascript">
$.setConfirmUnload()
</script>
<% end %>
<h1>編集</h1>
<%= render 'form' %>
<div class="row">
<div class="col-xs-6 col-md-4" id="sidebar" role="navigation">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-list" data-toggle="tab">List</a></li>
<li><a href="#tab-tree" data-toggle="tab">Tag Tree</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-list">
<div class="list-group">
<% @posts.each_with_index do |post, i| %>
<a href="#" data-post-id="<%= post.id %>" class="list-group-item post-list"><%= post.title %></a>
<% end %>
</div>
</div><!-- /.tab-pane -->
<div class="tab-pane" id="tab-tree">
<% cache('tag-tree', :expires_in => 1.hour) do %>
<div class="list-group">
<%= Tag.all.decorate.tree_view %>
</div>
<% end %>
</div><!-- /.tab-pane -->
</div><!-- /.tab-content -->
</div><!--/span-->
<div class="col-xs-12 col-sm-6 col-md-8">
<div id="list_post">
<p id="posts-placeholder" style="color:#aaa;font-size:30px">&lt;-- Select a post...</p>
</div>
</div><!--/span-->
</div><!--/row-->
json.array!(@posts) do |post|
json.extract! post, :title, :body
json.url post_url(post, format: :json)
end
<h1>新しい投稿</h1>
<%= render 'form' %>
......@@ -6,7 +6,7 @@
<div class="col-xs-4">
<div class="btn-group pull-right">
<a class="btn btn-primary" href="#">
<a class="btn btn-primary" href="<%= @tag.edit_path %>">
このページを編集する <span class="glyphicon glyphicon-pencil"></span>
</a>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
......
json.extract! @post, :title, :body, :created_at, :updated_at
Rendezvous::Application.routes.draw do
root 'home#top', as: 'root'
post 'posts/preview' => 'posts#preview'
# get 'posts/show_fragment' => 'posts#show_fragment'
get 'posts/:id/fork' => 'posts#fork', as: 'fork_post'
post 'posts/:id/mail' => 'posts#mail', as: 'mail_post'
post 'posts/:id/comment' => 'posts#comment', as: 'comment_post'
resources :posts
get 'tags/:name' => 'tags#show', as: 'show_tag'
post 'tags/:name/merge_to/:merge_to_name' => 'tags#merge_to', as: 'merge_to_tag'
resources :tags, :param => :name
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment