Class: Ig3tool::BibliotheekWindow

Inherits:
GladeHelper show all
Includes:
GetText
Defined in:
lib/ui/bibliotheekwindow.rb

Constant Summary collapse

["Bibliotheek", "Bibliotheek"]
ICON =
"stock_book_xklein.png"

Constants inherited from GladeHelper

GladeHelper::GLADE_DIR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GladeHelper

#_get_widget, #add_window_colorer, #make_debugger_combo, #make_eval_widget, #make_status_combo, #present, #show

Constructor Details

#initializeBibliotheekWindow

def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)

bindtextdomain(domain, localedir, nil, "UTF-8")


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ui/bibliotheekwindow.rb', line 26

def initialize

	super("bibliotheek.glade")

	# $client = Client.new("infogroep.be")

	@tabs = @glade.get_widget("tabs")

	@books_isbn      = @glade.get_widget("books_isbn")
	@books_title     = @glade.get_widget("books_title")
	@books_author    = @glade.get_widget("books_author")
	@books_publisher = @glade.get_widget("books_publisher")
	@books_year      = @glade.get_widget("books_year")
	@books_section   = @glade.get_widget("books_section")
	@books_copies    = @glade.get_widget("books_copies")

	@books_fields = {
	"isbn" => @books_isbn, 
	"title" => @books_title, 
	"author" => @books_author, 
	"publisher" => @books_publisher, 
	"year" => @books_year, 
	"copies" => @books_copies
	}


	@books_notification    = @glade.get_widget("books_notification")

	@loan_memberid   = @glade.get_widget("loan_memberid")
	@loan_isbn       = @glade.get_widget("loan_isbn")
	@loan_title       = @glade.get_widget("loan_title")
	@loan_warranty   = @glade.get_widget("loan_warranty")
	@loan_notification    = @glade.get_widget("loan_notification")

	@loan_fields = {
	"isbn" => @loan_isbn,
	"warranty" => @loan_warranty,
	"member" => @loan_memberid
	}

	@books_list   = @glade.get_widget("books_list")
	@loan_list    = @glade.get_widget("loan_list")
	@loan_list.model = @loan_list_store = Gtk::ListStore.new(Object, String, String, String, String, String)
	ll = Gtk::CellRendererText.new
	@loan_list.insert_column(-1, "loan date", ll) do |tvc, cell, m ,iter|
	cell.text = Time.parse(iter[0].loan_date).strftime("%d/%m/%y")
	end
	@loan_list.insert_column(-1, "return on", ll) do |tvc, cell, m ,iter|
	date = Time.parse(iter[0].return_date)
	ll.foreground = "red" if date > Time.now
	cell.text = date.strftime("%d/%m/%y")
	ll.foreground = "black"
	end
	@loan_list.insert_column(-1, "memberid", ll) do |tvc, cell, m ,iter|
	cell.text = iter[0].member_id
	end
	@loan_list.insert_column(-1, "isbn", ll) do |tvc, cell, m ,iter|
	cell.text = iter[0].isbn
	end
	@loan_list.insert_column(-1, "warranty", ll) do |tvc, cell, m ,iter|
	cell.text = iter[0].warranty
	end

	@books_list = @glade.get_widget("books_list")
	@books_list.model = @books_list_store = Gtk::ListStore.new(Object, String)
	bl = Gtk::CellRendererText.new
	@books_list.insert_column(-1, "title", bl) do |tvc, cell, m ,iter|
	cell.text = (iter[0].title.smaller(50) + " (#{iter[0].author})").smaller(62)
	end


	_update_sections
	_update_books_list
	_update_loan_list


end

Instance Attribute Details

#gladeObject (readonly)

Returns the value of attribute glade.



20
21
22
# File 'lib/ui/bibliotheekwindow.rb', line 20

def glade
  @glade
end

Instance Method Details

#books_clear(widget, all = true) ⇒ Object



293
294
295
296
297
# File 'lib/ui/bibliotheekwindow.rb', line 293

