OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[pettanr/pettanr.git] / app / assets / javascripts / sheets.js.coffee
1 $ ->
2   confirm_confirm_confirm = () ->
3     confirm(  )
4   editor = window.PettanrSheeter
5   
6   $('.sheet-editor').map ->
7     if $(@).attr('current') and parseInt($(@).attr('current')) > 0
8       editor.pettanr_current_sheet_id = parseInt($(@).attr('sheet_id'))
9   if editor.is_editting()
10     $('#tabs').tabs()
11     $('#elements-tabs').tabs()
12     $('#new-element-tabs').tabs()
13     $('#new-speech_balloon-tabs').tabs()
14     $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" )
15     $("#elements-tabs li").removeClass("ui-corner-top")
16     $("#elements-tabs li").addClass("ui-corner-left")
17     $("#elements-tabs li").map ->
18       $(@).mouseover -> 
19         switch $(@).attr('element_type')
20           when 'sheet_panel'
21             trace = editor.element_tag_id($(@)) 
22             t = $('.pettanr-comic-panel', $(trace))
23           else
24             t = null
25         if t
26           $('.ui-resizable-handle', t.parent()).map ->
27             $(@).css('display', 'block')
28       $(@).mouseout -> 
29         switch $(@).attr('element_type')
30           when 'sheet_panel'
31             trace = editor.element_tag_id($(@)) 
32             t = $('.pettanr-comic-panel', $(trace))
33           else
34             t = null
35         if t
36           $('.ui-resizable-handle', t.parent()).map ->
37             $(@).css('display', 'none')
38     
39     #destroy button
40     $('.ui-icon-destroy').map ->
41       $(@).button {
42         icons: {
43           primary: 'ui-icon-close', 
44           secondary: null
45         }, 
46         text: false
47       }
48       $(@).click -> 
49         if confirm('destroy ?')
50           trace = editor.element_tag_id($(@))
51           $(trace + '_destroy').val('true')
52           sheet_trace = editor.sheet_tag_id($(@))
53           update_t(sheet_trace + 'tsort')
54           update_z(sheet_trace + 'zsort')
55           # sync
56           $(trace + 'element_tab').css('display', 'none')
57           $(trace + 'tab_sheet').css('display', 'none')
58           $(trace + 'zsort').css('display', 'none')
59           $(trace + 'tsort').css('display', 'none')
60           $(trace).css('display', 'none')
61           
62     
63     $('#pettanr-sheet-submit').focusin ->
64       editor.refresh_attribute($('#pettanr-sheet-json'))
65     
66     # sheet
67     $('.sheet').map ->
68       if editor.is_editable($(@))
69         $(@).resizable {
70           stop: ( event, ui ) ->
71             trace = editor.sheet_tag_id($(@))
72             w = parseInt($(@).width())
73             h = parseInt($(@).height())
74             $(trace + 'width').val(w)
75             $(trace + 'height').val(h)
76           , autoHide: true
77         }
78     
79     # sync view 
80     $('input').map  ->
81       if $(@).attr('element_type')
82       else
83         if $(@).attr('sheet_id')
84           $(@).focusout ->
85             switch $(@).attr('column')
86               when 'width'
87                 trace = editor.sheet_tag_id($(@))
88                 $(trace).width(parseInt( $(@).val()))
89               when 'height'
90                 trace = editor.sheet_tag_id($(@))
91                 $(trace).height(parseInt( $(@).val()))
92     
93     $('.sheet_panel').map ->
94       $(@).draggable {
95         stop: ( event, ui ) ->
96           trace = editor.element_tag_id($(@))
97           left = $(@).position().left
98           top = $(@).position().top
99           $(trace + 'x').val(parseInt(left))
100           $(trace + 'y').val(parseInt(top))
101         , cursor: "crosshair"
102       }
103     
104     # sync view 
105     $('input').map  ->
106       if editor.element_is('sheet_panel', $(@))
107         $(@).focusout ->
108           switch $(@).attr('column')
109             when 'x'
110               trace = editor.element_tag_id($(@))
111               v = parseInt($(@).val()).toString() + 'px'
112               $(trace).css('left', v)
113             when 'y'
114               trace = editor.element_tag_id($(@))
115               v = parseInt($(@).val()).toString() + 'px'
116               $(trace).css('top', v)
117             else
118       else
119     
120     update_t = (ultrace) -> 
121       t = 0
122       $(ultrace + ' li').map ->
123         trace = editor.element_tag_id($(@))
124         if $(trace + '_destroy').val().length < 1
125           $(trace + 't').val(t)
126           t++
127         else
128     
129     $('.tsort').map -> 
130       $(@).sortable {
131         update: ( event, ui ) ->
132           trace = editor.sheet_tag_id($(@))
133           update_t(trace + 'tsort')
134       }
135     $('.t-sort li').map -> 
136       $(@).disableSelection()
137     
138     update_z = (ultrace) -> 
139       z = 1
140       $(ultrace + ' li').map ->
141         trace = editor.element_tag_id($(@))
142         # update panel
143         if $(trace + '_destroy').val().length < 1
144           $(trace + 'z').val(z)
145           switch $(@).attr('element_type')
146             when 'panel_picture'
147               trace = trace + 'div'
148           $(trace).css('zIndex', z)
149           z++
150         else
151     
152     $('.zsort').map -> 
153       $(@).sortable {
154         update: ( event, ui ) ->
155           trace = editor.sheet_tag_id($(@))
156           update_z(trace + 'zsort')
157       }
158     $('.z-sort li').map -> 
159       $(@).disableSelection()
160     
161     # all
162     # disable form actions
163     
164     $('.edit_sheet' ).map ->
165       if $(@).attr('jqform')
166       else
167         $(@).submit ->
168           false
169     
170     $('.submit' ).map ->
171       $(@).hide()
172     
173     # disable form z t
174     $('input').map  ->
175       if editor.is_element($(@))
176         switch $(@).attr('column')
177           when 'z' , 't'
178             $(@).hide()
179             $(@).parent().hide() #label
180     
181     # add button on new form
182     $('.submit-new-form').map ->
183       $(@).html('<button class="new-element">add</button>')
184     
185     $('.new-element').map ->
186       $(@).click -> 
187         false
188