-class Pettanr.Views.SpeechBalloon.NewElement extends Backbone.View\r
- tagName: 'div'\r
- className: 'new-element-body'\r
+class Pettanr.Views.SpeechBalloon.NewElementLauncher extends Editor.EditorModule.DockModule.NewElementLauncher\r
\r
initialize: (options) ->\r
- @parent = options.parent\r
- @model = options.model\r
- params = {\r
- controller: @model.path_name(), action: 'index',\r
- page_size: 6, format: 'pick'\r
- }\r
- @dialog().get(params, null)\r
+ super(options)\r
+ @links_conf = {}\r
+ _.extend(@links_conf, {\r
+ template: {\r
+ caption: 'Template',\r
+ params: {\r
+ controller: @model.pick_model().path_name(), action: 'index',\r
+ page_size: 6, format: 'html'\r
+ }\r
+ }\r
+ })\r
+ _.extend(@links_conf, {\r
+ inspire_recent: {\r
+ caption: "Inspire recent item",\r
+ params: {\r
+ controller: @model.path_name(), action: 'index',\r
+ page_size: 6, format: 'html'\r
+ }\r
+ }\r
+ })\r
+ if Pettanr.cache.operators.author\r
+ _.extend(@links_conf, {\r
+ inspire_my_recent: {\r
+ caption: 'Inspire my recent item',\r
+ params: {\r
+ controller: @model.path_name(), action: 'by_author', id: Pettanr.cache.operators.author.get('id'), \r
+ page_size: 6, format: 'html'\r
+ }\r
+ }\r
+ })\r
\r
render: () ->\r
- this.$el.html(@img.clear().el)\r
+ super()\r
+ @add_links()\r
this\r
\r
+ click_template: () ->\r
+ @click_default(@links_conf.template.params)\r
+ \r
+ click_inspire_recent: () ->\r
+ @click_default(@links_conf.inspire_recent.params)\r
+ \r
+ click_inspire_my_recent: () ->\r
+ @click_default(@links_conf.inspire_my_recent.params)\r
+ \r
+class Pettanr.Views.SpeechBalloon.NewElement extends Pettanr.View\r
+ \r
+ initialize: (options) ->\r
+ @parent = options.parent\r
+ @target_model = options.target_model\r
+ @pick_model = @target_model.pick_model()\r
+ \r
+ start: (@dialog, params) ->\r
+ @dialog.start(@target_model, params, null)\r
+ @listenTo(@dialog, 'pick', @pick)\r
+ @trigger('dialog:open', @dialog)\r
+ \r
+ pick: (item) ->\r
+ if item.item_name() == @target_model.item_name()\r
+ # Inspire\r
+ @listenTo(this, 'ready', @ready)\r
+ item.get_child('balloon', this, {\r
+ success: (balloon) =>\r
+ item.get_child('speech', this, {\r
+ success: (speech) =>\r
+ new_item = new @target_model(item.attributes)\r
+ new_item.unset('id', {silent: true})\r
+ new_item.set({panel_id: @editor().item.get('id')}, {silent: true})\r
+ new_balloon = balloon.clone()\r
+ new_balloon.unset('id', {silent: true})\r
+ new_balloon.unset('speech_balloon_id', {silent: true})\r
+ new_speech = speech.clone()\r
+ new_speech.unset('id', {silent: true})\r
+ new_speech.unset('speech_balloon_id', {silent: true})\r
+ new_item.boosts 'post'\r
+ new_balloon.boosts 'post'\r
+ new_speech.boosts 'post'\r
+ new_item.set({balloon: new_balloon, speech: new_speech}, {silent: true})\r
+ @trigger('ready', new_item)\r
+ })\r
+ })\r
+ else if @target_model.is_traceable(item.item_name())\r
+ # Trace\r
+ item.trace_to(item.my_class().pick_item_name(), this, {\r
+ success: (pick_item) => \r
+ @dialog.http_get(pick_item.show_url())\r
+ })\r
+ else if item.item_name() == @target_model.pick_item_name()\r
+ # Pick\r
+ @listenTo(this, 'ready', @ready)\r
+ speech_balloon_template = item\r
+ writing_format_list = Locmare.ListGroup.list(\r
+ 'writing_formats', 'index', {}\r
+ )\r
+ writing_format_list.open(this, {\r
+ success: (writing_formats) => \r
+ writing_format = writing_formats[0]\r
+ templates = {\r
+ speech_balloon_template: speech_balloon_template,\r
+ writing_format: writing_format\r
+ }\r
+ new_item = new @target_model()\r
+ new_item.templates = templates\r
+ new_item.set(new_item.pick(), {silent: true})\r
+ new_item.boosts 'post'\r
+ new_item.supply_default()\r
+ # prepare balloon\r
+ balloon = new Pettanr.Balloon()\r
+ balloon.templates = templates\r
+ balloon.set(balloon.pick(), {silent: true})\r
+ balloon.boosts 'post'\r
+ balloon.supply_default()\r
+ # prepare speech\r
+ speech = new Pettanr.Speech()\r
+ speech.templates = templates\r
+ speech.set(speech.pick(), {silent: true})\r
+ speech.boosts 'post'\r
+ speech.supply_default()\r
+ # join elements\r
+ new_item.set({balloon: balloon, speech: speech}, {silent: true})\r
+ @trigger('ready', new_item)\r
+ })\r
+ \r
+ ready: (new_item) ->\r
+ @dialog.stop()\r
+ @trigger('pick', new_item)\r
+ \r
dock: () ->\r
@parent.dock()\r
\r
editor: () ->\r
@dock().editor()\r
\r
- dialog: () ->\r
- @editor().dialog\r
- \r