OSDN Git Service

try sort
[pettanr/pettanr.git] / app / views / panels / _form.html.erb
1 <%= form_for(@panel) do |f| %>
2   <%= render 'system/error_explanation', :obj => @panel %>
3
4   <div class="field">
5     <%= f.label :caption %><br />
6     <%= f.text_field :caption %>
7   </div>
8   <div class="field">
9     <%= f.label :width %><br />
10     <%= f.number_field :width %>
11   </div>
12   <div class="field">
13     <%= f.label :height %><br />
14     <%= f.number_field :height %>
15   </div>
16   <div class="field">
17     <%= f.label :border %><br />
18     <%= f.number_field :border %>
19   </div>
20   <div class="field">
21     <%= f.label :publish %><br />
22     <%= f.collection_select :publish, t_select_items(MagicNumber['panel_visible_items']), :last, :first, :html => {:selected => @panel.publish} %>
23   </div>
24   <div class="actions">
25     <%= f.submit %>
26   </div>
27 <% end %>
28
29 <h2><%= t 'panels.create_from_json' -%></h2>
30 <%= form_for(@panel) do |f| %>
31   <%= render 'system/error_explanation', :obj => @panel %>
32
33   <div>
34     <label for="json">json data</label>
35   </div>
36   <%= text_field_tag "json" %>
37   <div>
38     <%= submit_tag t('panels.create_from_json') -%>
39   </div>
40 <% end %>
41
42 <h2><%= 't reorder' -%></h2>
43 <table id="t-sortable">
44   <tbody >
45   <% @panel.panel_elements.each do |elm| %>
46     <tr classname="<%= elm.class.to_s -%>" oid="<%= elm.id -%>">
47       <% case elm.class.to_s %>
48       <% when 'PanelPicture' %>
49         <td>
50           <%= link_to(tag(:img, elm.tmb_opt_img_tag), elm) %>
51         </td>
52       <% when 'SpeechBalloon' %>
53         <td>
54           <%= elm.id -%>
55           <%= elm.caption -%>
56         </td>
57       <% when 'GroundPicture' %>
58         <td>
59           <%= link_to(tag(:img, elm.tmb_opt_img_tag), elm.picture) -%>
60         </td>
61       <% when 'GroundColor' %>
62         <td style="color: #<%= format("%06x", elm.code ^ 0xffffff) -%>; background-color: #<%= format("%06x", elm.code) -%>;">
63           <%= format("%06x", elm.code ^ 0xffffff) %>
64         </td>
65       <% end %>
66       <td>
67         <%= h(truncate(elm.caption, :length => 12)) %>
68       </td>
69     </tr>
70   <% end %>
71   </tbody>
72 </table>
73 <%= form_for(@panel) do |f| %>
74   <%= hidden_field_tag "json", nil, :id => 't-reorder' %>
75   <% unless @panel.new_record? -%>
76     <%= content_tag :div, '', :id => "panel-id-elm", :oid => @panel.id -%>
77   <% end %>
78   <div>
79     <%= submit_tag t('panels.create.title') -%>
80   </div>
81 <% end %>
82
83 <script>
84 <!--
85 jQuery( function() {
86     jQuery( '#t-sortable tbody' ) . sortable( {
87         update: function( event, ui ) {
88           var panel_pictures_attributes = {};
89           var speech_balloons_attributes = {};
90           var ground_colors_attributes = {};
91           var ground_pictures_attributes = {};
92           var i = 0;
93           jQuery( '#t-sortable tr' ) . map( function() {
94             switch ( this.getAttribute("classname") ){
95             case 'PanelPicture':
96               panel_pictures_attributes[this.getAttribute("oid")] = {id: this.getAttribute("oid"), t: i};
97               break;
98             case 'SpeechBalloon':
99               speech_balloons_attributes[this.getAttribute("oid")] = {id: this.getAttribute("oid"), t: i};
100               break;
101             case 'GroundPicture':
102               ground_pictures_attributes[this.getAttribute("oid")] = {id: this.getAttribute("oid"), t: i};
103               break;
104             case 'GroundColor':
105               ground_colors_attributes[this.getAttribute("oid")] = {id: this.getAttribute("oid"), t: i};
106               break;
107             }
108             i++;
109           } );
110           var panel = {
111             panel_pictures_attributes: panel_pictures_attributes, 
112             speech_balloons_attributes: speech_balloons_attributes,
113             ground_pictures_attributes: ground_pictures_attributes,
114             ground_colors_attributes: ground_colors_attributes
115           };
116           if ( $("#panel-id-elm") ) 
117             panel['id'] = $( "#panel-id-elm").attr("oid") ;
118           $("#t-reorder").val(JSON.stringify(panel));
119           
120         }
121     } );
122     jQuery( '#t-sortable tbody' ) . disableSelection();
123 } );
124 // -->
125 </script>