2 #filer = new Filer('tt', ['ea','eb','ec'])
\r
3 #view = new FilerView( { filer: filer } )
\r
4 confirm_confirm_confirm = () ->
\r
6 editor = window.PettanrEditor
\r
7 WritingFormat = window.PettanrWritingFormat
\r
8 WritingFormat.load($('#writing_formats'))
\r
9 SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate
\r
10 SpeechBalloonTemplate.load($('#speech_balloon_templates'))
\r
11 for n, v of SpeechBalloonTemplate.scripts
\r
13 v.add_helper( n, '' )
\r
14 PictureSizeHelper = window.PettanrPictureSizeHelper
\r
15 ColorHelper = window.PettanrColorHelper
\r
16 PopupHelper = window.PettanrPopupHelper
\r
19 #pp = new PanelPicture
\r
20 #pp.set_panel(panel)
\r
21 #confirm( PanelPicture.test() )
\r
22 #confirm( pp.test() )
\r
23 find_configurations = ( hash, key) ->
\r
24 if typeof(hash[key]) == 'string'
\r
25 find_configurations(hash, hash[key])
\r
29 set_validates = (form) ->
\r
31 $('input', form).map ->
\r
32 model_name = $(@).attr('data-model')
\r
33 column_name = $(@).attr('column')
\r
34 name = $(@).attr('name')
\r
35 if model_name and column_name
\r
36 model = find_configurations(configurations['models'], model_name)
\r
37 rule = model['attributes'][column_name]['rules']
\r
38 trace = editor.element_tag_id($(@))
\r
42 if editor.is_panel(form)
\r
43 validate_panel(form)
\r
45 validate_element(form)
\r
46 if Object.keys(rules).length > 0
\r
47 v = form.validate({ignore:[],rules: rules})
\r
49 display_panel = (panel, vis) ->
\r
54 trace = editor.panel_tag_id(panel)
\r
55 $(trace).css('display', v)
\r
57 validate_panel = (form) ->
\r
58 valid = form.valid()
\r
63 $('a', $('#tabs-1-tab')).map ->
\r
64 $(@).css('background-color', bc)
\r
65 display_panel(form, valid)
\r
68 display_element = (element, vis) ->
\r
69 trace = editor.element_tag_id(element)
\r
70 d = $(trace + '_destroy').val()
\r
71 v = if vis and d.length < 1
\r
75 switch element.attr('element_type')
\r
76 when 'panel_picture'
\r
77 trace = trace + 'div'
\r
78 $(trace).css('display', v)
\r
80 validate_element = (form) ->
\r
81 valid = form.valid()
\r
86 display_element(form, valid)
\r
87 trace = editor.element_tag_id(form)
\r
88 $('.elements-tab', $(trace + 'element_tab')).map ->
\r
89 $(@).css('background-color', bc)
\r
92 validate_forms = () ->
\r
94 $('form', $('#tabs-1')).map ->
\r
95 form_name = $(@).attr('data-form-name')
\r
97 if validate_panel($(@))
\r
100 invalid_elements = []
\r
101 $('form', $('#tabs-2')).map ->
\r
102 form_name = $(@).attr('data-form-name')
\r
104 if validate_element($(@))
\r
107 invalid_elements.push form_name
\r
108 if invalid_elements.length > 0
\r
112 $('a', $('#tabs-2-tab')).map ->
\r
113 $(@).css('background-color', bc)
\r
116 form_name = $(@).attr('data-form-name')
\r
119 set_validates(form)
\r
120 $('.panel-editor').map ->
\r
121 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
122 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
123 if editor.is_editting()
\r
125 $('#elements-tabs').tabs()
\r
126 $('#new-element-tabs').tabs()
\r
127 $('#new-speech_balloon-tabs').tabs()
\r
128 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
129 $("#elements-tabs li").removeClass("ui-corner-top")
\r
130 $("#elements-tabs li").addClass("ui-corner-left")
\r
131 $("#elements-tabs li").map ->
\r
133 switch $(@).attr('element_type')
\r
134 when 'speech_balloon'
\r
135 trace = editor.element_tag_id($(@))
\r
136 t = $('img', $(trace))
\r
137 when 'panel_picture'
\r
138 trace = editor.element_tag_id($(@)) + 'img'
\r
143 $('.ui-resizable-handle', t.parent()).map ->
\r
144 $(@).css('display', 'block')
\r
146 switch $(@).attr('element_type')
\r
147 when 'speech_balloon'
\r
148 trace = editor.element_tag_id($(@))
\r
149 t = $('img', $(trace))
\r
150 when 'panel_picture'
\r
151 trace = editor.element_tag_id($(@)) + 'img'
\r
156 $('.ui-resizable-handle', t.parent()).map ->
\r
157 $(@).css('display', 'none')
\r
160 $('.ui-icon-destroy').map ->
\r
163 primary: 'ui-icon-close',
\r
169 if confirm('destroy ?')
\r
170 trace = editor.element_tag_id($(@))
\r
171 $(trace + '_destroy').val('true')
\r
172 panel_trace = editor.panel_tag_id($(@))
\r
173 update_t(panel_trace + 'tsort')
\r
174 update_z(panel_trace + 'zsort')
\r
176 $(trace + 'element_tab').css('display', 'none')
\r
177 $(trace + 'tab_panel').css('display', 'none')
\r
178 $(trace + 'zsort').css('display', 'none')
\r
179 $(trace + 'tsort').css('display', 'none')
\r
180 display_element($(@), false)
\r
182 $('#pettanr-panel-submit').focusin ->
\r
183 editor.refresh_attribute($('#pettanr-panel-json'))
\r
186 $('.pettanr-comic-panel').map ->
\r
187 if editor.is_editable($(@))
\r
189 stop: ( event, ui ) ->
\r
190 trace = editor.panel_tag_id($(@))
\r
191 w = parseInt($(@).width())
\r
192 h = parseInt($(@).height())
\r
193 $(trace + 'width').val(w)
\r
194 $(trace + 'height').val(h)
\r
195 $('.pettanr-comic-ground-picture').map ->
\r
198 $('.pettanr-comic-ground-color').map ->
\r
206 if $(@).attr('element_type')
\r
208 if $(@).attr('panel_id')
\r
210 switch $(@).attr('column')
\r
212 trace = editor.panel_tag_id($(@))
\r
213 $(trace).width(parseInt( $(@).val()))
\r
215 trace = editor.panel_tag_id($(@))
\r
216 $(trace).height(parseInt( $(@).val()))
\r
218 trace = editor.panel_tag_id($(@))
\r
219 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
222 PictureSizeHelper.add_helper()
\r
223 PopupHelper.add_helper()
\r
225 $('.pettanr-panel-picture-wrapper').map ->
\r
227 stop: ( event, ui ) ->
\r
228 trace = editor.element_tag_id($(@))
\r
229 img = $(trace + 'img')
\r
230 left = img.parent().position().left + $(@).position().left
\r
231 top = img.parent().position().top + $(@).position().top
\r
232 $(trace + 'x').val(parseInt(left))
\r
233 $(trace + 'y').val(parseInt(top))
\r
236 $('.panel-picture').map ->
\r
238 stop: ( event, ui ) ->
\r
240 panel_picture_div = resize_div.parent()
\r
241 trace = editor.element_tag_id(panel_picture_div)
\r
243 resize_div.css('top', '0px')
\r
244 resize_div.css('left', '0px')
\r
245 if ui.originalPosition.top != ui.position.top
\r
246 t = panel_picture_div.position().top + ui.position.top
\r
247 $(trace + 'y').val(Math.floor(t))
\r
248 panel_picture_div.css('top', t.toString() + 'px')
\r
249 if ui.originalPosition.left != ui.position.left
\r
250 l = panel_picture_div.position().left + ui.position.left
\r
251 $(trace + 'x').val(Math.floor(l))
\r
252 panel_picture_div.css('left', l.toString() + 'px')
\r
253 w = if $(trace + 'width').val() < 0
\r
257 h = if $(trace + 'height').val() < 0
\r
261 $(trace + 'width').val(w)
\r
262 $(trace + 'height').val(h)
\r
263 resize: ( event, ui ) ->
\r
265 panel_picture_div = resize_div.parent()
\r
266 trace = editor.element_tag_id(panel_picture_div)
\r
273 if editor.element_is('panel_picture', $(@))
\r
275 switch $(@).attr('column')
\r
277 trace = editor.element_tag_id($(@)) + 'div'
\r
278 v = parseInt($(@).val()).toString() + 'px'
\r
279 $(trace).css('left', v)
\r
281 trace = editor.element_tag_id($(@)) + 'div'
\r
282 v = parseInt($(@).val()).toString() + 'px'
\r
283 $(trace).css('top', v)
\r
285 trace = editor.element_tag_id($(@)) + 'img'
\r
286 w = parseInt($(@).val())
\r
287 $(trace).width(Math.abs(w))
\r
288 $(trace).parent().width(Math.abs(w))
\r
289 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
291 trace = editor.element_tag_id($(@)) + 'img'
\r
292 h = parseInt($(@).val())
\r
293 $(trace).height(Math.abs(h))
\r
294 $(trace).parent().height(Math.abs(h))
\r
295 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
297 PictureSizeHelper.refresh_picture($(trace), w, h)
\r
301 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
\r
303 $('.pettanr-comic-balloon' ).map ->
\r
305 stop: ( event, ui ) ->
\r
306 balloon = $('.pettanr-balloon', $(@))
\r
307 trace = editor.element_part_tag_id(balloon)
\r
308 left = $(@).position().left
\r
309 top = $(@).position().top
\r
310 $(trace + 'x').val(parseInt(left))
\r
311 $(trace + 'y').val(parseInt(top))
\r
314 $('.pettanr-balloon' ).map ->
\r
316 stop: ( event, ui ) ->
\r
318 speech_balloon_div = resize_div.parent()
\r
319 balloon = $('.pettanr-balloon', $(@))
\r
320 trace = editor.element_tag_id(speech_balloon_div)
\r
321 trace_balloon = editor.element_part_tag_id(balloon)
\r
323 resize_div.css('top', '0px')
\r
324 resize_div.css('left', '0px')
\r
327 if ui.originalPosition.top != ui.position.top
\r
328 t = speech_balloon_div.position().top + ui.position.top
\r
329 $(trace_balloon + 'y').val(Math.floor(t))
\r
330 speech_balloon_div.css('top', t.toString() + 'px')
\r
331 speech_balloon_div.css('height', h + 'px')
\r
332 if ui.originalPosition.left != ui.position.left
\r
333 l = speech_balloon_div.position().left + ui.position.left
\r
334 $(trace_balloon + 'x').val(Math.floor(l))
\r
335 speech_balloon_div.css('left', l.toString() + 'px')
\r
336 speech_balloon_div.css('width', w + 'px')
\r
337 $(trace_balloon + 'width').val(w)
\r
338 $(trace_balloon + 'height').val(h)
\r
339 speech_balloon_div.css('width', w.toString() + 'px')
\r
340 speech_balloon_div.css('height', h.toString() + 'px')
\r
341 resize: ( event, ui ) ->
\r
343 speech_balloon_div = resize_div.parent()
\r
344 balloon = $('.pettanr-balloon', $(@))
\r
345 trace = editor.element_tag_id(speech_balloon_div)
\r
346 trace_balloon = editor.element_part_tag_id(balloon)
\r
351 $('.pettanr-comic-speech-inner' ).map ->
\r
353 outer = $(@).parent()
\r
354 sb = outer.parent()
\r
355 trace = editor.element_tag_id(sb)
\r
356 img = $('.pettanr-balloon', $(trace))
\r
357 $('.ui-resizable-handle', img.parent()).map ->
\r
358 $(@).css('display', 'block')
\r
360 outer = $(@).parent()
\r
361 sb = outer.parent()
\r
362 trace = editor.element_tag_id(sb)
\r
363 img = $('.pettanr-balloon', $(trace))
\r
364 $('.ui-resizable-handle', img.parent()).map ->
\r
365 $(@).css('display', 'none')
\r
370 if editor.element_is('speech_balloon', $(@))
\r
372 switch $(@).attr('column')
\r
374 trace = editor.element_tag_id($(@))
\r
375 v = parseInt($(@).val()).toString() + 'px'
\r
376 $(trace).css('left', v)
\r
378 trace = editor.element_tag_id($(@))
\r
379 v = parseInt($(@).val()).toString() + 'px'
\r
380 $(trace).css('top', v)
\r
382 trace = editor.element_tag_id($(@))
\r
383 v = parseInt($(@).val())
\r
384 $(trace).width(Math.abs(v))
\r
385 img = $('.pettanr-balloon', $(trace))
\r
386 img.parent().width(v)
\r
389 trace = editor.element_tag_id($(@))
\r
390 v = parseInt($(@).val())
\r
391 $(trace).height(Math.abs(v))
\r
392 img = $('.pettanr-balloon', $(trace))
\r
393 img.parent().height(v)
\r
397 $('textarea').map ->
\r
398 if editor.element_is('speech_balloon', $(@))
\r
400 switch $(@).attr('column')
\r
402 trace = editor.element_part_tag_id($(@))
\r
403 wf_sel = $(trace + 'writing_format_id')
\r
404 wf_id = parseInt(wf_sel.val())
\r
405 v = WritingFormat.render(wf_id, $(@).val())
\r
407 $('textarea').map ->
\r
408 if editor.element_is('speech_balloon', $(@))
\r
409 switch $(@).attr('column')
\r
411 $(@).bind('textchange', (event, previousText) ->
\r
412 trace = editor.element_part_tag_id($(@))
\r
413 wf_sel = $(trace + 'writing_format_id')
\r
414 wf_id = parseInt(wf_sel.val())
\r
415 v = WritingFormat.render(wf_id, $(@).val())
\r
419 if editor.element_is('speech_balloon', $(@))
\r
421 switch $(@).attr('column')
\r
423 trace = editor.element_part_tag_id($(@))
\r
424 $(trace).css('font-size', $(@).val() + 'em')
\r
426 trace = editor.element_part_tag_id($(@))
\r
427 v = parseInt($(@).val())
\r
428 $(trace).css('text-align', editor.text_align_texts[v])
\r
431 if editor.element_is('speech_balloon', $(@))
\r
432 if $(@).attr('column') == 'fore_color'
\r
437 refresh_ground_picture = (element_trace) ->
\r
438 x = parseInt($(element_trace + 'x').val()).toString() + 'px'
\r
439 y = parseInt($(element_trace + 'y').val()).toString() + 'px'
\r
440 $(element_trace).css('background-position', x + ' ' + y)
\r
444 if editor.element_is('ground_picture', $(@))
\r
445 switch $(@).attr('column')
\r
448 trace = editor.element_tag_id($(@))
\r
449 refresh_ground_picture(trace)
\r
451 stop: ( event, ui ) ->
\r
452 trace = editor.element_tag_id($(@))
\r
453 refresh_ground_picture(trace)
\r
456 if editor.element_is('ground_picture', $(@))
\r
458 switch $(@).attr('column')
\r
460 trace = editor.element_tag_id($(@))
\r
461 v = parseInt($(@).val())
\r
462 $(trace).css('background-repeat', editor.repeat_texts[v])
\r
467 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
\r
469 refresh_ground_color = (element_trace) ->
\r
470 orientation = parseInt( $(element_trace + 'orientation').val() )
\r
471 xy = $(element_trace + 'xy').val()
\r
472 wh = $(element_trace + 'wh').val()
\r
481 div_x = if orientation == 0
\r
485 div_y = if orientation == 0
\r
489 div_width = if orientation == 0
\r
493 div_height = if orientation == 0
\r
497 div = $(element_trace)
\r
498 div.css('left', div_x.toString() + '%')
\r
499 div.css('top', div_y.toString() + '%')
\r
500 div.css('width', div_width.toString() + '%')
\r
501 div.css('height', div_height.toString() + '%')
\r
505 if editor.element_is('ground_color', $(@))
\r
506 switch $(@).attr('column')
\r
511 stop: ( event, ui ) ->
\r
512 trace = editor.element_tag_id($(@))
\r
513 refresh_ground_color(trace)
\r
518 trace = editor.element_tag_id($(@))
\r
519 refresh_ground_color(trace)
\r
522 if editor.element_is('ground_color', $(@))
\r
523 switch $(@).attr('column')
\r
526 trace = editor.element_tag_id($(@))
\r
527 refresh_ground_color(trace)
\r
529 update_t = (ultrace) ->
\r
531 $(ultrace + ' li').map ->
\r
532 trace = editor.element_tag_id($(@))
\r
533 if $(trace + '_destroy').val().length < 1
\r
534 $(trace + 't').val(t)
\r
538 $('.tsort').map ->
\r
540 update: ( event, ui ) ->
\r
541 trace = editor.panel_tag_id($(@))
\r
542 update_t(trace + 'tsort')
\r
544 $('.t-sort li').map ->
\r
545 $(@).disableSelection()
\r
547 update_z = (ultrace) ->
\r
549 $(ultrace + ' li').map ->
\r
550 trace = editor.element_tag_id($(@))
\r
552 if $(trace + '_destroy').val().length < 1
\r
553 $(trace + 'z').val(z)
\r
554 switch $(@).attr('element_type')
\r
555 when 'panel_picture'
\r
556 trace = trace + 'div'
\r
557 $(trace).css('zIndex', z)
\r
561 $('.zsort').map ->
\r
563 update: ( event, ui ) ->
\r
564 trace = editor.panel_tag_id($(@))
\r
565 update_z(trace + 'zsort')
\r
567 $('.z-sort li').map ->
\r
568 $(@).disableSelection()
\r
571 # disable form actions
\r
572 # hide submit buttons
\r
573 $('.edit_panel_picture' ).map ->
\r
576 $('.edit_speech_balloon' ).map ->
\r
579 $('.edit_ground_picture' ).map ->
\r
582 $('.edit_ground_color' ).map ->
\r
586 $('.edit_panel' ).map ->
\r
587 if $(@).attr('jqform')
\r
589 if validate_forms()
\r
597 $('.submit' ).map ->
\r
602 if editor.is_element($(@))
\r
603 switch $(@).attr('column')
\r
606 $(@).parent().hide() #label
\r
608 # add button on new form
\r
609 $('.submit-new-form').map ->
\r
610 $(@).html('<button class="new-element">add</button>')
\r
612 $('.new-element').map ->
\r