Subversion Repositories oidplus

Rev

Rev 490 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
360 daniel-mar 1
/*
2
 * OIDplus 2.0
511 daniel-mar 3
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
360 daniel-mar 4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
142 daniel-mar 18
g_hue_shift = null;
19
g_sat_shift = null;
20
g_val_shift = null;
286 daniel-mar 21
g_invcolors = null;
451 daniel-mar 22
g_activetheme = null;
23
 
144 daniel-mar 24
g_hue_shift_saved = null;
25
g_sat_shift_saved = null;
26
g_val_shift_saved = null;
286 daniel-mar 27
g_invcolors_saved = null;
451 daniel-mar 28
g_activetheme_saved = null;
142 daniel-mar 29
 
144 daniel-mar 30
function color_reset_sliders_factory() {
143 daniel-mar 31
        $("#hshift").val(g_hue_shift = 0);
32
        $("#sshift").val(g_sat_shift = 0);
33
        $("#vshift").val(g_val_shift = 0);
286 daniel-mar 34
        $("#icolor").val(g_invcolors = 0);
451 daniel-mar 35
        $("#theme").val(g_activetheme = "default");
143 daniel-mar 36
        $("#slider-hshift").slider("option", "value", g_hue_shift);
37
        $("#slider-sshift").slider("option", "value", g_sat_shift);
38
        $("#slider-vshift").slider("option", "value", g_val_shift);
286 daniel-mar 39
        $("#slider-icolor").slider("option", "value", g_invcolors);
451 daniel-mar 40
        $("#slider-icolor").slider("option", "value", g_invcolors);
41
        $("#slider-icolor").slider("option", "value", g_invcolors);
143 daniel-mar 42
        test_color_theme();
43
}
44
 
144 daniel-mar 45
function color_reset_sliders_cfg() {
46
        $("#hshift").val(g_hue_shift = g_hue_shift_saved);
47
        $("#sshift").val(g_sat_shift = g_sat_shift_saved);
48
        $("#vshift").val(g_val_shift = g_val_shift_saved);
286 daniel-mar 49
        $("#icolor").val(g_invcolors = g_invcolors_saved);
451 daniel-mar 50
        $("#theme").val(g_activetheme = g_activetheme_saved);
144 daniel-mar 51
        $("#slider-hshift").slider("option", "value", g_hue_shift);
52
        $("#slider-sshift").slider("option", "value", g_sat_shift);
53
        $("#slider-vshift").slider("option", "value", g_val_shift);
286 daniel-mar 54
        $("#slider-icolor").slider("option", "value", g_invcolors);
144 daniel-mar 55
        test_color_theme();
56
}
57
 
142 daniel-mar 58
function setup_color_sliders() {
59
        $("#slider-hshift").slider({
60
                value: g_hue_shift,
61
                min:   -360,
62
                max:   360,
63
                slide: function(event, ui) {
64
                        $("#hshift").val(ui.value);
65
                }
66
        });
67
        $("#hshift").val($("#slider-hshift").slider("value"));
68
 
69
        $("#slider-sshift").slider({
70
                value: g_sat_shift,
71
                min:   -100,
72
                max:   100,
73
                slide: function(event, ui) {
74
                        $("#sshift").val(ui.value);
75
                }
76
        });
77
        $("#sshift").val($("#slider-sshift").slider("value"));
78
 
79
        $("#slider-vshift").slider({
80
                value: g_val_shift,
81
                min:   -100,
82
                max:   100,
83
                slide: function(event, ui) {
84
                        $("#vshift").val(ui.value);
85
                }
86
        });
87
        $("#vshift").val($("#slider-vshift").slider("value"));
286 daniel-mar 88
 
89
        /* ToDo: Checkbox instead */
90
        $("#slider-icolor").slider({
91
                value: g_invcolors,
92
                min:   0,
93
                max:   1,
94
                slide: function(event, ui) {
95
                        $("#icolor").val(ui.value);
96
                }
97
        });
