Subversion Repositories oidplus

Rev

Rev 635 | Rev 767 | Go to most recent revision | View as "text/javascript" | Blame | Compare with Previous | Last modification | View Log | RSS feed

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