Class: Ig3tool::PeopleWindow

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

Constant Summary collapse

["Leden"]
ICON =
"members_xklein.png"
FIELDS =
%w(firstname lastname email username rolnummer phone mobile)
ALLFIELDS =
%w(firstname lastname email username rolnummer phone mobile address1 address2 barcode)

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, #speak

Constructor Details

#initializePeopleWindow

Returns a new instance of PeopleWindow.



16
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
# File 'lib/ui/peoplewindow.rb', line 16

def initialize
  super("people.glade")

  @username = @glade.get_widget("username")
  @firstname = @glade.get_widget("firstname")
  @lastname = @glade.get_widget("lastname")
  @barcode = @glade.get_widget("barcode")
  @email = @glade.get_widget("email")
  @notification = @glade.get_widget("notification")
  @status = @glade.get_widget("status")
  @mobile = @glade.get_widget("mobile")
  @address1 = @glade.get_widget("address1")
  @address2 = @glade.get_widget("address2")
  @phone = @glade.get_widget("phone")
  @rolnummer = @glade.get_widget("rolnummer")

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

  @people_view = _@glade.get_widget("names")
  @people_view.model = @people_store = Gtk::ListStore.new(Object, String)
  r = Gtk::CellRendererText.new
  @people_view.insert_column(-1, "name", r, :text => 1)
  @people_view.enable_search = true


  @history    = @glade.get_widget("history")
  @history.model = @history_store = Gtk::ListStore.new(Object, String, String, String, String)
  ll = Gtk::CellRendererText.new
  @history.insert_column(-1, "year", ll) do |tvc, cell, m ,iter|
  cell.text = iter[0].year
  end
  @history.insert_column(-1, "username", ll) do |tvc, cell, m ,iter|
  cell.text = iter[0].username
  end
  @history.insert_column(-1, "status", ll) do |tvc, cell, m ,iter|
  cell.text = iter[0].status
  end
  @history.insert_column(-1, "barcode", ll) do |tvc, cell, m ,iter|
  cell.text = iter[0].barcode
  end



  @statussearch.active = 0

  @statushash = {"non-member" => 0,
"member" => 1,
"debugger" => 2,
"honorary member" => 3,
  "ex-debugger" => 4}
  @statushashi = @statushash.invert

end

Instance Attribute Details

#gladeObject (readonly)

Returns the value of attribute glade.



14
15
16
# File 'lib/ui/peoplewindow.rb', line 14

def glade
  @glade
end

Instance Method Details

#clear(widget) ⇒ Object



108
109
110
111
112
113
# File 'lib/ui/peoplewindow.rb', line 108

def clear(widget)
  @statussearch.active = 0 if @statussearch.active == -1
  #@statussearch.active = 0
  # met of zonder if?
  clear_all(nil)
end

#clear_all(widget, clearnotification = true) ⇒ Object



209
210
211
212
213
# File 'lib/ui/peoplewindow.rb', line 209

def clear_all(widget, clearnotification=true)
  @username.text = ""
  clear_most(widget,clearnotification)
  @people_view.grab_focus
end

#clear_most(widget, clearnotification = true) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/ui/peoplewindow.rb', line 215

def clear_most(widget, clearnotification=true)
  @email.text = ""
  @firstname.text = ""
  @lastname.text = ""
  @barcode.text = ""
  @phone.text = ""
  @rolnummer.text = ""
  @mobile.text = ""
  @address1.text = ""
  @address2.text = ""
  @notification.text = "" if clearnotification
  #@statussearch.active = 0
  @status.active = -1
  @history_store.clear
end

#delete(widget) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/ui/peoplewindow.rb', line 70

def delete(widget)
  username = @username.text.strip
			begin
raise Needed, "please fill in a username..." if username.empty?
			$client.person_remove!("username" => username)
    @notification.text = "the imps killed username, they left no traces..."
			rescue Exception => e
    @notification.text = e.message
			end
end

#find(widget) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ui/peoplewindow.rb', line 175