def books_clear(widget, all=true)
	puts "-> books_clear"
	reset_books_fields(all)
	#_update_books_list
end

#books_delete(widget) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/ui/bibliotheekwindow.rb', line 194

def books_delete(widget)
	puts "-> books_delete"
	begin
		$client.bib_remove!(get_fields)
		_update_books_list
		reset_books_fields
		@books_notification.text = "the ig3tool imps trashed the book..."
	rescue Exception => e
		puts e.backtrace
		@loan_notification.text = e.message.smaller
	end
end

#books_find(widget) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/ui/bibliotheekwindow.rb', line 257

def books_find(widget)
	puts "-> books_find"
	puts "start find"
	Thread.new do
		begin
			books = $client.bib_lookup(get_fields)
			if books.size == 1
				puts "find 1"
				_show(books.first)
			else
				puts "find 2"
				_update_books_list(books)
			end
		rescue Exception => e
			puts e.backtrace
			@books_notification.text = e.message.smaller
		end
	end
	puts "end find"
end

#books_loan(widget) ⇒ Object



323
324
325
# File 'lib/ui/bibliotheekwindow.rb', line 323

def books_loan(widget)
	@tabs.page = 1
end

#books_refresh(widget) ⇒ Object



212
213
214
215
# File 'lib/ui/bibliotheekwindow.rb', line 212

def books_refresh(widget)
	puts "-> books_refresh"
	_update_books_list
end

#books_save(widget) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/ui/bibliotheekwindow.rb', line 151

def books_save(widget)
	puts "-> books_save"
	begin
		$client.bib_add!(get_fields)
		_update_books_list
		#books_clear
		@books_notification.text = "changes saved to book!"
	rescue Exception => e
		puts e.backtrace
		@books_notification.text = e.message.smaller
	end

end

#get_fieldsObject



132
133
134
135
136
137
138
139
140
# File 'lib/ui/bibliotheekwindow.rb', line 132

def get_fields
	puts "-> get_fields"
	fields = {}
	@books_fields.each do |k, f|
		fields[k] = f.text unless f.text.strip.empty?
	end
	fields["section"] = @books_section.active_iter[0].name unless @books_section.active_iter[0].nil?
	fields
end

#get_loan_fieldsObject



142
143
144
145
146
147
148
149
# File 'lib/ui/bibliotheekwindow.rb', line 142

def get_loan_fields
	puts "-> get_loan_fields"
	fields = {}
	@loan_fields.each do |k, f|
		fields[k] = f.text unless f.text.strip.empty?
	end
	fields
end

#hl_loan(a) ⇒ Object



177
178
179
# File 'lib/ui/bibliotheekwindow.rb', line 177

def hl_loan(a)
	puts "hl_loan: NYI"
end

#isbn_del(a, b, c, d) ⇒ Object



230
231
232
233
# File 'lib/ui/bibliotheekwindow.rb', line 230

def isbn_del(a,b,c,d)
	puts "-> isbn_del"
	reset_books_fields(false)
end

#isbn_ins(a, b, c) ⇒ Object



226
227
228
229
# File 'lib/ui/bibliotheekwindow.rb', line 226

def isbn_ins(a,b,c)
	puts "-> isbn_ins"
	reset_books_fields(false)
end

#loan_clear(widget, all = true) ⇒ Object



300
301
302
303
304
305
306
307
308
# File 'lib/ui/bibliotheekwindow.rb', line 300

def loan_clear(widget, all=true)
	puts "-> loan_clear"
	@loan_isbn.text = ""
	@loan_memberid.text = ""
	@loan_warranty.text = "5"
	@loan_notification.text = "" if all
	@loan_title.text = ""
	reset_books_fields
end

#loan_extend(widget) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/ui/bibliotheekwindow.rb', line 164

def loan_extend(widget)
	puts "-> loan_extend"
	begin
		$client.bib_extend!(get_loan_fields)
		_update_loan_list
		loan_clear(nil)
		@loan_notification.text = "the ig3tool imps extend the book for 3 weeks..."
	rescue Exception => e
		puts e.backtrace
		@loan_notification.text = e.message.smaller
	end
