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, #load_sounds, #make_debugger_combo, #make_eval_widget, #make_status_combo, #number_eval_widget, #play, #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")


17
18
19
20
21
22
23
24
25
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
# File 'lib/ui/bibliotheekwindow.rb', line 17

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, 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, "username", ll) do |tvc, cell, m ,iter|
	cell.text = $client.person_member(iter[0].member_id).username
	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.



11
12
13
# File 'lib/ui/bibliotheekwindow.rb', line 11

def glade
  @glade
end

Instance Method Details

#books_clear(widget, all = true) ⇒ Object



268
269
270
271
# File 'lib/ui/bibliotheekwindow.rb', line 268

def books_clear(widget, all=true)
	reset_books_fields(all)
	#_update_books_list
end

#books_delete(widget) ⇒ Object



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

def books_delete(widget)
	begin
		$client.bib_remove!(@books_isbn.text.strip)
		_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



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/ui/bibliotheekwindow.rb', line 234

def books_find(widget)
	Thread.new do
		begin
			books = $client.bib_lookup(get_fields)
			puts books
			case books.size
			when 0	#book not found in db
				_lookup_isbnbook(@books_isbn.text)
			when 1
				_show(books.first)
			else
				_update_books_list(books)
			end
		rescue Exception => e
			puts e.backtrace
			@books_notification.text = e.message.smaller
		end
	end
end

#books_loan(widget) ⇒ Object



305
306
307
# File 'lib/ui/bibliotheekwindow.rb', line 305

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

#books_refresh(widget) ⇒ Object



196
197
198
# File 'lib/ui/bibliotheekwindow.rb', line 196

def books_refresh(widget)
	_update_books_list
end

#books_save(widget) ⇒ Object



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

def books_save(widget)
	begin
		$client.bib_add!(get_fields(false))
		_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_fields(ignore_empty = true) ⇒ Object



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

def get_fields(ignore_empty = true)
	fields = {}
	@books_fields.each do |k, f|
		temp = f.text.strip
		fields[k] = temp unless temp.empty? and ignore_empty
	end
	fields["section"] = @books_section.active_iter[0].name unless @books_section.active_iter[0].nil?
	fields
end

#get_loan_fieldsObject



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

def 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



165
166
# File 'lib/ui/bibliotheekwindow.rb', line 165

def hl_loan(a)
end

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



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

def isbn_del(a,b,c,d)
	reset_books_fields(false)
end

#isbn_ins(a, b, c) ⇒ Object



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

def isbn_ins(a,b,c)
	reset_books_fields(false)
end

#loan_clear(widget, all = true) ⇒ Object



274
275
276
277
278
279
280
281
# File 'lib/ui/bibliotheekwindow.rb', line 274

def loan_clear(widget, all=true)
	@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



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

def loan_extend(widget)
	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



217
218
219
# File 'lib/ui/bibliotheekwindow.rb', line 217

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

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



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

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

#loan_isbn_set(widget) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/ui/bibliotheekwindow.rb', line 221

def loan_isbn_set(widget)
	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



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/ui/bibliotheekwindow.rb', line 283

def loan_loan(widget)
	@loan_notification.text = ""
	begin
		fields = get_loan_fields
		if fields["member"] =~ /[a-zA-Z]+/
			puts "username ipv barcode: #{fields["member"]}"
			membership = $client.person_membership(fields["member"])
			if membership.nil?
				raise IG3Error, "#{fields["member"]} is not a member..."
			else
				fields["member"] = membership.barcode
			end
		end
		$client.bib_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



192
193
194
# File 'lib/ui/bibliotheekwindow.rb', line 192

def loan_refresh(widget)
	_update_loan_list
end

#loan_return(widget) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/ui/bibliotheekwindow.rb', line 168

def loan_return(widget)
	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



254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/ui/bibliotheekwindow.rb', line 254

def reset_books_fields(all=true)
	@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



98
99
100
101
# File 'lib/ui/bibliotheekwindow.rb', line 98

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

#select_loan(widget, path, column) ⇒ Object



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

def select_loan(widget, path, column)
	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



112
113
114
115
116
117
118
119
120
121
# File 'lib/ui/bibliotheekwindow.rb', line 112

def 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



200
201
202
203
204
205
206
# File 'lib/ui/bibliotheekwindow.rb', line 200

def tabfocus(widget, arg0, arg1)
	if arg1 == 1
		_update_loan_list
	else
		_update_books_list
	end
end