Skip to content
This repository
Browse code

got new menu items working

  • Loading branch information...
commit 8c288781007743e74dfbb6d86722c7cdb0fbc375 1 parent 3a3472d
ethn authored March 29, 2013
9  app/assets/stylesheets/card.css
@@ -483,6 +483,8 @@ a.missing-labeled,
483 483
   display: inline;
484 484
 }
485 485
 
  486
+
  487
+
486 488
 /* CARDTYPE_SPECIFIC ------------------------------*/
487 489
 
488 490
 
@@ -580,6 +582,13 @@ div.search-result-list .search-result-item {
580 582
   margin-left: 40px;
581 583
 }
582 584
 
  585
+
  586
+/*---------( Set ) ---------- */
  587
+
  588
+h2.set-label {
  589
+  padding-bottom: 10px;
  590
+}
  591
+
583 592
 /*-----------( Image ) -----------*/
584 593
 
585 594
 
2  app/assets/stylesheets/settings.css
... ...
@@ -1,8 +1,10 @@
  1
+/*
1 2
 .settings-tab {
2 3
   border: 0px;
3 4
   margin-bottom: 20px;
4 5
   padding: 5px 15px;
5 6
 }
  7
+*/
6 8
 .set-select {
7 9
   margin: 10px;
8 10
 }
15  lib/cardlib/rules.rb
@@ -44,14 +44,13 @@ def rule_card_id setting_code, options={}
44 44
   
45 45
   def related_sets
46 46
     # refers to sets that users may configure from the current card - NOT to sets to which the current card belongs
47  
-    sets = ["#{name}+*self"]
48  
-    sets << "#{name}+*type" if type_id==Card::CardtypeID
49  
-    if cardname.simple?
50  
-      sets<< "#{name}+*right"
51  
-      Card.search(:type=>'Set',:left=>{:right=>name},:right=>'*type plus right',:return=>'name').each do |set_name|
52  
-        sets<< set_name
53  
-      end
54  
-    end
  47
+    sets =     [ ["#{name}+*self",  Cardlib::Patterns::SelfPattern.label( name) ] ]
  48
+    sets.unshift ["#{name}+*type",  Cardlib::Patterns::TypePattern.label( name) ] if type_id==Card::CardtypeID
  49
+    sets.push    ["#{name}+*right", Cardlib::Patterns::RightPattern.label(name) ] if cardname.simple?
  50
+      
  51
+#      Card.search(:type=>'Set',:left=>{:right=>name},:right=>'*type plus right',:return=>'name').each do |set_name|
  52
+#        sets<< set_name
  53
+#      end
55 54
     sets
56 55
   end
57 56
 
20  lib/wagn/renderer/html.rb
@@ -69,13 +69,13 @@ class Renderer::Html < Renderer
69 69
    }
70 70
    
71 71
    