98
        $("#icolor").val($("#slider-icolor").slider("value"));
142 daniel-mar 99
}
100
 
101
function test_color_theme() {
102
        g_hue_shift = $("#hshift").val();
103
        g_sat_shift = $("#sshift").val();
104
        g_val_shift = $("#vshift").val();
286 daniel-mar 105
        g_invcolors = $("#icolor").val();
451 daniel-mar 106
        g_activetheme = $("#theme").val();
453 daniel-mar 107
        changeCSS('oidplus.min.css.php'+
108
                '?theme='+encodeURIComponent($("#theme").val())+
109
                '&invert='+encodeURIComponent($("#icolor").val())+
110
                '&h_shift='+encodeURIComponent($("#hshift").val()/360)+
111
                '&s_shift='+encodeURIComponent($("#sshift" ).val()/100)+
490 daniel-mar 112
                '&v_shift='+encodeURIComponent($("#vshift" ).val()/100),
113
                findLinkIndex('oidplus.min.css.php'));
142 daniel-mar 114
}
115
 
490 daniel-mar 116
function findLinkIndex(searchString) {
117
        var links = document.getElementsByTagName("head").item(0).getElementsByTagName("link");
118
 
119
        for (i=0; i<links.length; i++) {
120
                if (links.item(i).href.includes(searchString)) return i;
121
        }
122
 
123
        return -1;
124
}
125
 
142 daniel-mar 126
function changeCSS(cssFile, cssLinkIndex) {
490 daniel-mar 127
        var oldlink = document.getElementsByTagName("head").item(0).getElementsByTagName("link").item(cssLinkIndex);
142 daniel-mar 128
 
129
        var newlink = document.createElement("link");
130
        newlink.setAttribute("rel", "stylesheet");
131
        newlink.setAttribute("type", "text/css");
132
        newlink.setAttribute("href", cssFile);
133
 
134
        document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);
135
}
136
 
137
function crudActionColorUpdate(name) {
360 daniel-mar 138
        if(!window.confirm(_L("Are you sure that you want to permanently change the color (for all users)? Please make sure you have tested the colors first, because if the contrast is too extreme, you might not be able to see the controls anymore, in order to correct the colors."))) return false;
286 daniel-mar 139
 
142 daniel-mar 140
        $.ajax({
141
                url:"ajax.php",
142
                method:"POST",
143
                data: {
424 daniel-mar 144
                        csrf_token:csrf_token,
320 daniel-mar 145
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.3.700",
142 daniel-mar 146
                        action:"color_update",
147
                        hue_shift:document.getElementById('hshift').value,
148
                        sat_shift:document.getElementById('sshift').value,
149
                        val_shift:document.getElementById('vshift').value,
286 daniel-mar 150
                        invcolors:document.getElementById('icolor').value,
451 daniel-mar 151
                        theme:document.getElementById('theme').value,
142 daniel-mar 152
                },
153
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 154
                        alert(_L("Error: %1",errorThrown));
142 daniel-mar 155
                },
156
                success:function(data) {
157
                        if ("error" in data) {
360 daniel-mar 158
                                alert(_L("Error: %1",data.error));
381 daniel-mar 159
                        } else if (data.status >= 0) {
144 daniel-mar 160
                                g_hue_shift_saved = g_hue_shift;
161
                                g_sat_shift_saved = g_sat_shift;
162
                                g_val_shift_saved = g_val_shift;
286 daniel-mar 163
                                g_invcolors_saved = g_invcolors;
142 daniel-mar 164
                                test_color_theme(); // apply visually
360 daniel-mar 165
                                alert(_L("Update OK"));
142 daniel-mar 166
                        } else {
360 daniel-mar 167
                                alert(_L("Error: %1",data));
142 daniel-mar 168
                        }
169
                }
170
        });
453 daniel-mar 171
}