1 class Pettanr.Views.SpeechBalloon.NewElementLauncher extends Editor.EditorModule.DockModule.NewElementLauncher
\r
3 initialize: (options) ->
\r
6 _.extend(@links_conf, {
\r
10 controller: @model.pick_model().path_name(), action: 'index',
\r
11 page_size: 6, format: 'html'
\r
15 _.extend(@links_conf, {
\r
17 caption: "Inspire recent item",
\r
19 controller: @model.path_name(), action: 'index',
\r
20 page_size: 6, format: 'html'
\r
24 if Pettanr.cache.operators.author
\r
25 _.extend(@links_conf, {
\r
26 inspire_my_recent: {
\r
27 caption: 'Inspire my recent item',
\r
29 controller: @model.path_name(), action: 'by_author', id: Pettanr.cache.operators.author.get('id'),
\r
30 page_size: 6, format: 'html'
\r
40 click_template: () ->
\r
41 @click_default(@links_conf.template.params)
\r
43 click_inspire_recent: () ->
\r
44 @click_default(@links_conf.inspire_recent.params)
\r
46 click_inspire_my_recent: () ->
\r
47 @click_default(@links_conf.inspire_my_recent.params)
\r
49 class Pettanr.Views.SpeechBalloon.NewElement extends Backbone.View
\r
51 initialize: (options) ->
\r
52 @parent = options.parent
\r
53 @target_model = options.target_model
\r
54 @pick_model = @target_model.pick_model()
\r
56 start: (@dialog, params) ->
\r
57 @dialog.start(@target_model, params, null)
\r
58 @listenTo(@dialog, 'pick', @pick)
\r
59 @trigger('dialog:open', @dialog)
\r
62 if item.item_name() == @target_model.item_name()
\r
64 @listenTo(this, 'ready', @ready)
\r
65 balloon_list = item.has_one('balloon')
\r
66 speech_list = item.has_one('speech')
\r
67 balloon_list.open(() =>
\r
68 balloon = balloon_list.items()[0]
\r
69 speech_list.open(() =>
\r
70 speech = speech_list.items()[0]
\r
71 new_item = new @target_model(item.attributes)
\r
72 new_item.unset('id', {silent: true})
\r
73 new_item.set({panel_id: @editor().item.get('id')}, {silent: true})
\r
74 balloon.unset('id', {silent: true})
\r
75 balloon.unset('speech_balloon_id', {silent: true})
\r
76 speech.unset('id', {silent: true})
\r
77 speech.unset('speech_balloon_id', {silent: true})
\r
78 new_item.boosts 'post'
\r
79 balloon.boosts 'post'
\r
80 speech.boosts 'post'
\r
81 new_item.set({balloon: balloon, speech: speech}, {silent: true})
\r
82 @trigger('ready', new_item)
\r
85 else if @target_model.is_traceable(item.item_name())
\r
87 tracer_class = @target_model['TraceFrom' + item.singular()]
\r
88 tracer = new tracer_class()
\r
89 @listenTo(tracer, 'trace', @trace)
\r
91 else if item.item_name() == @target_model.pick_item_name()
\r
93 @listenTo(this, 'ready', @ready)
\r
94 speech_balloon_template = item
\r
95 writing_format_list = Locmare.ListGroup.list(
\r
96 'writing_formats', 'index', {}
\r
98 writing_format_list.open(() =>
\r
99 writing_format = writing_format_list.items()[0]
\r
101 speech_balloon_template: speech_balloon_template,
\r
102 writing_format: writing_format
\r
104 new_item = new @target_model()
\r
105 new_item.templates = templates
\r
106 new_item.set(new_item.pick(), {silent: true})
\r
107 new_item.boosts 'post'
\r
108 new_item.supply_default()
\r
110 balloon = new Pettanr.Balloon()
\r
111 balloon.templates = templates
\r
112 balloon.set(balloon.pick(), {silent: true})
\r
113 balloon.boosts 'post'
\r
114 balloon.supply_default()
\r
116 speech = new Pettanr.Speech()
\r
117 speech.templates = templates
\r
118 speech.set(speech.pick(), {silent: true})
\r
119 speech.boosts 'post'
\r
120 speech.supply_default()
\r
122 new_item.set({balloon: balloon, speech: speech}, {silent: true})
\r
123 @trigger('ready', new_item)
\r
126 ready: (new_item) ->
\r
128 @trigger('pick', new_item)
\r
130 trace: (speech_balloon) ->
\r
131 @dialog.http_get(speech_balloon.show_url())
\r