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