Subversion Repositories oidplus

Rev

Rev 424 | 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;
144 daniel-mar 22
g_hue_shift_saved = null;
23
g_sat_shift_saved = null;
24
g_val_shift_saved = null;
286 daniel-mar 25
g_invcolors_saved = null;
142 daniel-mar 26
 
144 daniel-mar 27
function color_reset_sliders_factory() {
143 daniel-mar 28
        $("#hshift").val(g_hue_shift = 0);
29
        $("#sshift").val(g_sat_shift = 0);
30
        $("#vshift").val(g_val_shift = 0);
286 daniel-mar 31
        $("#icolor").val(g_invcolors = 0);
143 daniel-mar 32
        $("#slider-hshift").slider("option", "value", g_hue_shift);
33
        $("#slider-sshift").slider("option", "value", g_sat_shift);
34
        $("#slider-vshift").slider("option", "value", g_val_shift);
286 daniel-mar 35
        $("#slider-icolor").slider("option", "value", g_invcolors);
143 daniel-mar 36
        test_color_theme();
37
}
38
 
144 daniel-mar 39
function color_reset_sliders_cfg() {
40
        $("#hshift").val(g_hue_shift = g_hue_shift_saved);
41
        $("#sshift").val(g_sat_shift = g_sat_shift_saved);
42
        $("#vshift").val(g_val_shift = g_val_shift_saved);
286 daniel-mar 43
        $("#icolor").val(g_invcolors = g_invcolors_saved);
144 daniel-mar 44
        $("#slider-hshift").slider("option", "value", g_hue_shift);
45
        $("#slider-sshift").slider("option", "value", g_sat_shift);
46
        $("#slider-vshift").slider("option", "value", g_val_shift);
286 daniel-mar 47
        $("#slider-icolor").slider("option", "value", g_invcolors);
144 daniel-mar 48
        test_color_theme();
49
}
50
 
142 daniel-mar 51
function setup_color_sliders() {
52
        $("#slider-hshift").slider({
53
                value: g_hue_shift,
54
                min:   -360,
55
                max:   360,
56
                slide: function(event, ui) {
57
                        $("#hshift").val(ui.value);
58
                }
59
        });
60
        $("#hshift").val($("#slider-hshift").slider("value"));
61
 
62
        $("#slider-sshift").slider({
63
                value: g_sat_shift,
64
                min:   -100,
65
                max:   100,
66
                slide: function(event, ui) {
67
                        $("#sshift").val(ui.value);
68
                }
69
        });
70
        $("#sshift").val($("#slider-sshift").slider("value"));
71
 
72
        $("#slider-vshift").slider({
73
                value: g_val_shift,
74
                min:   -100,
75
                max:   100,
76
                slide: function(event, ui) {
77
                        $("#vshift").val(ui.value);
78
                }
79
        });
80
        $("#vshift").val($("#slider-vshift").slider("value"));
286 daniel-mar 81
 
82
        /* ToDo: Checkbox instead */
83
        $("#slider-icolor").slider({
84
                value: g_invcolors,
85
                min:   0,
86
                max:   1,
87
                slide: function(event, ui) {
88
                        $("#icolor").val(ui.value);
89
                }
90
        });
91
        $("#icolor").val($("#slider-icolor").slider("value"));
142 daniel-mar 92
}
93
 
94
function test_color_theme() {
95
        g_hue_shift = $("#hshift").val();
96
        g_sat_shift = $("#sshift").val();
97
        g_val_shift = $("#vshift").val();
286 daniel-mar 98
        g_invcolors = $("#icolor").val();
448 daniel-mar 99
        changeCSS('oidplus.min.css.php?theme='+g_activetheme+'&invert='+$("#icolor").val()+'&h_shift='+$("#hshift").val()/360+'&s_shift='+$("#sshift" ).val()/100+'&v_shift='+$("#vshift" ).val()/100, 0);
142 daniel-mar 100
}
101
 
102
function changeCSS(cssFile, cssLinkIndex) {
103
        var oldlink = document.getElementsByTagName("link").item(cssLinkIndex);
104
 
105
        var newlink = document.createElement("link");
106
        newlink.setAttribute("rel", "stylesheet");
107
        newlink.setAttribute("type", "text/css");
108
        newlink.setAttribute("href", cssFile);
109
 
110
        document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);
111
}
112
 
113
function crudActionColorUpdate(name) {
360 daniel-mar 114
        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 115
 
142 daniel-mar 116
        $.ajax({
117
                url:"ajax.php",
118
                method:"POST",
119
                data: {
424 daniel-mar 120
                        csrf_token:csrf_token,
320 daniel-mar 121
                        plugin:"1.3.6.1.4.1.37476.2.5.2.4.3.700",
142 daniel-mar 122
                        action:"color_update",
123
                        hue_shift:document.getElementById('hshift').value,
124
                        sat_shift:document.getElementById('sshift').value,
125
                        val_shift:document.getElementById('vshift').value,
286 daniel-mar 126
                        invcolors:document.getElementById('icolor').value,
142 daniel-mar 127
                },
128
                error:function(jqXHR, textStatus, errorThrown) {
360 daniel-mar 129
                        alert(_L("Error: %1",errorThrown));
142 daniel-mar 130
                },
131
                success:function(data) {
132
                        if ("error" in data) {
360 daniel-mar 133
                                alert(_L("Error: %1",data.error));
381 daniel-mar 134
                        } else if (data.status >= 0) {
144 daniel-mar 135
                                g_hue_shift_saved = g_hue_shift;
136
                                g_sat_shift_saved = g_sat_shift;
137
                                g_val_shift_saved = g_val_shift;
286 daniel-mar 138
                                g_invcolors_saved = g_invcolors;
142 daniel-mar 139
                                test_color_theme(); // apply visually
360 daniel-mar 140
                                alert(_L("Update OK"));
142 daniel-mar 141
                        } else {
360 daniel-mar 142
                                alert(_L("Error: %1",data));
142 daniel-mar 143
                        }
144
                }
145
        });
360 daniel-mar 146
}