Merge: doc: fixed some typos and other misc. corrections
[nit.git] / contrib / benitlux / src / client / features / manual_checkins.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Variation adding a button to manually check in and out
16 module manual_checkins
17
18 import checkins
19
20 redef class HomeWindow
21
22 redef fun refresh
23 do
24 super
25 update_checkin_text
26 end
27
28 private var checkin_button = new Button(parent=layout_user, align=0.0)
29
30 redef fun on_event(event)
31 do
32 super
33
34 if event isa ButtonPressEvent then
35 var sender = event.sender
36 if sender == checkin_button then
37 if app.currently_on_location then
38 app.on_check_out
39 else app.on_check_in
40 end
41 end
42 end
43
44 private fun update_checkin_text
45 do
46 if app.user != null then
47 if app.currently_on_location then
48 checkin_button.text = "Leaving? Check out".t
49 else
50 checkin_button.text = "On location? Check in".t
51 end
52 checkin_button.enabled = true
53 else
54 checkin_button.text = "Login to check in".t
55 checkin_button.enabled = false
56 end
57 end
58 end
59
60 redef class App
61 redef fun on_check_in
62 do
63 super
64 var window = window
65 if window isa HomeWindow then window.update_checkin_text
66 end
67
68 redef fun on_check_out
69 do
70 super
71 var window = window
72 if window isa HomeWindow then window.update_checkin_text
73 end
74 end