-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwidget_auth_switch.html
executable file
·219 lines (197 loc) · 11.2 KB
/
widget_auth_switch.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
* -----------------------------------------------------------------------------
* @package smartVISU
* @author Alexander Schwithal
* @copyright 2014
* @license GPL [http://www.gnu.de]
* -----------------------------------------------------------------------------
*/
/**
* A switch, build of two pics, but with necessary authentication
*
* @param unique id for this widget
* @param a gad/item
* @param the pic for the 'on' state (optional)
* @param the pic for the 'off' state (optional)
* @param value send for the 'on' state (optional, default 1)
* @param value send for the 'off' state (optional, default 0)
* @param value for the passwort, for example 1234
* @param text for the headline (optional, default Insert Key:)
* @param text for the wrong code notification (optional, default Wrong Code)
*/
{% macro auth_switch(id, gad, pic_on, pic_off, val_on, val_off, refpwd, headline, wrong_code) %}
{% set uid = uid(page, id) %}
<span>
<span id="{{ uid }}-switch" data-widget="basic.auth_switch" data-item="{{ gad }}"
data-val-on="{{ val_on|default('1') }}" data-val-off="{{ val_off|default('0') }}"
data-pic-on="{{ pic_on|default(icon1~'control_on_off.png') }}" data-pic-off="{{ pic_off|default(icon0~'control_on_off.png') }}">
<a><img id="{{ uid }}-image" class="icon" src="{{ pic_off|default(icon0~'control_on_off.png') }}" /></a>
</span>
<div id="{{ uid }}-switch-popup" data-role="popup" class="messagePopup" style="width:180px; height:300px;" data-dismissible="false" data-theme="a" data-overlay-theme="c">
<a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<form name="formkey">
{{ headline|default('Insert Key:') }}
<input type="password" name="pwd" id="{{ uid }}-account" autocomplete="off" maxlength="4" size="2" data-tip="Please enter a password" autofocus="autofocus">
<script type="text/javascript">
if (!('autofocus' in document.createElement('input')))
{
document.getElementById('{{ uid }}-account').focus();
}
function appendValue(in_value, field_id)
{
var textLength = document.getElementById(field_id).value.length;
if(document.getElementById(field_id).type == 'text')
{
document.getElementById(field_id).value = in_value;
document.getElementById(field_id).type = 'password';
}
else
{
if(textLength < 4)
document.getElementById(field_id).value = document.getElementById(field_id).value + in_value;
}
}
function resetValue(field_id)
{
document.getElementById(field_id).value = '';
document.getElementById(field_id).type = 'password';
}
function checkPw(field_id, switch_id, image_id, popup_id, pwd, wrong_note)
{
var code = document.getElementById(field_id).value;
if ( code == pwd ) {
document.getElementById(field_id).value = '';
if (document.getElementById(image_id).getAttribute('src') == document.getElementById(switch_id).getAttribute('data-pic-off') )
{
io.write(document.getElementById(switch_id).getAttribute('data-item'), document.getElementById(switch_id).getAttribute('data-val-on'));
}
else
{
io.write(document.getElementById(switch_id).getAttribute('data-item'), document.getElementById(switch_id).getAttribute('data-val-off'));
}
//$.mobile.activePage.find('.messagePopup').popup('close');
$.mobile.activePage.find(popup_id).popup('close');
}
else {
document.getElementById(field_id).value = wrong_note;
document.getElementById(field_id).type = 'text';
}
}
</script>
<table border="0" width=100%>
<tr>
<td align=center><a onclick="appendValue(1,'{{ uid }}-account');" id="{{ uid }}-button1" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">1 </a></td>
<td align=center><a onclick="appendValue(2,'{{ uid }}-account');" id="{{ uid }}-button2" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">2 </a></td>
<td align=center><a onclick="appendValue(3,'{{ uid }}-account');" id="{{ uid }}-button3" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">3 </a></td>
</tr>
<tr>
<td align=center><a onclick="appendValue(4,'{{ uid }}-account');" id="{{ uid }}-button4" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">4 </a></td>
<td align=center><a onclick="appendValue(5,'{{ uid }}-account');" id="{{ uid }}-button5" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">5 </a></td>
<td align=center><a onclick="appendValue(6,'{{ uid }}-account');" id="{{ uid }}-button6" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">6 </a></td>
</tr>
<tr>
<td align=center><a onclick="appendValue(7,'{{ uid }}-account');" id="{{ uid }}-button7" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">7 </a></td>
<td align=center><a onclick="appendValue(8,'{{ uid }}-account');" id="{{ uid }}-button8" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">8 </a></td>
<td align=center><a onclick="appendValue(9,'{{ uid }}-account');" id="{{ uid }}-button9" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">9 </a></td>
</tr>
<tr>
<td align=center><a onclick="resetValue('{{ uid }}-account');" id="{{ uid }}-buttonR" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">R</a></td>
<td align=center><a onclick="appendValue(0,'{{ uid }}-account');" id="{{ uid }}-button0" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">0</a></td>
<td align=center><a onclick="checkPw('{{ uid }}-account', '{{ uid }}-switch', '{{ uid }}-image', '[id={{ uid }}-switch-popup]', {{ refpwd }}, '{{ wrong_code|default('Wrong Code')}}' );" id="{{ uid }}-buttonOK" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">OK</a></td>
</tr>
</table>
</form>
</div>
</span>
{% endmacro %}
/**
* Displays an authenticated flip-switch
*
* @param unique id for this widget
* @param a gad/item
* @param text for the 'on' state (optional, default 'On')
* @param text for the 'off' state (optional, default 'Off')
* @param value for the passwort, for example 1234
*/
{% macro auth_flip(id, gad, txt_on, txt_off, refpwd, headline, wrong_code ) %}
{% set uid = uid(page, id) %}
<select id="{{ uid }}-flip" data-widget="basic.auth_flip" data-item="{{ gad }}"
data-role="slider">
<option value="off">{{ txt_off|default('Off') }}</option>
<option value="on">{{ txt_on|default('On') }}</option>
</select>
<div id="{{ uid }}-flip-popup" data-role="popup" class="messagePopup" style="width:180px; height:300px;" data-dismissible="false">
<a href="#" data-rel="back" data-role="button" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<form name="formkey">
{{ headline|default('Insert Key:') }}
<input type="password" name="pwd" id="{{ uid }}-account" autocomplete="off" maxlength="4" size="2" data-tip="Please enter a password" autofocus="autofocus">
<script type="text/javascript">
function appendValue(in_value, field_id)
{
var textLength = document.getElementById(field_id).value.length;
if(document.getElementById(field_id).type == 'text')
{
document.getElementById(field_id).value = in_value;
document.getElementById(field_id).type = 'password';
}
else
{
if(textLength < 4)
document.getElementById(field_id).value = document.getElementById(field_id).value + in_value;
}
}
function resetValue(field_id)
{
document.getElementById(field_id).value = '';
document.getElementById(field_id).type = 'password';
}
function checkPw(field_id, switch_id, image_id, popup_id, pwd, wrong_note)
{
var code = document.getElementById(field_id).value;
if ( code == pwd ) {
document.getElementById(field_id).value = '';
//if (document.getElementById(switch_id).val() == 'on') //does not work
if (document.getElementById(switch_id).value == 'on')
{
io.write(document.getElementById(switch_id).getAttribute('data-item'), 1);
//io.write($(this).attr('data-item'), ($(this).val() == 'on' ? 1 : 0));
}
else
{
io.write(document.getElementById(switch_id).getAttribute('data-item'), 0);
}
//$(this).val(response > 0 ? 'on' : 'off').slider('refresh');
$.mobile.activePage.find(popup_id).popup('close');
$.mobile.activePage.find(switch_id).slider('refresh');
}
else {
document.getElementById(field_id).value = wrong_note;
document.getElementById(field_id).type = 'text';
}
}
</script>
<table border="0" width=100%>
<tr>
<td align=center><a onclick="appendValue(1,'{{ uid }}-account');" id="{{ uid }}-button1" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">1 </a></td>
<td align=center><a onclick="appendValue(2,'{{ uid }}-account');" id="{{ uid }}-button2" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">2 </a></td>
<td align=center><a onclick="appendValue(3,'{{ uid }}-account');" id="{{ uid }}-button3" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">3 </a></td>
</tr>
<tr>
<td align=center><a onclick="appendValue(4,'{{ uid }}-account');" id="{{ uid }}-button4" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">4 </a></td>
<td align=center><a onclick="appendValue(5,'{{ uid }}-account');" id="{{ uid }}-button5" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">5 </a></td>
<td align=center><a onclick="appendValue(6,'{{ uid }}-account');" id="{{ uid }}-button6" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">6 </a></td>
</tr>
<tr>
<td align=center><a onclick="appendValue(7,'{{ uid }}-account');" id="{{ uid }}-button7" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">7 </a></td>
<td align=center><a onclick="appendValue(8,'{{ uid }}-account');" id="{{ uid }}-button8" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">8 </a></td>
<td align=center><a onclick="appendValue(9,'{{ uid }}-account');" id="{{ uid }}-button9" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">9 </a></td>
</tr>
<tr>
<td align=center><a onclick="resetValue('{{ uid }}-account');" id="{{ uid }}-buttonR" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">R</a></td>
<td align=center><a onclick="appendValue(0,'{{ uid }}-account');" id="{{ uid }}-button0" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">0</a></td>
<td align=center><a onclick="checkPw('{{ uid }}-account', '{{ uid }}-flip', '{{ uid }}-image', '[id={{ uid }}-flip-popup]', {{ refpwd }}, '{{ wrong_code|default('Wrong Code') }}' );" id="{{ uid }}-buttonOK" class="ui-mini" data-role="button" data-inline="true" data-iconpos="nopic">OK</a></td>
</tr>
</table>
</form>
</div>
{% endmacro %}