From 3e41aa9702a596316a8d143224a8802a36399e24 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Wed, 3 Sep 2014 07:56:56 +0900 Subject: [PATCH] fix filer edit box --- .../file_body/file_item/edit/account.js.coffee | 32 +++++------- .../file_body/file_item/edit/default.js.coffee | 46 +++++++++------- .../javascripts/locmare/filer/pager.js.coffee | 3 +- app/assets/javascripts/main.js.coffee | 3 +- .../manifest/controller/action/base.js.coffee | 2 +- .../javascripts/models/original_picture.js.coffee | 8 ++- app/assets/javascripts/models/picture.js.coffee | 8 ++- .../javascripts/models/resource_picture.js.coffee | 8 ++- app/assets/javascripts/models/user.js.coffee | 3 -- app/assets/javascripts/peta/content.js.coffee | 4 +- app/assets/javascripts/peta/item.js.coffee | 3 ++ app/assets/javascripts/peta/owner.js.coffee | 2 +- app/assets/javascripts/pettanr/operator.js.coffee | 61 +++++++--------------- app/assets/javascripts/pettanr/tags.js.coffee | 12 +++++ app/views/top/index.html.erb | 7 --- 15 files changed, 100 insertions(+), 102 deletions(-) diff --git a/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/account.js.coffee b/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/account.js.coffee index e5bf1d12..4d32e1f1 100644 --- a/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/account.js.coffee +++ b/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/account.js.coffee @@ -2,31 +2,27 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.EditItemColum initialize: (options) -> super(options) + @edit_icon = new Pettanr.Picture.SymbolImg({ + attr: {'src': @edit_img_file_name()}, + half: true + }) + @edit_btn = new Pettanr.Tag.A({ + href: '/home/configure', + content: @edit_icon.render().el + }) render: () -> - args = {'item_column': this} - template = _.template($("#" + @template_name()).html()) - this.$el.html(template(args)) + this.$el.html('') + if @is_own() + this.$el.append(@edit_btn.render().el) this - template_file_name: () -> + is_own: () -> if @item.is_own(@filer().operators) - 'account' + true else - 'none' + false edit_img_file_name: () -> @image_dir() + 'edit.png' - icon_size: () -> - Manifest.manifest().magic_numbers['thumbnail_width'] / 2 - - img_opt: () -> - { - 'width': Manifest.manifest().magic_numbers['thumbnail_width'] / 2, - 'height': Manifest.manifest().magic_numbers['thumbnail_height'] / 2 - } - - edit_img_opt: () -> - _.extend(@img_opt(), {'src': @edit_img_file_name()}) - diff --git a/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/default.js.coffee b/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/default.js.coffee index 3006b39c..9932daa7 100644 --- a/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/default.js.coffee +++ b/app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/default.js.coffee @@ -2,15 +2,35 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.EditItemColum initialize: (options) -> super(options) - - column_template_file_name: () -> - 'show' - - item_template_file_name: () -> + @edit_icon = new Pettanr.Picture.SymbolImg({ + attr: {'src': @edit_img_file_name()}, + half: true + }) + @edit_btn = new Pettanr.Tag.A({ + href: '/' + Pettanr.url(@item.table_name(), 'edit', {id: @item.get('id')}), + content: @edit_icon.render().el + }) + @remove_icon = new Pettanr.Picture.SymbolImg({ + attr: {'src': @remove_img_file_name()}, + half: true + }) + @remove_btn = new Pettanr.Tag.A({ + href: '/' + Pettanr.url(@item.table_name(), 'destroy', {id: @item.get('id')}), + content: @remove_icon.render().el + }) + + render: () -> + this.$el.html('') + if @is_own() + this.$el.append(@edit_btn.render().el) + this.$el.append(@remove_btn.render().el) + this + + is_own: () -> if @item.is_own(@filer().operators) - 'default' + true else - 'none' + false edit_img_file_name: () -> @image_dir() + 'edit.png' @@ -18,15 +38,3 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.EditItemColum remove_img_file_name: () -> @image_dir() + 'remove.png' - img_opt: () -> - { - 'width': Manifest.manifest().magic_numbers['thumbnail_width'] / 2, - 'height': Manifest.manifest().magic_numbers['thumbnail_height'] / 2 - } - - edit_img_opt: () -> - _.extend(@img_opt(), {'src': @edit_img_file_name()}) - - remove_img_opt: () -> - _.extend(@img_opt(), {'src': @remove_img_file_name()}) - diff --git a/app/assets/javascripts/locmare/filer/pager.js.coffee b/app/assets/javascripts/locmare/filer/pager.js.coffee index 52a3e600..9f4dd43d 100644 --- a/app/assets/javascripts/locmare/filer/pager.js.coffee +++ b/app/assets/javascripts/locmare/filer/pager.js.coffee @@ -42,7 +42,8 @@ class Locmare.FilerModule.DefaultPager extends Locmare.FilerModule.Pager this.$el.html('') _.each @parts, (part) -> _this.$el.append(part.render().el) - this.$el.append(div('row_break').render().el) + rb = new Pettanr.Tag.Div({class_name: 'row_break'}) + this.$el.append(rb.render().el) this build: () -> diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee index c7f4d18e..2c646dbb 100644 --- a/app/assets/javascripts/main.js.coffee +++ b/app/assets/javascripts/main.js.coffee @@ -15,7 +15,8 @@ $ -> author.fetch({}) artist = new Pettanr.Artist({id: artist_id}) artist.fetch({}) - window.operators = new Pettanr.Operator([author, artist]) + user = new Pettanr.User({id: author.get('user_id')}) + window.operators = new Pettanr.Operator([author, artist, user]) $.ajaxSetup({async: true}) Manifest.set_manifest(loaded_manifest) LocalManifest.set_manifest(loaded_local_manifest) diff --git a/app/assets/javascripts/manifest/controller/action/base.js.coffee b/app/assets/javascripts/manifest/controller/action/base.js.coffee index 21263e81..4c6886fd 100644 --- a/app/assets/javascripts/manifest/controller/action/base.js.coffee +++ b/app/assets/javascripts/manifest/controller/action/base.js.coffee @@ -21,7 +21,7 @@ class Manifest.ControllerModule.ActionModule.Base extends ManifestBase.TypeNameA encode_url: (action_name, params) -> c = @parent.name - a = if action_name == 'index' or action_name == 'show' + a = if action_name == 'index' or action_name == 'show' or action_name == 'destroy' '' else '/' + action_name diff --git a/app/assets/javascripts/models/original_picture.js.coffee b/app/assets/javascripts/models/original_picture.js.coffee index fe1ffa92..5132b7f0 100644 --- a/app/assets/javascripts/models/original_picture.js.coffee +++ b/app/assets/javascripts/models/original_picture.js.coffee @@ -28,8 +28,12 @@ class Pettanr.OriginalPicture extends Peta.Content {src: @r_url(), width: @get('width'), height: @get('height')} tmb_opt_img_tag: () -> - wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height')) - {src: @r_url(), width: wh[0], height: wh[1]} + new Pettanr.Picture.SymbolPicture({ + attr: { + src: @r_url() + }, + picture: this + }) symbol_option: (cb) -> _this = this diff --git a/app/assets/javascripts/models/picture.js.coffee b/app/assets/javascripts/models/picture.js.coffee index a0f42e47..393cedd4 100644 --- a/app/assets/javascripts/models/picture.js.coffee +++ b/app/assets/javascripts/models/picture.js.coffee @@ -30,8 +30,12 @@ class Pettanr.Picture extends Peta.Content {src: @r_url(), width: @get('width'), height: @get('height')} tmb_opt_img_tag: () -> - wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height')) - new Pettanr.AppHelperImg({src: @r_url(), size: wh[0]}) + new Pettanr.Picture.SymbolPicture({ + attr: { + src: @r_url() + }, + picture: this + }) tail_opt_img_tag: (img) -> {src: img, width: @get('width'), height: @get('height')} diff --git a/app/assets/javascripts/models/resource_picture.js.coffee b/app/assets/javascripts/models/resource_picture.js.coffee index 9f4bc4b1..efb2e176 100644 --- a/app/assets/javascripts/models/resource_picture.js.coffee +++ b/app/assets/javascripts/models/resource_picture.js.coffee @@ -31,8 +31,12 @@ class Pettanr.ResourcePicture extends Peta.Content '/resource_pictures/' + @filename() + opt tmb_opt_img_tag: () -> - wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height')) - new Pettanr.AppHelperImg({src: @r_url(), size: wh[0], alt: @get('caption')}) + new Pettanr.Picture.SymbolPicture({ + attr: { + src: @r_url() + }, + picture: this + }) opt_img_tag: () -> {src: @url('full'), width: @get('width'), height: @get('height')} diff --git a/app/assets/javascripts/models/user.js.coffee b/app/assets/javascripts/models/user.js.coffee index ab77bd05..469fde4c 100644 --- a/app/assets/javascripts/models/user.js.coffee +++ b/app/assets/javascripts/models/user.js.coffee @@ -14,6 +14,3 @@ class Pettanr.User extends Backbone.Model if @id @url = @url + @id -class Pettanr.User.Collection extends Backbone.Collection - model: Pettanr.User - url: '/users' diff --git a/app/assets/javascripts/peta/content.js.coffee b/app/assets/javascripts/peta/content.js.coffee index 8777ccb4..64b7ae4a 100644 --- a/app/assets/javascripts/peta/content.js.coffee +++ b/app/assets/javascripts/peta/content.js.coffee @@ -20,7 +20,7 @@ class Peta.Content extends Peta.Item @operator: (operators) -> return null if not @owner_type() - operators[@owner_type()]() + operators[@owner_type()] # Instance Methods @@ -37,7 +37,7 @@ class Peta.Content extends Peta.Item true is_own: (operators) -> - operator = self.class.operator operators + operator = @my_class().operator(operators) return false if not operator @owner_model().get(@my_class().owner_column()) == operator.id diff --git a/app/assets/javascripts/peta/item.js.coffee b/app/assets/javascripts/peta/item.js.coffee index 294ee7aa..8fbb457b 100644 --- a/app/assets/javascripts/peta/item.js.coffee +++ b/app/assets/javascripts/peta/item.js.coffee @@ -7,6 +7,9 @@ class Peta.Item extends Backbone.Model # ClassMethods + @my_class: () -> + this + my_class: () -> Pettanr[@constructor.name] diff --git a/app/assets/javascripts/peta/owner.js.coffee b/app/assets/javascripts/peta/owner.js.coffee index d7edd4b2..9cbf98da 100644 --- a/app/assets/javascripts/peta/owner.js.coffee +++ b/app/assets/javascripts/peta/owner.js.coffee @@ -2,5 +2,5 @@ class Peta.Owner extends Peta.Item is_own: (operators) -> return false if not operators.user - @user_id == operators.user.id + @get('user_id') == operators.user.get('id') diff --git a/app/assets/javascripts/pettanr/operator.js.coffee b/app/assets/javascripts/pettanr/operator.js.coffee index e0d8ee89..16d709b9 100644 --- a/app/assets/javascripts/pettanr/operator.js.coffee +++ b/app/assets/javascripts/pettanr/operator.js.coffee @@ -1,71 +1,46 @@ class Pettanr.Operator - initialize: (operators) -> + constructor: (operators) -> @operators = operators + @user = @find_user() + @author = @find_author() + @artist = @find_artist() + @admin = @find_admin() #InstanceMethods find_user: () -> - _.each @operators, (operator) -> - return operator if operator instanceof Pettanr.User - return operator.user if operator instanceof Pettanr.Author - return operator.user if operator instanceof Pettanr.Artist - nil + _.find @operators, (operator) -> + console.log operator.constructor.name + Pettanr[operator.constructor.name] == Pettanr.User find_author: () -> - _.each @operators, (operator) -> - return operator if operator instanceof Pettanr.Author - return operator.author if operator instanceof Pettanr.User - return operator.user.author if (operator instanceof Pettanr.Artist) and operator.user.author - nil + _.find @operators, (operator) -> + Pettanr[operator.constructor.name] == Pettanr.Author find_artist: () -> - _.each @operators, (operator) -> - return operator.user.artist if (operator instanceof Pettanr.Author) and operator.user.artist - return operator.artist if operator instanceof Pettanr.User - return operator if operator instanceof Pettanr.Artist - nil + _.find @operators, (operator) -> + Pettanr[operator.constructor.name] == Pettanr.Artist find_admin: () -> - _.each @operators, (operator) -> - return operator if operator instanceof Pettanr.Admin - nil - - user: () -> - return @user if @user - @user = @find_user() - - author: () -> - return @author if @author - @author = @find_author() - - artist: () -> - return @artist if @artist - @artist = @find_artist() - - admin: () -> - return @admin if @admin - @admin = @find_admin() + _.find @operators, (operator) -> + Pettanr[operator.constructor.name] == Pettanr.Admin is_guest: () -> true is_reader: () -> - _.each @operators, (operator) -> - return true if (operator instanceof Pettanr.Author) or (operator instanceof Pettanr.Artist) or (operator instanceof Pettanr.Admin) or (operator instanceof Pettanr.User) + return true if @author or @artist or @admin or @user false is_user: () -> - _.each @operators, (operator) -> - return true if (operator instanceof Pettanr.Author) or (operator instanceof Pettanr.Artist) or (operator instanceof Pettanr.User) + return true if @author or @artist or @user false is_resource_reader: () -> - _.each @operators, (operator) -> - return true if (operator instanceof Pettanr.Author) or (operator instanceof Artist) or (operator instanceof Pettanr.Admin) or (operator instanceof Pettanr.User) or (operator instanceof Pettanr.DemandUser) + return true if @author or @artist or @admin or @user or @demand_user false is_admin: () -> - _.each @operators, (operator) -> - return true if operator instanceof Pettanr.Admin + return true if @admin false diff --git a/app/assets/javascripts/pettanr/tags.js.coffee b/app/assets/javascripts/pettanr/tags.js.coffee index 844fb54d..ff14503a 100644 --- a/app/assets/javascripts/pettanr/tags.js.coffee +++ b/app/assets/javascripts/pettanr/tags.js.coffee @@ -28,3 +28,15 @@ class Pettanr.Tag.A extends Backbone.View this.$el.html(@content) this +class Pettanr.Tag.Div extends Backbone.View + tagName: 'div' + + initialize: (options) -> + @content = options.content + @class_name = options.class_name + + render: () -> + @el.className = @class_name + this.$el.html(@content) + this + diff --git a/app/views/top/index.html.erb b/app/views/top/index.html.erb index 654bd8d2..e68846b4 100644 --- a/app/views/top/index.html.erb +++ b/app/views/top/index.html.erb @@ -96,17 +96,10 @@ -