2 _.templateSettings = {
\r
3 interpolate: /\<\&\=(.+?)\&\>/g,
\r
4 evaluate: /\<\&(.+?)\&\>/g
\r
6 #filer = new Filer('tt', ['ea','eb','ec'])
\r
7 #view = new FilerView( { filer: filer } )
\r
8 confirm_confirm_confirm = () ->
\r
10 editor = window.PettanrEditor
\r
12 items: window.items,
\r
13 controllers: window.controllers,
\r
14 models: window.models,
\r
15 system_resources: window.system_resources,
\r
16 magic_numbers: window.magic_numbers,
\r
19 list_groups: window.list_groups,
\r
20 profilers: window.profilers,
\r
21 filers: window.filers,
\r
22 forms: window.forms,
\r
24 j = JSON.stringify(manifest, undefined, 2)
\r
25 $('#pettanr-manifest').val(j)
\r
26 j = JSON.stringify(local_manifest, undefined, 2)
\r
27 $('#pettanr-local_manifest').val(j)
\r
28 WritingFormat = window.PettanrWritingFormat
\r
29 WritingFormat.load($('#writing_formats'))
\r
30 SpeechBalloonTemplate = window.PettanrSpeechBalloonTemplate
\r
31 SpeechBalloonTemplate.load($('#speech_balloon_templates'))
\r
32 for n, v of SpeechBalloonTemplate.scripts
\r
34 v.add_helper( n, '' )
\r
35 PictureSizeHelper = window.PettanrPictureSizeHelper
\r
36 ColorHelper = window.PettanrColorHelper
\r
37 PopupHelper = window.PettanrPopupHelper
\r
40 #pp = new PanelPicture
\r
41 #pp.set_panel(panel)
\r
42 #confirm( PanelPicture.test() )
\r
43 #confirm( pp.test() )
\r
44 find_configurations = ( hash, key) ->
\r
45 if typeof(hash[key]) == 'string'
\r
46 find_configurations(hash, hash[key])
\r
50 set_validates = (form) ->
\r
52 $('input', form).map ->
\r
53 model_name = $(@).attr('data-model')
\r
54 column_name = $(@).attr('column')
\r
55 name = $(@).attr('name')
\r
56 if model_name and column_name
\r
57 model = find_configurations(configurations['models'], model_name)
\r
58 rule = model['attributes'][column_name]['rules']
\r
59 trace = editor.element_tag_id($(@))
\r
63 if editor.is_panel(form)
\r
64 validate_panel(form)
\r
66 validate_element(form)
\r
67 if Object.keys(rules).length > 0
\r
68 v = form.validate({ignore:[],rules: rules})
\r
70 display_panel = (panel, vis) ->
\r
75 trace = editor.panel_tag_id(panel)
\r
76 $(trace).css('display', v)
\r
78 validate_panel = (form) ->
\r
79 valid = form.valid()
\r
84 $('a', $('#tabs-1-tab')).map ->
\r
85 $(@).css('background-color', bc)
\r
86 display_panel(form, valid)
\r
89 display_element = (element, vis) ->
\r
90 trace = editor.element_tag_id(element)
\r
91 d = $(trace + '_destroy').val()
\r
92 v = if vis and d.length < 1
\r
96 switch element.attr('element_type')
\r
97 when 'panel_picture'
\r
98 trace = trace + 'div'
\r
99 $(trace).css('display', v)
\r
101 validate_element = (form) ->
\r
102 valid = form.valid()
\r
107 display_element(form, valid)
\r
108 trace = editor.element_tag_id(form)
\r
109 $('.elements-tab', $(trace + 'element_tab')).map ->
\r
110 $(@).css('background-color', bc)
\r
113 validate_forms = () ->
\r
115 $('form', $('#tabs-1')).map ->
\r
116 form_name = $(@).attr('data-form-name')
\r
118 if validate_panel($(@))
\r
121 invalid_elements = []
\r
122 $('form', $('#tabs-2')).map ->
\r
123 form_name = $(@).attr('data-form-name')
\r
125 if validate_element($(@))
\r
128 invalid_elements.push form_name
\r
129 if invalid_elements.length > 0
\r
133 $('a', $('#tabs-2-tab')).map ->
\r
134 $(@).css('background-color', bc)
\r
137 form_name = $(@).attr('data-form-name')
\r
140 set_validates(form)
\r
141 $('.panel-editor').map ->
\r
142 if $(@).attr('current') and parseInt($(@).attr('current')) > 0
\r
143 editor.pettanr_current_panel_id = parseInt($(@).attr('panel_id'))
\r
144 if editor.is_editting()
\r
146 $('#elements-tabs').tabs()
\r
147 $('#new-element-tabs').tabs()
\r
148 $('#new-speech_balloon-tabs').tabs()
\r
149 $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
\r
150 $("#elements-tabs li").removeClass("ui-corner-top")
\r
151 $("#elements-tabs li").addClass("ui-corner-left")
\r
152 $("#elements-tabs li").map ->
\r
154 switch $(@).attr('element_type')
\r
155 when 'speech_balloon'
\r
156 trace = editor.element_tag_id($(@))
\r
157 t = $('img', $(trace))
\r
158 when 'panel_picture'
\r
159 trace = editor.element_tag_id($(@)) + 'img'
\r
164 $('.ui-resizable-handle', t.parent()).map ->
\r
165 $(@).css('display', 'block')
\r
167 switch $(@).attr('element_type')
\r
168 when 'speech_balloon'
\r
169 trace = editor.element_tag_id($(@))
\r
170 t = $('img', $(trace))
\r
171 when 'panel_picture'
\r
172 trace = editor.element_tag_id($(@)) + 'img'
\r
177 $('.ui-resizable-handle', t.parent()).map ->
\r
178 $(@).css('display', 'none')
\r
181 $('.ui-icon-destroy').map ->
\r
184 primary: 'ui-icon-close',
\r
190 if confirm('destroy ?')
\r
191 trace = editor.element_tag_id($(@))
\r
192 $(trace + '_destroy').val('true')
\r
193 panel_trace = editor.panel_tag_id($(@))
\r
194 update_t(panel_trace + 'tsort')
\r
195 update_z(panel_trace + 'zsort')
\r
197 $(trace + 'element_tab').css('display', 'none')
\r
198 $(trace + 'tab_panel').css('display', 'none')
\r
199 $(trace + 'zsort').css('display', 'none')
\r
200 $(trace + 'tsort').css('display', 'none')
\r
201 display_element($(@), false)
\r
203 $('#pettanr-panel-submit').focusin ->
\r
204 editor.refresh_attribute($('#pettanr-panel-json'))
\r
207 $('.pettanr-comic-panel').map ->
\r
208 if editor.is_editable($(@))
\r
210 stop: ( event, ui ) ->
\r
211 trace = editor.panel_tag_id($(@))
\r
212 w = parseInt($(@).width())
\r
213 h = parseInt($(@).height())
\r
214 $(trace + 'width').val(w)
\r
215 $(trace + 'height').val(h)
\r
216 $('.pettanr-comic-ground-picture').map ->
\r
219 $('.pettanr-comic-ground-color').map ->
\r
227 if $(@).attr('element_type')
\r
229 if $(@).attr('panel_id')
\r
231 switch $(@).attr('column')
\r
233 trace = editor.panel_tag_id($(@))
\r
234 $(trace).width(parseInt( $(@).val()))
\r
236 trace = editor.panel_tag_id($(@))
\r
237 $(trace).height(parseInt( $(@).val()))
\r
239 trace = editor.panel_tag_id($(@))
\r
240 $(trace).css('border-width', parseInt($(@).val()).toString() + 'px')
\r
243 PictureSizeHelper.add_helper()
\r
244 PopupHelper.add_helper()
\r
246 $('.pettanr-panel-picture-wrapper').map ->
\r
248 stop: ( event, ui ) ->
\r
249 trace = editor.element_tag_id($(@))
\r
250 img = $(trace + 'img')
\r
251 left = img.parent().position().left + $(@).position().left
\r
252 top = img.parent().position().top + $(@).position().top
\r
253 $(trace + 'x').val(parseInt(left))
\r
254 $(trace + 'y').val(parseInt(top))
\r
257 $('.panel-picture').map ->
\r
259 stop: ( event, ui ) ->
\r
261 panel_picture_div = resize_div.parent()
\r
262 trace = editor.element_tag_id(panel_picture_div)
\r
264 resize_div.css('top', '0px')
\r
265 resize_div.css('left', '0px')
\r
266 if ui.originalPosition.top != ui.position.top
\r
267 t = panel_picture_div.position().top + ui.position.top
\r
268 $(trace + 'y').val(Math.floor(t))
\r
269 panel_picture_div.css('top', t.toString() + 'px')
\r
270 if ui.originalPosition.left != ui.position.left
\r
271 l = panel_picture_div.position().left + ui.position.left
\r
272 $(trace + 'x').val(Math.floor(l))
\r
273 panel_picture_div.css('left', l.toString() + 'px')
\r
274 w = if $(trace + 'width').val() < 0
\r
278 h = if $(trace + 'height').val() < 0
\r
282 $(trace + 'width').val(w)
\r
283 $(trace + 'height').val(h)
\r
284 resize: ( event, ui ) ->
\r
286 panel_picture_div = resize_div.parent()
\r
287 trace = editor.element_tag_id(panel_picture_div)
\r
294 if editor.element_is('panel_picture', $(@))
\r
296 switch $(@).attr('column')
\r
298 trace = editor.element_tag_id($(@)) + 'div'
\r
299 v = parseInt($(@).val()).toString() + 'px'
\r
300 $(trace).css('left', v)
\r
302 trace = editor.element_tag_id($(@)) + 'div'
\r
303 v = parseInt($(@).val()).toString() + 'px'
\r
304 $(trace).css('top', v)
\r
306 trace = editor.element_tag_id($(@)) + 'img'
\r
307 w = parseInt($(@).val())
\r
308 $(trace).width(Math.abs(w))
\r
309 $(trace).parent().width(Math.abs(w))
\r
310 h = parseInt($(editor.element_tag_id($(@)) + 'height').val())
\r
312 trace = editor.element_tag_id($(@)) + 'img'
\r
313 h = parseInt($(@).val())
\r
314 $(trace).height(Math.abs(h))
\r
315 $(trace).parent().height(Math.abs(h))
\r
316 w = parseInt($(editor.element_tag_id($(@)) + 'width').val())
\r
318 PictureSizeHelper.refresh_picture($(trace), w, h)
\r
322 ColorHelper.add_helper($('.speech-fore_color-wrap'), 'fore_color')
\r
324 $('.pettanr-comic-balloon' ).map ->
\r
326 stop: ( event, ui ) ->
\r
327 balloon = $('.pettanr-balloon', $(@))
\r
328 trace = editor.element_part_tag_id(balloon)
\r
329 left = $(@).position().left
\r
330 top = $(@).position().top
\r
331 $(trace + 'x').val(parseInt(left))
\r
332 $(trace + 'y').val(parseInt(top))
\r
335 $('.pettanr-balloon' ).map ->
\r
337 stop: ( event, ui ) ->
\r
339 speech_balloon_div = resize_div.parent()
\r
340 balloon = $('.pettanr-balloon', $(@))
\r
341 trace = editor.element_tag_id(speech_balloon_div)
\r
342 trace_balloon = editor.element_part_tag_id(balloon)
\r
344 resize_div.css('top', '0px')
\r
345 resize_div.css('left', '0px')
\r
348 if ui.originalPosition.top != ui.position.top
\r
349 t = speech_balloon_div.position().top + ui.position.top
\r
350 $(trace_balloon + 'y').val(Math.floor(t))
\r
351 speech_balloon_div.css('top', t.toString() + 'px')
\r
352 speech_balloon_div.css('height', h + 'px')
\r
353 if ui.originalPosition.left != ui.position.left
\r
354 l = speech_balloon_div.position().left + ui.position.left
\r
355 $(trace_balloon + 'x').val(Math.floor(l))
\r
356 speech_balloon_div.css('left', l.toString() + 'px')
\r
357 speech_balloon_div.css('width', w + 'px')
\r
358 $(trace_balloon + 'width').val(w)
\r
359 $(trace_balloon + 'height').val(h)
\r
360 speech_balloon_div.css('width', w.toString() + 'px')
\r
361 speech_balloon_div.css('height', h.toString() + 'px')
\r
362 resize: ( event, ui ) ->
\r
364 speech_balloon_div = resize_div.parent()
\r
365 balloon = $('.pettanr-balloon', $(@))
\r
366 trace = editor.element_tag_id(speech_balloon_div)
\r
367 trace_balloon = editor.element_part_tag_id(balloon)
\r
372 $('.pettanr-comic-speech-inner' ).map ->
\r
374 outer = $(@).parent()
\r
375 sb = outer.parent()
\r
376 trace = editor.element_tag_id(sb)
\r
377 img = $('.pettanr-balloon', $(trace))
\r
378 $('.ui-resizable-handle', img.parent()).map ->
\r
379 $(@).css('display', 'block')
\r
381 outer = $(@).parent()
\r
382 sb = outer.parent()
\r
383 trace = editor.element_tag_id(sb)
\r
384 img = $('.pettanr-balloon', $(trace))
\r
385 $('.ui-resizable-handle', img.parent()).map ->
\r
386 $(@).css('display', 'none')
\r
391 if editor.element_is('speech_balloon', $(@))
\r
393 switch $(@).attr('column')
\r
395 trace = editor.element_tag_id($(@))
\r
396 v = parseInt($(@).val()).toString() + 'px'
\r
397 $(trace).css('left', v)
\r
399 trace = editor.element_tag_id($(@))
\r
400 v = parseInt($(@).val()).toString() + 'px'
\r
401 $(trace).css('top', v)
\r
403 trace = editor.element_tag_id($(@))
\r
404 v = parseInt($(@).val())
\r
405 $(trace).width(Math.abs(v))
\r
406 img = $('.pettanr-balloon', $(trace))
\r
407 img.parent().width(v)
\r
410 trace = editor.element_tag_id($(@))
\r
411 v = parseInt($(@).val())
\r
412 $(trace).height(Math.abs(v))
\r
413 img = $('.pettanr-balloon', $(trace))
\r
414 img.parent().height(v)
\r
418 $('textarea').map ->
\r
419 if editor.element_is('speech_balloon', $(@))
\r
421 switch $(@).attr('column')
\r
423 trace = editor.element_part_tag_id($(@))
\r
424 wf_sel = $(trace + 'writing_format_id')
\r
425 wf_id = parseInt(wf_sel.val())
\r
426 v = WritingFormat.render(wf_id, $(@).val())
\r
428 $('textarea').map ->
\r
429 if editor.element_is('speech_balloon', $(@))
\r
430 switch $(@).attr('column')
\r
432 $(@).bind('textchange', (event, previousText) ->
\r
433 trace = editor.element_part_tag_id($(@))
\r
434 wf_sel = $(trace + 'writing_format_id')
\r
435 wf_id = parseInt(wf_sel.val())
\r
436 v = WritingFormat.render(wf_id, $(@).val())
\r
440 if editor.element_is('speech_balloon', $(@))
\r
442 switch $(@).attr('column')
\r
444 trace = editor.element_part_tag_id($(@))
\r
445 $(trace).css('font-size', $(@).val() + 'em')
\r
447 trace = editor.element_part_tag_id($(@))
\r
448 v = parseInt($(@).val())
\r
449 $(trace).css('text-align', editor.text_align_texts[v])
\r
452 if editor.element_is('speech_balloon', $(@))
\r
453 if $(@).attr('column') == 'fore_color'
\r
458 refresh_ground_picture = (element_trace) ->
\r
459 x = parseInt($(element_trace + 'x').val()).toString() + 'px'
\r
460 y = parseInt($(element_trace + 'y').val()).toString() + 'px'
\r
461 $(element_trace).css('background-position', x + ' ' + y)
\r
465 if editor.element_is('ground_picture', $(@))
\r
466 switch $(@).attr('column')
\r
469 trace = editor.element_tag_id($(@))
\r
470 refresh_ground_picture(trace)
\r
472 stop: ( event, ui ) ->
\r
473 trace = editor.element_tag_id($(@))
\r
474 refresh_ground_picture(trace)
\r
477 if editor.element_is('ground_picture', $(@))
\r
479 switch $(@).attr('column')
\r
481 trace = editor.element_tag_id($(@))
\r
482 v = parseInt($(@).val())
\r
483 $(trace).css('background-repeat', editor.repeat_texts[v])
\r
488 ColorHelper.add_helper($('.ground_color-code-wrap'), 'code')
\r
490 refresh_ground_color = (element_trace) ->
\r
491 orientation = parseInt( $(element_trace + 'orientation').val() )
\r
492 xy = $(element_trace + 'xy').val()
\r
493 wh = $(element_trace + 'wh').val()
\r
502 div_x = if orientation == 0
\r
506 div_y = if orientation == 0
\r
510 div_width = if orientation == 0
\r
514 div_height = if orientation == 0
\r
518 div = $(element_trace)
\r
519 div.css('left', div_x.toString() + '%')
\r
520 div.css('top', div_y.toString() + '%')
\r
521 div.css('width', div_width.toString() + '%')
\r
522 div.css('height', div_height.toString() + '%')
\r
526 if editor.element_is('ground_color', $(@))
\r
527 switch $(@).attr('column')
\r
532 stop: ( event, ui ) ->
\r
533 trace = editor.element_tag_id($(@))
\r
534 refresh_ground_color(trace)
\r
539 trace = editor.element_tag_id($(@))
\r
540 refresh_ground_color(trace)
\r
543 if editor.element_is('ground_color', $(@))
\r
544 switch $(@).attr('column')
\r
547 trace = editor.element_tag_id($(@))
\r
548 refresh_ground_color(trace)
\r
550 update_t = (ultrace) ->
\r
552 $(ultrace + ' li').map ->
\r
553 trace = editor.element_tag_id($(@))
\r
554 if $(trace + '_destroy').val().length < 1
\r
555 $(trace + 't').val(t)
\r
559 $('.tsort').map ->
\r
561 update: ( event, ui ) ->
\r
562 trace = editor.panel_tag_id($(@))
\r
563 update_t(trace + 'tsort')
\r
565 $('.t-sort li').map ->
\r
566 $(@).disableSelection()
\r
568 update_z = (ultrace) ->
\r
570 $(ultrace + ' li').map ->
\r
571 trace = editor.element_tag_id($(@))
\r
573 if $(trace + '_destroy').val().length < 1
\r
574 $(trace + 'z').val(z)
\r
575 switch $(@).attr('element_type')
\r
576 when 'panel_picture'
\r
577 trace = trace + 'div'
\r
578 $(trace).css('zIndex', z)
\r
582 $('.zsort').map ->
\r
584 update: ( event, ui ) ->
\r
585 trace = editor.panel_tag_id($(@))
\r
586 update_z(trace + 'zsort')
\r
588 $('.z-sort li').map ->
\r
589 $(@).disableSelection()
\r
592 # disable form actions
\r
593 # hide submit buttons
\r
594 $('.edit_panel_picture' ).map ->
\r
597 $('.edit_speech_balloon' ).map ->
\r
600 $('.edit_ground_picture' ).map ->
\r
603 $('.edit_ground_color' ).map ->
\r
607 $('.edit_panel' ).map ->
\r
608 if $(@).attr('jqform')
\r
610 if validate_forms()
\r
618 $('.submit' ).map ->
\r
623 if editor.is_element($(@))
\r
624 switch $(@).attr('column')
\r
627 $(@).parent().hide() #label
\r
629 # add button on new form
\r
630 $('.submit-new-form').map ->
\r
631 $(@).html('<button class="new-element">add</button>')
\r
633 $('.new-element').map ->
\r