def find(widget)
  attrs = {}

  FIELDS.each do |k|
    #v = _get_widget(k).text.strip
    v = @glade.get_widget(k).text.strip
    fld = fix(k)
    attrs[fld] = v unless v.nil? or v.empty?
  end

  begin
    people = $client.person_lookup(attrs)
    _show(people[0]) if people.size == 1
    _update_names(people)
  rescue Exception => e
    @notification.text =  "Error: Lookup: #{e.message}"
  end

end

#find_by_barcode(widget) ⇒ Object



98
99
100
101
102
103
104
105
106
107
# File 'lib/ui/peoplewindow.rb', line 98

def find_by_barcode(widget)
  begin
    barc = @barcode.text
    p = $client.person_member(barc)
    clear_all(nil)
    _show(p)
  rescue Exception => e
    @notification.text = "no user with barcode #{barc} found..."
  end
end

#fix(field) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/ui/peoplewindow.rb', line 160

def fix(field)
  case field
  when "firstname"
  "first_name"
  when "lastname"
  "last_name"
  when "rolnummer"
  "rolnr"
  when "mobile"
  "gsm"
  else
    field
  end
end

#log_row_activated(widget, arg0, arg1) ⇒ Object



118
119
120
# File 'lib/ui/peoplewindow.rb', line 118

def log_row_activated(widget, arg0, arg1)
  clear_most(nil)
end

#notification_focus_in_event_cb(widget, arg0) ⇒ Object



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

def notification_focus_in_event_cb(widget, arg0)
  puts "notification_focus_in_event_cb() is not implemented yet."
end

#refresh(widget) ⇒ Object



114
115
116
117
# File 'lib/ui/peoplewindow.rb', line 114

def refresh(widget)
  puts "refresh!"
  _update_names(nil) unless @statussearch.active == -1
end

#refreshhist(widget) ⇒ Object



80
81
82
# File 'lib/ui/peoplewindow.rb', line 80

def refreshhist(widget)
  puts "refreshhist() is not implemented yet."
end

#save(widget) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/ui/peoplewindow.rb', line 128

def save(widget)
  attrs = {}

  ALLFIELDS.each do |k|
    #v = _get_widget(k).text.strip
    v = @glade.get_widget(k).text.strip
    fld = fix(k)
    attrs[fld] = v unless v.nil? or v.empty?
  end
  if attrs["address1"] and attrs["address2"]
    attrs["address"] = attrs["address1"] + ", " + attrs["address2"]
  elsif attrs["address1"]
    attrs["address"] = attrs["address1"]
  elsif attrs["address2"]
    attrs["address"] = attrs["address2"]
  end
  attrs.delete "address1"
  attrs.delete "address2"

  attrs["status"] = @statushashi[@status.active]

  begin
    $client.person_save!(attrs)
    @notification.text =  "Person succesfully saved, clearing the form..."
    sleep 2
    clear_all(nil)
    _update_names
  rescue Exception => e
    @notification.text =  "Error: Save: #{e.message}"
  end
end

#select(widget, path, column) ⇒ Object



202
203
204
205
206
207
# File 'lib/ui/peoplewindow.rb', line 202

def select (widget, path, column)
  iter = widget.model.get_iter(path)
  clear_all(nil)
  u = $client.person_lookup("username", iter[0].username.to_s)[0]
  _show(u)
end

#smart_search(widget) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ui/peoplewindow.rb', line 83

def smart_search(widget)
  username = @username.text
  if username.strip.empty?
    @notification.text = "please fill in a username..."
  else

    p = $client.person_lookup("username", username)[0]
    if p.nil?
      @notification.text = "no user with username #{username} found..."
    else
      clear_all(nil)
      _show(p)
    end
  end
end

#tabfocus(widget, arg0, arg1) ⇒ Object



124
125
126
# File 'lib/ui/peoplewindow.rb', line 124

def tabfocus(widget, arg0, arg1)
  puts "tabfocus() is not implemented yet."
end

#username_del(widget, arg0, arg1) ⇒ Object



121
122
123
# File 'lib/ui/peoplewindow.rb', line 121

def username_del(widget, arg0, arg1)
  clear_most(nil)
end

#username_ins(widget, arg0, arg1, arg2) ⇒ Object



199
200
201
# File 'lib/ui/peoplewindow.rb', line 199

def username_ins(widget, arg0, arg1, arg2)
  puts "username_ins() is not implemented yet."
end