Subversion Repositories oidplus

Rev

Rev 424 | Go to most recent revision | View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  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.  
  18. g_hue_shift = null;
  19. g_sat_shift = null;
  20. g_val_shift = null;
  21. g_invcolors = null;
  22. g_hue_shift_saved = null;
  23. g_sat_shift_saved = null;
  24. g_val_shift_saved = null;
  25. g_invcolors_saved = null;
  26.  
  27. function color_reset_sliders_factory() {
  28.         $("#hshift").val(g_hue_shift = 0);
  29.         $("#sshift").val(g_sat_shift = 0);
  30.         $("#vshift").val(g_val_shift = 0);
  31.         $("#icolor").val(g_invcolors = 0);
  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);
  35.         $("#slider-icolor").slider("option", "value", g_invcolors);
  36.         test_color_theme();
  37. }
  38.  
  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);
  43.         $("#icolor").val(g_invcolors = g_invcolors_saved);
  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);
  47.         $("#slider-icolor").slider("option", "value", g_invcolors);
  48.         test_color_theme();
  49. }
  50.  
  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"));
  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"));
  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();
  98.         g_invcolors = $("#icolor").val();
  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);
  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) {
  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;
  115.  
  116.         $.ajax({
  117.                 url:"ajax.php",
  118.                 method:"POST",
  119.                 data: {
  120.                         csrf_token:csrf_token,
  121.                         plugin:"1.3.6.1.4.1.37476.2.5.2.4.3.700",
  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,
  126.                         invcolors:document.getElementById('icolor').value,
  127.                 },
  128.                 error:function(jqXHR, textStatus, errorThrown) {
  129.                         alert(_L("Error: %1",errorThrown));
  130.                 },
  131.                 success:function(data) {
  132.                         if ("error" in data) {
  133.                                 alert(_L("Error: %1",data.error));
  134.                         } else if (data.status >= 0) {
  135.                                 g_hue_shift_saved = g_hue_shift;
  136.                                 g_sat_shift_saved = g_sat_shift;
  137.                                 g_val_shift_saved = g_val_shift;
  138.                                 g_invcolors_saved = g_invcolors;
  139.                                 test_color_theme(); // apply visually
  140.                                 alert(_L("Update OK"));
  141.                         } else {
  142.                                 alert(_L("Error: %1",data));
  143.                         }
  144.                 }
  145.         });
  146. }