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 new_item = new @target_model(item.attributes)
\r
29 @trigger('ready', new_item)
\r
30 else if @target_model.is_traceable(item.item_name())
\r
32 n = @target_model['trace_from_' + item.item_name()]
\r
34 else if item.item_name() == @target_model.pick_item_name()
\r
36 speech_balloon_template = item
\r
37 writing_format = new Pettanr.WritingFormat({id: 1})
\r
38 writing_format.fetch({cache: true}).done =>
\r
40 speech_balloon_template: speech_balloon_template,
\r
41 writing_format: writing_format
\r
43 new_item = new @target_model()
\r
44 new_item.set(new_item.pick(templates), {silent: true})
\r
45 new_item.boosts 'post'
\r
46 new_item.supply_default(templates)
\r
48 balloon = new Pettanr.Balloon()
\r
49 balloon.set(balloon.pick(templates), {silent: true})
\r
50 balloon.boosts 'post'
\r
51 balloon.supply_default(templates)
\r
53 speech = new Pettanr.Speech()
\r
54 speech.set(speech.pick(templates), {silent: true})
\r
55 speech.boosts 'post'
\r
56 speech.supply_default(templates)
\r
58 new_item.set({balloon: balloon, speech: speech}, {silent: true})
\r
59 @trigger('ready', new_item)
\r
61 ready: (new_item) ->
\r
63 @trigger('pick', new_item)
\r