end

#loan_isbn_del(a, b, c) ⇒ Object



238
239
240
241
# File 'lib/ui/bibliotheekwindow.rb', line 238

def loan_isbn_del(a,b,c)
	puts "-> loan_isbn_del"
	@loan_title.text = ""
end

#loan_isbn_ins(a, b, c, d) ⇒ Object



234
235
236
237
# File 'lib/ui/bibliotheekwindow.rb', line 234

def loan_isbn_ins(a,b,c,d)
	puts "-> loan_isbn_ins"
	@loan_title.text = ""
end

#loan_isbn_set(widget) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/ui/bibliotheekwindow.rb', line 243

def loan_isbn_set(widget)
	puts "-> loan_isbn_set"
	begin
		book = $client.bib_info(@loan_isbn.text)
		raise Exception, "the ig3tool imps found no such book..." if book.nil?
		_show(book)
		#@loan_title.text = book.title
	rescue Exception => e
		puts e.backtrace
		@loan_notification.text = e.message.smaller
	end
end

#loan_loan(widget) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/ui/bibliotheekwindow.rb', line 310

def loan_loan(widget)
	puts "-> loan_loan"
	@loan_notification.text = ""
	begin
		$client.bib_loan!(get_loan_fields)
		_update_loan_list
		loan_clear(nil)
	rescue Exception => e
		puts e.backtrace
		@loan_notification.text = e.message.smaller(65)
	end
end

#loan_refresh(widget) ⇒ Object



207
208
209
210
# File 'lib/ui/bibliotheekwindow.rb', line 207

def loan_refresh(widget)
	puts "-> loan_refresh"
	_update_loan_list
end

#loan_return(widget) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/ui/bibliotheekwindow.rb', line 181

def loan_return(widget)
	puts "-> loan_return"
	begin
		$client.bib_return!(get_loan_fields)
		_update_loan_list
		loan_clear(nil)
		@loan_notification.text = "book returned to the ig3tool imps..."
	rescue Exception => e
		puts e.backtrace
		@loan_notification.text = e.message.smaller
	end
end

#reset_books_fields(all = true) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/ui/bibliotheekwindow.rb', line 278

def reset_books_fields(all=true)
	puts "-> reset_books_fields"
	@books_isbn.text = "" if all
	@loan_isbn.text = ""
	@books_title.text = ""
	@loan_title.text = ""
	@loan_memberid.text = ""
	@books_author.text = ""
	@books_publisher.text = ""
	@books_year.text = ""
	@books_copies.text = ""
	@books_section.active = 0
	@books_notification.text = ""
end

#select_book(widget, path, column) ⇒ Object



104
105
106
107
108
# File 'lib/ui/bibliotheekwindow.rb', line 104

def select_book(widget, path, column)
	puts "-> select_book"
	iter = widget.model.get_iter(path)
	_show iter[0]
end

#select_loan(widget, path, column) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/ui/bibliotheekwindow.rb', line 110

def select_loan(widget, path, column)
	puts "-> select_loan"
	iter = widget.model.get_iter(path)
	@loan_isbn.text = iter[0].isbn
	loan_isbn_set(nil)
	@loan_memberid.text = iter[0].member_id
	@loan_warranty.text = iter[0].warranty
end

#select_sectionObject



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/ui/bibliotheekwindow.rb', line 120

def select_section()
	puts "-> select_section"
	#Thread.new do
	#  if @books_section.active_iter[0].nil?
	#    books = nil
	#  else
	#    books = $client.bib_lookup({"section" => @books_section.active_iter[0].name})
	#  end
	#  _update_books_list(books)
	#end
end

#tabfocus(widget, arg0, arg1) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/ui/bibliotheekwindow.rb', line 217

def tabfocus(widget, arg0, arg1)
	puts "-> tabfocus"
	if arg1 == 1
		_update_loan_list
	else
		_update_books_list
	end
end