2 confirm_confirm_confirm = () ->
\r
4 editor = window.PettanrEditor
\r
5 _.extend(window.configurations, window.configurations2)
\r
6 j = JSON.stringify(window.configurations, undefined, 2)
\r
7 $('#pettanr-configurations').val(j)
\r
8 configurations = window.configurations
\r
9 WritingFormat = window.PettanrWritingFormat
\r
10 WritingFormat.load($('#writing_formats'))
\r
11 SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate
\r
12 SpeechBalloonTemplate.load($('#speech_balloon_templates'))
\r
13 for n, v of SpeechBalloonTemplate.scripts
\r
15 v.add_helper( n, '' )
\r
16 PictureSizeHelper = window.PettanrPictureSizeHelper
\r
17 ColorHelper = window.PettanrColorHelper
\r
18 PopupHelper = window.PettanrPopupHelper
\r
21 #pp = new PanelPicture
\r
22 #pp.set_panel(panel)
\r
23 #confirm( PanelPicture.test() )
\r
24 #confirm( pp.test() )
\r
25 find_configurations = ( hash, key) ->
\r
26 if typeof(hash[key]) == 'string'
\r
27 find_configurations(hash, hash[key])
\r
31 set_validates = (form) ->
\r
33 $('input', form).map ->
\r
34 model_name = $(@).attr('data-model')
\r
35 column_name = $(@).attr('column')
\r
36 name = $(@).attr('name')
\r
37 if model_name and column_name
\r
38 model = find_configurations(configurations['models'], model_name)
\r
39 rule = model['attributes'][column_name]['rules']
\r
40 trace = editor.element_tag_id($(@))
\r
44 if editor.is_panel(form)
\r
45 validate_panel(form)
\r
47 validate_element(form)
\r
48 if Object.keys(rules).length > 0
\r
49 v = form.validate({ignore:[],rules: rules})
\r
51 display_panel = (panel, vis) ->
\r
56 trace = editor.panel_tag_id(panel)
\r
57 $(trace).css('display', v)
\r
59 validate_panel = (form) ->
\r
60 valid = form.valid()
\r
65 $('a', $('#tabs-1-tab')).map ->
\r
66 $(@).css('background-color', bc)
\r
67 display_panel(form, valid)
\r
70 display_element = (element, vis) ->
\r
71 trace = editor.element_tag_id(element)
\r
72 d = $(trace + '_destroy').val()
\r
73 v = if vis and d.length < 1
\r
77 switch element.attr('element_type')
\r
78 when 'panel_picture'
\r
79 trace = trace + 'div'
\r
80 $(trace).css('display', v)
\r
82 validate_element = (form) ->
\r
83 valid = form.valid()
\r
88 display_element(form, valid)
\r
89 trace = editor.element_tag_id(form)
\r
90 $('.elements-tab', $(trace + 'element_tab')).map ->
\r
91 $(@).css('background-color', bc)
\r
94 validate_forms = () ->
\r
96 $('form', $('#tabs-1')).map ->
\r
97 form_name = $(@).attr('data-form-name')
\r
99 if validate_panel($(@))
\r
102 invalid_elements = []
\r
103 $('form', $('#tabs-2')).map ->
\r
104 form_name = $(@).attr('data-form-name')
\r
106 if validate_element($(@))
\r
109 invalid_elements.push form_name
\r
110 if invalid_elements.length > 0
\r
114 $('a', $('#tabs-2-tab')).map ->
\r
115 $(@).css('background-color', bc)
\r
118 form_name = $(@).attr('data-form-name')
\r
121 set_validates(form)
\r
122 $('.panel-editor').map ->
\r
123 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
124 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
125 if editor.is_editting()
\r
127 $('#elements-tabs').tabs()
\r
128 $('#new-element-tabs').tabs()
\r
129 $('#new-speech_balloon-tabs').tabs()
\r
130 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
131 $("#elements-tabs li").removeClass("ui-corner-top")
\r
132 $("#elements-tabs li").addClass("ui-corner-left")
\r
133 $("#elements-tabs li").map ->
\r
135 switch $(@).attr('element_type')
\r
136 when 'speech_balloon'
\r
137 trace = editor.element_tag_id($(@))
\r
138 t = $('img', $(trace))
\r
139 when 'panel_picture'
\r
140 trace = editor.element_tag_id($(@)) + 'img'
\r
145 $('.ui-resizable-handle', t.parent()).map ->
\r
146 $(@).css('display', 'block')
\r
148 switch $(@).attr('element_type')
\r
149 when 'speech_balloon'
\r
150 trace = editor.element_tag_id($(@))
\r
151 t = $('img', $(trace))
\r
152 when 'panel_picture'
\r
153 trace = editor.element_tag_id($(@)) + 'img'
\r
158 $('.ui-resizable-handle', t.parent()).map ->
\r
159 $(@).css('display', 'none')
\r
162 $('.ui-icon-destroy').map ->
\r
165 primary: 'ui-icon-close',
\r
171 if confirm('destroy ?')
\r
172 trace = editor.element_tag_id($(@))
\r
173 $(trace + '_destroy').val('true')
\r
174 panel_trace = editor.panel_tag_id($(@))
\r
175 update_t(panel_trace + 'tsort')
\r
176 update_z(panel_trace + 'zsort')
\r
178 $(trace + 'element_tab').css('display', 'none')
\r
179 $(trace + 'tab_panel').css('display', 'none')
\r
180 $(trace + 'zsort').css('display', 'none')
\r
181 $(trace + 'tsort').css('display', 'none')
\r
182 display_element($(@), false)
\r
184 $('#pettanr-panel-submit').focusin ->
\r
185 editor.refresh_attribute($('#pettanr-panel-json'))
\r
188 $('.pettanr-comic-panel').map ->
\r
189 if editor.is_editable($(@))
\r
191 stop: ( event, ui ) ->
\r
192 trace = editor.panel_tag_id($(@))
\r
193 w = parseInt($(@).width())
\r
194 h = parseInt($(@).height())
\r
195 $(trace + 'width').val(w)
\r
196 $(trace + 'height').val(h)
\r
197 $('.pettanr-comic-ground-picture').map ->
\r
200 $('.pettanr-comic-ground-color').map ->
\r
208 if $(@).attr('element_type')
\r
210 if $(@).attr('panel_id')
\r
212 switch $(@).attr('column')
\r
214 trace = editor.panel_tag_id($(@))
\r
215 $(trace).width(parseInt( $(@).val()))
\r
217 trace = editor.panel_tag_id($(@))
\r
218 $(trace).height(parseInt( $(@).val()))
\r
220 trace = editor.panel_tag_id($(@))
\r
221 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
224 PictureSizeHelper.add_helper()
\r
225 PopupHelper.add_helper()
\r
227 $('.pettanr-panel-picture-wrapper').map ->
\r
229 stop: ( event, ui ) ->
\r
230 trace = editor.element_tag_id($(@))
\r
231 img = $(trace + 'img')
\r
232 left = img.parent().position().left + $(@).position().left
\r
233 top = img.parent().position().top + $(@).position().top
\r
234 $(trace + 'x').val(parseInt(left))
\r
235 $(trace + 'y').val(parseInt(top))
\r
238 $('.panel-picture').map ->
\r
240 stop: ( event, ui ) ->
\r
242 panel_picture_div = resize_div.parent()
\r
243 trace = editor.element_tag_id(panel_picture_div)
\r
245 resize_div.css('top', '0px')
\r
246 resize_div.css('left', '0px')
\r
247 if ui.originalPosition.top != ui.position.top
\r
248 t = panel_picture_div.position().top + ui.position.top
\r
249 $(trace + 'y').val(Math.floor(t))
\r
250 panel_picture_div.css('top', t.toString() + 'px')
\r
251 if ui.originalPosition.left != ui.position.left
\r
252 l = panel_picture_div.position().left + ui.position.left
\r
253 $(trace + 'x').val(Math.floor(l))
\r
254 panel_picture_div.css('left', l.toString() + 'px')
\r
255 w = if $(trace + 'width').val() < 0
\r
259 h = if $(trace + 'height').val() < 0
\r
263 $(trace + 'width').val(w)
\r
264 $(trace + 'height').val(h)
\r
265 resize: ( event, ui ) ->
\r
267 panel_picture_div = resize_div.parent()
\r
268 trace = editor.element_tag_id(panel_picture_div)
\r
275 if editor.element_is('panel_picture', $(@))
\r
277 switch $(@).attr('column')
\r
279 trace = editor.element_tag_id($(@)) + 'div'
\r
280 v = parseInt($(@).val()).toString() + 'px'
\r
281 $(trace).css('left', v)
\r
283 trace = editor.element_tag_id($(@)) + 'div'
\r
284 v = parseInt($(@).val()).toString() + 'px'
\r
285 $(trace).css('top', v)
\r
287 trace = editor.element_tag_id($(@)) + 'img'
\r
288 w = parseInt($(@).val())
\r
289 $(trace).width(Math.abs(w))
\r
290 $(trace).parent().width(Math.abs(w))
\r
291 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
293 trace = editor.element_tag_id($(@)) + 'img'
\r
294 h = parseInt($(@).val())
\r
295 $(trace).height(Math.abs(h))
\r
296 $(trace).parent().height(Math.abs(h))
\r
297 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
299 PictureSizeHelper.refresh_picture($(trace), w, h)
\r
303 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
\r
305 $('.pettanr-comic-balloon' ).map ->
\r
307 stop: ( event, ui ) ->
\r
308 balloon = $('.pettanr-balloon', $(@))
\r
309 trace = editor.element_part_tag_id(balloon)
\r
310 left = $(@).position().left
\r
311 top = $(@).position().top
\r
312 $(trace + 'x').val(parseInt(left))
\r
313 $(trace + 'y').val(parseInt(top))
\r
316 $('.pettanr-balloon' ).map ->
\r
318 stop: ( event, ui ) ->
\r
320 speech_balloon_div = resize_div.parent()
\r
321 balloon = $('.pettanr-balloon', $(@))
\r
322 trace = editor.element_tag_id(speech_balloon_div)
\r
323 trace_balloon = editor.element_part_tag_id(balloon)
\r
325 resize_div.css('top', '0px')
\r
326 resize_div.css('left', '0px')
\r
329 if ui.originalPosition.top != ui.position.top
\r
330 t = speech_balloon_div.position().top + ui.position.top
\r
331 $(trace_balloon + 'y').val(Math.floor(t))
\r
332 speech_balloon_div.css('top', t.toString() + 'px')
\r
333 speech_balloon_div.css('height', h + 'px')
\r
334 if ui.originalPosition.left != ui.position.left
\r
335 l = speech_balloon_div.position().left + ui.position.left
\r
336 $(trace_balloon + 'x').val(Math.floor(l))
\r
337 speech_balloon_div.css('left', l.toString() + 'px')
\r
338 speech_balloon_div.css('width', w + 'px')
\r
339 $(trace_balloon + 'width').val(w)
\r
340 $(trace_balloon + 'height').val(h)
\r
341 speech_balloon_div.css('width', w.toString() + 'px')
\r
342 speech_balloon_div.css('height', h.toString() + 'px')
\r
343 resize: ( event, ui ) ->
\r
345 speech_balloon_div = resize_div.parent()
\r
346 balloon = $('.pettanr-balloon', $(@))
\r
347 trace = editor.element_tag_id(speech_balloon_div)
\r
348 trace_balloon = editor.element_part_tag_id(balloon)
\r
353 $('.pettanr-comic-speech-inner' ).map ->
\r
355 outer = $(@).parent()
\r
356 sb = outer.parent()
\r
357 trace = editor.element_tag_id(sb)
\r
358 img = $('.pettanr-balloon', $(trace))
\r
359 $('.ui-resizable-handle', img.parent()).map ->
\r
360 $(@).css('display', 'block')
\r
362 outer = $(@).parent()
\r
363 sb = outer.parent()
\r
364 trace = editor.element_tag_id(sb)
\r
365 img = $('.pettanr-balloon', $(trace))
\r
366 $('.ui-resizable-handle', img.parent()).map ->
\r
367 $(@).css('display', 'none')
\r
372 if editor.element_is('speech_balloon', $(@))
\r
374 switch $(@).attr('column')
\r
376 trace = editor.element_tag_id($(@))
\r
377 v = parseInt($(@).val()).toString() + 'px'
\r
378 $(trace).css('left', v)
\r
380 trace = editor.element_tag_id($(@))
\r
381 v = parseInt($(@).val()).toString() + 'px'
\r
382 $(trace).css('top', v)
\r
384 trace = editor.element_tag_id($(@))
\r
385 v = parseInt($(@).val())
\r
386 $(trace).width(Math.abs(v))
\r
387 img = $('.pettanr-balloon', $(trace))
\r
388 img.parent().width(v)
\r
391 trace = editor.element_tag_id($(@))
\r
392 v = parseInt($(@).val())
\r
393 $(trace).height(Math.abs(v))
\r
394 img = $('.pettanr-balloon', $(trace))
\r
395 img.parent().height(v)
\r
399 $('textarea').map ->
\r
400 if editor.element_is('speech_balloon', $(@))
\r
402 switch $(@).attr('column')
\r
404 trace = editor.element_part_tag_id($(@))
\r
405 wf_sel = $(trace + 'writing_format_id')
\r
406 wf_id = parseInt(wf_sel.val())
\r
407 v = WritingFormat.render(wf_id, $(@).val())
\r
409 $('textarea').map ->
\r
410 if editor.element_is('speech_balloon', $(@))
\r
411 switch $(@).attr('column')
\r
413 $(@).bind('textchange', (event, previousText) ->
\r
414 trace = editor.element_part_tag_id($(@))
\r
415 wf_sel = $(trace + 'writing_format_id')
\r
416 wf_id = parseInt(wf_sel.val())
\r
417 v = WritingFormat.render(wf_id, $(@).val())
\r
421 if editor.element_is('speech_balloon', $(@))
\r
423 switch $(@).attr('column')
\r
425 trace = editor.element_part_tag_id($(@))
\r
426 $(trace).css('font-size', $(@).val() + 'em')
\r
428 trace = editor.element_part_tag_id($(@))
\r
429 v = parseInt($(@).val())
\r
430 $(trace).css('text-align', editor.text_align_texts[v])
\r
433 if editor.element_is('speech_balloon', $(@))
\r
434 if $(@).attr('column') == 'fore_color'
\r
439 refresh_ground_picture = (element_trace) ->
\r
440 x = parseInt($(element_trace + 'x').val()).toString() + 'px'
\r
441 y = parseInt($(element_trace + 'y').val()).toString() + 'px'
\r
442 $(element_trace).css('background-position', x + ' ' + y)
\r
446 if editor.element_is('ground_picture', $(@))
\r
447 switch $(@).attr('column')
\r
450 trace = editor.element_tag_id($(@))
\r
451 refresh_ground_picture(trace)
\r
453 stop: ( event, ui ) ->
\r
454 trace = editor.element_tag_id($(@))
\r
455 refresh_ground_picture(trace)
\r
458 if editor.element_is('ground_picture', $(@))
\r
460 switch $(@).attr('column')
\r
462 trace = editor.element_tag_id($(@))
\r
463 v = parseInt($(@).val())
\r
464 $(trace).css('background-repeat', editor.repeat_texts[v])
\r
469 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
\r
471 refresh_ground_color = (element_trace) ->
\r
472 orientation = parseInt( $(element_trace + 'orientation').val() )
\r
473 xy = $(element_trace + 'xy').val()
\r
474 wh = $(element_trace + 'wh').val()
\r
483 div_x = if orientation == 0
\r
487 div_y = if orientation == 0
\r
491 div_width = if orientation == 0
\r
495 div_height = if orientation == 0
\r
499 div = $(element_trace)
\r
500 div.css('left', div_x.toString() + '%')
\r
501 div.css('top', div_y.toString() + '%')
\r
502 div.css('width', div_width.toString() + '%')
\r
503 div.css('height', div_height.toString() + '%')
\r
507 if editor.element_is('ground_color', $(@))
\r
508 switch $(@).attr('column')
\r
513 stop: ( event, ui ) ->
\r
514 trace = editor.element_tag_id($(@))
\r
515 refresh_ground_color(trace)
\r
520 trace = editor.element_tag_id($(@))
\r
521 refresh_ground_color(trace)
\r
524 if editor.element_is('ground_color', $(@))
\r
525 switch $(@).attr('column')
\r
528 trace = editor.element_tag_id($(@))
\r
529 refresh_ground_color(trace)
\r
531 update_t = (ultrace) ->
\r
533 $(ultrace + ' li').map ->
\r
534 trace = editor.element_tag_id($(@))
\r
535 if $(trace + '_destroy').val().length < 1
\r
536 $(trace + 't').val(t)
\r
540 $('.tsort').map ->
\r
542 update: ( event, ui ) ->
\r
543 trace = editor.panel_tag_id($(@))
\r
544 update_t(trace + 'tsort')
\r
546 $('.t-sort li').map ->
\r
547 $(@).disableSelection()
\r
549 update_z = (ultrace) ->
\r
551 $(ultrace + ' li').map ->
\r
552 trace = editor.element_tag_id($(@))
\r
554 if $(trace + '_destroy').val().length < 1
\r
555 $(trace + 'z').val(z)
\r
556 switch $(@).attr('element_type')
\r
557 when 'panel_picture'
\r
558 trace = trace + 'div'
\r
559 $(trace).css('zIndex', z)
\r
563 $('.zsort').map ->
\r
565 update: ( event, ui ) ->
\r
566 trace = editor.panel_tag_id($(@))
\r
567 update_z(trace + 'zsort')
\r
569 $('.z-sort li').map ->
\r
570 $(@).disableSelection()
\r
573 # disable form actions
\r
574 # hide submit buttons
\r
575 $('.edit_panel_picture' ).map ->
\r
578 $('.edit_speech_balloon' ).map ->
\r
581 $('.edit_ground_picture' ).map ->
\r
584 $('.edit_ground_color' ).map ->
\r
588 $('.edit_panel' ).map ->
\r
589 if $(@).attr('jqform')
\r
591 if validate_forms()
\r
599 $('.submit' ).map ->
\r
604 if editor.is_element($(@))
\r
605 switch $(@).attr('column')
\r
608 $(@).parent().hide() #label
\r
610 # add button on new form
\r
611 $('.submit-new-form').map ->
\r
612 $(@).html('<button class="new-element">add</button>')
\r
614 $('.new-element').map ->
\r