1 class Pettanr.Views.SpeechBalloon.NewElement extends Backbone.View
\r
3 className: 'new-element-body'
\r
5 initialize: (options) ->
\r
6 @parent = options.parent
\r
7 @target_model = options.target_model
\r
8 @pick_model = @target_model.pick_model()
\r
13 controller: @pick_model.path_name(), action: 'index',
\r
14 page_size: 6, format: 'html'
\r
16 @dialog().start(@target_model, params, null)
\r
17 @listenTo(@dialog(), 'pick', @pick)
\r
25 @listenTo(this, 'ready', @ready)
\r
26 if item.item_name() == @target_model.item_name()
\r
28 balloon_list = item.has_one('balloon')
\r
29 speech_list = item.has_one('speech')
\r
30 balloon_list.open(() =>
\r
31 balloon = balloon_list.items()[0]
\r
32 speech_list.open(() =>
\r
33 speech = speech_list.items()[0]
\r
34 new_item = new @target_model(item.attributes)
\r
35 new_item.unset('id', {silent: true})
\r
36 new_item.set({panel_id: @editor().item.get('id')}, {silent: true})
\r
37 balloon.unset('id', {silent: true})
\r
38 balloon.unset('speech_balloon_id', {silent: true})
\r
39 speech.unset('id', {silent: true})
\r
40 speech.unset('speech_balloon_id', {silent: true})
\r
41 new_item.boosts 'post'
\r
42 balloon.boosts 'post'
\r
43 speech.boosts 'post'
\r
44 new_item.set({balloon: balloon, speech: speech}, {silent: true})
\r
45 @trigger('ready', new_item)
\r
48 else if @target_model.is_traceable(item.item_name())
\r
50 n = @target_model['trace_from_' + item.item_name()]
\r
52 else if item.item_name() == @target_model.pick_item_name()
\r
54 speech_balloon_template = item
\r
55 writing_format = new Pettanr.WritingFormat({id: 1})
\r
56 writing_format.fetch({cache: true}).done =>
\r
58 speech_balloon_template: speech_balloon_template,
\r
59 writing_format: writing_format
\r
61 new_item = new @target_model()
\r
62 new_item.set(new_item.pick(templates), {silent: true})
\r
63 new_item.boosts 'post'
\r
64 new_item.supply_default(templates)
\r
66 balloon = new Pettanr.Balloon()
\r
67 balloon.set(balloon.pick(templates), {silent: true})
\r
68 balloon.boosts 'post'
\r
69 balloon.supply_default(templates)
\r
71 speech = new Pettanr.Speech()
\r
72 speech.set(speech.pick(templates), {silent: true})
\r
73 speech.boosts 'post'
\r
74 speech.supply_default(templates)
\r
76 new_item.set({balloon: balloon, speech: speech}, {silent: true})
\r
77 @trigger('ready', new_item)
\r
79 ready: (new_item) ->
\r
81 @trigger('pick', new_item)
\r