72  
-    @@default_menu ||= [ 
  72
+    @@default_menu = [ 
73 73
       { :view=>:edit, :text=>'edit', :if=>:edit, :sub=>[
74 74
           { :view=>:edit,      :text=>'content'       },
75 75
           { :view=>:edit_name, :text=>'name'          },
76 76
           { :view=>:edit_type, :text=>'type: %{type}' },
77 77
           { :related=>{ :name=>:structure, :view=>:edit }, :text=>'structure', :if=>:structure },
78  
-#          { :view=>:edit_type, :text=>'type: %{type}' },
  78
+          { :link=>:delete,    :if=>:delete           }
79 79
         ] },
80 80
       { :view=>:home, :text=>'view', :sub=> [
81 81
           { :view=>:home,                    :text=>'refresh'                    },
@@ -86,7 +86,14 @@ class Renderer::Html < Renderer
86 86
         ] },
87 87
       { :related=>{ :name=>"+discussion" }, :text=>'discuss', :if=>:discuss },
88 88
       { :view=>:options, :text=>'advanced', :sub=>[
89  
-          { :view=>:options, :text=>'rules' },
  89
+          { :view=>:options, :text=>'rules', :sub=>[
  90
+              :list => { :related_sets=> { :view=>:options, :text=>:text, :path_opts=>:path_opts } }
  91
+            ] },
  92
+          { :plain=>'related', :sub=>[
  93
+              { :list=> { :piecenames => { :page=>:item } }, :if => :piecenames },
  94
+              { :related=>"+*plus cards", :text=>'children' },
  95
+              { :related=>"+*plus parts", :text=>'mates'    },
  96
+            ] },
90 97
           { :related=>"+*referred to by",     :text=>"references to", :sub=>[
91 98
               { :related=>"+*referred to by", :text=>"all"        },                  
92 99
               { :related=>"+*linkers",        :text=>"links"      },                  
@@ -96,12 +103,7 @@ class Renderer::Html < Renderer
96 103
               { :related=>"+*refers to",      :text=>"all"        },
97 104
               { :related=>"+*links",          :text=>"links"      },
98 105
               { :related=>"+*inclusions",     :text=>"inclusions" }                  
99  
-            ] },
100  
-          { :plain=>'related', :sub=>[
101  
-              { :plain=>'ancestors', :if=>:piecenames, :sub=>{ :piecenames => { :page=>:item } } },
102  
-              { :related=>"+*plus cards", :text=>'children' },
103  
-              { :related=>"+*plus parts", :text=>'mates'    },
104  
-            ] },              
  106
+            ] },           
105 107
           { :related=>'+*editors', :text=>'editors', :if=>:creator, :sub=>[
106 108
               { :related=>"+*editors", :text=>'all editors'             },
107 109
               { :page=>:creator,       :text=>"creator: %{creator}"     },
145  lib/wagn/set/all/rich_html.rb
@@ -108,11 +108,12 @@ module Set::All::RichHtml
108 108
       end
109 109
       
110 110
       @menu_vars = {
111  
-        :self       => card.name,
112  
-        :type       => card.type_name,
113  
-        :structure  => card.hard_template && card.template.ok?(:update) && card.template.name,
114  
-        :discuss    => disc_card && disc_card.ok?( disc_card.new_card? ? :create : :read),
115  
-        :piecenames => card.junction? && card.cardname.piece_names[0..-2],
  111
+        :self         => card.name,
  112
+        :type         => card.type_name,
  113
+        :structure    => card.hard_template && card.template.ok?(:update) && card.template.name,
  114
+        :discuss      => disc_card && disc_card.ok?( disc_card.new_card? ? :create : :read),
  115
+        :piecenames   => card.junction? && card.cardname.piece_names[0..-2].map { |n| { :item=>n } },
  116
+        :related_sets => card.related_sets.map { |name,label| { :text=>label, :path_opts=>{ :current_set => name } } }
116 117
       }
117 118
       if card.real?
118 119
         @menu_vars.merge!({
@@ -120,7 +121,12 @@ module Set::All::RichHtml
120 121
           :account   => card.account && card.update_account_ok?,
121 122
           :watch     => Account.logged_in? && render_watch,
122 123
           :creator   => card.creator.name,
123  
-          :updater   => card.updater.name,          
  124
+          :updater   => card.updater.name,
  125
+          :delete    => card.ok?(:delete) && link_to( 'delete', path(:action=>:delete),
  126
+            :class=>'slotter standard-delete', 
  127
+            :'data-confirm'=> "Are you sure you want to delete #{card.name}?"
  128
+          )
  129
+
124 130
         })
125 131
       end
126 132
     
@@ -242,36 +248,26 @@ module Set::All::RichHtml
242 248
 
243 249
   ###---(  EDIT VIEWS )
244 250
     define_view :edit, :perms=>:update, :tags=>:unknown_ok do |args|
245  
-      confirm_delete = "Are you sure you want to delete #{card.name}?"
246  
-      if dependents = card.dependents and dependents.any?
247  
-        confirm_delete +=  %{ \n\nThat would mean removing #{dependents.size} related piece(s) of information. }
248  
-      end
249  
-      
250 251
       wrap :edit, args.merge(:frame=>true) do
251 252
         %{
252  
-        #{ help_text :edit_help }
253  
-        #{_render_header }
254  
-        #{ wrap_content :edit, :body=>true, :class=>'card-editor' do
255  
-           card_form :update, 'card-form card-edit-form autosave' do |f|
256  
-            @form= f
257  
-            %{
258  
-            <div>#{ edit_slot args }</div>
259  
-            <fieldset>
260  
-              <div class="button-area">
261  
-                #{ submit_tag 'Submit', :class=>'submit-button' }
262  
-                #{ button_tag 'Cancel', :class=>'cancel-button slotter', :href=>path, :type=>'button'}
263  
-                #{ 
264  
-                if !card.new_card?
265  
-                  button_tag "Delete", :href=>path(:action=>:delete), :type=>'button',
266  
-                    :class=>'delete-button slotter standard-delete', :'data-confirm'=>confirm_delete
267  
-                end
268  
-                }            
269  
-              </div>
270  
-            </fieldset>
271  
-            }
  253
+          #{ help_text :edit_help }
  254
+          #{_render_header }
  255
+          #{ wrap_content :edit, :body=>true, :class=>'card-editor' do
  256
+            card_form :update, 'card-form card-edit-form autosave' do |f|
  257
+              @form= f
  258
+              %{
  259
+                <div>#{ edit_slot args }</div>
  260
+                <fieldset>
  261
+                  <div class="button-area">
  262
+                    #{ submit_tag 'Submit', :class=>'submit-button' }
  263
+                    #{ button_tag 'Cancel', :class=>'cancel-button slotter', :href=>path, :type=>'button' }
  264
+                  </div>
  265
+                </fieldset>
  266
+              }
  267
+            end
272 268
           end
273  
-        end }
274  
-        #{ notice }
  269
+          }
  270
+          #{ notice }
275 271
         }
276 272
       end
277 273
     end
@@ -400,43 +396,25 @@ module Set::All::RichHtml
400 396
     end
401 397
   
402 398
     define_view :options do |args|
403  
-      related_sets = card.related_sets
404  
-      current_set = params[:current_set] || related_sets[(card.type_id==Card::CardtypeID ? 1 : 0)]  #FIXME - explicit cardtype reference
405  
-      set_options = related_sets.map do |set_name|
406  
-        set_card = Card.fetch set_name
407  
-        selected = set_card.key == current_set.to_name.key ? 'selected="selected"' : ''
408  
-        %{<option value="#{ set_card.key }" #{ selected }>#{ set_card.label }</option>}
409  
-      end.join
  399
+      current_set = Card.fetch( params[:current_set] || card.related_sets[0][0] )
410 400
 
411 401
       wrap :options, args.merge(:frame=>true) do
412  
-        %{ #{ _render_header }
413  
-            <div class="options-body">
414  
-              <div class="settings-tab">
415  
-                #{ if !related_sets.empty?
416  
-                  %{ <div class="set-selection">
417  
-                    #{ form_tag path(:view=>:options), :method=>'get', :remote=>true, :class=>'slotter' }
418  
-                        <label>Set:</label>
419  
-                        <select name="current_set" class="set-select">#{ set_options }</select>
420  
-                    </form>
421  
-                  </div>}
422  
-                end }
423  
-
424  
-                <div class="current-set">
425  
-                  #{ raw subrenderer( Card.fetch current_set).render_content }
426  
-                </div>
  402
+        %{
  403
+          #{ _render_header }
  404
+          <div class="card-body">
  405
+            #{ subrenderer( current_set ).render_content }
427 406
 
428  
-                #{ if card.accountable?
429  
-                    %{<div class="new-account-link">
430  
-                    #{ link_to %{Add a sign-in account for "#{card.name}"}, path(:view=>:new_account),
431  
-                         :class=>'slotter new-account-link', :remote=>true }
432  
-                    </div>}
433  
-                   end
434  
-                }
435  
-              </div>
436  
-            </div>
437  
-            #{ notice }
438  
-          }
439  
-       end
  407
+            #{ if card.accountable?
  408
+                %{<div class="new-account-link">
  409
+                #{ link_to %{Add a sign-in account for "#{card.name}"}, path(:view=>:new_account),
  410
+                     :class=>'slotter new-account-link', :remote=>true }
  411
+                </div>}
  412
