ydim-html 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.travis.yml +29 -0
  4. data/Gemfile +12 -0
  5. data/History.txt +11 -0
  6. data/LICENSE.txt +339 -0
  7. data/Manifest.txt +47 -0
  8. data/Rakefile +21 -0
  9. data/bin/ydim-htmld +38 -0
  10. data/doc/favicon.ico +0 -0
  11. data/doc/index.rbx +16 -0
  12. data/doc/resources/javascript/dojo.js +5940 -0
  13. data/doc/resources/javascript/iframe_history.html +53 -0
  14. data/doc/resources/javascript/ydim.js +67 -0
  15. data/doc/resources/ydim/ydim.css +113 -0
  16. data/lib/ydim/html.rb +10 -0
  17. data/lib/ydim/html/config.rb +37 -0
  18. data/lib/ydim/html/state/ajax_values.rb +17 -0
  19. data/lib/ydim/html/state/autoinvoice.rb +94 -0
  20. data/lib/ydim/html/state/confirm.rb +16 -0
  21. data/lib/ydim/html/state/debitor.rb +82 -0
  22. data/lib/ydim/html/state/debitors.rb +24 -0
  23. data/lib/ydim/html/state/global.rb +100 -0
  24. data/lib/ydim/html/state/global_predefine.rb +14 -0
  25. data/lib/ydim/html/state/init.rb +21 -0
  26. data/lib/ydim/html/state/invoice.rb +180 -0
  27. data/lib/ydim/html/state/invoices.rb +70 -0
  28. data/lib/ydim/html/state/pdf.rb +17 -0
  29. data/lib/ydim/html/util/lookandfeel.rb +133 -0
  30. data/lib/ydim/html/util/server.rb +37 -0
  31. data/lib/ydim/html/util/session.rb +29 -0
  32. data/lib/ydim/html/util/validator.rb +63 -0
  33. data/lib/ydim/html/version.rb +7 -0
  34. data/lib/ydim/html/view/ajax_values.rb +27 -0
  35. data/lib/ydim/html/view/autoinvoice.rb +80 -0
  36. data/lib/ydim/html/view/autoinvoices.rb +42 -0
  37. data/lib/ydim/html/view/confirm.rb +28 -0
  38. data/lib/ydim/html/view/debitor.rb +118 -0
  39. data/lib/ydim/html/view/debitors.rb +45 -0
  40. data/lib/ydim/html/view/htmlgrid.rb +104 -0
  41. data/lib/ydim/html/view/init.rb +30 -0
  42. data/lib/ydim/html/view/invoice.rb +218 -0
  43. data/lib/ydim/html/view/invoices.rb +159 -0
  44. data/lib/ydim/html/view/navigation.rb +29 -0
  45. data/lib/ydim/html/view/pdf.rb +24 -0
  46. data/lib/ydim/html/view/template.rb +71 -0
  47. data/readme.md +28 -0
  48. data/spec/smoketest_spec.rb +234 -0
  49. data/spec/spec_helper.rb +117 -0
  50. data/spec/stub/http_server.rb +157 -0
  51. data/test/selenium.rb +1690 -0
  52. data/test/selenium/selenium-server.jar +0 -0
  53. data/test/selenium/test_autoinvoice.rb +319 -0
  54. data/test/selenium/test_debitor.rb +344 -0
  55. data/test/selenium/test_debitors.rb +47 -0
  56. data/test/selenium/test_init.rb +105 -0
  57. data/test/selenium/test_invoice.rb +296 -0
  58. data/test/selenium/test_invoices.rb +176 -0
  59. data/test/selenium/unit.rb +125 -0
  60. data/test/stub/http_server.rb +141 -0
  61. data/test/suite.rb +15 -0
  62. data/ydim-html.gemspec +36 -0
  63. metadata +302 -0
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::Util::Server -- ydim -- 12.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'openssl'
6
+ require 'sbsm/drbserver'
7
+ require 'ydim/html/util/session'
8
+ require 'ydim/html/util/validator'
9
+ require 'ydim/client'
10
+
11
+ module YDIM
12
+ module Html
13
+ module Util
14
+ class Server < SBSM::DRbServer
15
+ SESSION = Html::Util::Session
16
+ VALIDATOR = Html::Util::Validator
17
+ def initialize(server)
18
+ @server = server
19
+ @private_key = OpenSSL::PKey::DSA.new(File.read(Html.config.root_key))
20
+ @system = YDIM::Client.new(Html.config)
21
+ super(@system)
22
+ end
23
+ def login(email, pass_hash)
24
+ (email == Html.config.email) && (pass_hash == Html.config.md5_pass)
25
+ end
26
+ def method_missing(meth, *args)
27
+ @system.login(@server, @private_key)
28
+ begin
29
+ @system.send(meth, *args)
30
+ ensure
31
+ @system.logout
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::Util::Session -- ydim -- 12.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'sbsm/session'
6
+ require 'ydim/html/state/global'
7
+ require 'ydim/html/util/lookandfeel'
8
+
9
+ module YDIM
10
+ module Html
11
+ module Util
12
+ class Session < SBSM::Session
13
+ DEFAULT_FLAVOR = "ydim"
14
+ DEFAULT_LANGUAGE = 'de'
15
+ DEFAULT_STATE = Html::State::Init
16
+ LOOKANDFEEL = Html::Custom::Lookandfeel
17
+ def login
18
+ @app.login(user_input(:email), user_input(:pass))
19
+ end
20
+ def invoices
21
+ @app.invoice_infos(user_input(:status) || 'is_open')
22
+ end
23
+ def method_missing(meth, *args)
24
+ @app.send(meth, *args)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::Util::Validator -- ydim -- 12.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'sbsm/validator'
6
+
7
+ module YDIM
8
+ module Html
9
+ module Util
10
+ class Validator < SBSM::Validator
11
+ BOOLEAN = [:payment_received, :deleted, :suppress_vat]
12
+ DATES = [:date, :hosting_invoice_date]
13
+ ALLOWED_TAGS = %{a b br div font h1 h2 h3 i img invoice li ol p pre span
14
+ strong u ul year}
15
+ ENUMS = {
16
+ :currency => [ 'CHF', 'EUR', ],
17
+ :debitor_type => [ nil, 'dt_hosting', 'dt_pharmacy', 'dt_pharma',
18
+ 'dt_insurance', 'dt_info', 'dt_hospital', 'dt_health', 'dt_doctor',
19
+ 'dt_consulting' ],
20
+ :invoice_interval => [ 'inv_12', 'inv_6', 'inv_3', 'inv_24', 'inv_m', ],
21
+ :salutation => [ nil, 'Frau', 'Herr', ],
22
+ :status => [ nil, 'is_open', 'is_due', 'is_paid', 'is_trash'],
23
+ }
24
+ EVENTS = [ :ajax_collect_garbage, :ajax_create_item, :ajax_debitor,
25
+ :ajax_delete_autoinvoice, :ajax_delete_item, :ajax_item,
26
+ :ajax_invoice, :ajax_invoices, :ajax_status, :autoinvoice,
27
+ :create_autoinvoice, :create_debitor, :create_invoice, :debitor,
28
+ :debitors, :generate_invoice, :invoice, :invoices, :login, :logout,
29
+ :pdf, :send_invoice, :sort, :update ]
30
+ STRINGS = [ :name, :contact, :contact_firstname, :contact_title,
31
+ :country, :description, :location, :sortvalue, :text, :unit ]
32
+ NUMERIC = [ :unique_id, :hosting_price, :index, :precision, :price,
33
+ :quantity ]
34
+ HTML = [ :reminder_body, :reminder_subject ]
35
+ def address_lines(value)
36
+ validate_string(value).split(/\r|\n|\r\n/)
37
+ end
38
+ def emails(value)
39
+ value.to_s.split(/\s*,\s*/).collect do |val| email(val) end
40
+ rescue SBSM::InvalidDataError => err
41
+ raise SBSM::InvalidDataError.new(err.message, :emails, value)
42
+ end
43
+ def phone(value)
44
+ str = value.to_s.strip
45
+ return if(str.empty?)
46
+ if(/^00[0-9 ]{10,}$/.match(str))
47
+ str
48
+ else
49
+ raise SBSM::InvalidDataError.new(:e_invalid_phone, :phone, str)
50
+ end
51
+ end
52
+ def validate_numeric(key, value)
53
+ match = /-?\d*(\.\d{1,2})?/.match(value)
54
+ if(match[1])
55
+ match[0].to_f
56
+ else
57
+ match[0].to_i
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ module YDIM
4
+ module Html
5
+ VERSION = '1.0.1'
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::AjaxValues -- ydim -- 18.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'htmlgrid/component'
6
+ require 'cgi'
7
+
8
+ module YDIM
9
+ module Html
10
+ module View
11
+ class AjaxValues < HtmlGrid::Component
12
+ HTTP_HEADERS = {
13
+ 'Content-Type' => 'text/javascript; charset=UTF-8',
14
+ }
15
+ def to_html(context)
16
+ if @model.is_a?(Array)
17
+ "var ajaxResponse = {\n" << @model.collect { |key, val|
18
+ "'#{escape(key)}': '#{escape(val)}'"
19
+ }.join(",\n") << "\n};"
20
+ else
21
+ "var ajaxResponse = {\n'" << escape(@model.to_s) + "'\n};"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::AutoInvoice -- ydim -- 13.12.2006 -- hwyss@ywesee.com
4
+
5
+ require 'ydim/html/view/invoice'
6
+
7
+ module YDIM
8
+ module Html
9
+ module View
10
+ class AutoInvoiceInnerComposite < InvoiceInnerComposite
11
+ COMPONENTS = {
12
+ [0,0] => :unique_id,
13
+ [0,1,0] => :debitor_name,
14
+ [1,1,1] => 'dash',
15
+ [1,1,2] => :debitor_email,
16
+ [0,2] => :description,
17
+ [0,3] => :date,
18
+ [0,4] => :currency,
19
+ [0,5] => :precision,
20
+ [0,6] => :invoice_interval,
21
+ }
22
+ end
23
+ class AutoInvoiceReminderComposite < HtmlGrid::Composite
24
+ COMPONENTS = {
25
+ [0,0] => :reminder_subject,
26
+ [0,1] => :reminder_body,
27
+ [1,2] => :reminder_date,
28
+ }
29
+ CSS_MAP = {
30
+ [0,1] => 'top',
31
+ }
32
+ COMPONENT_CSS_MAP = {
33
+ [0,0] => 'extralarge',
34
+ }
35
+ LABELS = true
36
+ def reminder_body(model)
37
+ input = HtmlGrid::Textarea.new(:reminder_body, model, @session, self)
38
+ input.set_attribute('wrap', 'hard')
39
+ input.set_attribute('cols', '72')
40
+ input.set_attribute('style', 'font-family: fixed;')
41
+ input.label = true
42
+ input.unescaped = true
43
+ value = model.reminder_body
44
+ if(value.nil? || value.empty?)
45
+ input.value = @session.state.format_invoice
46
+ end
47
+ input
48
+ end
49
+ def reminder_date(model)
50
+ body = model.reminder_body.to_s.strip
51
+ subject = model.reminder_subject.to_s.strip
52
+ if(body.empty? || subject.empty? || !model.date)
53
+ @lookandfeel.lookup(:reminder_none)
54
+ else
55
+ (model.date << 1).strftime(@lookandfeel.lookup(:reminder_date))
56
+ end
57
+ end
58
+ end
59
+ class AutoInvoiceComposite < InvoiceComposite
60
+ COMPONENTS = {
61
+ [0,0] => AutoInvoiceInnerComposite,
62
+ [0,1] => :items,
63
+ [0,2] => InvoiceTotalComposite,
64
+ [0,3] => AutoInvoiceReminderComposite,
65
+ [0,4] => :submit,
66
+ [1,4] => :generate_invoice,
67
+ }
68
+ CSS_MAP = {
69
+ 4 => 'padded'
70
+ }
71
+ def generate_invoice(model)
72
+ button(:generate_invoice, model)
73
+ end
74
+ end
75
+ class AutoInvoice < Invoice
76
+ CONTENT = AutoInvoiceComposite
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::AutoInvoices -- de.oddb.org -- 13.12.2006 -- hwyss@ywesee.com
4
+
5
+ require 'ydim/html/view/invoices'
6
+
7
+ module YDIM
8
+ module Html
9
+ module View
10
+ class AutoInvoiceList < InvoiceList
11
+ COMPONENTS = {
12
+ [0,0] => :unique_id,
13
+ [1,0] => :name,
14
+ [2,0] => :email,
15
+ [3,0] => :description,
16
+ [4,0] => :formatted_date,
17
+ [5,0] => :total_netto,
18
+ [6,0] => :total_brutto,
19
+ [7,0] => :currency,
20
+ [8,0] => :generate_invoice,
21
+ [9,0] => :delete,
22
+ }
23
+ CSS_ID = 'autoinvoices'
24
+ links :autoinvoice, :date, :unique_id, :description
25
+ def delete(model)
26
+ link = HtmlGrid::Link.new(:delete, model, @session, self)
27
+ url = @lookandfeel._event_url(:ajax_delete_autoinvoice,
28
+ [:unique_id, model.unique_id])
29
+ link.href = sprintf("javascript: reload_list('%s', '%s')",
30
+ css_id, url)
31
+ link
32
+ end
33
+ def generate_invoice(model)
34
+ link = HtmlGrid::Link.new(:generate_invoice, model, @session, self)
35
+ link.href = @lookandfeel._event_url(:generate_invoice,
36
+ {:unique_id => model.unique_id})
37
+ link
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::Confirm -- ydim -- 18.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'ydim/html/view/template'
6
+ require 'htmlgrid/div'
7
+
8
+ module YDIM
9
+ module Html
10
+ module View
11
+ class ConfirmComponent < HtmlGrid::Div
12
+ CSS_ID = 'confirm'
13
+ def init
14
+ @value = @model
15
+ end
16
+ end
17
+ class Confirm < Template
18
+ CONTENT = ConfirmComponent
19
+ def http_headers
20
+ headers = super
21
+ url = @lookandfeel._event_url(:invoices)
22
+ headers.store('Refresh', "5; URL=#{url}")
23
+ headers
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::Debitor -- ydim -- 12.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'ydim/html/view/template'
6
+ require 'ydim/html/view/autoinvoices'
7
+ require 'ydim/html/view/invoices'
8
+ require 'htmlgrid/inputtext'
9
+ require 'htmlgrid/inputdate'
10
+ require 'htmlgrid/labeltext'
11
+ require 'htmlgrid/select'
12
+ require 'htmlgrid/textarea'
13
+
14
+ module YDIM
15
+ module Html
16
+ module View
17
+ class Textarea < HtmlGrid::Textarea
18
+ LABEL = true
19
+ end
20
+ class DebitorForm < HtmlGrid::Form
21
+ COMPONENTS = {
22
+ [0,0] => :unique_id,
23
+ [0,1] => :debitor_type,
24
+ [0,2] => :name,
25
+ [0,3] => :salutation,
26
+ [0,4] => :contact,
27
+ [0,5] => :contact_firstname,
28
+ [0,6] => :contact_title,
29
+ [0,7] => :address_lines,
30
+ [0,8] => :location,
31
+ [0,9] => :country,
32
+ [0,10] => :emails,
33
+ [0,11] => :phone,
34
+ [1,12] => :submit,
35
+ }
36
+ FORM_ID = 'debitor'
37
+ EVENT = :update
38
+ SYMBOL_MAP = {
39
+ :debitor_type => HtmlGrid::Select,
40
+ :unique_id => HtmlGrid::Value,
41
+ :salutation => HtmlGrid::Select,
42
+ }
43
+
44
+ def address_lines(model, session=@session)
45
+ input = HtmlGrid::InputText.new(:address_lines, model, @session, self)
46
+ input.value = model.address_lines.join(", ").force_encoding('utf-8') if model.address_lines
47
+ input
48
+ end
49
+ def emails(model, session=@session)
50
+ input = HtmlGrid::InputText.new(:emails, model, @session, self)
51
+ if error = @session.error(:emails)
52
+ input.value = error.value
53
+ else
54
+ input.value = model.emails.join(', ')
55
+ end
56
+ input.css_class = 'extralarge'
57
+ input
58
+ end
59
+ def hidden_fields(context)
60
+ super << context.hidden('unique_id', @model.unique_id)
61
+ end
62
+ end
63
+ class DebitorComposite < HtmlGrid::DivComposite
64
+ COMPONENTS = {
65
+ [0,0] => DebitorForm,
66
+ [0,1] => :is_open,
67
+ [1,1] => :is_due,
68
+ [2,1] => :is_paid,
69
+ [3,1] => :is_trash,
70
+ [0,2] => :invoices,
71
+ [0,3] => :invoice_list,
72
+ [0,4] => :create_invoice,
73
+ [0,5] => :autoinvoices,
74
+ [0,6] => :autoinvoice_list,
75
+ [0,7] => :create_autoinvoice,
76
+ }
77
+ CSS_MAP = {
78
+ 1 => 'subnavigation',
79
+ 2 => 'padded',
80
+ 4 => 'padded',
81
+ 5 => 'padded',
82
+ 7 => 'padded',
83
+ }
84
+ SYMBOL_MAP = {
85
+ :invoices => HtmlGrid::LabelText,
86
+ :autoinvoices => HtmlGrid::LabelText,
87
+ }
88
+ def autoinvoice_list(model)
89
+ AutoInvoiceList.new(@session.state.autoinvoice_infos, @session, self)
90
+ end
91
+ def button(key, model)
92
+ if(model.unique_id)
93
+ button = HtmlGrid::Button.new(key, model, @session, self)
94
+ args = {:unique_id => model.unique_id}
95
+ url = @lookandfeel._event_url(key, args)
96
+ button.set_attribute('onClick', "document.location.href='#{url}'")
97
+ button
98
+ end
99
+ end
100
+ def create_autoinvoice(model)
101
+ button(:create_autoinvoice, model)
102
+ end
103
+ def create_invoice(model)
104
+ button(:create_invoice, model)
105
+ end
106
+ def invoice_list(model)
107
+ InvoiceList.new(@session.state.invoice_infos, @session, self)
108
+ end
109
+ end
110
+ class Debitor < Template
111
+ CONTENT = DebitorComposite
112
+ def subnavigation(model)
113
+ InvoicesSubnavigation.new(model, @session, self)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Html::View::Debitors -- ydim -- 12.01.2006 -- hwyss@ywesee.com
4
+
5
+ require 'ydim/html/view/template'
6
+ require 'htmlgrid/formlist'
7
+
8
+ module YDIM
9
+ module Html
10
+ module View
11
+ class DebitorList < HtmlGrid::FormList
12
+ COMPONENTS = {
13
+ [0,0] => :unique_id,
14
+ [1,0] => :name,
15
+ [2,0] => :email,
16
+ [3,0] => :phone,
17
+ [4,0] => :next_invoice_date,
18
+ [5,0] => :debitor_type,
19
+ }
20
+ EVENT = :create_debitor
21
+ SORT_DEFAULT = nil
22
+ def debitor_type(model)
23
+ @lookandfeel.lookup(model.debitor_type)
24
+ end
25
+ def next_invoice_date(model)
26
+ if(date = model.next_invoice_date)
27
+ @lookandfeel.format_date(date)
28
+ end
29
+ end
30
+ def phone(model)
31
+ if(phone = model.phone)
32
+ link = HtmlGrid::Link.new(:phone, model, @session, self)
33
+ link.href = "callto://#{phone.delete(' ')}"
34
+ link.value = phone
35
+ link
36
+ end
37
+ end
38
+ links :debitor, :name, :unique_id
39
+ end
40
+ class Debitors < Template
41
+ CONTENT = DebitorList
42
+ end
43
+ end
44
+ end
45
+ end