Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
635 daniel-mar 1
/*
2
 * OIDplus 2.0
3
 * Copyright 2019 - 2021 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
 
767 daniel-mar 18
// TODO: We can't change $("meta[name='theme-color']").attr("content", ...) here,
19
//       because this property (and the color manipulation) can only be accessed in PHP.
20
 
635 daniel-mar 21
var OIDplusPageAdminColors = {
22
 
23
        oid: "1.3.6.1.4.1.37476.2.5.2.4.3.700",
24
 
25
        g_hue_shift: null,
26
        g_sat_shift: null,
27
        g_val_shift: null,
28
        g_invcolors: null,
29
        g_activetheme: null,
30
 
31
        g_hue_shift_saved: null,
32
        g_sat_shift_saved: null,
33
        g_val_shift_saved: null,
34
        g_invcolors_saved: null,
35
        g_activetheme_saved: null,
36
 
37
        color_reset_sliders_factory: function() {
38
                $("#hshift").val(OIDplusPageAdminColors.hue_shift = 0);
39
                $("#sshift").val(OIDplusPageAdminColors.sat_shift = 0);
40
                $("#vshift").val(OIDplusPageAdminColors.val_shift = 0);
41
                $("#icolor").val(OIDplusPageAdminColors.invcolors = 0);
42
                $("#theme").val(OIDplusPageAdminColors.activetheme = "default");
43
                $("#slider-hshift").slider("option", "value", OIDplusPageAdminColors.hue_shift);
44
                $("#slider-sshift").slider("option", "value", OIDplusPageAdminColors.sat_shift);
45
                $("#slider-vshift").slider("option", "value", OIDplusPageAdminColors.val_shift);
46
                $("#slider-icolor").slider("option", "value", OIDplusPageAdminColors.invcolors);
47
                $("#slider-icolor").slider("option", "value", OIDplusPageAdminColors.invcolors);
48
                $("#slider-icolor").slider("option", "value", OIDplusPageAdminColors.invcolors);
49
                OIDplusPageAdminColors.test_color_theme();
50
        },
51
 
52
        color_reset_sliders_cfg: function() {
53
                $("#hshift").val(OIDplusPageAdminColors.hue_shift = OIDplusPageAdminColors.hue_shift_saved);
54
                $("#sshift").val(OIDplusPageAdminColors.sat_shift = OIDplusPageAdminColors.sat_shift_saved);
55
                $("#vshift").val(OIDplusPageAdminColors.val_shift = OIDplusPageAdminColors.val_shift_saved);
56
                $("#icolor").val(OIDplusPageAdminColors.invcolors = OIDplusPageAdminColors.invcolors_saved);
57
                $("#theme").val(OIDplusPageAdminColors.activetheme = OIDplusPageAdminColors.activetheme_saved);
58
                $("#slider-hshift").slider("option", "value", OIDplusPageAdminColors.hue_shift);
59
                $("#slider-sshift").slider("option", "value", OIDplusPageAdminColors.sat_shift);
60
                $("#slider-vshift").slider("option", "value", OIDplusPageAdminColors.val_shift);
61
                $("#slider-icolor").slider("option", "value", OIDplusPageAdminColors.invcolors);
62
                OIDplusPageAdminColors.test_color_theme();
63
        },
64
 
65
        setup_color_sliders: function() {
66
                $("#slider-hshift").slider({
67
                        value: OIDplusPageAdminColors.hue_shift,
68
                        min:   -360,
69
                        max:   360,
70
                        slide: function(event, ui) {
71
                                $("#hshift").val(ui.value);
72
                        }
73
                });
74
                $("#hshift").val($("#slider-hshift").slider("value"));
75
 
76
                $("#slider-sshift").slider({
77
                        value: OIDplusPageAdminColors.sat_shift,
78
                        min:   -100,
79
                        max:   100,
80
                        slide: function(event, ui) {
81
                                $("#sshift").val(ui.value);
82
                        }
83
                });
84
                $("#sshift").val($("#slider-sshift").slider("value"));
85
 
86
                $("#slider-vshift").slider({
87
                        value: OIDplusPageAdminColors.val_shift,
88
                        min:   -100,
89
                        max:   100,
90
                        slide: function(event, ui) {
91
                                $("#vshift").val(ui.value);
92
                        }
93
                });
94
                $("#vshift").val($("#slider-vshift").slider("value"));
95
 
96
                /* ToDo: Checkbox instead */