+               end
  413
+            }
  414
+          </div>
  415
+          #{ notice }
  416
+        }
  417
+      end
440 418
     end
441 419
     
442 420
     define_view :option_roles do |args|
@@ -689,7 +667,9 @@ module Set::All::RichHtml
689 667
   class Renderer::Html < Renderer
690 668
     
691 669
     def build_menu_items array
  670
+      
692 671
       array.map do |h|
  672
+        add_li_tag = true
693 673
         h = h.clone if Hash===h
694 674
         if !h[:if] or @menu_vars[ h[:if] ]
695 675
           h[:text] = h[:text] % @menu_vars if h[:text]
@@ -701,6 +681,19 @@ def build_menu_items array
701 681
             when h[:page]
702 682
               next unless h[:page] = menu_subs( h[:page] )
703 683
               link_to_page (raw("#{h[:text] || h[:page]} &crarr;")), h[:page]
  684
+            when h[:list]
  685
+              items = []
  686
+              h[:list].each do |k1,v1| # piecenames, {pages=>itmes}
  687
+                items = menu_subs(k1).map do |item_val| #[names].each do |name|
  688
+                  menu_item = v1.clone
  689
+                  menu_item.each do |k2, v2| # | :page, :item|
  690
+                    menu_item[k2] = item_val[v2] if item_val.has_key?(v2)
  691
