Subversion Repositories oidplus

Rev

Rev 451 | 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
3
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
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)+
112
                '&v_shift='+encodeURIComponent($("#vshift" ).val()/100), 0);
142 daniel-mar 113
}
114
 
115
function changeCSS(cssFile, cssLinkIndex) {
116
        var oldlink = document.getElementsByTagName("link").item(cssLinkIndex);
117
 
118
        var newlink = document.createElement("link");
119
        newlink.setAttribute("rel", "stylesheet");
120
        newlink.setAttribute("type", "text/css");
121
        newlink.setAttribute("href", cssFile);
122
 
123
        document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);
124
}
125
 
126
function crudActionColorUpdate(name) {
360 daniel-mar 127
        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 128
 
142 daniel-mar 129
        $.ajax({
130
                url:"ajax.php",
131
                method:"POST",
132
                data: {
424 daniel-mar 133
                        csrf_token:csrf_token,
320 daniel-mar 134
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.3.700",
142 daniel-mar 135
                        action:"color_update",
136
                        hue_shift:document.getElementById('hshift').value,
137
                        sat_shift:document.getElementById('sshift').value,
138
                        val_shift:document.getElementById('vshift').value,
286 daniel-mar 139
                        invcolors:document.getElementById('icolor').value,
451 daniel-mar 140
                        theme:document.getElementById('theme').value,
142 daniel-mar 141
                },
142
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 143
                        alert(_L("Error: %1",errorThrown));
142 daniel-mar 144
                },
145
                success:function(data) {
146
                        if ("error" in data) {
360 daniel-mar 147
                                alert(_L("Error: %1",data.error));
381 daniel-mar 148
                        } else if (data.status >= 0) {
144 daniel-mar 149
                                g_hue_shift_saved = g_hue_shift;
150
                                g_sat_shift_saved = g_sat_shift;
151
                                g_val_shift_saved = g_val_shift;
286 daniel-mar 152
                                g_invcolors_saved = g_invcolors;
142 daniel-mar 153
                                test_color_theme(); // apply visually
360 daniel-mar 154
                                alert(_L("Update OK"));
142 daniel-mar 155
                        } else {
360 daniel-mar 156
                                alert(_L("Error: %1",data));
142 daniel-mar 157
                        }
158
                }
159
        });
453 daniel-mar 160
}