ig3tool 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ig3tool +17 -21
- data/lib/actions/bib.rb +295 -0
- data/lib/actions/bitching.rb +19 -0
- data/lib/actions/cultuur.rb +3 -0
- data/lib/actions/interne.rb +98 -0
- data/lib/actions/kaching.rb +90 -0
- data/lib/actions/people.rb +178 -0
- data/lib/actions/printing.rb +125 -0
- data/lib/actions/product.rb +154 -0
- data/lib/bib.rb +94 -0
- data/lib/billing.rb +112 -0
- data/lib/bitching.rb +49 -0
- data/lib/config.rb +19 -0
- data/lib/glade/cola_light_small.png +0 -0
- data/lib/glade/cola_light_xsmall.png +0 -0
- data/lib/glade/cola_small.png +0 -0
- data/lib/glade/cola_xsmall.png +0 -0
- data/lib/glade/doos_small.png +0 -0
- data/lib/glade/doos_xsmall.png +0 -0
- data/lib/glade/icons/cola_light_small.png +0 -0
- data/lib/glade/icons/cola_light_xsmall.png +0 -0
- data/lib/glade/icons/cola_small.png +0 -0
- data/lib/glade/icons/cola_xsmall.png +0 -0
- data/lib/glade/icons/doos_small.png +0 -0
- data/lib/glade/icons/doos_xsmall.png +0 -0
- data/lib/glade/icons/piggy_small.png +0 -0
- data/lib/glade/icons/piggy_xsmall.png +0 -0
- data/lib/glade/money_small.png +0 -0
- data/lib/glade/money_xsmall.png +0 -0
- data/lib/glade/newinterne.glade +504 -0
- data/lib/glade/piggy_small.png +0 -0
- data/lib/glade/piggy_xsmall.png +0 -0
- data/lib/glade/sales.glade +89 -87
- data/lib/horrible_hack.rb +15 -0
- data/lib/interne.rb +111 -0
- data/lib/ldap.rb +104 -0
- data/lib/log.rb +25 -0
- data/lib/membership.rb +32 -0
- data/lib/mymd5.rb +95 -0
- data/lib/people.rb +143 -0
- data/lib/printing.rb +238 -0
- data/lib/request.rb +14 -0
- data/lib/sales.rb +158 -0
- data/lib/ui/automaatwindow.rb +2 -2
- data/lib/ui/bibliotheekwindow.rb +16 -17
- data/lib/ui/bibwindow.rb +15 -15
- data/lib/ui/gladehelper.rb +20 -6
- data/lib/ui/internewindow.rb +12 -9
- data/lib/ui/loginwindow.rb +2 -4
- data/lib/ui/memberswindow.rb +9 -9
- data/lib/ui/newinterne.rb +258 -0
- data/lib/ui/peoplewindow.rb +14 -16
- data/lib/ui/printenwindow.rb +11 -11
- data/lib/ui/printingwindow.rb +19 -20
- data/lib/ui/productswindow.rb +27 -15
- data/lib/ui/saleswindow.rb +21 -8
- data/lib/ui/toolwindow.rb +5 -3
- data/lib/utils.rb +106 -0
- data/lib/web.rb +98 -0
- metadata +48 -3
data/lib/ui/printenwindow.rb
CHANGED
@@ -104,7 +104,7 @@ module Ig3tool
|
|
104
104
|
return if username.nil? or username.empty?
|
105
105
|
|
106
106
|
begin
|
107
|
-
user = $
|
107
|
+
user = $client.print_userinfo([ username ])
|
108
108
|
|
109
109
|
@glade.get_widget('user').text = username # Kan username of alias zijn waarop men zoekt
|
110
110
|
if user.nil?
|
@@ -152,7 +152,7 @@ module Ig3tool
|
|
152
152
|
when :adduser
|
153
153
|
@undo.method = :none
|
154
154
|
begin
|
155
|
-
answer = $
|
155
|
+
answer = $client.print_delaccount!({ :username => @undo.username })
|
156
156
|
@undo.method = :deluser
|
157
157
|
rescue Exception => e
|
158
158
|
_print_msg "Fout: Undo: #{$!}"
|
@@ -162,7 +162,7 @@ module Ig3tool
|
|
162
162
|
when :deluser
|
163
163
|
@undo.method = :none
|
164
164
|
begin
|
165
|
-
answer = $
|
165
|
+
answer = $client.print_addaccount!({ :username => @undo.username, :email => @undo.email, :amount => @undo.amount })
|
166
166
|
@undo.method = :adduser
|
167
167
|
rescue Exception => e
|
168
168
|
_print_msg "Fout: Undo: #{$!}"
|
@@ -172,7 +172,7 @@ module Ig3tool
|
|
172
172
|
when :addcredit
|
173
173
|
@undo.method = :none
|
174
174
|
begin
|
175
|
-
answer = $
|
175
|
+
answer = $client.print_addcredit!({ :username => @undo.username, :email => @undo.email, :amount => - @undo.amount })
|
176
176
|
@undo.method = :addcredit
|
177
177
|
@undo.amount = - @undo.amount
|
178
178
|
rescue Exception => e
|
@@ -212,10 +212,10 @@ module Ig3tool
|
|
212
212
|
begin
|
213
213
|
# Indien de gebruiker nog niet bestaat, creeer automatisch een account wanneer er
|
214
214
|
# op 'toevoegen krediet' wordt geklikt
|
215
|
-
if !$
|
216
|
-
$
|
215
|
+
if !$client.print_userinfo([ username ])
|
216
|
+
$client.print_addaccount!({ :username => username, :email => email })
|
217
217
|
end
|
218
|
-
answer = $
|
218
|
+
answer = $client.print_addcredit!({ :username => username, :amount => amount })
|
219
219
|
_print_msg "#{@user_entry.text} Gets #{amount} Credits"
|
220
220
|
rescue Exception => e
|
221
221
|
_print_msg "Fout: Toepassen: #{$!}"
|
@@ -266,7 +266,7 @@ module Ig3tool
|
|
266
266
|
|
267
267
|
def _unrefund(selected)
|
268
268
|
begin
|
269
|
-
answer = $
|
269
|
+
answer = $client.print_unrefund!({ :jobid => selected.jobid }) # TODO-CHECK
|
270
270
|
@log_list.model.row_changed selection.path, selection # Zorgt voor row update appearance
|
271
271
|
@refund.label = "Terugbetalen"
|
272
272
|
rescue Exception => e
|
@@ -287,7 +287,7 @@ module Ig3tool
|
|
287
287
|
|
288
288
|
def _refund(selected)
|
289
289
|
begin
|
290
|
-
answer = $
|
290
|
+
answer = $client.print_refund!({ :jobid => selected.jobid })
|
291
291
|
@log_list.model.row_changed selection.path, selection
|
292
292
|
@refund.label = "Toch betalen"
|
293
293
|
rescue Exception => e
|
@@ -299,7 +299,7 @@ module Ig3tool
|
|
299
299
|
@credits_list.model.model.clear
|
300
300
|
begin
|
301
301
|
# Haal alle printusers hun print-info op
|
302
|
-
answer = $
|
302
|
+
answer = $client.print_credits
|
303
303
|
answer.each { |l| @credits_list.model.model.append[0] = l }
|
304
304
|
rescue Exception => e
|
305
305
|
_print_msg "Fout: Credits: #{$!}"
|
@@ -310,7 +310,7 @@ module Ig3tool
|
|
310
310
|
@log_list.model.clear
|
311
311
|
begin
|
312
312
|
# Haal de laatste 50 Printjobs op
|
313
|
-
answer = $
|
313
|
+
answer = $client.print_log( [ 50 ] )
|
314
314
|
answer.each { |l| @log_list.model.append[0] = l }
|
315
315
|
rescue Exception => e
|
316
316
|
_print_msg "Fout: Log: #{$!}"
|
data/lib/ui/printingwindow.rb
CHANGED
@@ -12,8 +12,7 @@ module Ig3tool
|
|
12
12
|
def initialize
|
13
13
|
super("printing.glade")
|
14
14
|
|
15
|
-
|
16
|
-
@c = $global["client"]
|
15
|
+
#$client = Client.new("infogroep.be")
|
17
16
|
|
18
17
|
#bindtextdomain(domain, localedir, nil, "UTF-8")
|
19
18
|
#@glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}
|
@@ -93,7 +92,7 @@ module Ig3tool
|
|
93
92
|
_show(logentry.username)
|
94
93
|
else
|
95
94
|
begin
|
96
|
-
|
95
|
+
$client.print_refund!({"logid" => logentry["id"]})
|
97
96
|
@notification.text = "refunded print of #{logentry["amount"]} to #{logentry["username"]}"
|
98
97
|
_update_log
|
99
98
|
rescue Exception => e
|
@@ -109,7 +108,7 @@ module Ig3tool
|
|
109
108
|
_show(logentry.username)
|
110
109
|
else
|
111
110
|
begin
|
112
|
-
|
111
|
+
$client.print_refund!({"logid" => logentry["id"]})
|
113
112
|
@notification.text = "refunded print of #{logentry["amount"]} to #{logentry["username"]}"
|
114
113
|
rescue Exception => e
|
115
114
|
#puts "ERR: " + e.message.to_s
|
@@ -173,29 +172,29 @@ module Ig3tool
|
|
173
172
|
clear_all(nil, false)
|
174
173
|
else
|
175
174
|
begin
|
176
|
-
user =
|
177
|
-
person =
|
175
|
+
user = $client.print_user(@username.text)
|
176
|
+
person = $client.person_lookup({"username" => @username.text})
|
178
177
|
raise NotFound, "the ig3tool imps found no such user..." if person.nil?
|
179
178
|
person = person[0]
|
180
179
|
@email.text = person["email"]
|
181
180
|
@saldo.text = user["saldo"]
|
182
181
|
@firstname.text = person["first_name"]
|
183
182
|
@lastname.text = person["last_name"]
|
184
|
-
@status.text =
|
183
|
+
@status.text = $client.person_status(person["username"])
|
185
184
|
@notification.text = "the ig3tool imps found #{user["username"]}..."
|
186
185
|
@apply.image = Gtk::Image.new(Gtk::Stock::ADD, Gtk::IconSize::BUTTON)
|
187
186
|
@apply.label = Gtk::Stock::ADD
|
188
187
|
@delta.grab_focus
|
189
188
|
rescue Exception => e
|
190
189
|
begin
|
191
|
-
person =
|
190
|
+
person = $client.person_lookup({"username" => @username.text})
|
192
191
|
raise NotFound, "the ig3tool imps found no such user..." if person.nil? or person.empty?
|
193
192
|
person = person[0]
|
194
193
|
@email.text = person["email"]
|
195
194
|
@saldo.text = "0"
|
196
195
|
@firstname.text = person["first_name"]
|
197
196
|
@lastname.text = person["last_name"]
|
198
|
-
@status.text =
|
197
|
+
@status.text = $client.person_status(person["username"])
|
199
198
|
@notification.text = "the ig3tool imps found #{person["username"]}..."
|
200
199
|
@apply.image = Gtk::Image.new(Gtk::Stock::ADD, Gtk::IconSize::BUTTON)
|
201
200
|
@apply.label = Gtk::Stock::ADD
|
@@ -247,7 +246,7 @@ module Ig3tool
|
|
247
246
|
|
248
247
|
def smart_add(widget)
|
249
248
|
begin
|
250
|
-
|
249
|
+
$client.print_addcredit!({:username => @username.text, :amount => @delta.text})
|
251
250
|
@notification.text = "the imps added #{@delta.text} euro's to #{@username.text}'s account..."
|
252
251
|
rescue Exception => e
|
253
252
|
@notification.text = (e.class.to_s + " - " + e.message).smaller
|
@@ -268,7 +267,7 @@ module Ig3tool
|
|
268
267
|
if amount.to_f < 0
|
269
268
|
quick_message("\n the ig3tool imps do not accept negative values... \n")
|
270
269
|
else
|
271
|
-
|
270
|
+
$client.print_update!({:username => @username.text,
|
272
271
|
:first_name => @firstname.text,
|
273
272
|
:last_name => @lastname.text,
|
274
273
|
:email => @email.text,
|
@@ -295,14 +294,14 @@ module Ig3tool
|
|
295
294
|
def _show(username)
|
296
295
|
#puts "show: #{username}"
|
297
296
|
begin
|
298
|
-
user =
|
299
|
-
person =
|
297
|
+
user = $client.print_user(username)
|
298
|
+
person = $client.person_lookup({"username", username})[0]
|
300
299
|
@username.text = username
|
301
300
|
@email.text = person["email"]
|
302
301
|
@saldo.text = user["saldo"].from_c.to_s
|
303
302
|
@firstname.text = person["first_name"]
|
304
303
|
@lastname.text = person["last_name"]
|
305
|
-
@status.text =
|
304
|
+
@status.text = $client.person_status(username)
|
306
305
|
@notification.text = "the ig3tool imps found #{username}..."
|
307
306
|
@apply.image = Gtk::Image.new(Gtk::Stock::ADD, Gtk::IconSize::BUTTON)
|
308
307
|
@apply.label = Gtk::Stock::ADD
|
@@ -310,7 +309,7 @@ module Ig3tool
|
|
310
309
|
rescue Exception => e
|
311
310
|
#puts "EXC: " + e.message
|
312
311
|
begin
|
313
|
-
person =
|
312
|
+
person = $client.person_lookup({"username", @username.text})
|
314
313
|
raise NotFound, "the ig3tool imps found no such user..." if person.nil? or person.empty?
|
315
314
|
person = person[0]
|
316
315
|
@username.text = username
|
@@ -318,7 +317,7 @@ module Ig3tool
|
|
318
317
|
@saldo.text = "0"
|
319
318
|
@firstname.text = person["first_name"]
|
320
319
|
@lastname.text = person["last_name"]
|
321
|
-
@status.text =
|
320
|
+
@status.text = $client.person_status(username)
|
322
321
|
@notification.text = "the ig3tool imps found #{username}..."
|
323
322
|
@apply.image = Gtk::Image.new(Gtk::Stock::ADD, Gtk::IconSize::BUTTON)
|
324
323
|
@apply.label = Gtk::Stock::ADD
|
@@ -339,9 +338,9 @@ module Ig3tool
|
|
339
338
|
@usernames_store.clear if clear
|
340
339
|
Thread.new do
|
341
340
|
if @statussearch.active > 0
|
342
|
-
users =
|
341
|
+
users = $client.person_everybody.sort{|x,y| x["username"] <=> y["username"]}
|
343
342
|
else
|
344
|
-
users =
|
343
|
+
users = $client.print_users
|
345
344
|
end
|
346
345
|
users.each do |user|
|
347
346
|
row = @usernames_store.append
|
@@ -355,7 +354,7 @@ module Ig3tool
|
|
355
354
|
def _update_log(clear=true)
|
356
355
|
@filteredlog_store.clear if clear
|
357
356
|
Thread.new do
|
358
|
-
loglines =
|
357
|
+
loglines = $client.print_logs
|
359
358
|
loglines.each do |ll|
|
360
359
|
@filteredlog_store.append[0] = ll
|
361
360
|
end
|
@@ -365,7 +364,7 @@ module Ig3tool
|
|
365
364
|
def _update_biglog(clear=true)
|
366
365
|
@log_store.clear if clear
|
367
366
|
Thread.new do
|
368
|
-
loglines =
|
367
|
+
loglines = $client.print_logs
|
369
368
|
loglines.each do |ll|
|
370
369
|
@log_store.append[0] = ll
|
371
370
|
end
|
data/lib/ui/productswindow.rb
CHANGED
@@ -2,7 +2,7 @@ module Ig3tool
|
|
2
2
|
|
3
3
|
class ProductsWindow < GladeHelper
|
4
4
|
MENU_PATH = ["Producten", "Producten"]
|
5
|
-
ICON = "
|
5
|
+
ICON = "doos_xsmall.png"
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
super("products.glade")
|
@@ -30,13 +30,15 @@ module Ig3tool
|
|
30
30
|
s2.add_widget(@glade.get_widget(w))
|
31
31
|
end
|
32
32
|
|
33
|
-
@purchase_list = Gtk::ListStore.new(Object, String, String, Integer,
|
33
|
+
@purchase_list = Gtk::ListStore.new(Object, String, String, String, Integer, Integer)
|
34
34
|
@purchase_view.model = @purchase_list
|
35
35
|
renderer = Gtk::CellRendererText.new
|
36
36
|
renderer.xalign = 1
|
37
37
|
@purchase_view.insert_column(-1, "Datum", renderer, :text => 1)
|
38
38
|
@purchase_view.insert_column(-1, "Totaalprijs", renderer, :text => 2)
|
39
|
-
@purchase_view.insert_column(-1, "
|
39
|
+
@purchase_view.insert_column(-1, "Stukprijs", renderer, :text => 3)
|
40
|
+
@purchase_view.insert_column(-1, "Huidig", renderer, :text => 4)
|
41
|
+
@purchase_view.insert_column(-1, "Aantal", renderer, :text => 5)
|
40
42
|
|
41
43
|
renderer = Gtk::CellRendererText.new
|
42
44
|
@products = Gtk::ListStore.new(Object, String)
|
@@ -45,7 +47,7 @@ module Ig3tool
|
|
45
47
|
|
46
48
|
cat_model = Gtk::ListStore.new(String)
|
47
49
|
cat_model.prepend[0] = "Alle categorieën"
|
48
|
-
$
|
50
|
+
$client.product_categories.collect {|x| x.name}.sort.each do |cat|
|
49
51
|
r = cat_model.append
|
50
52
|
r[0] = cat
|
51
53
|
end
|
@@ -95,18 +97,21 @@ module Ig3tool
|
|
95
97
|
|
96
98
|
def add_button_clicked
|
97
99
|
return if @selected_product.nil?
|
98
|
-
amount = @new_stock.text
|
99
|
-
price = @new_price.text
|
100
|
+
amount = @new_stock.text.to_i
|
101
|
+
price = @new_price.text.to_f
|
100
102
|
|
101
|
-
args = { :debugger =>
|
102
|
-
|
103
|
+
args = { :debugger => $client.username,
|
104
|
+
:items => { @selected_product.barcode => [amount, amount * price.to_c] }
|
105
|
+
}
|
103
106
|
|
104
|
-
$
|
107
|
+
$client.product_purchase! args
|
108
|
+
p = $client.product_purchases(@selected_product.barcode).first
|
109
|
+
_add_purchase(p, false)
|
105
110
|
end
|
106
111
|
|
107
112
|
def category_combo_changed
|
108
113
|
active = @category_combo.active
|
109
|
-
products = $
|
114
|
+
products = $client.product_all
|
110
115
|
if active > 0
|
111
116
|
category = @category_combo.active_iter[0]
|
112
117
|
products = products.select {|p| p.category == category}
|
@@ -145,14 +150,21 @@ module Ig3tool
|
|
145
150
|
@purchase_list.clear
|
146
151
|
return if @selected_product.nil?
|
147
152
|
@selected_product.purchases.each do |p|
|
148
|
-
|
149
|
-
row[0] = p
|
150
|
-
row[1] = p.time.to_s
|
151
|
-
row[2] = sprintf("%.2f", p.cost.to_s)
|
152
|
-
row[3] = p.count.to_i
|
153
|
+
_add_purchase(p)
|
153
154
|
end
|
154
155
|
end
|
155
156
|
|
157
|
+
def _add_purchase(p, at_end = true)
|
158
|
+
row = at_end ? @purchase_list.append : @purchase_list.prepend
|
159
|
+
row[0] = p
|
160
|
+
row[1] = p.time.to_s
|
161
|
+
row[2] = sprintf("%.2f", p.cost.from_c)
|
162
|
+
row[3] = sprintf("%.2f", p.cost.from_c/p.count.to_i)
|
163
|
+
row[4] = p.current.to_i
|
164
|
+
row[5] = p.count.to_i
|
165
|
+
end
|
166
|
+
|
167
|
+
|
156
168
|
end
|
157
169
|
|
158
170
|
register_window(ProductsWindow)
|
data/lib/ui/saleswindow.rb
CHANGED
@@ -17,8 +17,12 @@ module Ig3tool
|
|
17
17
|
@items.insert_column(-1, "Aantal", r, :text => 0)
|
18
18
|
@items.insert_column(-1, "Product", r, :text => 1)
|
19
19
|
@items.insert_column(-1, "Prijs", r, :text => 2)
|
20
|
+
@member_id = @glade.get_widget("member_id")
|
20
21
|
|
21
22
|
@window.show
|
23
|
+
@statushash = {1 => "member", 0 => "non-member", 2 => "debugger"}
|
24
|
+
@statushashi = @statushash.invert
|
25
|
+
|
22
26
|
end
|
23
27
|
|
24
28
|
def smartzap_activate
|
@@ -30,6 +34,7 @@ module Ig3tool
|
|
30
34
|
when "non member"
|
31
35
|
@target = nil
|
32
36
|
@status = "non member"
|
37
|
+
@member_id.active = @statushashi[@status]
|
33
38
|
return
|
34
39
|
|
35
40
|
when "kaching"
|
@@ -45,13 +50,14 @@ module Ig3tool
|
|
45
50
|
# is het een debugger?
|
46
51
|
when /^[a-z]/
|
47
52
|
wanted = {"username", value, "status", "debugger"}
|
48
|
-
pers = $
|
53
|
+
pers = $client.person_lookup(wanted)
|
49
54
|
|
50
55
|
unless pers.empty?
|
51
56
|
pers = pers.first
|
52
57
|
|
53
|
-
@target = pers.username
|
54
58
|
@status = "debugger"
|
59
|
+
@member_id.active = @statushashi[@status]
|
60
|
+
@target = @debugger = pers.username
|
55
61
|
|
56
62
|
_get_widget("debugger").model.each do |m, p, i|
|
57
63
|
if i[1] == @target
|
@@ -65,17 +71,18 @@ module Ig3tool
|
|
65
71
|
|
66
72
|
# is het een member?
|
67
73
|
begin
|
68
|
-
memb = $
|
74
|
+
memb = $client.membership_lookup(value)
|
69
75
|
|
70
76
|
@target = memb.barcode
|
71
77
|
@status = "member"
|
78
|
+
@member_id.active = @statushashi[@status]
|
72
79
|
return
|
73
80
|
rescue Exception => e
|
74
81
|
end
|
75
82
|
|
76
83
|
# is het een product?
|
77
84
|
begin
|
78
|
-
prod = $
|
85
|
+
prod = $client.product_lookup(value)
|
79
86
|
qty = _get_widget("count").text.to_i
|
80
87
|
_add_product(prod, qty)
|
81
88
|
return
|
@@ -83,6 +90,10 @@ module Ig3tool
|
|
83
90
|
# het is een vliegtuig!
|
84
91
|
end
|
85
92
|
|
93
|
+
def debugger_changed
|
94
|
+
@debugger = _get_widget("debugger").active_iter[1]
|
95
|
+
end
|
96
|
+
|
86
97
|
def delete_clicked
|
87
98
|
sel = @items.selection.selected
|
88
99
|
@items.model.remove(sel) if sel
|
@@ -104,6 +115,8 @@ module Ig3tool
|
|
104
115
|
|
105
116
|
def clear_clicked
|
106
117
|
@items.model.clear
|
118
|
+
@status = "non-member"
|
119
|
+
@member_id.active = @statushashi[@status]
|
107
120
|
_update_total
|
108
121
|
end
|
109
122
|
|
@@ -127,11 +140,11 @@ module Ig3tool
|
|
127
140
|
items = _get_items
|
128
141
|
|
129
142
|
return if items.empty?
|
130
|
-
params = { "debugger" => @
|
143
|
+
params = { "debugger" => @debugger,
|
131
144
|
"items" => items }
|
132
145
|
|
133
146
|
begin
|
134
|
-
$
|
147
|
+
$client.scribble! params
|
135
148
|
clear_clicked
|
136
149
|
# XXX make sound
|
137
150
|
rescue Exception => e
|
@@ -142,12 +155,12 @@ module Ig3tool
|
|
142
155
|
def _kaching
|
143
156
|
items = _get_items
|
144
157
|
|
145
|
-
params = { "debugger" =>
|
158
|
+
params = { "debugger" => @debugger,
|
146
159
|
"items" => items,
|
147
160
|
"status" => @status }
|
148
161
|
|
149
162
|
begin
|
150
|
-
$
|
163
|
+
$client.kaching! params
|
151
164
|
clear_clicked
|
152
165
|
# XXX make sound
|
153
166
|
rescue Exception => e
|
data/lib/ui/toolwindow.rb
CHANGED
@@ -29,9 +29,11 @@ module Ig3tool
|
|
29
29
|
icon = (klass::ICON || "no.xpm")
|
30
30
|
button = create_button(name, icon.to_s)
|
31
31
|
button.signal_connect("clicked") do
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
Thread.new do
|
33
|
+
@@windows[klass] ||= klass.new
|
34
|
+
@@windows[klass].show
|
35
|
+
@@windows[klass].present
|
36
|
+
end
|
35
37
|
end
|
36
38
|
bigbox.add(button)
|
37
39
|
end
|
data/lib/utils.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
class Time
|
2
|
+
# bepaling van de week van het academiejaar
|
3
|
+
def week
|
4
|
+
t = start_werkjaar(Time.werkjaar)
|
5
|
+
return 1 + ((self - t) / (86400*7)).to_int
|
6
|
+
end
|
7
|
+
|
8
|
+
# we bepalen de start van het werkjaar (laatste ma van sept)
|
9
|
+
def self.start_werkjaar(jaar)
|
10
|
+
t = Time.mktime(jaar, 9, 30)
|
11
|
+
t = t - 86400 until t.wday == 1
|
12
|
+
t
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.werkjaar
|
16
|
+
t = Time.now()
|
17
|
+
t > start_werkjaar(t.year) ? t.year : t.year - 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Fixnum
|
22
|
+
# Convenience method
|
23
|
+
def weeks
|
24
|
+
self * 86400 * 7
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Integer
|
29
|
+
def to_b
|
30
|
+
!zero?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Array
|
35
|
+
# File facets/conversion.rb, line 38
|
36
|
+
def to_h(arrayed=nil)
|
37
|
+
h = {}
|
38
|
+
if arrayed #or (flatten.size % 2 == 1)
|
39
|
+
#each{ |e| h[e.first] = e.slice(1..-1) }
|
40
|
+
each{ |k,*v| h[k] = v }
|
41
|
+
else
|
42
|
+
h = Hash[*(self.flatten)]
|
43
|
+
end
|
44
|
+
h
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Hash
|
49
|
+
# File facets/hash/keyize.rb, line 49
|
50
|
+
def normalize_keys!( &block )
|
51
|
+
keys.each{ |k|
|
52
|
+
nk = block[k]
|
53
|
+
self[nk]=delete(k) if nk
|
54
|
+
}
|
55
|
+
self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# XXX MOVE THIS TO BETTER PLACE
|
60
|
+
|
61
|
+
def send_email(from, from_alias, to, to_alias, subject, message)
|
62
|
+
msg = %q{<<END_OF_MESSAGE
|
63
|
+
|From: #{from_alias} <#{from}>
|
64
|
+
|To: #{to_alias} <#{to}>
|
65
|
+
|Subject: #{subject}
|
66
|
+
|
67
|
+
|#{message}}
|
68
|
+
|
69
|
+
Net::SMTP.start('localhost') do |smtp|
|
70
|
+
smtp.send_message msg, from, to
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def email(from, to, subject, message)
|
75
|
+
from_alias = "#{from.first_name} #{from.last_name}"
|
76
|
+
to_alias = "#{to.first_name} #{to.last_name}"
|
77
|
+
send_email(from.email, from_alias, to.email, to_alias, subject, message)
|
78
|
+
end
|
79
|
+
|
80
|
+
module ActiveRecord
|
81
|
+
class Base
|
82
|
+
def self.hash_lookup(search, valid_keys)
|
83
|
+
search = search.to_h unless search.is_a? Hash
|
84
|
+
|
85
|
+
return find(:all) if search.empty?
|
86
|
+
|
87
|
+
clauses = []
|
88
|
+
values = []
|
89
|
+
search.normalize_keys! { |k| k.to_s.downcase }
|
90
|
+
|
91
|
+
search.each do |k, v|
|
92
|
+
raise "Invalid search key '#{k}'" unless valid_keys.include? k
|
93
|
+
if %w(barcode username).include? k or k == primary_key
|
94
|
+
clauses << "#{k} = ?"
|
95
|
+
values << v
|
96
|
+
else
|
97
|
+
clauses << "#{k} like ?"
|
98
|
+
v = "%#{v}%"
|
99
|
+
values << v
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
find(:all, :conditions => [ clauses.join(" AND "), *values ])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|