97
                $("#slider-icolor").slider({
98
                        value: OIDplusPageAdminColors.invcolors,
99
                        min:   0,
100
                        max:   1,
101
                        slide: function(event, ui) {
102
                                $("#icolor").val(ui.value);
103
                        }
104
                });
105
                $("#icolor").val($("#slider-icolor").slider("value"));
106
        },
107
 
108
        test_color_theme: function() {
109
                OIDplusPageAdminColors.hue_shift = $("#hshift").val();
110
                OIDplusPageAdminColors.sat_shift = $("#sshift").val();
111
                OIDplusPageAdminColors.val_shift = $("#vshift").val();
112
                OIDplusPageAdminColors.invcolors = $("#icolor").val();
113
                OIDplusPageAdminColors.activetheme = $("#theme").val();
114
                OIDplusPageAdminColors.changeCSS('oidplus.min.css.php'+
115
                                                 '?theme='+encodeURIComponent($("#theme").val())+
116
                                                 '&invert='+encodeURIComponent($("#icolor").val())+
117
                                                 '&h_shift='+encodeURIComponent($("#hshift").val()/360)+
118
                                                 '&s_shift='+encodeURIComponent($("#sshift" ).val()/100)+
119
                                                 '&v_shift='+encodeURIComponent($("#vshift" ).val()/100),
120
                                                 OIDplusPageAdminColors.findLinkIndex('oidplus.min.css.php'));
121
        },
122
 
123
        findLinkIndex: function(searchString) {
124
                var links = $("head link");
125
 
126
                for (i=0; i<links.length; i++) {
127
                        if (links[i].href.includes(searchString)) return i;
128
                }
129
 
130
                return -1;
131
        },
132
 
133
        changeCSS: function(cssFile, cssLinkIndex) {
134
                $("head link")[cssLinkIndex].href = cssFile;
135
        },
136
 
137
        crudActionColorUpdate: function(name) {
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;
139
 
140
                $.ajax({
141
                        url:"ajax.php",
142
                        method:"POST",
143
                        beforeSend: function(jqXHR, settings) {
144
                                $.xhrPool.abortAll();
145
                                $.xhrPool.add(jqXHR);
146
                        },
147
                        complete: function(jqXHR, text) {
148
                                $.xhrPool.remove(jqXHR);
149
                        },
150
                        data: {
151
                                csrf_token: csrf_token,
152
                                plugin: OIDplusPageAdminColors.oid,
153
                                action: "color_update",
154
                                hue_shift: $("#hshift")[0].value,
155
                                sat_shift: $("#sshift")[0].value,
156
                                val_shift: $("#vshift")[0].value,
157
                                invcolors: $("#icolor")[0].value,
158
                                theme: $("#theme")[0].value,
159
                        },
160
                        error:function(jqXHR, textStatus, errorThrown) {
161
                                if (errorThrown == "abort") return;
833 daniel-mar 162
                                alertError(_L("Error: %1",errorThrown));
635 daniel-mar 163
                        },
164
                        success:function(data) {
165
                                if ("error" in data) {
833 daniel-mar 166
                                        alertError(_L("Error: %1",data.error));
635 daniel-mar 167
                                } else if (data.status >= 0) {
168
                                        OIDplusPageAdminColors.hue_shift_saved = OIDplusPageAdminColors.hue_shift;
169
                                        OIDplusPageAdminColors.sat_shift_saved = OIDplusPageAdminColors.sat_shift;
170
                                        OIDplusPageAdminColors.val_shift_saved = OIDplusPageAdminColors.val_shift;
171
                                        OIDplusPageAdminColors.invcolors_saved = OIDplusPageAdminColors.invcolors;
172
                                        OIDplusPageAdminColors.test_color_theme(); // apply visually
833 daniel-mar 173
                                        alertSuccess(_L("Update OK"));
635 daniel-mar 174
                                } else {
833 daniel-mar 175
                                        alertError(_L("Error: %1",data));
635 daniel-mar 176
                                }
177
                        }
178
                });
179
        }
180
 
181
};