OSDN Git Service

modified key when using "edit-entry" and "delete-entry"
authorelixirel <elixirel@users.sourceforge.jp>
Sat, 12 Sep 2009 15:51:58 +0000 (00:51 +0900)
committerelixirel <elixirel@users.sourceforge.jp>
Sat, 12 Sep 2009 15:51:58 +0000 (00:51 +0900)
erbtemp/delentry.html.erb
erbtemp/editentry.html.erb
feedgenerator.rb

index f7457e9..62cfc3e 100644 (file)
@@ -18,6 +18,7 @@
             <form action="<%= cgi.script_name %>" method="POST">
                 <% case params["action"]
                 when "confirm" %>
+                <input type="hidden" name="delid" value="<%= session["delid"] %>">
                 <table align="center" style="width: <%= (TABLEWIDTH - 20) %>px;">
                     <tbody>
                         <tr>
                             </td>
                         </tr>
                         <% db.transaction do
-                        entry = db["entry"][db["delindex"]]
+                        entry = nil
+                        db["entry"].each_with_index { |e, i|
+                        entry = db["entry"][i] if e.entryid == session["delid"]
+                        }
                         entry.paramlist.each do |val| %>
                         <tr style="display: <%= entry.display[val] %>;">
                             <td class="formnavi" style="width: 140px;">
                                 <%= entry.name[val] %>
                             </td>
-                            <td class="forminput"><% if val != "content" %><%= entry.send(val) %><% else %><%= entry.content_for_view %><% end %></td>
+                            <td class="forminput">
+                                <% if val != "content" %><%= entry.send(val) %><% else %><%= entry.content_for_view %><% end %>
+                            </td>
                         </tr>
                         <% end %>
                         <% end %>
                     </tbody>
                 </table>
                 <br>
-                <input type="hidden" name="mode" value="delentry"><input type="hidden" name="action" value=""><input type="button" value="戻る" onclick="switchsubmit(this.form, '')"> <input type="button" value="確定" onclick="switchsubmit(this.form, 'exec')">
-                <% when "exec" %>
+                <input type="hidden" name="mode" value="delentry"><input type="hidden" name="action" value=""><input type="button" value="戻る" onclick="switchsubmit(this.form, '')"> <input type="button" value="確定" onclick="switchsubmit(this.form, 'exec')"><% when "exec" %>
                 <table align="center" style="width: <%= TABLEWIDTH %>px">
                     <tbody>
                         <tr>
@@ -62,7 +67,9 @@
                             </td>
                         </tr>
                         <tr>
-                            <td class="formheader"> </td>
+                            <td class="formheader">
+                                  
+                            </td>
                             <td class="formheader" style="text-align: center;">
                                 記事のタイトル
                             </td>
@@ -73,7 +80,7 @@
                         <% db["entry"].each_with_index do |entry, i| %>
                         <tr>
                             <td class="forminput" style="width: 30px; text-align: center;">
-                                <input type="radio" name="delindex" value="<%= i %>">
+                                <input type="radio" name="delid" value="<%= entry.send("entryid") %>">
                             </td>
                             <td class="forminput">
                                 <%= entry.send("title") %>
index 348a358..58ff03a 100644 (file)
@@ -25,6 +25,7 @@
             <form action="<%= cgi.script_name %>" method="POST">
                 <% case params["action"]
                 when "confirm" %>
+                <input type="hidden" name="editid" value="<%= session["editid"] %>">
                 <table align="center" style="width: <%= (TABLEWIDTH - 20) %>px;">
                     <tbody>
                         <tr>
@@ -39,7 +40,9 @@
                             <td class="formnavi" style="width: 140px;">
                                 <%= entry.name[val] %>
                             </td>
-                            <td class="forminput"><% if val != "content" %><%= entry.send(val) %><% else %><%= entry.content_for_view %><% end %></td>
+                            <td class="forminput">
+                                <% if val != "content" %><%= entry.send(val) %><% else %><%= entry.content_for_view %><% end %>
+                            </td>
                         </tr>
                         <% end %>
                         <% end %>
@@ -59,6 +62,7 @@
                 <br>
                 <a href="<%= cgi.script_name %>">メニューに戻る</a>
                 <% when "edit" %>
+                <input type="hidden" name="editid" value="<%= session["editid"] %>">
                 <table align="center" style="width: <%= (TABLEWIDTH - 20) %>px;">
                     <tbody>
                         <tr>
                             </td>
                         </tr>
                         <% db.transaction do
-                        entry = db["entry"][db["editindex"]]
+                        entry = nil
+                        db["entry"].each_with_index { |e, i|
+                        entry = db["entry"][i] if e.entryid == session["editid"]
+                        }
                         entry.paramlist.each do |val| %>
                         <tr style="display: <%= entry.display[val] %>;">
                             <td class="formnavi" style="width: 140px;">
@@ -76,7 +83,7 @@
                             </td>
                             <td class="forminput">
                                 <% if val == "content" %>
-                                  <textarea name="<%= val %>" rows="10" style="width: 100%" id="contenteditor"><%= entry.content_for_generator %></textarea>
+                                <textarea name="<%= val %>" rows="10" style="width: 100%" id="contenteditor"><%= entry.content_for_generator %></textarea>
                                 <% elsif val == "updated" %>
                                 <input type="text" name="<%= val %>" value="<%= Time.now.iso8601 %>" style="width: 100%;"><% else %>
                                 <input type="text" name="<%= val %>" value="<%= entry.send(val) %>" style="width: 100%;"><% end %>
@@ -87,6 +94,7 @@
                 </table>
                 <br>
                 <input type="hidden" name="mode" value="editentry"><input type="hidden" name="action" value="confirm"><input type="submit" value="確認"><% when "back" %>