+                  end
  692
+                  menu_item
  693
+                end
  694
+              end
  695
+              add_li_tag = false
  696
+              build_menu_items items
704 697
             else
705 698
               if h[:related]
706 699
                 h[:related] = if String === h[:related]
@@ -720,30 +713,16 @@ def build_menu_items array
720 713
                 raise "bad menu item"
721 714
               end
722 715
             end
723  
-          if Hash === h[:sub]
724  
-            arr = []
725  
-            h[:sub].each do |k1,v1| # piecenames, {pages=>itmes}
726  
-              menu_subs(k1).each do |item_val| #[names].each do |name|
727  
-                menu_item = v1.clone
728  
-                menu_item.each do |k2, v2|
729  
-                  menu_item[k2] = item_val if v2 == :item
730  
-                end
731  
-                arr << menu_item
732  
-              end            
733  
-            end
734  
-            h[:sub] = arr
735  
-          end
736 716
           sub = h[:sub] && "\n<ul>\n#{build_menu_items h[:sub]}\n</ul>\n"
737  
-          "<li>#{link} #{sub}</li>"
  717
+          add_li_tag ? "<li>#{link} #{sub}</li>" : link
738 718
         end
739  
-      end.compact * "\n"
  719
+      end.flatten.compact * "\n"
740 720
     end
741 721
     
742 722
     def menu_subs key
743 723
       Symbol===key ? @menu_vars[key] : key
744 724
     end
745 725
     
746  
-    
747 726
     def watching_type_cards
748 727
       %{<div class="faint">(following)</div>} #yuck
749 728
     end
6  lib/wagn/set/type/set.rb
@@ -18,8 +18,10 @@ module Set
18 18
           process_inclusion rule_card, :view=>:closed_rule
19 19
         end * "\n" )
20 20
       end.compact * ''
21  
-
22  
-      content_tag('table', :class=>'set-rules') { body }
  21
+      %{
  22
+        <h2 class="set-label">#{ card.label }</h2>
  23
+        #{ content_tag('table', :class=>'set-rules') { body } }
  24
+      }
23 25
     end
24 26
 
25 27
 
20  spec/lib/cardlib/setting_spec.rb
@@ -45,16 +45,16 @@
45 45
         sets = Card['Cardtype A'].related_sets
46 46
         sets.should == ['Cardtype A+*self', 'Cardtype A+*type', 'Cardtype A+*right']
47 47
       end
48  
-      it "should show type plus right sets when they exist" do
49  
-        Account.as_bot { Card.create :name=>'Basic+A+*type plus right', :content=>'' }
50  
-        sets = Card['A'].related_sets
51  
-        sets.should == ['A+*self', 'A+*right', 'Basic+A+*type plus right']
52  
-      end
53  
-      it "should show type plus right sets when they exist, and type" do
54  
-        Account.as_bot { Card.create :name=>'Basic+Cardtype A+*type plus right', :content=>'' }
55  
-        sets = Card['Cardtype A'].related_sets
56  
-        sets.should == ['Cardtype A+*self', 'Cardtype A+*type', 'Cardtype A+*right', 'Basic+Cardtype A+*type plus right']
57  
-      end
  48
+#      it "should show type plus right sets when they exist" do
  49
+#        Account.as_bot { Card.create :name=>'Basic+A+*type plus right', :content=>'' }
  50
+#        sets = Card['A'].related_sets
  51
+#        sets.should == ['A+*self', 'A+*right', 'Basic+A+*type plus right']
  52
+#      end
  53
+#      it "should show type plus right sets when they exist, and type" do
  54
+#        Account.as_bot { Card.create :name=>'Basic+Cardtype A+*type plus right', :content=>'' }
  55
+#        sets = Card['Cardtype A'].related_sets
  56
+#        sets.should == ['Cardtype A+*self', 'Cardtype A+*type', 'Cardtype A+*right', 'Basic+Cardtype A+*type plus right']
  57
+#      end
58 58
       it "should have sets for a non-simple card" do
59 59
         sets = Card['A+B'].related_sets
60 60
         sets.should == ['A+B+*self']

0 notes on commit 8c28878

Please sign in to comment.
Something went wrong with that request. Please try again.