From f25bedea8e4e22d2ac9b65f3694fcc90a9dfa91c Mon Sep 17 00:00:00 2001 From: yasushiito Date: Mon, 29 Jun 2015 11:03:51 +0900 Subject: [PATCH] fix:asoc system --- app/assets/javascripts/controllers.js.coffee | 17 ++-- .../javascripts/controllers/comics.js.coffee | 19 ++-- .../javascripts/controllers/scrolls.js.coffee | 29 +++--- .../javascripts/controllers/sheets.js.coffee | 19 ++-- .../javascripts/controllers/stories.js.coffee | 19 ++-- .../javascripts/editor/panel_editor.js.coffee | 6 +- .../caption/default/face/method.js.coffee | 10 +- .../symbol/default/face/picture.js.coffee | 7 +- .../locmare/form/field/tag/select.js.coffee | 11 ++- .../locmare/list_group/list/base.js.coffee | 16 +++- .../profiler/association/belongs_to.js.coffee | 3 +- .../profiler/association/has_many.js.coffee | 9 +- .../locmare/profiler/association/has_one.js.coffee | 9 +- app/assets/javascripts/models/balloon.js.coffee | 25 ++--- app/assets/javascripts/models/comic.js.coffee | 3 - .../javascripts/models/comic_story.js.coffee | 6 -- app/assets/javascripts/models/folder.js.coffee | 4 +- .../javascripts/models/ground_color.js.coffee | 3 - .../javascripts/models/ground_picture.js.coffee | 50 +--------- app/assets/javascripts/models/license.js.coffee | 15 +-- .../javascripts/models/original_picture.js.coffee | 16 +--- app/assets/javascripts/models/panel.js.coffee | 3 - .../javascripts/models/panel_picture.js.coffee | 50 +--------- app/assets/javascripts/models/picture.js.coffee | 12 ++- .../javascripts/models/resource_picture.js.coffee | 15 +-- .../models/resource_picture_picture.js.coffee | 13 +-- app/assets/javascripts/models/scroll.js.coffee | 3 - .../javascripts/models/scroll_panel.js.coffee | 6 -- app/assets/javascripts/models/sheet.js.coffee | 3 - .../javascripts/models/sheet_panel.js.coffee | 6 -- app/assets/javascripts/models/speech.js.coffee | 27 ++---- .../javascripts/models/speech_balloon.js.coffee | 60 +++--------- .../models/speech_balloon_template.js.coffee | 12 +-- app/assets/javascripts/models/story.js.coffee | 3 - .../javascripts/models/story_sheet.js.coffee | 6 -- .../javascripts/models/system_picture.js.coffee | 9 +- app/assets/javascripts/models/user.js.coffee | 4 - .../javascripts/models/writing_format.js.coffee | 12 +-- app/assets/javascripts/peta/item.js.coffee | 93 ++++++++++++++++++ .../javascripts/views/artists/show.js.coffee | 21 +++-- .../javascripts/views/authors/show.js.coffee | 50 +++++----- .../views/ground_pictures/new_element.js.coffee | 11 +-- .../views/original_pictures/publish.js.coffee | 59 ++++++------ .../views/original_pictures/summary.js.coffee | 15 ++- .../views/panel_pictures/element.js.coffee | 15 +-- .../views/panel_pictures/new_element.js.coffee | 11 +-- .../javascripts/views/scrolls/play.js.coffee | 25 ++--- .../views/speech_balloons/new_element.js.coffee | 104 ++++++++++----------- .../javascripts/views/users/account.js.coffee | 24 ++--- app/assets/javascripts/work/models.js.coffee.erb | 8 ++ public/manifest.json | 14 ++- 51 files changed, 449 insertions(+), 541 deletions(-) diff --git a/app/assets/javascripts/controllers.js.coffee b/app/assets/javascripts/controllers.js.coffee index 7a1356a9..f9c9fb59 100644 --- a/app/assets/javascripts/controllers.js.coffee +++ b/app/assets/javascripts/controllers.js.coffee @@ -30,17 +30,12 @@ class Pettanr.AppController filer_list: () -> @set_list() - @list.open(() => - pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, @params) - filer = new Locmare.Filer({ - item_name: @list.item_name, - items: @list.items(), - pager: pager - }) - @listenTo(filer, 'navigate', @navigate) - filer.render() - @trigger('ready', filer) - ) + @list.to_filer(this, { + success: (filer) => + @listenTo(filer, 'navigate', @navigate) + filer.render() + @trigger('ready', filer) + }) false set_play: (render_func) -> diff --git a/app/assets/javascripts/controllers/comics.js.coffee b/app/assets/javascripts/controllers/comics.js.coffee index 140995e9..70f83717 100644 --- a/app/assets/javascripts/controllers/comics.js.coffee +++ b/app/assets/javascripts/controllers/comics.js.coffee @@ -40,15 +40,16 @@ class Pettanr.ComicsController extends Pettanr.AppController @set_play(@render_play) render_play: (@item) -> - @list.open(() => - @trigger('title', @params, @item.get('title')) - show = new Pettanr.Views.Comic.Play({ - item: @item, - list: @list, - }) - show.render() - @trigger('ready', show) - ) + @list.open(this, { + success: (items) => + @trigger('title', @params, @item.get('title')) + show = new Pettanr.Views.Comic.Play({ + item: @item, + list: items, + }) + show.render() + @trigger('ready', show) + }) @trigger('done', @params) count: () -> diff --git a/app/assets/javascripts/controllers/scrolls.js.coffee b/app/assets/javascripts/controllers/scrolls.js.coffee index 5f9b1721..609d0578 100644 --- a/app/assets/javascripts/controllers/scrolls.js.coffee +++ b/app/assets/javascripts/controllers/scrolls.js.coffee @@ -39,20 +39,21 @@ class Pettanr.ScrollsController extends Pettanr.AppController @set_play(@render_play) render_play: (@item) -> - @list.open(() => - pager = Locmare.ListGroupModule.LibModule.PlayPager.factory(@list.page_status, @params) - @trigger('title', @params, @item.get('title')) - show = new Pettanr.Views.Scroll.Play({ - item: @item, - list: @list, - pager: pager - }) - @listenTo(show, 'insert', @insert) - @listenTo(show, 'move', @move) - @listenTo(show, 'dialog:close', @close_dialog) - show.render() - @trigger('ready', show) - ) + @list.open(this, { + success: (items) => + pager = Locmare.ListGroupModule.LibModule.PlayPager.factory(@list.page_status, @params) + @trigger('title', @params, @item.get('title')) + show = new Pettanr.Views.Scroll.Play({ + item: @item, + list: @list, + pager: pager + }) + @listenTo(show, 'insert', @insert) + @listenTo(show, 'move', @move) + @listenTo(show, 'dialog:close', @close_dialog) + show.render() + @trigger('ready', show) + }) @trigger('done', @params) insert: (dialog) -> diff --git a/app/assets/javascripts/controllers/sheets.js.coffee b/app/assets/javascripts/controllers/sheets.js.coffee index cb1fc429..542d0ae4 100644 --- a/app/assets/javascripts/controllers/sheets.js.coffee +++ b/app/assets/javascripts/controllers/sheets.js.coffee @@ -43,15 +43,16 @@ class Pettanr.SheetsController extends Pettanr.AppController @set_play(@render_play) render_play: (@item) -> - @list.open(() => - @trigger('title', @params, @item.get('caption')) - show = new Pettanr.Views.Sheet.Play({ - item: @item, - list: @list, - }) - show.render() - @trigger('ready', show) - ) + @list.open(this, { + success: (items) => + @trigger('title', @params, @item.get('caption')) + show = new Pettanr.Views.Sheet.Play({ + item: @item, + list: items, + }) + show.render() + @trigger('ready', show) + }) @trigger('done', @params) count: () -> diff --git a/app/assets/javascripts/controllers/stories.js.coffee b/app/assets/javascripts/controllers/stories.js.coffee index bef042fe..9e90f637 100644 --- a/app/assets/javascripts/controllers/stories.js.coffee +++ b/app/assets/javascripts/controllers/stories.js.coffee @@ -45,15 +45,16 @@ class Pettanr.StoriesController extends Pettanr.AppController @set_play(@render_play) render_play: (@item) -> - @list.open(() => - @trigger('title', @params, @item.get('title')) - show = new Pettanr.Views.Story.Play({ - item: @item, - list: @list, - }) - show.render() - @trigger('ready', show) - ) + @list.open(this, { + success: (items) => + @trigger('title', @params, @item.get('title')) + show = new Pettanr.Views.Story.Play({ + item: @item, + list: items, + }) + show.render() + @trigger('ready', show) + }) @trigger('done', @params) count: () -> diff --git a/app/assets/javascripts/editor/panel_editor.js.coffee b/app/assets/javascripts/editor/panel_editor.js.coffee index 3b2c2aa2..45855127 100644 --- a/app/assets/javascripts/editor/panel_editor.js.coffee +++ b/app/assets/javascripts/editor/panel_editor.js.coffee @@ -11,7 +11,7 @@ class Editor.PanelEditor extends Pettanr.View spot: null }) @dock = new Editor.PanelEditor.Dock({parent: this}) - @credits = new Pettanr.Views.Panel.ShowModule.Credits({pictures: {}}) + @credits = new Pettanr.Views.Common.Credits(parent: this) @body.on('panel:resize', @panel_resize) @listenTo(@dock, 'http_post', @http_post) @@ -27,7 +27,9 @@ class Editor.PanelEditor extends Pettanr.View @body.add_element(element) add_credit: (element) -> - @credits.add_picture(element.picture()) + r = {} + r[element.get('picture_id')] = null + @credits.push(r) open_dialog: (dialog) -> @dialogs[dialog.cid] = dialog diff --git a/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/face/method.js.coffee b/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/face/method.js.coffee index 3593b606..4aabfe2c 100644 --- a/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/face/method.js.coffee +++ b/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/face/method.js.coffee @@ -7,12 +7,12 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.CaptionItemCo # get caption data and send message render: () -> if @item[@method_name()] - @listenTo(@item, 'ready:caption', @ready_caption) - @item[@method_name()]() + @item[@method_name()].call(@item, this, { + success: (caption) => + @trigger('ready:caption', Pettanr.Views.Common.replace_empty(caption)) + }) + this method_name: () -> @my_manifest.method_name - ready_caption: (caption) -> - @trigger('ready:caption', Pettanr.Views.Common.replace_empty(caption)) - diff --git a/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/face/picture.js.coffee b/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/face/picture.js.coffee index 46e65bcc..e83c1ea8 100644 --- a/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/face/picture.js.coffee +++ b/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/face/picture.js.coffee @@ -7,13 +7,14 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.SymbolItemCol # get symbol data and send message render: () -> if @item[@method_name()] - @listenTo(@item, 'ready:symbol', @ready_symbol) - @item[@method_name()]() + @item[@method_name()].call(@item, this, { + success: (symbol) => + @trigger('ready:symbol', symbol) + }) this method_name: () -> @my_manifest.method_name ready_symbol: (symbol) -> - @trigger('ready:symbol', symbol) diff --git a/app/assets/javascripts/locmare/form/field/tag/select.js.coffee b/app/assets/javascripts/locmare/form/field/tag/select.js.coffee index 59b815d4..4f98f989 100644 --- a/app/assets/javascripts/locmare/form/field/tag/select.js.coffee +++ b/app/assets/javascripts/locmare/form/field/tag/select.js.coffee @@ -56,11 +56,12 @@ class Locmare.FormModule.FieldModule.TagModule.SelectTag extends Locmare.FormMod else {} list = Locmare.ListGroup.list(resource_controller_name, resource_action_name, params) - list.open((page_status) -> - members = _.map list.models, (member) -> - [member.get(caption_name), member.get('id')] - cb(members) - ) + list.open(this, { + success: (page_status) -> + members = _.map list.models, (member) -> + [member.get(caption_name), member.get('id')] + cb(members) + }) else members = Manifest.manifest().system_resources.select_items[@select_item_name()] cb(members) diff --git a/app/assets/javascripts/locmare/list_group/list/base.js.coffee b/app/assets/javascripts/locmare/list_group/list/base.js.coffee index 9cd9c811..6bf90f5c 100644 --- a/app/assets/javascripts/locmare/list_group/list/base.js.coffee +++ b/app/assets/javascripts/locmare/list_group/list/base.js.coffee @@ -28,9 +28,21 @@ class Locmare.ListGroupModule.Base extends Backbone.Collection count: () -> new Pettanr.CounterModel({}, {url: '/' + @action_manifest.counter_url(@params)}) - open: (cb) -> + open: (context, options) -> @url = '/' + @action_manifest.url(@params) @fetch().done => # @boost(items) - cb() + options.success.call(context, @items()) + + to_filer: (context, options) -> + @open(context, { + success: (items) => + pager = Locmare.ListGroupModule.LibModule.Pager.factory(@page_status, @params) + filer = new Locmare.Filer({ + item_name: @item_name, + items: items, + pager: pager + }) + options.success.call(context, filer) + }) diff --git a/app/assets/javascripts/locmare/profiler/association/belongs_to.js.coffee b/app/assets/javascripts/locmare/profiler/association/belongs_to.js.coffee index 2725b4d9..50bc6b9a 100644 --- a/app/assets/javascripts/locmare/profiler/association/belongs_to.js.coffee +++ b/app/assets/javascripts/locmare/profiler/association/belongs_to.js.coffee @@ -7,8 +7,7 @@ class Locmare.ProfilerModule.AssociationModule.BelongsTo extends Pettanr.View clear: () -> this.$el.html('') - f = - @parent_model().retrieve(@parent_id(), this, { + @item().get_parent(@belongs_to_manifest.name, this, { success: (@parent_item) => @set_filer() @render() diff --git a/app/assets/javascripts/locmare/profiler/association/has_many.js.coffee b/app/assets/javascripts/locmare/profiler/association/has_many.js.coffee index d8c6a895..fd953c4a 100644 --- a/app/assets/javascripts/locmare/profiler/association/has_many.js.coffee +++ b/app/assets/javascripts/locmare/profiler/association/has_many.js.coffee @@ -17,10 +17,11 @@ class Locmare.ProfilerModule.AssociationModule.HasMany extends Pettanr.View clear: () -> this.$el.html('') - @list.open((page_status) => - @set_filer() - @render() - ) + @list.open(this, { + success: (page_status) => + @set_filer() + @render() + }) this render: () -> diff --git a/app/assets/javascripts/locmare/profiler/association/has_one.js.coffee b/app/assets/javascripts/locmare/profiler/association/has_one.js.coffee index 07eadee3..d1bb3d08 100644 --- a/app/assets/javascripts/locmare/profiler/association/has_one.js.coffee +++ b/app/assets/javascripts/locmare/profiler/association/has_one.js.coffee @@ -14,10 +14,11 @@ class Locmare.ProfilerModule.AssociationModule.HasOne extends Pettanr.View clear: () -> this.$el.html('') - @list.open((page_status) => - @set_filer() - @render() - ) + @list.open(this, { + success: (page_status) => + @set_filer() + @render() + }) this render: () -> diff --git a/app/assets/javascripts/models/balloon.js.coffee b/app/assets/javascripts/models/balloon.js.coffee index b23303ee..9136fa0c 100644 --- a/app/assets/javascripts/models/balloon.js.coffee +++ b/app/assets/javascripts/models/balloon.js.coffee @@ -15,6 +15,12 @@ class Pettanr.Balloon extends Peta.Element r: 0 } + @trace_routes: () -> + { + speech_balloon: 'speech_balloon', + symbol: ['speech_balloon', 'speech_balloon_template', 'system_picture'] + } + pick: () -> # speech_balloon_template = @templates.speech_balloon_template @@ -23,26 +29,11 @@ class Pettanr.Balloon extends Peta.Element speech_balloon_template_module_name: speech_balloon_template.get('module_name'), } - speech_balloon: () -> - new Pettanr.Cache.Retriever(Pettanr.SpeechBalloon, @get('speech_balloon_id')) - - system_picture: () -> - new Pettanr.Cache.Retriever(Pettanr.SystemPicture, @get('system_picture_id')) - r_url: () -> '/system_pictures/' + @system_picture().filename() - symbol_option: () -> - @get_parent('speech_balloon', this, { - success: (speech_balloon) => - speech_balloon.get_parent('speech_balloon_template', this, { - success: (speech_balloon_template) => - speech_balloon_template.get_parent('system_picture', this, { - success: (system_picture) => - @trigger('ready:symbol', system_picture.tmb_opt_img_tag()) - }) - }) - }) + plain_scenario: () -> + '' initialize: (attr, options) -> super(attr, options) diff --git a/app/assets/javascripts/models/comic.js.coffee b/app/assets/javascripts/models/comic.js.coffee index 70f5c577..de9689b9 100644 --- a/app/assets/javascripts/models/comic.js.coffee +++ b/app/assets/javascripts/models/comic.js.coffee @@ -12,9 +12,6 @@ class Pettanr.Comic extends Peta.Binder author_id: null } - author: () -> - new Pettanr.Cache.Retriever(Pettanr.Author, @get('author_id')) - is_visible: (operators = Pettanr.cache.operators) -> switch super(operators) when null diff --git a/app/assets/javascripts/models/comic_story.js.coffee b/app/assets/javascripts/models/comic_story.js.coffee index e441d269..85a223b9 100644 --- a/app/assets/javascripts/models/comic_story.js.coffee +++ b/app/assets/javascripts/models/comic_story.js.coffee @@ -13,12 +13,6 @@ class Pettanr.ComicStory extends Peta.Leaf t: null } - comic: () -> - new Pettanr.Cache.Retriever(Pettanr.Comic, @get('comic_id')) - - story: () -> - new Pettanr.Cache.Retriever(Pettanr.Story, @get('story_id')) - has_story: () -> if @get('story_id') true diff --git a/app/assets/javascripts/models/folder.js.coffee b/app/assets/javascripts/models/folder.js.coffee index f6caecca..4cfe6137 100644 --- a/app/assets/javascripts/models/folder.js.coffee +++ b/app/assets/javascripts/models/folder.js.coffee @@ -14,9 +14,9 @@ class Pettanr.Folder extends Peta.Owner caption: () -> @get('name').replace(/\/$/, '').split('/').pop() - filer_caption: () -> + filer_caption: (context, options) -> caption = _.escape(@caption()) - @trigger('ready:caption', caption) + options.success.call(context, caption) is_remote: () -> if @get('category_id') == 10 diff --git a/app/assets/javascripts/models/ground_color.js.coffee b/app/assets/javascripts/models/ground_color.js.coffee index 129c91b7..381f219d 100644 --- a/app/assets/javascripts/models/ground_color.js.coffee +++ b/app/assets/javascripts/models/ground_color.js.coffee @@ -28,9 +28,6 @@ class Pettanr.GroundColor extends Peta.Element @pick_item_name: () -> '' - panel: () -> - new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id')) - element_face: () -> new Pettanr.Views.GroundColor.ElementFace({element: this}) diff --git a/app/assets/javascripts/models/ground_picture.js.coffee b/app/assets/javascripts/models/ground_picture.js.coffee index 0498bef2..139fe61a 100644 --- a/app/assets/javascripts/models/ground_picture.js.coffee +++ b/app/assets/javascripts/models/ground_picture.js.coffee @@ -25,11 +25,11 @@ class Pettanr.GroundPicture extends Peta.Element pick: (picked_item) -> {picture_id: picked_item.get('picture_id')} - panel: () -> - new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id')) - - picture: () -> - new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id')) + @trace_routes: () -> + { + resource_picture: ['picture', 'resource_picture_picture', 'resource_picture'], + symbol: 'picture' + } @has_picture: () -> true @@ -43,12 +43,6 @@ class Pettanr.GroundPicture extends Peta.Element picture: picture }) - symbol_option: () -> - @get_parent('picture', this, { - success: (picture) => - @trigger('ready:symbol', picture.tmb_opt_img_tag()) - }) - repeat_text: () -> Pettanr.GroundPicture.repeat_texts()[@get('repeat')] @@ -58,37 +52,3 @@ class Pettanr.GroundPicture extends Peta.Element initialize: (attr, options) -> super(attr, options) -class Pettanr.GroundPicture.TraceFromPicture - - constructor: (options) -> - _.extend(this, Backbone.Events) - - trace: (picture) -> - @picture(picture) - - picture: (picture) -> - resource_picture_picture_list = picture.has_one('resource_picture_picture') - resource_picture_picture_list.open(() => - resource_picture_picture = resource_picture_picture_list.items()[0] - Pettanr.ResourcePicture.retrieve(resource_picture_picture.get('resource_picture_id'), this, { - success: (resource_picture) => - @trigger('trace', resource_picture) - }) - ) - -class Pettanr.GroundPicture.TraceFromPanelPicture extends Pettanr.GroundPicture.TraceFromPicture - - trace: (panel_picture) -> - @panel_picture(panel_picture) - - panel_picture: (panel_picture) -> - Pettanr.Picture.retrieve(panel_picture.get('picture_id'), this, { - success: (picture) => - tracer = new Pettanr.GroundPicture.TraceFromPicture() - @listenTo(tracer, 'trace', @success) - tracer.trace(picture) - }) - - success: (resource_picture) -> - @trigger('trace', resource_picture) - diff --git a/app/assets/javascripts/models/license.js.coffee b/app/assets/javascripts/models/license.js.coffee index 511d2faa..9b064ed0 100644 --- a/app/assets/javascripts/models/license.js.coffee +++ b/app/assets/javascripts/models/license.js.coffee @@ -10,17 +10,10 @@ class Pettanr.License extends Peta.SystemResource id: null } - license_group: () -> - new Pettanr.Cache.Retriever(Pettanr.LicenseGroup, @get('license_group_id')) - - system_picture: () -> - new Pettanr.Cache.Retriever(Pettanr.SystemPicture, @get('system_picture_id')) - - symbol_option: () -> - @get_parent('system_picture', this, { - success: (system_picture) => - @trigger('ready:symbol', system_picture.tmb_opt_img_tag()) - }) + @trace_routes: () -> + { + symbol: ['system_picture'] + } caption_with_group: () -> @get_parent('license_group', this, { diff --git a/app/assets/javascripts/models/original_picture.js.coffee b/app/assets/javascripts/models/original_picture.js.coffee index dc43e9a2..7c169b50 100644 --- a/app/assets/javascripts/models/original_picture.js.coffee +++ b/app/assets/javascripts/models/original_picture.js.coffee @@ -11,12 +11,6 @@ class Pettanr.OriginalPicture extends Peta.Content artist_id: null } - picture: () -> - new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id')) - - artist: () -> - new Pettanr.Cache.Retriever(Pettanr.Artist, @get('artist_id')) - is_visible: (operators = Pettanr.cache.operators) -> @is_own(operators) @@ -43,13 +37,13 @@ class Pettanr.OriginalPicture extends Peta.Content picture: this }) - symbol_option: () -> + symbol_option: (context, options) -> @retrieve(this, { - success: (item) => - @trigger('ready:symbol', item.tmb_opt_img_tag()) + success: (symbol_item) => + options.success.call(context, symbol_item.to_symbol()) }) - filer_caption: () -> + filer_caption: (context, options) -> history = @history() history.fetch({cache: true}).done => caption = if _.isEmpty(history.models) @@ -57,7 +51,7 @@ class Pettanr.OriginalPicture extends Peta.Content else head = _.first(history.models) Pettanr.to_s(head.get('revision')) - @trigger('ready:caption', caption) + options.success.call(context, caption) revision: () -> new Pettanr.OriginalPicture.Head({original_picture: this}) diff --git a/app/assets/javascripts/models/panel.js.coffee b/app/assets/javascripts/models/panel.js.coffee index 8bfd9d85..ff766dae 100644 --- a/app/assets/javascripts/models/panel.js.coffee +++ b/app/assets/javascripts/models/panel.js.coffee @@ -14,9 +14,6 @@ class Pettanr.Panel extends Peta.Root publish: 0 } - author: () -> - new Pettanr.Cache.Retriever(Pettanr.Author, @get('author_id')) - with_elements: () -> new Pettanr.Panel.WithElements({id: @get('id')}) diff --git a/app/assets/javascripts/models/panel_picture.js.coffee b/app/assets/javascripts/models/panel_picture.js.coffee index 78c3c297..83a5e268 100644 --- a/app/assets/javascripts/models/panel_picture.js.coffee +++ b/app/assets/javascripts/models/panel_picture.js.coffee @@ -23,11 +23,11 @@ class Pettanr.PanelPicture extends Peta.Element height: picked_item.get('height') } - picture: () -> - new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id')) - - panel: () -> - new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id')) + @trace_routes: () -> + { + resource_picture: ['picture', 'resource_picture_picture', 'resource_picture'] + symbol: 'picture' + } @has_picture: () -> true @@ -65,49 +65,9 @@ class Pettanr.PanelPicture extends Peta.Element picture: picture }) - symbol_option: () -> - @get_parent('picture', this, { - success: (picture) => - @trigger('ready:symbol', picture.tmb_opt_img_tag()) - }) - element_face: () -> new Pettanr.Views.PanelPicture.ElementFace({element: this}) initialize: (attr, options) -> super(attr, options) -class Pettanr.PanelPicture.TraceFromPicture - - constructor: (options) -> - _.extend(this, Backbone.Events) - - trace: (picture) -> - @picture(picture) - - picture: (picture) -> - resource_picture_picture_list = picture.has_one('resource_picture_picture') - resource_picture_picture_list.open(() => - resource_picture_picture = resource_picture_picture_list.items()[0] - resource_picture_picture.get_parent('resource_picture', this, { - success: (resource_picture) => - @trigger('trace', resource_picture) - }) - ) - -class Pettanr.PanelPicture.TraceFromGroundPicture extends Pettanr.PanelPicture.TraceFromPicture - - trace: (ground_picture) -> - @ground_picture(ground_picture) - - ground_picture: (ground_picture) -> - ground_picture.get_parent('picture', this, { - success: (picture) => - tracer = new Pettanr.PanelPicture.TraceFromPicture() - @listenTo(tracer, 'trace', @success) - tracer.trace(picture) - }) - - success: (resource_picture) -> - @trigger('trace', resource_picture) - diff --git a/app/assets/javascripts/models/picture.js.coffee b/app/assets/javascripts/models/picture.js.coffee index 2795754c..1a2d4e52 100644 --- a/app/assets/javascripts/models/picture.js.coffee +++ b/app/assets/javascripts/models/picture.js.coffee @@ -10,6 +10,11 @@ class Pettanr.Picture extends Peta.Content id: null } + @trace_routes: () -> + { + resource_picture: ['resource_picture_picture', 'resource_picture'] + } + is_visible: (operators = Pettanr.cache.operators) -> return true @@ -48,8 +53,11 @@ class Pettanr.Picture extends Peta.Content ln = Pettanr.to_s(@license().get('caption')) lgn + '[' + ln + ']' - symbol_option: () -> - @tmb_opt_img_tag() + symbol_option: (context, options) -> + @retrieve(this, { + success: (symbol_item) => + options.success.call(context, symbol_item.to_symbol()) + }) is_enable: () -> if @head().resource_picture() diff --git a/app/assets/javascripts/models/resource_picture.js.coffee b/app/assets/javascripts/models/resource_picture.js.coffee index f3a361e4..e9f093f5 100644 --- a/app/assets/javascripts/models/resource_picture.js.coffee +++ b/app/assets/javascripts/models/resource_picture.js.coffee @@ -10,15 +10,6 @@ class Pettanr.ResourcePicture extends Peta.Content id: null } - original_picture: () -> - new Pettanr.Cache.Retriever(Pettanr.OriginalPicture, @get('original_picture_id')) - - picture: () -> - new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id')) - - artist: () -> - new Pettanr.Cache.Retriever(Pettanr.Artist, @get('artist_id')) - is_visible: (operators = Pettanr.cache.operators) -> @is_user_visible(operators) @@ -56,10 +47,10 @@ class Pettanr.ResourcePicture extends Peta.Content ln = Pettanr.to_s(@license().get('caption')) lgn + '[' + ln + ']' - symbol_option: () -> + symbol_option: (context, options) -> @retrieve(this, { - success: (picture) => - @trigger('ready:symbol', picture.tmb_opt_img_tag()) + success: (symbol_item) => + options.success.call(context, symbol_item.to_symbol()) }) credit_icon_view: () -> diff --git a/app/assets/javascripts/models/resource_picture_picture.js.coffee b/app/assets/javascripts/models/resource_picture_picture.js.coffee index 574d5490..e041baf6 100644 --- a/app/assets/javascripts/models/resource_picture_picture.js.coffee +++ b/app/assets/javascripts/models/resource_picture_picture.js.coffee @@ -10,19 +10,14 @@ class Pettanr.ResourcePicturePicture extends Peta.Item id: null } - picture: () -> - new Pettanr.Picture({id: @get('picture_id')}) + @trace_routes: () -> + { + symbol: ['picture'] + } is_visible: (operators = Pettanr.cache.operators) -> true - symbol_option: () -> - @get_parent('picture', this, { - success: (picture) => - @trigger('ready:symbol', picture.tmb_opt_img_tag()) - force: true - }) - initialize: (attr = {}, options = {}) -> super(attr, options) diff --git a/app/assets/javascripts/models/scroll.js.coffee b/app/assets/javascripts/models/scroll.js.coffee index a3166070..ca3f00b5 100644 --- a/app/assets/javascripts/models/scroll.js.coffee +++ b/app/assets/javascripts/models/scroll.js.coffee @@ -11,9 +11,6 @@ class Pettanr.Scroll extends Peta.Binder visible: 0 } - author: () -> - new Pettanr.Cache.Retriever(Pettanr.Author, @get('author_id')) - overwrite: (options) -> operators = Pettanr.cache.operators return false if not operators.author diff --git a/app/assets/javascripts/models/scroll_panel.js.coffee b/app/assets/javascripts/models/scroll_panel.js.coffee index 27d794bd..e8065f50 100644 --- a/app/assets/javascripts/models/scroll_panel.js.coffee +++ b/app/assets/javascripts/models/scroll_panel.js.coffee @@ -30,12 +30,6 @@ class Pettanr.ScrollPanel extends Peta.Leaf ) Pettanr.Panel.licensed_pictures(panels) - scroll: () -> - new Pettanr.Cache.Retriever(Pettanr.Scroll, @get('scroll_id')) - - panel: () -> - new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id')) - has_panel: () -> if @get('panel_id') true diff --git a/app/assets/javascripts/models/sheet.js.coffee b/app/assets/javascripts/models/sheet.js.coffee index a25518ac..e9e49ddf 100644 --- a/app/assets/javascripts/models/sheet.js.coffee +++ b/app/assets/javascripts/models/sheet.js.coffee @@ -12,9 +12,6 @@ class Pettanr.Sheet extends Peta.Root author_id: null } - author: () -> - new Pettanr.Cache.Retriever(Pettanr.Author, @get('author_id')) - overwrite: (options) -> operators = Pettanr.cache.operators return false if not operators.author diff --git a/app/assets/javascripts/models/sheet_panel.js.coffee b/app/assets/javascripts/models/sheet_panel.js.coffee index 5127427a..2f0be20b 100644 --- a/app/assets/javascripts/models/sheet_panel.js.coffee +++ b/app/assets/javascripts/models/sheet_panel.js.coffee @@ -16,12 +16,6 @@ class Pettanr.SheetPanel extends Peta.Leaf t: null } - sheet: () -> - new Pettanr.Cache.Retriever(Pettanr.Sheet, @get('sheet_id')) - - panel: () -> - new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id')) - initialize: (attr = {}, options = {}) -> super(attr, options) diff --git a/app/assets/javascripts/models/speech.js.coffee b/app/assets/javascripts/models/speech.js.coffee index b0b31192..20945522 100644 --- a/app/assets/javascripts/models/speech.js.coffee +++ b/app/assets/javascripts/models/speech.js.coffee @@ -14,6 +14,12 @@ class Pettanr.Speech extends Peta.Element height: 100 } + @trace_routes: () -> + { + speech_balloon: 'speech_balloon', + symbol: ['speech_balloon', 'speech_balloon_template', 'system_picture'] + } + pick: () -> # speech_balloon_template = @templates.speech_balloon_template @@ -25,27 +31,9 @@ class Pettanr.Speech extends Peta.Element writing_format_module_name: writing_format.get('module_name'), } - speech_balloon: () -> - new Pettanr.Cache.Retriever(Pettanr.SpeechBalloon, @get('speech_balloon_id')) - - writing_format: () -> - new Pettanr.Cache.Retriever(Pettanr.WritingFormat, @get('writing_format_id')) - @text_align_texts: () -> ['left', 'left', 'right', 'center'] - symbol_option: () -> - @get_parent('speech_balloon', this, { - success: (speech_balloon) => - speech_balloon.get_parent('speech_balloon_template', this, { - success: (speech_balloon_template) => - speech_balloon_template.get_parent('system_picture', this, { - success: (system_picture) => - @trigger('ready:symbol', system_picture.tmb_opt_img_tag()) - }) - }) - }) - text_align_text: () -> Pettanr.Speech.text_align_texts()[@get('text_align')] @@ -53,6 +41,9 @@ class Pettanr.Speech extends Peta.Element @boosts('read') @render(@escape('content')) + plain_scenario: () -> + @escape('content') + initialize: (attr, options) -> super(attr, options) diff --git a/app/assets/javascripts/models/speech_balloon.js.coffee b/app/assets/javascripts/models/speech_balloon.js.coffee index e04db12b..6fb8af1e 100644 --- a/app/assets/javascripts/models/speech_balloon.js.coffee +++ b/app/assets/javascripts/models/speech_balloon.js.coffee @@ -26,34 +26,26 @@ class Pettanr.SpeechBalloon extends Peta.Element speech_balloon_template_module_name: speech_balloon_template.get('module_name') } - panel: () -> - new Pettanr.Cache.Retriever(Pettanr.Panel, @get('panel_id')) - - speech_balloon_template: () -> - new Pettanr.Cache.Retriever(Pettanr.SpeechBalloonTemplate, @get('speech_balloon_template_id')) + @trace_routes: () -> + { + symbol: ['speech_balloon_template', 'system_picture'], + } @has_picture: () -> false - symbol_option: () -> - @get_parent('speech_balloon_template', this, { - success: (speech_balloon_template) => - speech_balloon_template.get_parent('system_picture', this, { - success: (system_picture) => - @trigger('ready:symbol', system_picture.tmb_opt_img_tag()) + filer_caption: (context, options) -> + @get_child('balloon', this, { + success: (balloon) => + @get_child('speech', this, { + success: (speech) => + plain_scenario = @plain_scenario() + balloon.plain_scenario() + speech.plain_scenario() + options.success.call(context, plain_scenario) }) }) - - filer_caption: () -> - @retrieve(this, { - success: (speech_balloon) => - caption = speech_balloon.escape('caption') - @trigger('ready:caption', caption) - }) - plain_scenario: () -> - @get('caption') + @escape('caption') element_face: () -> new Pettanr.Views.SpeechBalloon.ElementFace({element: this}) @@ -61,31 +53,3 @@ class Pettanr.SpeechBalloon extends Peta.Element initialize: (attr, options) -> super(attr, options) -class Pettanr.SpeechBalloon.TraceFromBalloon - - constructor: (options) -> - _.extend(this, Backbone.Events) - - trace: (balloon) -> - @balloon(balloon) - - balloon: (balloon) -> - balloon.get_parent('speech_balloon', this, { - success: (speech_balloon) => - @trigger('trace', speech_balloon) - }) - -class Pettanr.SpeechBalloon.TraceFromSpeech - - constructor: (options) -> - _.extend(this, Backbone.Events) - - trace: (speech) -> - @speech(speech) - - speech: (speech) -> - speech.get_parent('speech_balloon', this, { - success: (speech_balloon) => - @trigger('trace', speech_balloon) - }) - diff --git a/app/assets/javascripts/models/speech_balloon_template.js.coffee b/app/assets/javascripts/models/speech_balloon_template.js.coffee index 9bdc6b6f..d7dde806 100644 --- a/app/assets/javascripts/models/speech_balloon_template.js.coffee +++ b/app/assets/javascripts/models/speech_balloon_template.js.coffee @@ -10,14 +10,10 @@ class Pettanr.SpeechBalloonTemplate extends Peta.Template id: null } - system_picture: () -> - new Pettanr.Cache.Retriever(Pettanr.SystemPicture, @get('system_picture_id')) - - symbol_option: () -> - @get_parent('system_picture', this, { - success: (system_picture) => - @trigger('ready:symbol', system_picture.tmb_opt_img_tag()) - }) + @trace_routes: () -> + { + symbol: ['system_picture'] + } parsed_settings: () -> JSON.parse(@get('settings')) diff --git a/app/assets/javascripts/models/story.js.coffee b/app/assets/javascripts/models/story.js.coffee index 606df47c..9357443b 100644 --- a/app/assets/javascripts/models/story.js.coffee +++ b/app/assets/javascripts/models/story.js.coffee @@ -12,9 +12,6 @@ class Pettanr.Story extends Peta.Binder author_id: null } - author: () -> - new Pettanr.Cache.Retriever(Pettanr.Author, @get('author_id')) - overwrite: (options) -> operators = Pettanr.cache.operators return false if not operators.author diff --git a/app/assets/javascripts/models/story_sheet.js.coffee b/app/assets/javascripts/models/story_sheet.js.coffee index 6d367f0a..1446c00f 100644 --- a/app/assets/javascripts/models/story_sheet.js.coffee +++ b/app/assets/javascripts/models/story_sheet.js.coffee @@ -13,12 +13,6 @@ class Pettanr.StorySheet extends Peta.Leaf t: null } - story: () -> - new Pettanr.Cache.Retriever(Pettanr.Story, @get('story_id')) - - sheet: () -> - new Pettanr.Cache.Retriever(Pettanr.Sheet, @get('sheet_id')) - has_sheet: () -> if @get('sheet_id') true diff --git a/app/assets/javascripts/models/system_picture.js.coffee b/app/assets/javascripts/models/system_picture.js.coffee index d5a943c8..311b0404 100644 --- a/app/assets/javascripts/models/system_picture.js.coffee +++ b/app/assets/javascripts/models/system_picture.js.coffee @@ -10,9 +10,6 @@ class Pettanr.SystemPicture extends Peta.SystemResource id: null } - picture: () -> - new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id')) - filename: () -> @get('id') + '.' + @get('ext') @@ -33,10 +30,10 @@ class Pettanr.SystemPicture extends Peta.SystemResource picture: this }) - symbol_option: () -> + symbol_option: (context, options) -> @retrieve(this, { - success: (picture) => - @trigger('ready:symbol', picture.tmb_opt_img_tag()) + success: (symbol_item) => + options.success.call(context, symbol_item.to_symbol()) }) initialize: (attr = {}, options = {}) -> diff --git a/app/assets/javascripts/models/user.js.coffee b/app/assets/javascripts/models/user.js.coffee index 2b2d1c5c..30fde566 100644 --- a/app/assets/javascripts/models/user.js.coffee +++ b/app/assets/javascripts/models/user.js.coffee @@ -3,10 +3,6 @@ class Pettanr.User extends Backbone.Model defaults: { } - author: () -> - - artist: () -> - initialize: (attr = {}, options = {}) -> super(attr, options) _.extend(this, Backbone.Events) diff --git a/app/assets/javascripts/models/writing_format.js.coffee b/app/assets/javascripts/models/writing_format.js.coffee index b18f8779..b6e60f04 100644 --- a/app/assets/javascripts/models/writing_format.js.coffee +++ b/app/assets/javascripts/models/writing_format.js.coffee @@ -10,14 +10,10 @@ class Pettanr.WritingFormat extends Peta.Template id: null } - system_picture: () -> - new Pettanr.Cache.Retriever(Pettanr.SystemPicture, @get('system_picture_id')) - - symbol_option: () -> - @get_parent('system_picture', this, { - success: (system_picture) => - @trigger('ready:symbol', system_picture.tmb_opt_img_tag()) - }) + @trace_routes: () -> + { + symbol: ['system_picture'] + } initialize: (attr = {}, options = {}) -> super(attr, options) diff --git a/app/assets/javascripts/peta/item.js.coffee b/app/assets/javascripts/peta/item.js.coffee index f2ec457d..b919c374 100644 --- a/app/assets/javascripts/peta/item.js.coffee +++ b/app/assets/javascripts/peta/item.js.coffee @@ -88,6 +88,9 @@ class Peta.Item extends Backbone.Model item = new this({id: id}) item.retrieve(context, options) + @trace_routes: () -> + {} + #InstanceMethods default_url: () -> @@ -122,6 +125,60 @@ class Peta.Item extends Backbone.Model else @item_name() + get_association: (routes, context, options) -> + console.log 'get_association' + routes = [routes] if _.isString(routes) + console.log routes + route = routes.shift() + if _.isEmpty(routes) + # fetching terminate association. callback + console.log 'fetching terminate association' + cxt = options.context || context + @fetch_association(route, cxt, { + success: (association_item, options) => + console.log 'success' + console.log association_item + console.log options + options.success.call(context, association_item) + context: context, + options: options + }) + else + # fetching through associations + console.log 'fetching through associations' + @fetch_association(route, this, { + success: (association_item, options) => + console.log 'success' + console.log association_item + console.log options + association_item.get_association(routes, this, options) + context: context, + options: options + }) + + fetch_association: (name, context, options) => + console.log context + console.log options + a = @my_class().my_manifest().associations + fetch_options = { + success: (association_item) => + options.success.call(context, association_item, options.options) + } + if a.belongs_to[name] + console.log 'belongs_to' + console.log name + @get_parent(name, context, fetch_options) + else if a.has_many[name] + console.log 'has_many' + console.log name + @get_children(name, context, fetch_options) + else if a.has_one[name] + console.log 'has_one' + console.log name + @get_child(name, context, fetch_options) + else + console.error('association does not exist in model manifest') + get_parent: (belongs_to_name, context, options = null) -> m = Manifest.item_name_to_model(belongs_to_name) retriever = new Pettanr.Cache.Retriever(m, @get(belongs_to_name + '_id')) @@ -131,6 +188,23 @@ class Peta.Item extends Backbone.Model ) retriever.retrieve() + get_child: (has_one_name, context, options = null) -> + list = @has_one(has_one_name) + list.open(context, { + success: (items) => + callback = options.success + item = items[0] + callback.call(context, item) + }) + + get_children: (has_many_name, context, options = null) -> + list = @has_many(has_many_name) + list.open(context, { + success: (items) => + callback = options.success + callback.call(context, items) + }) + has_many: (has_many_name) -> has_many_manifest = @my_class().my_manifest().associations.has_many[has_many_name] action_name = has_many_manifest.list_action_name @@ -146,6 +220,16 @@ class Peta.Item extends Backbone.Model controller_name, action_name, {id: @get('id')} ) + trace_to: (trace_name, context, options) -> + routes = @my_class().trace_routes()[trace_name] + if !routes + console.error('no trace route') + return + @get_association(routes, this, { + success: (association) => + options.success.call(context, association) + }) + boosts: (level) -> c = @my_class().my_peta().boost _.each c, (boost_manifest, boost_name) => @@ -209,6 +293,15 @@ class Peta.Item extends Backbone.Model else 'none' + symbol_option: (context, options) -> + @trace_to('symbol', this, { + success: (symbol_item) => + options.success.call(context, symbol_item.to_symbol()) + }) + + to_symbol: () -> + @tmb_opt_img_tag() + icon_view: (half) -> new Pettanr.Views[@my_class().singular()].Icon({item: this, half: half}) diff --git a/app/assets/javascripts/views/artists/show.js.coffee b/app/assets/javascripts/views/artists/show.js.coffee index 3662a813..ed656507 100644 --- a/app/assets/javascripts/views/artists/show.js.coffee +++ b/app/assets/javascripts/views/artists/show.js.coffee @@ -18,16 +18,17 @@ class Pettanr.Views.Artist.ShowModule.ResourcePictures extends Pettanr.View @list = Locmare.ListGroup.list( params['controller'], params['action'], params ) - @list.open(() => - pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, params) - filer = new Locmare.Filer({ - item_name: @list.item_name, - items: @list.items(), - pager: pager - }) - @listenTo(filer, 'http_get', @http_get) - this.$el.append(filer.render().el) - ) + @list.open(this, { + success: (items) => + pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, params) + filer = new Locmare.Filer({ + item_name: @list.item_name, + items: items, + pager: pager + }) + @listenTo(filer, 'http_get', @http_get) + this.$el.append(filer.render().el) + }) this http_get: (url) -> diff --git a/app/assets/javascripts/views/authors/show.js.coffee b/app/assets/javascripts/views/authors/show.js.coffee index 24881749..b88468d6 100644 --- a/app/assets/javascripts/views/authors/show.js.coffee +++ b/app/assets/javascripts/views/authors/show.js.coffee @@ -18,16 +18,17 @@ class Pettanr.Views.Author.ShowModule.Scrolls extends Pettanr.View @list = Locmare.ListGroup.list( params['controller'], params['action'], params ) - @list.open(() => - pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, params) - filer = new Locmare.Filer({ - item_name: @list.item_name, - items: @list.items(), - pager: pager - }) - @listenTo(filer, 'http_get', @http_get) - this.$el.append(filer.render().el) - ) + @list.open(this, { + success: (items) => + pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, params) + filer = new Locmare.Filer({ + item_name: @list.item_name, + items: items, + pager: pager + }) + @listenTo(filer, 'http_get', @http_get) + this.$el.append(filer.render().el) + }) this http_get: (url) -> @@ -47,19 +48,20 @@ class Pettanr.Views.Author.ShowModule.PanelsBody extends Pettanr.View @list = Locmare.ListGroup.list( params['controller'], params['action'], params ) - @list.open(() => - pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, params) - _.each @list.items(), (panel) => - panel = panel.with_elements() # retake panel for 'with_elements' mode - panel.fetch({cache: false}).done => - panel.attributes = panel.replaced_attributes() - body = new Pettanr.Views.Panel.Body({ - panel: panel, - spot: null - }) - @trigger('ready', panel) - this.$el.append(body.render().el) - ) + @list.open(this, { + success: (items) => + pager = Locmare.ListGroupModule.LibModule.Pager.factory(@list.page_status, params) + _.each items, (panel) => + panel = panel.with_elements() # retake panel for 'with_elements' mode + panel.fetch({cache: false}).done => + panel.attributes = panel.replaced_attributes() + body = new Pettanr.Views.Panel.Body({ + panel: panel, + spot: null + }) + @trigger('ready', panel) + this.$el.append(body.render().el) + }) this class Pettanr.Views.Author.ShowModule.Panels extends Pettanr.View @@ -68,7 +70,7 @@ class Pettanr.Views.Author.ShowModule.Panels extends Pettanr.View super(options) @item = options.item @panels_body = new Pettanr.Views.Author.ShowModule.PanelsBody({item: @item}) - @credits = new Pettanr.Views.Scroll.PlayModule.Credits({parent: this}) + @credits = new Pettanr.Views.Common.Credits({parent: this}) render: () -> @listenTo(@panels_body, 'ready', @ready) diff --git a/app/assets/javascripts/views/ground_pictures/new_element.js.coffee b/app/assets/javascripts/views/ground_pictures/new_element.js.coffee index 39a9e5c9..ced7cfc3 100644 --- a/app/assets/javascripts/views/ground_pictures/new_element.js.coffee +++ b/app/assets/javascripts/views/ground_pictures/new_element.js.coffee @@ -81,10 +81,10 @@ class Pettanr.Views.GroundPicture.NewElement extends Pettanr.View @trigger('ready', new_item) else if @target_model.is_traceable(item.item_name()) # Trace - tracer_class = @target_model['TraceFrom' + item.singular()] - tracer = new tracer_class() - @listenTo(tracer, 'trace', @trace) - tracer.trace(item) + item.trace_to(item.my_class().pick_item_name(), this, { + success: (resource_picture) => + @dialog.http_get(resource_picture.show_url()) + }) else if item.item_name() == @target_model.pick_item_name() # Pick resource_picture to ground_picture @listenTo(this, 'ready', @ready) @@ -96,9 +96,6 @@ class Pettanr.Views.GroundPicture.NewElement extends Pettanr.View @dialog.stop() @trigger('pick', new_item) - trace: (resource_picture) -> - @dialog.http_get(resource_picture.show_url()) - dock: () -> @parent.dock() diff --git a/app/assets/javascripts/views/original_pictures/publish.js.coffee b/app/assets/javascripts/views/original_pictures/publish.js.coffee index 9076a674..cdaf1e64 100644 --- a/app/assets/javascripts/views/original_pictures/publish.js.coffee +++ b/app/assets/javascripts/views/original_pictures/publish.js.coffee @@ -9,37 +9,36 @@ class Pettanr.Views.OriginalPicture.Publish extends Pettanr.View render: () -> this.$el.html('') if @is_own() - resource_picture_list = @item.has_one('resource_picture') - resource_picture_list.open(() => - @resource_picture = resource_picture_list.items()[0] - if @resource_picture - @stop_btn = new Tag.A({ - attr: {href: '/' + @resource_picture.destroy_url()}, - content: I18n.t('original_pictures.index.stop') + @item.get_child('resource_picture', this, { + success: (@resource_picture) => + if @resource_picture + @stop_btn = new Tag.A({ + attr: {href: '/' + @resource_picture.destroy_url()}, + content: I18n.t('original_pictures.index.stop') + }) + @listenTo(@stop_btn, 'click', @click_stop) + this.$el.append(@stop_btn.render().el) + @edit_icon = new Pettanr.Image.SymbolImg({ + attr: {'src': @edit_img_file_name()}, + half: true }) - @listenTo(@stop_btn, 'click', @click_stop) - this.$el.append(@stop_btn.render().el) - @edit_icon = new Pettanr.Image.SymbolImg({ - attr: {'src': @edit_img_file_name()}, - half: true - }) - @edit_btn = new Tag.A({ - attr: {href: '/' + @item.edit_url()}, - content: @edit_icon.render().el - }) - @remove_icon = new Pettanr.Image.SymbolImg({ - attr: {'src': @remove_img_file_name()}, - half: true - }) - @remove_btn = new Tag.A({ - attr: {href: '/' + @item.destroy_url()}, - content: @remove_icon.render().el - }) - @listenTo(@edit_btn, 'click', @click_edit) - @listenTo(@remove_btn, 'click', @click_remove) - this.$el.append(@edit_btn.render().el) - this.$el.append(@remove_btn.render().el) - ) + @edit_btn = new Tag.A({ + attr: {href: '/' + @item.edit_url()}, + content: @edit_icon.render().el + }) + @remove_icon = new Pettanr.Image.SymbolImg({ + attr: {'src': @remove_img_file_name()}, + half: true + }) + @remove_btn = new Tag.A({ + attr: {href: '/' + @item.destroy_url()}, + content: @remove_icon.render().el + }) + @listenTo(@edit_btn, 'click', @click_edit) + @listenTo(@remove_btn, 'click', @click_remove) + this.$el.append(@edit_btn.render().el) + this.$el.append(@remove_btn.render().el) + }) this is_own: () -> diff --git a/app/assets/javascripts/views/original_pictures/summary.js.coffee b/app/assets/javascripts/views/original_pictures/summary.js.coffee index 3418eaa4..de82aae6 100644 --- a/app/assets/javascripts/views/original_pictures/summary.js.coffee +++ b/app/assets/javascripts/views/original_pictures/summary.js.coffee @@ -16,14 +16,13 @@ class Pettanr.Views.OriginalPicture.Summary extends Pettanr.Views.Common.Summary content: I18n.t('original_pictures.' + @item.state()) }) this.$el.append(@visible.render().el) - resource_picture_list = @item.has_one('resource_picture') - resource_picture_list.open(() => - @resource_picture = resource_picture_list.items()[0] - if @resource_picture - @credit = @resource_picture.credit_view(true) - @listenTo(@credit, 'click:icon', @resource_picture_click) - this.$el.append(@credit.render().el) - ) + @item.get_child('resource_picture', this, { + success: (@resource_picture) => + if @resource_picture + @credit = @resource_picture.credit_view(true) + @listenTo(@credit, 'click:icon', @resource_picture_click) + this.$el.append(@credit.render().el) + }) @rb() this diff --git a/app/assets/javascripts/views/panel_pictures/element.js.coffee b/app/assets/javascripts/views/panel_pictures/element.js.coffee index d7aaf566..128a11c6 100644 --- a/app/assets/javascripts/views/panel_pictures/element.js.coffee +++ b/app/assets/javascripts/views/panel_pictures/element.js.coffee @@ -13,20 +13,21 @@ class Pettanr.Views.PanelPicture.Element extends Pettanr.View render: () -> @element.get_parent('picture', this, { success: (@picture) => - @init_picture() img_class = @img_class() - @img = new img_class({ + img = new img_class({ wrapper: this, element: @element, picture: @picture, spot: @spot }) @restyle() - this.$el.html(@img.render().el) + this.$el.html(img.render().el) + @init_picture(img) }) this - init_picture: () -> + init_picture: (img) -> + @img = img restyle: () -> attr = {style: Pettanr.to_style(@style())} @@ -92,8 +93,8 @@ class Pettanr.Views.PanelPicture.Element.Edit extends Pettanr.Views.PanelPicture @listenTo(@element, 'active', @active) @listenTo(@element, 'inactive', @inactive) - init_picture: () -> - img = @img + init_picture: (img) -> + super(img) wrapper = this this.$el.draggable { stop: (event, ui) -> @@ -103,7 +104,7 @@ class Pettanr.Views.PanelPicture.Element.Edit extends Pettanr.Views.PanelPicture elm.trigger('move') } elm = @element - @img.$el.resizable { + img.$el.resizable { stop: (event, ui) -> resize_div = ui.element panel_picture_div = wrapper.$el diff --git a/app/assets/javascripts/views/panel_pictures/new_element.js.coffee b/app/assets/javascripts/views/panel_pictures/new_element.js.coffee index e7bec5d1..0b516d6e 100644 --- a/app/assets/javascripts/views/panel_pictures/new_element.js.coffee +++ b/app/assets/javascripts/views/panel_pictures/new_element.js.coffee @@ -93,10 +93,10 @@ class Pettanr.Views.PanelPicture.NewElement extends Pettanr.View @trigger('ready', new_item) else if @target_model.is_traceable(item.item_name()) # Trace - tracer_class = @target_model['TraceFrom' + item.singular()] - tracer = new tracer_class() - @listenTo(tracer, 'trace', @trace) - tracer.trace(item) + item.trace_to(item.my_class().pick_item_name(), this, { + success: (resource_picture) => + @dialog.http_get(resource_picture.show_url()) + }) else if item.item_name() == @target_model.pick_item_name() # Pick resource_picture to panel_picture @listenTo(this, 'ready', @ready) @@ -109,9 +109,6 @@ class Pettanr.Views.PanelPicture.NewElement extends Pettanr.View @dialog.stop() @trigger('pick', new_item) - trace: (resource_picture) -> - @dialog.http_get(resource_picture.show_url()) - dock: () -> @parent.dock() diff --git a/app/assets/javascripts/views/scrolls/play.js.coffee b/app/assets/javascripts/views/scrolls/play.js.coffee index cd5da1aa..38053d5a 100644 --- a/app/assets/javascripts/views/scrolls/play.js.coffee +++ b/app/assets/javascripts/views/scrolls/play.js.coffee @@ -519,18 +519,19 @@ class Pettanr.Views.Scroll.PlayModule.Body extends Pettanr.View continue_list = Locmare.ListGroup.list( @list.list_group_name, @list.list_name, params ) - continue_list.open(() => - _.each continue_list.items(), (scroll_panel) => - @items.push(scroll_panel) - @panels.append_scroll_panel(scroll_panel) - @list = continue_list - continue_pager = Locmare.ListGroupModule.LibModule.PlayPager.factory(@list.page_status, params) - @listenTo(continue_pager, 'page', @continue) - @pager.$el.replaceWith(continue_pager.render().el) - @pager = continue_pager - if !@pager.hasNextPage() - @appender.enable() - ) + continue_list.open(this, { + success: (next_page_items) => + _.each next_page_items, (scroll_panel) => + @items.push(scroll_panel) + @panels.append_scroll_panel(scroll_panel) + @list = continue_list + continue_pager = Locmare.ListGroupModule.LibModule.PlayPager.factory(@list.page_status, params) + @listenTo(continue_pager, 'page', @continue) + @pager.$el.replaceWith(continue_pager.render().el) + @pager = continue_pager + if !@pager.hasNextPage() + @appender.enable() + }) class Pettanr.Views.Scroll.Play extends Pettanr.View tagName: 'div' diff --git a/app/assets/javascripts/views/speech_balloons/new_element.js.coffee b/app/assets/javascripts/views/speech_balloons/new_element.js.coffee index 976acb3b..2e7d4519 100644 --- a/app/assets/javascripts/views/speech_balloons/new_element.js.coffee +++ b/app/assets/javascripts/views/speech_balloons/new_element.js.coffee @@ -62,32 +62,30 @@ class Pettanr.Views.SpeechBalloon.NewElement extends Pettanr.View if item.item_name() == @target_model.item_name() # Inspire @listenTo(this, 'ready', @ready) - balloon_list = item.has_one('balloon') - speech_list = item.has_one('speech') - balloon_list.open(() => - balloon = balloon_list.items()[0] - speech_list.open(() => - speech = speech_list.items()[0] - new_item = new @target_model(item.attributes) - new_item.unset('id', {silent: true}) - new_item.set({panel_id: @editor().item.get('id')}, {silent: true}) - balloon.unset('id', {silent: true}) - balloon.unset('speech_balloon_id', {silent: true}) - speech.unset('id', {silent: true}) - speech.unset('speech_balloon_id', {silent: true}) - new_item.boosts 'post' - balloon.boosts 'post' - speech.boosts 'post' - new_item.set({balloon: balloon, speech: speech}, {silent: true}) - @trigger('ready', new_item) - ) - ) + item.get_child('balloon', this, { + success: (balloon) => + item.get_child('speech', this, { + success: (speech) => + new_item = new @target_model(item.attributes) + new_item.unset('id', {silent: true}) + new_item.set({panel_id: @editor().item.get('id')}, {silent: true}) + balloon.unset('id', {silent: true}) + balloon.unset('speech_balloon_id', {silent: true}) + speech.unset('id', {silent: true}) + speech.unset('speech_balloon_id', {silent: true}) + new_item.boosts 'post' + balloon.boosts 'post' + speech.boosts 'post' + new_item.set({balloon: balloon, speech: speech}, {silent: true}) + @trigger('ready', new_item) + }) + }) else if @target_model.is_traceable(item.item_name()) # Trace - tracer_class = @target_model['TraceFrom' + item.singular()] - tracer = new tracer_class() - @listenTo(tracer, 'trace', @trace) - tracer.trace(item) + item.trace_to(item.my_class().pick_item_name(), this, { + success: (pick_item) => + @dialog.http_get(pick_item.show_url()) + }) else if item.item_name() == @target_model.pick_item_name() # Pick @listenTo(this, 'ready', @ready) @@ -95,41 +93,39 @@ class Pettanr.Views.SpeechBalloon.NewElement extends Pettanr.View writing_format_list = Locmare.ListGroup.list( 'writing_formats', 'index', {} ) - writing_format_list.open(() => - writing_format = writing_format_list.items()[0] - templates = { - speech_balloon_template: speech_balloon_template, - writing_format: writing_format - } - new_item = new @target_model() - new_item.templates = templates - new_item.set(new_item.pick(), {silent: true}) - new_item.boosts 'post' - new_item.supply_default() - # prepare balloon - balloon = new Pettanr.Balloon() - balloon.templates = templates - balloon.set(balloon.pick(), {silent: true}) - balloon.boosts 'post' - balloon.supply_default() - # prepare speech - speech = new Pettanr.Speech() - speech.templates = templates - speech.set(speech.pick(), {silent: true}) - speech.boosts 'post' - speech.supply_default() - # join elements - new_item.set({balloon: balloon, speech: speech}, {silent: true}) - @trigger('ready', new_item) - ) + writing_format_list.open(this, { + success: (writing_formats) => + writing_format = writing_formats[0] + templates = { + speech_balloon_template: speech_balloon_template, + writing_format: writing_format + } + new_item = new @target_model() + new_item.templates = templates + new_item.set(new_item.pick(), {silent: true}) + new_item.boosts 'post' + new_item.supply_default() + # prepare balloon + balloon = new Pettanr.Balloon() + balloon.templates = templates + balloon.set(balloon.pick(), {silent: true}) + balloon.boosts 'post' + balloon.supply_default() + # prepare speech + speech = new Pettanr.Speech() + speech.templates = templates + speech.set(speech.pick(), {silent: true}) + speech.boosts 'post' + speech.supply_default() + # join elements + new_item.set({balloon: balloon, speech: speech}, {silent: true}) + @trigger('ready', new_item) + }) ready: (new_item) -> @dialog.stop() @trigger('pick', new_item) - trace: (speech_balloon) -> - @dialog.http_get(speech_balloon.show_url()) - dock: () -> @parent.dock() diff --git a/app/assets/javascripts/views/users/account.js.coffee b/app/assets/javascripts/views/users/account.js.coffee index b99eec58..d11fa3e7 100644 --- a/app/assets/javascripts/views/users/account.js.coffee +++ b/app/assets/javascripts/views/users/account.js.coffee @@ -73,12 +73,13 @@ class Pettanr.Views.User.Account.Quick extends Pettanr.View list = Locmare.ListGroup.list( 'folders', 'index', params ) - list.open(() => - if !_.isEmpty(list.items()) - @mydoc = list.items()[0] - @add_mydoc() - @create() - ) + list.open(this, { + success: (items) => + if !_.isEmpty(list.items()) + @mydoc = list.items()[0] + @add_mydoc() + @create() + }) create: () -> params = { @@ -89,11 +90,12 @@ class Pettanr.Views.User.Account.Quick extends Pettanr.View list = Locmare.ListGroup.list( 'folders', 'index', params ) - list.open(() => - if !_.isEmpty(list.items()) - @mynew = list.items()[0] - @add_mynew() - ) + list.open(this, { + success: (items) => + if !_.isEmpty(list.items()) + @mynew = list.items()[0] + @add_mynew() + }) add_mydoc: () -> mydoc_icon = new Pettanr.Views.User.Account.LinkedMydocIcon({item: @mydoc, half: true}) diff --git a/app/assets/javascripts/work/models.js.coffee.erb b/app/assets/javascripts/work/models.js.coffee.erb index 6aba6448..ef01e4c6 100644 --- a/app/assets/javascripts/work/models.js.coffee.erb +++ b/app/assets/javascripts/work/models.js.coffee.erb @@ -533,6 +533,8 @@ belongs_to: { panel: { }, + picture: { + }, }, has_many: { }, @@ -899,6 +901,8 @@ belongs_to: { panel: { }, + picture: { + }, }, has_many: { }, @@ -1122,6 +1126,10 @@ }, }, has_many: { + panel_pictures: { + }, + ground_pictures: { + }, }, has_one: { resource_picture_picture: { diff --git a/public/manifest.json b/public/manifest.json index 7a4932a0..e045a5c4 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -937,7 +937,8 @@ "type": "show" }, "history": { - "type": "show" + "type": "list", + "args": {} }, "new": { "type": "new" @@ -1897,7 +1898,8 @@ "panel_picture": { "associations": { "belongs_to": { - "panel": {} + "panel": {}, + "picture": {} }, "has_many": {} }, @@ -2246,7 +2248,8 @@ "ground_picture": { "associations": { "belongs_to": { - "panel": {} + "panel": {}, + "picture": {} }, "has_many": {} }, @@ -2465,7 +2468,10 @@ "artist": {}, "system_picture": {} }, - "has_many": {}, + "has_many": { + "panel_pictures": {}, + "ground_pictures": {} + }, "has_one": { "resource_picture_picture": {} } -- 2.11.0