+                <input type="hidden" name="editid" value="<%= session["editid"] %>">
                 <table align="center" style="width: <%= (TABLEWIDTH - 20) %>px;">
                     <tbody>
                         <tr>
                             </td>
                         </tr>
                         <% db.transaction do
-                        entry = db["editentry"]
+                        entry = nil
+                        db["entry"].each_with_index { |e, i|
+                        entry = db["entry"][i] if e.entryid == session["editid"]
+                        }
                         entry.paramlist.each do |val| %>
                         <tr style="display: <%= entry.display[val] %>;">
                             <td class="formnavi" style="width: 140px;">
                                 <% if val == "content" %>
                                 <textarea name="<%= val %>" rows="10" style="width: 100%" id="contenteditor"><%= entry.content_for_generator %></textarea>
                                 <% else %>
-                                <input type="text" name="<%= val %>" value="<%= entry.send(val) %>" style="width: 100%;">
-                                <% end %>
+                                <input type="text" name="<%= val %>" value="<%= entry.send(val) %>" style="width: 100%;"><% end %>
                             </td>
-                        </tr>
-                        <% end %>
+                        </tr><% end %>
                         <% end %>
                     </tbody>
                 </table>
                         <% db["entry"].each_with_index do |entry, i| %>
                         <tr>
                             <td class="forminput" style="width: 30px; text-align: center;">
-                                <input type="radio" name="editindex" value="<%= i %>">
+                                <input type="radio" name="editid" value="<%= entry.send("entryid") %>">
                             </td>
                             <td class="forminput">
                                 <%= entry.send("title") %>
index bcbc3f6..3f594bf 100644 (file)
@@ -97,7 +97,7 @@ class AbstractEntry
     @paramlist.each do |key|
       val = hash[key.to_sym] || hash[key.to_s]
       if val
-        val.strip!
+        val.strip!
         val.gsub!(/\r\n|\r/, "\n")
         @attr[key.to_sym] = CGI.escapeHTML(val)
       else
@@ -350,7 +350,7 @@ class Entry < AbstractEntry
   # データソースから読み取ったHTMLを、エディタで編集可能な形式に変換するメソッドです
   def content_for_generator
     str = @attr[:content].dup
-    str.strip!
+    str.strip!
     str.gsub!(/(&lt;\/(?:p|h\d|div)(?:&gt;|>))\n/i, '\1')
     str.gsub!(/\n/, '&lt;br&gt;') if REPLACEBRTAG
     str.gsub!(/(&lt;(?:(?!&gt;).)*?)#{Regexp.escape(FEEDXMLDIR)}/) { "#$1#{XMLPATH}" }
@@ -361,7 +361,7 @@ class Entry < AbstractEntry
   def content_for_blog
     str = @attr[:content].dup
     str = CGI.unescapeHTML(str)
-    str.strip!
+    str.strip!
     str.gsub!(/(\r\n|\n)/, "")
     str.gsub!(/<br>/i, "\n") if REPLACEBRTAG
     str.gsub!(/(<br>|<\/p>|<\/h\d>|<\/div>)(?=[^\n])/i) { "#$1\n" } unless REPLACEBRTAG
@@ -373,7 +373,7 @@ class Entry < AbstractEntry
   def content_for_view
     str = @attr[:content].dup
     str = CGI.unescapeHTML(str)
-    str.strip!
+    str.strip!
     str.gsub!(/<br>/i, "\n") if REPLACEBRTAG
     str.gsub!(/(<[^>]*?)#{Regexp.escape(FEEDXMLDIR)}/) { "#$1#{XMLPATH}" }
     str
@@ -584,6 +584,8 @@ class Controller
           feedwriter.to_xml(db["feed"], db["entry"])
         else 
           # New Diary - Default
+          db["feed"] = Feed.readxml(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
+          db["entry"] = Entry.readxml(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
         end
         
         # 記事編集部分
@@ -591,17 +593,23 @@ class Controller
         case params["action"]
           # 編集画面
           when "edit"
-          db["editindex"] = cgi["editindex"].to_i
+          session["editid"] = cgi["editid"].to_s
           # 確認画面
           when "confirm"
+          session["editid"] = cgi["editid"].to_s
           db["editentry"] = Entry.new(params)
           db["editentry"].content = db["editentry"].content_for_blog
           # 記事の変更を実際にファイルに反映
           when "exec"
-          db["entry"][db["editindex"]] = db["editentry"]
+          db["entry"].each_with_index { |e, i|
+            db["entry"][i] = db["editentry"] if e.entryid == cgi["editid"].to_s
+          }
           feedwriter = FeedWriter.new(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
           feedwriter.to_xml(db["feed"], db["entry"])
         else
+          # Edit Diary - Default
+          db["feed"] = Feed.readxml(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
+          db["entry"] = Entry.readxml(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
         end
         
         # 記事削除部分
@@ -609,12 +617,20 @@ class Controller
         case params["action"]
           # 確認画面
           when "confirm"
-          db["delindex"] = cgi["delindex"].to_i
+          session["delid"] = cgi["delid"].to_s
           # 記事の削除を実際にファイルに反映
           when "exec"
-          db["entry"].delete_at(db["delindex"])
+          delindex = nil
+          db["entry"].each_with_index { |e, i|
+            delindex = i if e.entryid == cgi["delid"].to_s
+          }
+          db["entry"].delete_at(delindex) unless delindex == nil
           feedwriter = FeedWriter.new(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
           feedwriter.to_xml(db["feed"], db["entry"])
+        else
+          # Delete Diary - Default
+          db["feed"] = Feed.readxml(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
+          db["entry"] = Entry.readxml(XMLPATH + session["filepath"].match(/[^\/]*?$/).to_a[0])
         end
         
         # Feed情報変更部分