diff -ur rubywebdialogs-0.0.3.tar.gz/rubywebdialogs/lib/rwd.lib.rb rubywebdialogs-0.0.4.tar.gz/rubywebdialogs/lib/rwd.lib.rb
--- rubywebdialogs-0.0.3.tar.gz/rubywebdialogs/lib/rwd.lib.rb 2004-04-21 22:37:44.000000000 +0200
+++ rubywebdialogs-0.0.4.tar.gz/rubywebdialogs/lib/rwd.lib.rb 2004-04-23 00:08:14.000000000 +0200
@@ -12,10 +12,11 @@
$".push "win32/registry.rb"
end
-exit if ARGV.include?("--rwd-exit")
+exit if ARGV.include?("--rwd-exit") # Hack ???
+
+$rwd_debug = ($rwd_debug or false)
+$rwd_border = ($rwd_border or 0)
-Debug = false
-Border = 0
RWDEmptyline = "..."
rcfile = nil
@@ -269,12 +270,12 @@
end
class OpenTag
- def prechildren(res, before, after, vars, switches, help, firstaction, tabs, tab)
+ def prechildren(res, before, after, vars, switches, help, oneormorefields, firstaction, tabs, tab)
bef = before[-1]
- res.concat Format % ["Before", @subtype] if (Debug and not bef.nil?)
+ res.concat Format % ["Before", @subtype] if ($rwd_debug and not bef.nil?)
res.concat bef if not bef.nil?
- res.concat Format % ["Pre", @subtype] if Debug
+ res.concat Format % ["Pre", @subtype] if $rwd_debug
align = AC
align = "align=´#{@args["align"]}´" if @args.include?("align")
@@ -312,14 +313,20 @@
else
res.concat "<a href=´javascript:document.bodyform.rwd_action.value=\"#{@args["action"]}\";document.bodyform.submit();´>"
end
- when "vertical" then res.concat "<table #{AC} border=´#{Border}´ cellspacing=´3´ cellpadding=´0´>"
- when "horizontal" then res.concat "<table #{AC} border=´#{Border}´ cellspacing=´3´ cellpadding=´0´><tr #{align} #{valign}>"
- when "table" then res.concat "<table #{AC} border=´#{Border}´ cellspacing=´3´ cellpadding=´0´>"
+ when "vertical" then res.concat "<table #{AC} border=´#{$rwd_border}´ cellspacing=´3´ cellpadding=´0´>"
+ when "horizontal" then res.concat "<table #{AC} border=´#{$rwd_border}´ cellspacing=´3´ cellpadding=´0´><tr #{align} #{valign}>"
+ when "table" then res.concat "<table #{AC} border=´#{$rwd_border}´ cellspacing=´3´ cellpadding=´0´>"
when "row" then res.concat "<tr #{align} #{valign}>"
when "hidden" then res.concat "<p #{align}><input name=´#{@args["name"]}´ value=´#{value}´ type=´hidden´>"
- when "text" then res.concat "<p #{align}><input name=´#{@args["name"]}´ value=´#{value}´ type=´text´>"
- when "textarea" then res.concat "<p #{align}><textarea name=´#{@args["name"]}´>#{value}</textarea>"
- when "password" then res.concat "<p #{align}><input name=´#{@args["name"]}´ value=´#{value}´ type=´password´>"
+ when "text"
+ res.concat "<p #{align}><input name=´#{@args["name"]}´ value=´#{value}´ type=´text´>"
+ oneormorefields << "true"
+ when "textarea"
+ res.concat "<p #{align}><textarea name=´#{@args["name"]}´>#{value}</textarea>"
+ oneormorefields << "true"
+ when "password"
+ res.concat "<p #{align}><input name=´#{@args["name"]}´ value=´#{value}´ type=´password´>"
+ oneormorefields << "true"
when "checkbox"
if vars[@args["name"]] == "on"
switches[@args["name"]] = true
@@ -328,16 +335,19 @@
switches[@args["name"]] = false
res.concat "<p #{align}><input name=´#{@args["name"]}´ type=´checkbox´>"
end
+ oneormorefields << "true"
when "radio"
if vars[@args["name"]] == value
res.concat "<p #{align}><input name=´#{@args["name"]}´ checked=´on´ value=´#{value}´ type=´radio´>"
else
res.concat "<p #{align}><input name=´#{@args["name"]}´ value=´#{value}´ type=´radio´>"
end
+ oneormorefields << "true"
when "select"
res.concat "<select #{align} name=´#{@args["name"]}´ width=´#{@args["width"]}´>"
name = @args["name"]
$select = vars[name]
+ oneormorefields << "true"
when "option"
if $select == @children[0].text
res.concat "<option selected=´true´>"
@@ -347,21 +357,27 @@
when "button"
res.concat "<input type=´submit´ value=´#{@args["caption"]}´ onclick=´document.bodyform.rwd_action.value=\"#{@args["action"]}\";´>"
firstaction << @args["action"] if (firstaction.empty? and @args.include?("action"))
+ oneormorefields << "true"
when "back"
res.concat "<input type=´submit´ value=´Back´ onclick=´document.bodyform.rwd_action.value=\"rwd_back\";´>"
firstaction << "rwd_back" if firstaction.empty?
+ oneormorefields << "true"
when "help"
res.concat "<input type=´submit´ value=´Help´ onclick=´document.bodyform.rwd_action.value=\"rwd_help\";´>"
firstaction << "rwd_help" if firstaction.empty?
+ oneormorefields << "true"
when "quit"
res.concat "<input type=´submit´ value=´Quit´ onclick=´document.bodyform.rwd_action.value=\"rwd_quit\";´>"
firstaction << "rwd_quit" if firstaction.empty?
+ oneormorefields << "true"
when "close"
res.concat "<input type=´submit´ value=´Close´ onclick=´window.close();´>"
firstaction << "rwd_quit" if firstaction.empty?
+ oneormorefields << "true"
when "reset"
res.concat "<input type=´reset´ value=´Reset´>"
firstaction << "rwd_quit" if firstaction.empty?
+ oneormorefields << "true"
when "closewindow"
#res.concat "<script type=´text/javascript´>\n"
#res.concat "<!--\n"
@@ -369,10 +385,10 @@
#res.concat "//-->\n"
#res.concat "</script>"
when "tabs"
- res.concat "<table #{AC} border=´#{Border}´ cellspacing=´3´ cellpadding=´0´>"
+ res.concat "<table #{AC} border=´#{$rwd_border}´ cellspacing=´3´ cellpadding=´0´>"
res.concat " <tr #{AC}>"
res.concat " <td #{AC}>"
- res.concat " <table #{AC} border=´#{Border}´ cellspacing=´3´ cellpadding=´0´>"
+ res.concat " <table #{AC} border=´#{$rwd_border}´ cellspacing=´3´ cellpadding=´0´>"
res.concat " <tr #{AC}>"
tabs.each do |obj|
name = obj.args["name"]
@@ -399,7 +415,7 @@
case @subtype
when "vertical", "window", "helpwindow"
- res.concat Format % ["AftPre", @subtype] if Debug
+ res.concat Format % ["AftPre", @subtype] if $rwd_debug
if @args.include?("spacing")
s = "<tr><td> </td></tr>" * (@args["spacing"].to_i)
else
@@ -408,7 +424,7 @@
bef = "#{s}<tr #{align} #{valign}><td #{align}>"
aft = "</td></tr>"
when "horizontal", "row"
- res.concat Format % ["AftPre", @subtype] if Debug
+ res.concat Format % ["AftPre", @subtype] if $rwd_debug
bef = "<td #{align}>"
aft = "</td>"
end
@@ -417,18 +433,18 @@
after.push(aft)
end
- def postchildren(res, before, after, vars, switches, help, firstaction, tabs, tab)
+ def postchildren(res, before, after, vars, switches, help, oneormorefields, firstaction, tabs, tab)
case @subtype
when "vertical", "window", "helpwindow"
- res.concat Format % ["BefPost", @subtype] if Debug
+ res.concat Format % ["BefPost", @subtype] if $rwd_debug
if @args.include?("spacing")
res.concat "<tr><td> </td></tr>" * (@args["spacing"].to_i)
end
when "horizontal", "row"
- res.concat Format % ["BefPost", @subtype] if Debug
+ res.concat Format % ["BefPost", @subtype] if $rwd_debug
end
- res.concat Format % ["Post", @subtype] if Debug
+ res.concat Format % ["Post", @subtype] if $rwd_debug
case @subtype
when "application"
@@ -483,7 +499,7 @@
after.pop
aft = after[-1]
- res.concat Format % ["After", @subtype] if (Debug and not aft.nil?)
+ res.concat Format % ["After", @subtype] if ($rwd_debug and not aft.nil?)
res.concat aft if not aft.nil?
end
@@ -524,9 +540,9 @@
end
class Text
- def prechildren(res, before, after, vars, switches, help, firstaction, tabs, tab)
+ def prechildren(res, before, after, vars, switches, help, oneormorefields, firstaction, tabs, tab)
if not @text.scan(/[^ \t\r\n]/).empty?
- res.concat Format % ["Text", ""] if Debug
+ res.concat Format % ["Text", ""] if $rwd_debug
res.concat "#{@text}"
end
end
@@ -562,9 +578,10 @@
end
def render(vars=Hash.new, switches=Hash.new, help=false, tab="")
- vars2 = Hash.new
- firstaction = ""
- html = ""
+ vars2 = Hash.new
+ oneormorefields = ""
+ firstaction = ""
+ html = ""
vars.each do |key, value|
if not key.empty?
@@ -596,16 +613,16 @@
end
if help
- helpobject.parsetree("prechildren", "postchildren", html, [""], [""], vars2, switches, false, firstaction, tabs, tab)
+ helpobject.parsetree("prechildren", "postchildren", html, [""], [""], vars2, switches, false, oneormorefields, firstaction, tabs, tab)
else
- windowobject.parsetree("prechildren", "postchildren", html, [""], [""], vars2, switches, (not @helprwd.empty?), firstaction, tabs, tab)
+ windowobject.parsetree("prechildren", "postchildren", html, [""], [""], vars2, switches, (not @helprwd.empty?), oneormorefields, firstaction, tabs, tab)
end
- html.gsub!(/%%*[[:alnum:]_\-]+%%*/, "") if not Debug
+ html.gsub!(/%%*[[:alnum:]_\-]+%%*/, "") if not $rwd_debug
html.gsub!(/%%/, "%")
html.gsub!(/\n\n*/, "\n")
- if firstaction.empty?
+ if oneormorefields.empty?
focus = ""
else
focus = "document.bodyform.elements[0].focus();"
@@ -632,7 +649,7 @@
class RWDDone < RWDWindow
def initialize(exitbrowser)
- super("<window title=´RWD Message´ nobackbuttons noclosebutton><p>Done.</p><horizontal><close/>#{exitbrowser ? "" : "<button caption=´Login´/>"}</horizontal>#{exitbrowser ? "<closewindow/>" : ""}</window>")
+ super("<window title=´RWD Message´ nobackbuttons noclosebutton><p>Done.</p><horizontal><close/>#{exitbrowser ? "" : "<button caption=´Again´/>"}</horizontal>#{exitbrowser ? "<closewindow/>" : ""}</window>")
end
end
@@ -679,31 +696,32 @@
# Copy the vars from the window to vars. vars wil later on be copied to instance variables.
post.sort.each do |key, value|
- puts "Post: #{key} -> #{value.from_html.inspect}" if Debug
+ puts "Post: #{key} -> #{value.from_html.inspect}" if $rwd_debug
vars[key] = value.from_html
end
- # Stack handling for rwd_action and rwd_window.
+ # Stack handling for rwd_action, rwd_window and rwd_tab.
@rwd_action = vars["rwd_action"]
@rwd_action, @rwd_args = @rwd_action.split(/\//, 2) unless @rwd_action.nil?
if @rwd_action =~ /^rwd_tab_/
- tab = @rwd_action.sub(/^rwd_tab_/, "")
+ @rwd_tab = @rwd_action.sub(/^rwd_tab_/, "")
+ @rwd_history[-1][2] = @rwd_tab
else
case @rwd_action
when "rwd_back"
@rwd_history.pop
- @rwd_action = (@rwd_history[-1] or [nil, nil])[0]
- @rwd_window = (@rwd_history[-1] or [nil, nil])[1]
- @rwd_tab = nil
+ @rwd_action = (@rwd_history[-1] or [nil, nil, nil])[0]
+ @rwd_window = (@rwd_history[-1] or [nil, nil, nil])[1]
+ @rwd_tab = (@rwd_history[-1] or [nil, nil, nil])[2]
back = true
when "rwd_help"
help = true
when "rwd_main"
- @rwd_action = "main"
- @rwd_window = "main"
+ @rwd_action = nil
+ @rwd_window = nil
@rwd_tab = nil
@rwd_history = []
when "rwd_quit"
@@ -713,13 +731,15 @@
# History stuff
@rwd_history = @rwd_history[-100..-1] if @rwd_history.length >= 100
+ @rwd_args = [] if @rwd_args.nil?
@rwd_action = "main" if @rwd_action.nil?
@rwd_action = "main" if @rwd_action.empty?
- @rwd_args = [] if @rwd_args.nil?
@rwd_window = "main" if @rwd_window.nil?
+ @rwd_tab = "" if @rwd_tab.nil?
vars["rwd_action"] = @rwd_action
vars["rwd_window"] = @rwd_window
+ vars["rwd_tab"] = @rwd_tab
# Copy vars from window to instance.
@@ -731,18 +751,16 @@
if not back
begin
- puts "Method: #{@rwd_action}(#{@rwdargs.join(", ")})" if Debug
+ puts "Method: #{@rwd_action}(#{@rwd_args.join(", ")})" if $rwd_debug
method(@rwd_action).call(*@rwd_args)
rescue NameError
end
- tab = @rwd_tab unless @rwd_tab.nil?
-
# History stuff
- @rwd_history = [["main", "main"]] if @rwd_action == "main"
- @rwd_history = [["main", "main"]] if @rwd_history.empty?
- @rwd_history.push [@rwd_action, @rwd_window] if (@rwd_history[-1] != [@rwd_action, @rwd_window] or not @rwd_msg.nil?)
+ @rwd_history = [["main", "main", nil]] if @rwd_action == "main"
+ @rwd_history = [["main", "main", nil]] if @rwd_history.empty?
+ @rwd_history.push [@rwd_action, @rwd_window, @rwd_tab] if (@rwd_history[-1] != [@rwd_action, @rwd_window, @rwd_tab] or not @rwd_msg.nil?)
end
end
@@ -756,7 +774,7 @@
# just ignore.
vars.sort.each do |key, value|
- puts "Pre: #{key} -> #{value.inspect}" if Debug
+ puts "Pre: #{key} -> #{value.inspect}" if $rwd_debug
end
# Answer to browser.
@@ -768,8 +786,9 @@
res << RWDMessage.new(@rwd_msg).render if @rwd_msgtype == "message"
res << RWDError.new(@rwd_msg).render if @rwd_msgtype == "error"
else
- puts "Window: #{@rwd_window}" if Debug
- res << RWDWindow.new(@rwd_xml, @rwd_window).render(vars, @rwd_switches, help, tab)
+ puts "Window: #{@rwd_window}" if $rwd_debug
+ puts "Tab: #{@rwd_tab}" if $rwd_debug
+ res << RWDWindow.new(@rwd_xml, @rwd_window).render(vars, @rwd_switches, help, @rwd_tab)
end
end
@@ -836,7 +855,7 @@
@rack = rack.to_s
@cleanup = SessionCleanup.new(self, 3600, 24*3600) if cleanup
@sessions = {}
- #@store = PStore.new("#{temp}/store.#{@rack}.#{user}")
+ #@store = PStore.new("#{temp}/store.#{@rack}.#{user}") # ???
#@store.transaction do
#@store[@rack] = {} if not @store.root?(@rack)
@@ -958,11 +977,11 @@
if session.nil?
if auth.nil?
- session = RWDSession.new(MD5.new(req.peeraddr[3].to_s + @object.inspect.to_s).to_s)
- session["object"] = @object
+ session = RWDSession.new(MD5.new(req.peeraddr[3].to_s + @object.inspect.to_s).to_s)
+ session["object"] = @object
else
- session = RWDSession.new(MD5.new(Time.new.to_s + req.peeraddr[3].to_s + @object.inspect.to_s).to_s)
- session["object"] = @object.clone
+ session = RWDSession.new(MD5.new(Time.new.to_s + req.peeraddr[3].to_s + @object.inspect.to_s).to_s)
+ session["object"] = @object.clone
end
if oldsessionid.nil? or oldsessionid.empty?
@@ -972,10 +991,10 @@
us = vars["rwd_a"]
pa = vars["rwd_b"]
-
+
if us.nil? or pa.nil? or auths[us] != pa
- session = RWDSession.new
- session["object"] = RWDLogin.new(realm)
+ session = RWDSession.new
+ session["object"] = RWDLogin.new(realm)
else
session.authenticated = true
@sessions[session.sessionid] = session