//= require_directory ./views/stories
//= require_directory ./views/story_sheets
//= require_directory ./views/system_pictures
+//= require_directory ./views/top
+//= require_directory ./views/users
//= require_directory ./views/writing_formats
//= require_directory ./addons/pettanr_creative_commons_v30_licenses
//= require_directory ./addons/pettanr_pettan_commons_v01_licenses
--- /dev/null
+class Pettanr.TopController extends Pettanr.AppController\r
+ \r
+ index: () ->\r
+ r = new Pettanr.Views.Top.Index({operators: window.operators})\r
+ $("html").html(r.render().el)\r
+ \r
class Pettanr.UsersController extends Pettanr.AppController\r
\r
+ index: () ->\r
+ r = new Pettanr.Views.User.Index({})\r
+ $("#pettanr").html(r.render().el)\r
+ \r
loaded_local_manifest = new LocalManifest(data)\r
)\r
$.ajaxSetup({async: true})\r
- author_id = $("#pettanr").attr('author_id')\r
- artist_id = $("#pettanr").attr('artist_id')\r
- author = new Pettanr.Author({id: author_id})\r
- author.fetch({cache: true}).done ->\r
- artist = new Pettanr.Artist({id: artist_id})\r
- artist.fetch({cache: true}).done ->\r
- user = new Pettanr.User({id: author.get('user_id')})\r
+ \r
+ Manifest.set_manifest(loaded_manifest)\r
+ LocalManifest.set_manifest(loaded_local_manifest)\r
+ loaded_manifest.init()\r
+ loaded_local_manifest.init()\r
+ window.operators = new Pettanr.Operator({})\r
+ \r
+ r = new Pettanr.Views.Top.Index({})\r
+ $("#header").html(r.render().el)\r
+ \r
+ # try getting current user(copy paste from users/index)\r
+ user = new Backbone.Model()\r
+ user.url = '/users/sign_in'\r
+ user.save({}, {\r
+ success: (model, response, options) ->\r
+ author = new Pettanr.Author(user.get('author')) if user.get('author')\r
+ artist = new Pettanr.Artist(user.get('artist')) if user.get('artist')\r
window.operators = new Pettanr.Operator({\r
+ user: user, \r
author: author, \r
- artist: artist, \r
- user: user\r
+ artist: artist\r
})\r
- Manifest.set_manifest(loaded_manifest)\r
- LocalManifest.set_manifest(loaded_local_manifest)\r
- loaded_manifest.init()\r
- loaded_local_manifest.init()\r
- \r
- window.onbeforeunload = (e)->\r
- return('leave?')\r
- window.router = new Pettanr.Router()\r
- Backbone.history.start({pushState: true})\r
+ r = new Pettanr.Views.Top.Account({operators: window.operators})\r
+ $('#account').html(r.render().el)\r
window.router.navigate('', true)\r
+ error: (model, response, options) ->\r
+ response.status\r
+ })\r
+ \r
+ window.onbeforeunload = (e)->\r
+ return('leave?')\r
+ window.router = new Pettanr.Router()\r
+ Backbone.history.start({pushState: true})\r
+ window.router.navigate('', true)\r
\r
t: () ->\r
#i = new Pettanr.Balloon({id: 49})\r
name: 'no name'\r
} \r
\r
+ icon_with_caption_view: (half = true, column_name = 'name', length = 12) ->\r
+ new Pettanr.Views.Common.IconWithCaption({item: this, half: half, column_name: column_name, length: length})\r
+ \r
initialize: () ->\r
if @id\r
@url = @url + @id\r
name: 'no name'\r
} \r
\r
- name_view: (length = null) ->\r
- new Pettanr.Views.Author.Name({item: this, length: length})\r
- \r
- icon_with_caption_view: (half, column_name, length) ->\r
+ icon_with_caption_view: (half = true, column_name = 'name', length = 12) ->\r
new Pettanr.Views.Common.IconWithCaption({item: this, half: half, column_name: column_name, length: length})\r
\r
initialize: () ->\r
this.route(':controller/:id', 'c_i')\r
this.route(':controller?*query_string', 'c')\r
this.route(':controller', 'c')\r
+ this.route('users/sign_in', 'user_sign_in')\r
\r
home: () ->\r
params = {}\r
params['action'] = 'root'\r
@fire(params)\r
\r
+ user_sign_in: () ->\r
+ r = new Pettanr.UsersController()\r
+ r.index()\r
+ \r
hoge: () ->\r
names = _.map Manifest.manifest().controllers, (controller_manifest, controller_name) ->\r
c = Pettanr[Pettanr.camelize(controller_name) + 'Controller']\r
class Pettanr.Views.Author extends Pettanr.Views.Base\r
class Pettanr.Views.Artist extends Pettanr.Views.Base\r
class Pettanr.Views.SystemPicture extends Pettanr.Views.Base\r
+class Pettanr.Views.Top extends Pettanr.Views.Base\r
+class Pettanr.Views.User extends Pettanr.Views.Base\r
class Pettanr.Views.Home extends Pettanr.Views.Base\r
+++ /dev/null
-class Pettanr.Views.Author.Name extends Backbone.View\r
- tagName: 'span'\r
- \r
- initialize: (options) ->\r
- @item = options.item\r
- @length = options.length\r
- @name = Pettanr.truncate(@item.get('name'), @length)\r
- @url = Pettanr.url(@item.table_name(), 'show', {id: @item.get('id')})\r
- @linked_name = new Tag.A({\r
- attr: {href: '/' + @url}, \r
- handler_name: @url,\r
- content: @name\r
- })\r
- \r
- render: () ->\r
- this.$el.html(@linked_name.render().el)\r
- this\r
- \r
\r
initialize: (options) ->\r
@item = options.item\r
+ options['visible_t'] = 'panel_publish_items'\r
+ options['visible_column_name'] = 'publish'\r
@visible = new Tag.Div({\r
content: Pettanr.AppHelper.t_selected_item(@visible_t, @item.get(@visible_column_name))\r
})\r
--- /dev/null
+class Pettanr.Views.Top.Account extends Backbone.View\r
+ tagName: 'div'\r
+ \r
+ initialize: (options) ->\r
+ @operators = options.operators\r
+ \r
+ render: () ->\r
+ this.$el.html('')\r
+ if au = @operators.author\r
+ author = au.icon_with_caption_view()\r
+ this.$el.append(author.render().el)\r
+ if ar = @operators.artist\r
+ artist = ar.icon_with_caption_view()\r
+ this.$el.append(artist.render().el)\r
+ sign_out = new Tag.A({attr: {href: '/'}, class_name: 'sign_out', content: 'sign out'})\r
+ this.$el.append(sign_out.render().el)\r
+ @delegateEvents({'click .sign_out': 'sign_out'})\r
+ this\r
+ \r
+ sign_out: () ->\r
+ user = new Backbone.Model({id: 0})\r
+ user.url = '/users/sign_out'\r
+ user.destroy({success: () ->\r
+ r = new Pettanr.Views.Top.Index({})\r
+ $("#header").html(r.render().el)\r
+ $("#pettanr").html('')\r
+ })\r
+ return false\r
+ \r
--- /dev/null
+class Pettanr.Views.Top.Index extends Backbone.View\r
+ tagName: 'div'\r
+ className: 'account'\r
+ \r
+ initialize: (options) ->\r
+ @operators = options.operators\r
+ \r
+ render: () ->\r
+ this.$el.html('')\r
+ t = _.template($("#header_template").html())\r
+ this.$el.append(t())\r
+ @delegateEvents({'click .sign_in': 'click_sign_in'})\r
+ this\r
+ \r
+ click_sign_in: () ->\r
+ window.router.navigate('users/sign_in', true)\r
+ return false\r
+ \r
--- /dev/null
+class Pettanr.Views.User.Index extends Backbone.View\r
+ tagName: 'div'\r
+ \r
+ initialize: (options) ->\r
+ @operators = options.operators\r
+ \r
+ render: () ->\r
+ this.$el.html('')\r
+ t = _.template($("#sign_in").html())\r
+ this.$el.append(t())\r
+ @delegateEvents({'submit': 'sign_in'})\r
+ this\r
+ \r
+ sign_in: () ->\r
+ m = $('#user_email').val()\r
+ p = $('#user_password').val()\r
+ user = new Backbone.Model()\r
+ user.url = '/users/sign_in'\r
+ user.save({user: {email: m, password: p}}, {\r
+ success: (model, response, options) ->\r
+ author = new Pettanr.Author(user.get('author')) if user.get('author')\r
+ artist = new Pettanr.Artist(user.get('artist')) if user.get('artist')\r
+ window.operators = new Pettanr.Operator({\r
+ user: user, \r
+ author: author, \r
+ artist: artist\r
+ })\r
+ r = new Pettanr.Views.Top.Account({operators: window.operators})\r
+ $('#account').html(r.render().el)\r
+ window.router.navigate('', true)\r
+ error: (model, response, options) ->\r
+ response.status\r
+ })\r
+ return false\r
+ \r
float: left;
}
-.op-smy div,span {
+.op-smy div {
+ float: left;
+}
+
+.op-smy span {
float: left;
}
before_filter :authenticate_user, :only => []
before_filter :authenticate_author, :only => []
else
- before_filter :authenticate_reader, :only => [:index, :ap]
+ before_filter :authenticate_reader, :only => []#[:index]
before_filter :authenticate_user, :only => []
before_filter :authenticate_author, :only => []
end
--- /dev/null
+class UserSessionsController < Devise::SessionsController
+ prepend_before_filter :require_no_authentication, :only => [:create ]
+ respond_to :json
+
+ def create
+ if request.xhr?
+ resource = warden.authenticate!(scope: resource_name, recall: "#{controller_path}#failure")
+ sign_in(resource_name, resource)
+ return render :json => current_user.to_json({:include => {:author => {}, :artist => {}} })
+ else
+ super
+ end
+ end
+
+ def destroy
+ if request.xhr?
+ Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
+ return render :json => {:success => true}
+ else
+ super
+ end
+ end
+
+ def xhr_failure
+ return render :json => {:success => false, :errors => ["Login failed."]}
+ end
+
+ def require_no_authentication
+ if request.xhr?
+ true
+ else
+ super
+ end
+ end
+
+end
</head>\r
<body>\r
\r
-<div width="100%">\r
-<table class="no-border">\r
- <tr>\r
- <td width="50%">\r
- <h3><%= link_to manifest.magic_numbers['profile']['users']['caption'], main_app.root_path %></h3>\r
- </td>\r
- <td width="30%">\r
- <% if user_signed_in? %>\r
- <%# link_to t('top.metro.title'), '/top/metro' %>\r
- <% end %>\r
- </td>\r
- <td>\r
- <div>\r
- <% if @operators.author %>\r
- <%= link_to h(truncate(@operators.author.name, :length => 12)), main_app.author_path(@operators.author) %>\r
- <% end %>\r
- </div>\r
- <div>\r
- <% if @operators.artist %>\r
- <%= link_to h(truncate(@operators.artist.name, :length => 12)), main_app.artist_path(@operators.artist) %>\r
- <% end %>\r
- </div>\r
- </td>\r
- <td>\r
- <% if user_signed_in? %>\r
- <%= link_to t('home.configure.title'), '/home/configure' %>\r
- <%= link_to t('home.sign_out.title'), main_app.destroy_user_session_path, :method => :delete %>\r
- <% else %>\r
- <%= link_to "sign in", main_app.new_user_session_path %>\r
- <% end %>\r
- </td>\r
- </tr>\r
-</table>\r
+<div id="header">\r
</div>\r
-<%= yield %>\r
-<div width="100%" style="background-color: #faddfa; padding: 5px;">\r
- <%= link_to t('tab.demander.title'), main_app.demanders_path %>\r
- <% if demand_user_signed_in? %>\r
- <%= link_to t_m('Demander'), main_app.demanders_path %>\r
- <%= link_to t('home.sign_out.title'), main_app.destroy_demand_user_session_path, :method => :delete %>\r
- <% else %>\r
- <%= link_to t('home.sign_in.title'), main_app.new_demand_user_session_path %>\r
- <% end %>\r
+<div id="body">\r
+<div id="pettanr">\r
</div>\r
-<div width="100%" style="background-color: #ddddfa; padding: 5px;">\r
- <%= link_to t('tab.system.title'), '/system' %>\r
- <% if admin_signed_in? %>\r
- <%= link_to t('tab.system.browse'), '/system/browse' %>\r
- <%= link_to t('tab.system.approve'), '/system/waiting_list' %>\r
- <%= link_to t('tab.system.port'), '/system/import' %>\r
- <%= link_to t('tab.system.token'), '/system/auth_token' %>\r
- <%= link_to t('home.sign_out.title'), main_app.destroy_admin_session_path, :method => :delete %>\r
- <% else %>\r
- <%= link_to t('home.sign_in.title'), main_app.new_admin_session_path %>\r
- <% end %>\r
</div>\r
-<%= javascript_tag 'var server_result=' + @server_result.to_json + ';' %>\r
+<div id="footer">\r
+</div>\r
+<script type="text/template" id="header_template">\r
+ <div id="account">\r
+ <a class="sign_in" href="/users/sign_in">sign_in</a>\r
+ </div>\r
+</script>\r
+<script type="text/template" id="sign_in">\r
+ <h3><&= 'title' &></h3>\r
+ <form method="post" action="/users/sign_in" accept-charset="UTF-8">\r
+ <div>\r
+ <label for="user_email">em</label><br>\r
+ <input type="email" value="" size="30" name="user[email]" id="user_email">\r
+ </div>\r
+\r
+ <div>\r
+ <label for="user_password">pw</label><br>\r
+ <input type="password" size="30" name="user[password]" id="user_password">\r
+ </div>\r
+\r
+ <div>\r
+ <input type="hidden" value="0" name="user[remember_me]">\r
+ <input type="checkbox" value="1" name="user[remember_me]" id="user_remember_me">\r
+ <label for="user_remember_me">remember_me</label>\r
+ </div>\r
\r
+ <div>\r
+ <input type="submit" value="login" name="commit">\r
+ </div>\r
+</form>\r
+</script>\r
</body>\r
</html>\r
-<div id="pettanr">\r
-</div>\r
-<script type="text/template" id="templates-filer-filer">\r
- <&= filer.header.render().el.innerHTML &>\r
- <&= filer.body.render().el.innerHTML &>\r
-</script>\r
-<script type="text/template" id="templates-filer-header">\r
- <&= Pettanr.AppHelper.icon_tag(header.icon_name(), {'size': header.icon_size()}) &>\r
- <a href="#" class="model_name_human">\r
- <&= Pettanr.AppHelper.t_m(header.model().singular()) &>\r
- </a>\r
-</script>\r
-<script type="text/template" id="templates-filer-body">\r
- <ul class="filer-body">\r
- <&= body.file_header.render().el.outerHTML &>\r
- <&= body.file_body.render().el.outerHTML &>\r
- </ul>\r
- <div class="row_break">\r
- </div>\r
-</script>\r
-<script type="text/template" id="templates-filer-file_header">\r
- <&= file_header.symbol.render().el.outerHTML &>\r
- <&= file_header.caption.render().el.outerHTML &>\r
- <&= file_header.summary.render().el.outerHTML &>\r
- <&= file_header.icon.render().el.outerHTML &>\r
- <&= file_header.date.render().el.outerHTML &>\r
- <&= file_header.edit.render().el.outerHTML &>\r
-</script>\r
-<script type="text/template" id="templates-filer-file_body">\r
- <&= file_body.file_item.render().el.outerHTML &>\r
-</script>\r
-<script type="text/template" id="templates-filer-header_column-show">\r
- <&= I18n.t('filer.header.' + header_column.column_name) &>\r
-</script>\r
-<script type="text/template" id="templates-filer-header_column-none">\r
-</script>\r
-<script type="text/template" id="templates-filer-item_column-show">\r
- <&= item_column.render_item().el.innerHTML &>\r
-</script>\r
-<script type="text/template" id="templates-filer-item_column-none">\r
-</script>\r
-\r
-<script type="text/template" id="templates-filer-symbol-default">\r
- <a href="javascript:void(0)">\r
- <&= item_column.face.render().el &>\r
- </a>\r
-</script>\r
-<script type="text/template" id="templates-filer-symbol-default_without_link">\r
- <&= item_column.face.render().el &>\r
-</script>\r
-<script type="text/template" id="templates-filer-symbol-template">\r
- <&= item_column.template_name &>\r
-</script>\r
-<script type="text/template" id="templates-filer-symbol_face-image">\r
- <&= Pettanr.AppHelper.image_tag(item_column.url(), {'size': item_column.icon_size()}) &>\r
-</script>\r
-<script type="text/template" id="templates-filer-symbol_face-picture">\r
- <&= Pettanr.AppHelper.image_tag(item_column.url(), {'size': item_column.icon_size()}) &>\r
-</script>\r
-\r
-<script type="text/template" id="templates-filer-caption-default">\r
- <&= item_column.face.render().el.outerHTML &>\r
-</script>\r
-<script type="text/template" id="templates-filer-caption-default_without_link">\r
- <&= item_column.face.render() &>\r
-</script>\r
-<script type="text/template" id="templates-filer-caption-template">\r
- <&= item_column.template_name &>\r
-</script>\r
-<script type="text/template" id="templates-filer-caption_face-column">\r
- <&= item_column.face() &>\r
-</script>\r
-<script type="text/template" id="templates-filer-caption_face-method">\r
- <&= item_column.face() &>\r
-</script>\r
-<script type="text/template" id="templates-filer-caption_face-empty">\r
- <&= 'empty' &>\r
-</script>\r
-\r
-<script type="text/template" id="templates-filer-summary-template">\r
- <&= item_column.template_name &>\r
-</script>\r
-<script type="text/template" id="templates-filer-summary-none">\r
-</script>\r
-\r
-<script type="text/template" id="templates-filer-icon-default">\r
- <a href="<&= item_column.path_name() &>">\r
- <&= Pettanr.AppHelper.image_tag(item_column.icon_file_name(), {'size': item_column.icon_size()}) &>\r
- </a>\r
-</script>\r
-<script type="text/template" id="templates-filer-date-default">\r
- <&= item_column.time_ago() &>\r
-</script>\r
-<script type="text/template" id="templates-filer-date-none">\r
-</script>\r
-<script type="text/template" id="templates-filer-edit-default">\r
- <&= item_column.template_name &>\r
- # link_to tag(:img, item_column.edit_img_opt), polymorphic_path(item_column.item, :action => :edit)\r
- # link_to tag(:img, item_column.remove_img_opt), item_column.item, confirm: 'Are you sure?', :method => :delete \r
-</script>\r
-<script type="text/template" id="templates-filer-edit-account">\r
- <a href="<&= '/home/configure' &>">\r
- <&= Pettanr.AppHelper.image_tag(item_column.edit_img_file_name(), {'size': item_column.icon_size()}) &>\r
- </a>\r
-</script>\r
-<script type="text/template" id="templates-filer-edit-template">\r
- <&= item_column.template_name &>\r
- # render item_column.template_name, :item => item_column.item\r
-</script>\r
-<script type="text/template" id="templates-filer-edit-none">\r
-</script>\r
-\r
-\r
-<script type="text/template" id="folders-summary">\r
-</script>\r
-<script type="text/template" id="scrolls-show">\r
-show\r
-</script>\r
-<script type="text/template" id="scrolls-summary">\r
-</script>\r
-<script type="text/template" id="scroll_panels-summary">\r
-</script>\r
-<script type="text/template" id="comics-summary">\r
-</script>\r
-<script type="text/template" id="comic_stories-summary">\r
- P.\r
-</script>\r
-<script type="text/template" id="stories-summary">\r
- P.\r
-</script>\r
-<script type="text/template" id="story_sheets-summary">\r
-</script>\r
-<script type="text/template" id="sheets-summary">\r
-</script>\r
-<script type="text/template" id="sheet_panels-summary">\r
-</script>\r
-<script type="text/template" id="panels-summary">\r
-</script>\r
-<script type="text/template" id="panel_pictures-summary">\r
-</script>\r
-<script type="text/template" id="speech_balloons-summary">\r
-</script>\r
-<script type="text/template" id="speeches-summary">\r
-</script>\r
-<script type="text/template" id="balloons-summary">\r
-</script>\r
-<script type="text/template" id="ground_pictures-summary">\r
-</script>\r
-<script type="text/template" id="ground_colors-summary">\r
-</script>\r
-<script type="text/template" id="original_pictures-summary">\r
-</script>\r
-<script type="text/template" id="pictures-summary">\r
-</script>\r
-<script type="text/template" id="resource_pictures-summary">\r
-</script>\r
-<script type="text/template" id="speech_balloon_templates-summary">\r
-</script>\r
-<script type="text/template" id="writing_formats-summary">\r
-</script>\r
-<script type="text/template" id="license_groups-summary">\r
-</script>\r
-<script type="text/template" id="licenses-summary">\r
-</script>\r
-<script type="text/template" id="authors-summary">\r
-</script>\r
-<script type="text/template" id="artists-summary">\r
- P.\r
-</script>\r
-<div id="pettanr" author_id="<%= @operators.author.id -%>" artist_id="<%= @operators.artist.id -%>">\r
+<div id="pettanr">\r
</div>\r
-<script type="text/javascript" id="manifest">\r
- <% if @operators.author -%>;\r
- author_id = <%= @operators.author.id -%>;\r
- <% end -%>;\r
- <% if @operators.artist -%>;\r
- artist_id = <%= @operators.artist.id -%>;\r
- <% end -%>;\r
-</script>\r
# config.http_authenticatable = false
# If http headers should be returned for AJAX requests. True by default.
- # config.http_authenticatable_on_xhr = true
+ config.http_authenticatable_on_xhr = true
# The realm used in Http Basic Authentication. "Application" by default.
# config.http_authentication_realm = "Application"
#
# The :"*/*" and "*/*" formats below is required to match Internet
# Explorer requests.
- # config.navigational_formats = [:"*/*", "*/*", :html]
+ config.navigational_formats = [:"*/*", "*/*", :html, :json]
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
Pettanr::Application.routes.draw do
- devise_for :users
+ devise_for :users, controllers: {sessions: 'user_sessions'}
devise_for :admins
devise_for :demand_users