svghmi/widget_keypad.ysl2
author Edouard Tisserant
Thu, 27 Aug 2020 09:59:35 +0200
branchsvghmi
changeset 3042 ed43facc7137
parent 3033 52f6548982d4
child 3047 c113904f0e62
permissions -rw-r--r--
SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
2908
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
     1
// widget_keypad.ysl2
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
     2
2943
304e88bae115 SVGHMI: added more meaningful namespaces to emit javascript code from.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2941
diff changeset
     3
emit "declarations:keypad" {
2941
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     4
    |
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     5
    | var keypads = {
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     6
    foreach "$keypads_descs"{
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     7
        const "keypad_id","@id";
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     8
        foreach "arg"{
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
     9
            const "g", "$geometry[@Id = $keypad_id]";
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    10
    |     "«@value»":["«$keypad_id»", «$g/@x», «$g/@y»],
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    11
        }
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    12
    }
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    13
    | }
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    14
}
ef13a4007538 SVGHMI: spread JS code from svghmi/scripts.ysl2 in other .ysl2 files, using dedicated preamble and epilogue namespaces
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2920
diff changeset
    15
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    16
template "widget[@type='Keypad']", mode="widget_class"
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    17
    ||
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    18
    class KeypadWidget extends Widget{
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    19
         moving = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    20
         enTimer = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    21
         offset = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    22
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    23
         on_position_click(evt) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    24
             this.moving = true;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    25
             this.enTimer = true;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    26
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    27
             // get click position offset from widget x,y and save it to variable
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    28
             var keypad_borders = this.position_elt.getBoundingClientRect();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    29
             var clickX = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    30
             var clickY = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    31
             if (evt.type == "touchstart"){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    32
                 clickX = Math.ceil(evt.touches[0].clientX);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    33
                 clickY = Math.ceil(evt.touches[0].clientY);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    34
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    35
             else{
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    36
                 clickX = evt.pageX;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    37
                 clickY = evt.pageY;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    38
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    39
             this.offset=[clickX-keypad_borders.left,clickY-keypad_borders.top]
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    40
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    41
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    42
         off_position_click(evt) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    43
            if(this.moving)
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    44
                this.moving = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    45
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    46
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    47
         on_move(evt) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    48
             if(this.moving && this.enTimer){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    49
                 //get keyboard pos in html
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    50
                 let [eltid, tmpgrp] = current_modal;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    51
                 let [xcoord,ycoord] = this.coordinates;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    52
                 let [xdest,ydest,svgWidth,svgHeight] = page_desc[current_visible_page].bbox;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    53
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    54
                 //get mouse coordinates
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    55
                 var clickX = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    56
                 var clickY = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    57
                 if (evt.type == "touchmove"){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    58
                     clickX = Math.ceil(evt.touches[0].clientX);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    59
                     clickY = Math.ceil(evt.touches[0].clientY);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    60
                 }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    61
                 else{
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    62
                     clickX = evt.pageX;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    63
                     clickY = evt.pageY;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    64
                 }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    65
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    66
                 //translate keyboard position
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    67
                 let mouseX = ((clickX-this.offset[0])/window.innerWidth)*svgWidth;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    68
                 let mouseY = ((clickY-this.offset[1])/window.innerHeight)*svgHeight;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    69
                 tmpgrp.setAttribute("transform","translate("+String(xdest-xcoord+mouseX)+","+String(ydest-ycoord+mouseY)+")");
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    70
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    71
                 //reset timer
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    72
                 this.enTimer = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    73
                 setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    74
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    75
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    76
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    77
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    78
         on_key_click(symbols) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    79
             var syms = symbols.split(" ");
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    80
             this.shift |= this.caps;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    81
             this.editstr += syms[this.shift?syms.length-1:0];
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    82
             this.shift = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    83
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    84
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    85
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    86
         on_Esc_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    87
             end_modal.call(this);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    88
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    89
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
    90
         on_Enter_click() {
3033
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
    91
             let coercedval = (typeof this.initial) == "number" ? Number(this.editstr) : this.editstr;
3042
ed43facc7137 SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents: 3033
diff changeset
    92
             if(typeof coercedval == 'number' && isNaN(coercedval)){
ed43facc7137 SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents: 3033
diff changeset
    93
                 // revert to initial so it explicitely shows input was ignored
3033
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
    94
                 this.editstr = String(this.initial);
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
    95
                 this.update();
3042
ed43facc7137 SVGHMI: Fix keypad : non-number input was always considered invalid because of missing type checking.
Edouard Tisserant
parents: 3033
diff changeset
    96
             } else { 
3033
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
    97
                 let callback_obj = this.result_callback_obj;
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
    98
                 end_modal.call(this);
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
    99
                 callback_obj.edit_callback(coercedval);
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
   100
             }
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   101
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   102
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   103
         on_BackSpace_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   104
             this.editstr = this.editstr.slice(0,this.editstr.length-1);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   105
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   106
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   107
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   108
         on_Sign_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   109
             if(this.editstr[0] == "-")
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   110
                 this.editstr = this.editstr.slice(1,this.editstr.length);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   111
             else
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   112
                 this.editstr = "-" + this.editstr;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   113
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   114
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   115
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   116
         on_NumDot_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   117
             if(this.editstr.indexOf(".") == "-1"){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   118
                 this.editstr += ".";
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   119
                 this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   120
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   121
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   122
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   123
         on_Space_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   124
             this.editstr += " ";
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   125
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   126
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   127
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   128
         caps = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   129
         _caps = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   130
         on_CapsLock_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   131
             this.caps = !this.caps;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   132
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   133
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   134
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   135
         shift = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   136
         _shift = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   137
         on_Shift_click() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   138
             this.shift = !this.shift;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   139
             this.caps = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   140
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   141
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   142
         editstr = "";
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   143
         _editstr = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   144
         result_callback_obj = undefined;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   145
         start_edit(info, valuetype, callback_obj, initial,size) {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   146
             show_modal.call(this,size);
3033
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
   147
             this.editstr = String(initial);
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   148
             this.result_callback_obj = callback_obj;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   149
             this.Info_elt.textContent = info;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   150
             this.shift = false;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   151
             this.caps = false;
3033
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
   152
             this.initial = initial;
52f6548982d4 SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
Edouard Tisserant
parents: 3010
diff changeset
   153
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   154
             this.update();
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   155
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   156
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   157
         update() {
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   158
             if(this.editstr != this._editstr){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   159
                 this._editstr = this.editstr;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   160
                 this.Value_elt.textContent = this.editstr;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   161
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   162
             if(this.shift != this._shift){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   163
                 this._shift = this.shift;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   164
                 (this.shift?widget_active_activable:widget_inactive_activable)(this.Shift_sub);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   165
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   166
             if(this.caps != this._caps){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   167
                 this._caps = this.caps;
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   168
                 (this.caps?widget_active_activable:widget_inactive_activable)(this.CapsLock_sub);
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   169
             }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   170
         }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   171
    }
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   172
    ||
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   173
2908
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
   174
template "widget[@type='Keypad']", mode="widget_defs" {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   175
    param "hmi_element";
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   176
    labels("Esc Enter BackSpace Keys Info Value");
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   177
    optional_labels("Sign Space NumDot position");
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2919
diff changeset
   178
    activable_labels("CapsLock Shift");
2911
211d6a185e31 SVGHMI: More infrastructure for editing values with a keypad.
Edouard Tisserant
parents: 2908
diff changeset
   179
    |     init: function() {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   180
    foreach "$hmi_element/*[@inkscape:label = 'Keys']/*" {
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   181
    |         id("«@id»").setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_key_click('«func:escape_quotes(@inkscape:label)»')");
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   182
    }
2920
3ee337c8c769 SVGHMI: finished shift and capslock support n keypad widget. Added a helper in widgets_common to collect subelements likle active/inactive/disabled...
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2919
diff changeset
   183
    foreach "str:split('Esc Enter BackSpace Sign Space NumDot CapsLock Shift')" {
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   184
    |         if(this.«.»_elt)
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   185
    |             this.«.»_elt.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_«.»_click()");
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   186
    }
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   187
    |         if(this.position_elt){
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   188
    |            this.position_elt.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)");
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   189
    |            this.position_elt.setAttribute("ontouchstart", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)");
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   190
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   191
    |            window.addEventListener("mouseup", hmi_widgets[this.element_id].off_position_click.bind(this));
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   192
    |            window.addEventListener("touchend", hmi_widgets[this.element_id].off_position_click.bind(this));
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   193
    |            window.addEventListener("touchcancel", hmi_widgets[this.element_id].off_position_click.bind(this));
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   194
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   195
    |            window.addEventListener("mousemove", hmi_widgets[this.element_id].on_move.bind(this));
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   196
    |            window.addEventListener("touchmove", hmi_widgets[this.element_id].on_move.bind(this));
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   197
    |        }
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   198
    |     },
3010
893cc309f5e2 Changed keyboard to show on defined position.
usveticic
parents: 2943
diff changeset
   199
    |
2917
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   200
    const "g", "$geometry[@Id = $hmi_element/@id]"; 
c8d923dd707f SVGHMI: Keypad working for HMI_STRING, still Shift/CapsLock not finished.
Edouard Tisserant
parents: 2911
diff changeset
   201
    |     coordinates: [«$g/@x», «$g/@y»],
2908
01352aca1cae SVGHMI: empty widget_keypad.ysl2, WIP
Edouard Tisserant
parents:
diff changeset
   202
}