1 // widget_keypad.ysl2 |
1 // widget_keypad.ysl2 |
2 |
2 |
3 template "widget[@type='Keypad']", mode="widget_defs" { |
3 template "widget[@type='Keypad']", mode="widget_defs" { |
|
4 param "hmi_element"; |
|
5 labels("Esc Enter BackSpace Keys Info Value"); |
|
6 optional_labels("Sign CapsLock Shift Space"); |
4 | init: function() { |
7 | init: function() { |
|
8 foreach "$hmi_element/*[@inkscape:label = 'Keys']/*" { |
|
9 | id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_key_click('«func:escape_quotes(@inkscape:label)»')"); |
|
10 } |
|
11 foreach "str:split('Esc Enter BackSpace Sign Space CapsLock Shift')" { |
|
12 | if(this.«.»_elt) |
|
13 | this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()"); |
|
14 } |
|
15 | }, |
|
16 | on_key_click: function(symbols) { |
|
17 | var syms = symbols.split(" "); |
|
18 | this.shift = this.caps; |
|
19 | this.editstr += syms[this.shift?syms.length:0]; |
|
20 | this.shift = false; |
|
21 | this.update(); |
|
22 | console.log(symbols); |
|
23 | }, |
|
24 | on_Esc_click: function() { |
|
25 | end_modal.call(this); |
|
26 | console.log("Esc"); |
|
27 | }, |
|
28 | on_Enter_click: function() { |
|
29 | end_modal.call(this); |
|
30 | callback_obj = this.result_callback_obj; |
|
31 | callback_obj.edit_callback(this.editstr); |
|
32 | console.log("Enter"); |
|
33 | }, |
|
34 | on_BackSpace_click: function() { |
|
35 | this.editstr = this.editstr.slice(0,this.editstr.length-1); |
|
36 | this.update(); |
|
37 | console.log("BackSpace"); |
|
38 | }, |
|
39 | on_Sign_click: function() { |
|
40 | if(this.editstr[0] == "-") |
|
41 | this.editstr = this.editstr.slice(1,this.editstr.length); |
|
42 | else |
|
43 | this.editstr = "-" + this.editstr; |
|
44 | console.log("Sign"); |
|
45 | }, |
|
46 | on_Space_click: function() { |
|
47 | this.editstr += " "; |
|
48 | console.log("Space"); |
|
49 | }, |
|
50 | caps: false, |
|
51 | on_CapsLock_click: function() { |
|
52 | this.caps = !this.caps; |
|
53 | console.log("CapsLock"); |
|
54 | }, |
|
55 | shift: false, |
|
56 | on_Shift_click: function() { |
|
57 | this.shift = true; |
|
58 | console.log("Shift"); |
|
59 | }, |
|
60 const "g", "$geometry[@Id = $hmi_element/@id]"; |
|
61 | coordinates: [«$g/@x», «$g/@y»], |
|
62 | editstr: "", |
|
63 | result_callback_obj: undefined, |
|
64 | start_edit: function(info, valuetype, callback_obj, initial) { |
|
65 | show_modal.call(this); |
|
66 | this.editstr = initial; |
|
67 | this.result_callback_obj = callback_obj; |
|
68 | this.Info_elt.textContent = info; |
|
69 | this.shift = false; |
|
70 | this.caps = false; |
|
71 | this.update(); |
|
72 | }, |
|
73 | update: function() { |
|
74 | /* TODO Swith shift and capslock active/inactive elements */ |
|
75 | this.Value_elt.textContent = this.editstr; |
5 | }, |
76 | }, |
6 } |
77 } |