1 class Pettanr.Views.SpeechBalloon.NewElementLauncher extends Editor.EditorModule.DockModule.NewElementLauncher
\r
3 initialize: (options) ->
\r
6 speech_balloon_template: {
\r
7 caption: 'Speech Balloon Template',
\r
9 controller: @model.pick_model().path_name(), action: 'index',
\r
10 page_size: 6, format: 'html'
\r
20 click_speech_balloon_template: () ->
\r
21 @click_default(@links_conf.speech_balloon_template.params)
\r
23 class Pettanr.Views.SpeechBalloon.NewElement extends Backbone.View
\r
25 initialize: (options) ->
\r
26 @parent = options.parent
\r
27 @target_model = options.target_model
\r
28 @pick_model = @target_model.pick_model()
\r
30 start: (@dialog, params) ->
\r
31 @dialog.start(@target_model, params, null)
\r
32 @listenTo(@dialog, 'pick', @pick)
\r
33 @trigger('dialog:open', @dialog)
\r
36 if item.item_name() == @target_model.item_name()
\r
38 @listenTo(this, 'ready', @ready)
\r
39 balloon_list = item.has_one('balloon')
\r
40 speech_list = item.has_one('speech')
\r
41 balloon_list.open(() =>
\r
42 balloon = balloon_list.items()[0]
\r
43 speech_list.open(() =>
\r
44 speech = speech_list.items()[0]
\r
45 new_item = new @target_model(item.attributes)
\r
46 new_item.unset('id', {silent: true})
\r
47 new_item.set({panel_id: @editor().item.get('id')}, {silent: true})
\r
48 balloon.unset('id', {silent: true})
\r
49 balloon.unset('speech_balloon_id', {silent: true})
\r
50 speech.unset('id', {silent: true})
\r
51 speech.unset('speech_balloon_id', {silent: true})
\r
52 new_item.boosts 'post'
\r
53 balloon.boosts 'post'
\r
54 speech.boosts 'post'
\r
55 new_item.set({balloon: balloon, speech: speech}, {silent: true})
\r
56 @trigger('ready', new_item)
\r
59 else if @target_model.is_traceable(item.item_name())
\r
61 tracer_class = @target_model['TraceFrom' + item.singular()]
\r
62 tracer = new tracer_class()
\r
63 @listenTo(tracer, 'trace', @trace)
\r
65 else if item.item_name() == @target_model.pick_item_name()
\r
67 @listenTo(this, 'ready', @ready)
\r
68 speech_balloon_template = item
\r
69 writing_format_list = Locmare.ListGroup.list(
\r
70 'writing_formats', 'index', {}
\r
72 writing_format_list.open(() =>
\r
73 writing_format = writing_format_list.items()[0]
\r
75 speech_balloon_template: speech_balloon_template,
\r
76 writing_format: writing_format
\r
78 new_item = new @target_model()
\r
79 new_item.templates = templates
\r
80 new_item.set(new_item.pick(), {silent: true})
\r
81 new_item.boosts 'post'
\r
82 new_item.supply_default()
\r
84 balloon = new Pettanr.Balloon()
\r
85 balloon.templates = templates
\r
86 balloon.set(balloon.pick(), {silent: true})
\r
87 balloon.boosts 'post'
\r
88 balloon.supply_default()
\r
90 speech = new Pettanr.Speech()
\r
91 speech.templates = templates
\r
92 speech.set(speech.pick(), {silent: true})
\r
93 speech.boosts 'post'
\r
94 speech.supply_default()
\r
96 new_item.set({balloon: balloon, speech: speech}, {silent: true})
\r
97 @trigger('ready', new_item)
\r
100 ready: (new_item) ->
\r
102 @trigger('pick', new_item)
\r
104 trace: (speech_balloon) ->
\r
105 @dialog.http_get(speech_balloon.show_url())
\r