Class: Ig3tool::PrintenWindow
- Inherits:
-
GladeHelper
- Object
- GladeHelper
- Ig3tool::PrintenWindow
- Defined in:
- lib/ui/printenwindow.rb
Defined Under Namespace
Classes: PrintUndo
Constant Summary collapse
- MENU_PATH =
["Printer", "Printen"]
- ICON =
"stock_print.png"
Constants inherited from GladeHelper
Instance Method Summary collapse
- #activate_user ⇒ Object
- #delta_focus_out ⇒ Object
- #errors_changed ⇒ Object
- #focus_changed ⇒ Object
-
#initialize ⇒ PrintenWindow
constructor
A new instance of PrintenWindow.
- #is_user_visible(username) ⇒ Object
- #list_row_activated(view, path, column) ⇒ Object
- #log_list_cursor_changed(view) ⇒ Object
- #log_list_row_activated(view, path, column) ⇒ Object
-
#refresh_clicked ⇒ Object
PrintLog.
- #refund_clicked ⇒ Object
- #show_user(username = nil) ⇒ Object
- #toepassen_activate_cb ⇒ Object
- #undo_activate_cb ⇒ Object
Methods inherited from GladeHelper
#_get_widget, #add_window_colorer, #make_debugger_combo, #make_eval_widget, #make_status_combo, #present, #show
Constructor Details
#initialize ⇒ PrintenWindow
Returns a new instance of PrintenWindow.
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 |
# File 'lib/ui/printenwindow.rb', line 35 def initialize () super("printen.glade") @notification = @glade.("notification") # PrintKrediet @credits_list = @glade.("credits_list") @user_entry = @glade.("user") @refund = @glade.("refund") # Username(PRIMARY), Email, Saldo, People_id model = Gtk::ListStore.new(String) renderer = Gtk::CellRendererText.new @credits_list.insert_column(-1, "Gebruiker", renderer) { |tvc, cell, m, iter| cell.text = iter[0].user } @credits_list.insert_column(-1, "Saldo", renderer) { |tvc, cell, m, iter| cell.text = sprintf("%.2f", iter[0].saldo) } @credits_list.insert_column(-1, "Categorie", renderer) { |tvc, cell, m, iter| cell.text = iter[0].price_category } @credits_list.insert_column(-1, "Email", renderer) { |tvc, cell, m, iter| cell.text = iter[0].email } filteredmodel = Gtk::TreeModelFilter.new(model) filteredmodel.set_visible_func do |model, iter| is_user_visible(iter[0].user) end @credits_list.model = filteredmodel _show_credits @window.show_all # PrintLog @log_refund = @glade.("log_refund") @log_list = @glade.("log_list") # TODO - ADD JOBID IN DE LIJST VOOR REFUND! @log_list.model = Gtk::ListStore.new(String, String, String, String, String, String) # Meerdere selecteerbaar -> Grote refund indien nodig ;) @log_list.selection.mode = Gtk::SELECTION_MULTIPLE log_renderer = Gtk::CellRendererText.new log_renderer2 = Gtk::CellRendererText.new @log_list.insert_column(-1, "Uur", log_renderer) do |tvc, cell, m, iter| cell.text = iter[0].time.strftime('%a %H:%M') end @log_list.insert_column(-1, "User", log_renderer) do |tvc, cell, m, iter| cell.text = iter[0].user end @log_list.insert_column(-1, "Boodschap", log_renderer2) do |tvc, cell, m, iter| cell.text = iter[0]. cell.strikethrough = iter[0].refunded end _show_log @window.show_all @undo = PrintUndo.new end |
Instance Method Details
#activate_user ⇒ Object
127 128 129 |
# File 'lib/ui/printenwindow.rb', line 127 def activate_user show_user @glade.("user").text end |
#delta_focus_out ⇒ Object
144 145 146 147 |
# File 'lib/ui/printenwindow.rb', line 144 def delta_focus_out Ig3tool::(@glade.("delta")) false end |
#errors_changed ⇒ Object
136 137 138 |
# File 'lib/ui/printenwindow.rb', line 136 def errors_changed @credits_list.model.refilter end |
#focus_changed ⇒ Object
131 132 133 134 |
# File 'lib/ui/printenwindow.rb', line 131 def focus_changed @notification.text = "" if @notification false end |
#is_user_visible(username) ⇒ Object
99 100 101 |
# File 'lib/ui/printenwindow.rb', line 99 def is_user_visible(username) username.include?(@user_entry.text) if @matcher.nil? end |
#list_row_activated(view, path, column) ⇒ Object
140 141 142 |
# File 'lib/ui/printenwindow.rb', line 140 def list_row_activated (view, path, column) show_user @credits_list.model.model.get_iter(path)[0].user end |
#log_list_cursor_changed(view) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/ui/printenwindow.rb', line 232 def log_list_cursor_changed (view) if selected = view.selection.selected printlog = selected[0] if @refund.sensitive = (printlog. =~ /printed/) if !printlog.refunded @refund.label = "Terugbetalen" else @refund.label = "Toch betalen" end end end end |
#log_list_row_activated(view, path, column) ⇒ Object
249 250 251 252 |
# File 'lib/ui/printenwindow.rb', line 249 def log_list_row_activated (view, path, column) printlog = @log_list.model.get_iter(path)[0] show_user(printlog.user) end |
#refresh_clicked ⇒ Object
PrintLog
227 228 229 230 |
# File 'lib/ui/printenwindow.rb', line 227 def refresh_clicked _show_credits _show_log end |
#refund_clicked ⇒ Object
245 246 247 |
# File 'lib/ui/printenwindow.rb', line 245 def refund_clicked _refund_selection(@log_list.selection.select_all) end |
#show_user(username = nil) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ui/printenwindow.rb', line 103 def show_user (username = nil) return if username.nil? or username.empty? begin user = $client.print_userinfo([ username ]) @glade.('user').text = username # Kan username of alias zijn waarop men zoekt if user.nil? @glade.('saldo').text = '0' @glade.('email').text = "#{username}@vub.ac.be" # Klaarzetten om toe te voegen @glade.('status').active = 0 @glade.('delta').grab_focus else @glade.('saldo').text = sprintf '%.2f', user.saldo @glade.('email').text = user.email @glade.('status').active = user.debugger? ? 1 : 0 @glade.('delta').grab_focus end rescue Exception => e _print_msg "Fout: Userinfo: #{$!}" end end |
#toepassen_activate_cb ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/ui/printenwindow.rb', line 204 def toepassen_activate_cb delta = @glade.("delta") Ig3tool::(delta) amount = delta.text.to_i username = @glade.('user').text email = @glade.('email').text unless amount == 0 begin # Indien de gebruiker nog niet bestaat, creeer automatisch een account wanneer er # op 'toevoegen krediet' wordt geklikt if !$client.print_userinfo([ username ]) $client.print_addaccount!({ :username => username, :email => email }) end answer = $client.print_addcredit!({ :username => username, :amount => amount }) _print_msg "#{@user_entry.text} Gets #{amount} Credits" rescue Exception => e _print_msg "Fout: Toepassen: #{$!}" end end end |
#undo_activate_cb ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ui/printenwindow.rb', line 149 def undo_activate_cb # @Undo.method toont de LAATST GEBRUIKTE ACTIE aan case @undo.method when :adduser @undo.method = :none begin answer = $client.print_delaccount!({ :username => @undo.username }) @undo.method = :deluser rescue Exception => e _print_msg "Fout: Undo: #{$!}" else _print_msg "Print Account #{@undo.username} werd verwijderd" end when :deluser @undo.method = :none begin answer = $client.print_addaccount!({ :username => @undo.username, :email => @undo.email, :amount => @undo.amount }) @undo.method = :adduser rescue Exception => e _print_msg "Fout: Undo: #{$!}" else _print_msg "Print Account #{@undo.username} heraangemaakt met #{@undo.amount} krediet(en)!" end when :addcredit @undo.method = :none begin answer = $client.print_addcredit!({ :username => @undo.username, :email => @undo.email, :amount => - @undo.amount }) @undo.method = :addcredit @undo.amount = - @undo.amount rescue Exception => e _print_msg "Fout: Undo: #{$!}" else _print_msg "Print Account #{@undo.username} werd veranderd met #{@undo.amount} krediet(en)" end when :refund @undo.method = :none begin _unrefund @undo.selection rescue Exception => e _print_msg "Fout: Undo: #{$!}" else _print_msg "Het terugbetalen van de Print Job (#{@undo.jobid}) van #{@undo.username} werd ongedaan gemaakt (#{@undo.amount} krediet(en))" end when :unrefund @undo.method = :none begin _refund @undo.selection rescue Exception => e _print_msg "Fout: Undo: #{$!}" else _print_msg "Het terugbetalen van de Print Job (#{@undo.jobid}) van #{@undo.username} werd uitgevoerd (#{@undo.amount} krediet(en))" end end end |