OSDN Git Service

c9ebf21be8335e0e4d02dcb68ca972fa090667ec
[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.panel_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_panel').css('display', 'none')
58           $(trace + 'zsort').css('display', 'none')
59           $(trace + 'tsort').css('display', 'none')
60           switch $(@).attr('element_type')
61             when 'panel_picture'
62               trace = trace + 'div'
63           $(trace).css('display', 'none')
64           
65     
66     $('#pettanr-sheet-submit').focusin ->
67       editor.refresh_attribute($('#pettanr-sheet-json'))
68     
69     # sheet
70     $('.sheet').map ->
71       if editor.is_editable($(@))
72         $(@).resizable {
73           stop: ( event, ui ) ->
74             trace = editor.sheet_tag_id($(@))
75             w = parseInt($(@).width())
76             h = parseInt($(@).height())
77             $(trace + 'width').val(w)
78             $(trace + 'height').val(h)
79           , autoHide: true
80         }
81     
82     # sync view 
83     $('input').map  ->
84       if $(@).attr('element_type')
85       else
86         if $(@).attr('sheet_id')
87           $(@).focusout ->
88             switch $(@).attr('column')
89               when 'width'
90                 trace = editor.sheet_tag_id($(@))
91                 $(trace).width(parseInt( $(@).val()))
92               when 'height'
93                 trace = editor.sheet_tag_id($(@))
94                 $(trace).height(parseInt( $(@).val()))
95     
96     $('.sheet_panel').map ->
97       $(@).draggable {
98         stop: ( event, ui ) ->
99           trace = editor.element_tag_id($(@))
100           left = $(@).position().left
101           top = $(@).position().top
102           $(trace + 'x').val(parseInt(left))
103           $(trace + 'y').val(parseInt(top))
104         , cursor: "crosshair"
105       }
106     
107     # sync view 
108     $('input').map  ->
109       if editor.element_is('sheet_panel', $(@))
110         $(@).focusout ->
111           switch $(@).attr('column')
112             when 'x'
113               trace = editor.element_tag_id($(@))
114               v = parseInt($(@).val()).toString() + 'px'
115               $(trace).css('left', v)
116             when 'y'
117               trace = editor.element_tag_id($(@))
118               v = parseInt($(@).val()).toString() + 'px'
119               $(trace).css('top', v)
120             else
121       else
122     
123     update_t = (ultrace) -> 
124       t = 0
125       $(ultrace + ' li').map ->
126         trace = editor.element_tag_id($(@))
127         if $(trace + '_destroy').val().length < 1
128           $(trace + 't').val(t)
129           t++
130         else
131     
132     $('.tsort').map -> 
133       $(@).sortable {
134         update: ( event, ui ) ->
135           trace = editor.sheet_tag_id($(@))
136           update_t(trace + 'tsort')
137       }
138     $('.t-sort li').map -> 
139       $(@).disableSelection()
140     
141     update_z = (ultrace) -> 
142       z = 1
143       $(ultrace + ' li').map ->
144         trace = editor.element_tag_id($(@))
145         # update panel
146         if $(trace + '_destroy').val().length < 1
147           $(trace + 'z').val(z)
148           switch $(@).attr('element_type')
149             when 'panel_picture'
150               trace = trace + 'div'
151           $(trace).css('zIndex', z)
152           z++
153         else
154     
155     $('.zsort').map -> 
156       $(@).sortable {
157         update: ( event, ui ) ->
158           trace = editor.sheet_tag_id($(@))
159           update_z(trace + 'zsort')
160       }
161     $('.z-sort li').map -> 
162       $(@).disableSelection()
163     
164     # all
165     # disable form actions
166     
167     $('.edit_sheet' ).map ->
168       if $(@).attr('jqform')
169       else
170         $(@).submit ->
171           false
172     
173     $('.submit' ).map ->
174       $(@).hide()
175     
176     # disable form z t
177     $('input').map  ->
178       if editor.is_element($(@))
179         switch $(@).attr('column')
180           when 'z' , 't'
181             $(@).hide()
182             $(@).parent().hide() #label
183     
184     # add button on new form
185     $('.submit-new-form').map ->
186       $(@).html('<button class="new-element">add</button>')
187     
188     $('.new-element').map ->
189       $(@).click -> 
190         false
191