Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. //Accordion
  7.  
  8. $(document).ready(function() {
  9.   $("> div", "#questionsDispos").draggable({
  10.     helper: "clone",
  11.     revert: "invalid",
  12.     cursor: "move",
  13.     handle: "h3",
  14.     connectToSortable: ".questions"
  15.   });
  16.  
  17.   $(".replot_box").accordion({
  18.     header: "> div > h3",
  19.     collapsible: true,
  20.     active: false,
  21.     autoHeight: false,
  22.     autoActivate: true
  23.   });
  24.  
  25.   $(".replot_box").sortable({
  26.     axis: "y",
  27.     handle: "h3",
  28.     items: "div",
  29.     receive: function(event, ui) {
  30.       $(ui.item).removeClass();
  31.       $(ui.item).removeAttr("style");
  32.       $(".replot_box").accordion("add", "<div>" + ui.item.hmtl() + "</div>");
  33.     }
  34.   });
  35.  
  36.   $("#questionsDispos").accordion({
  37.     header: "> div > h3",
  38.     collapsible: true,
  39.     active: false,
  40.     autoHeight: false
  41.   });
  42.   $("button").button();
  43.   $('#addAccordion').click(function() {
  44.     var newDiv = "<div><h3>Q4 New Question</h3><div>"+accordion_content+"</div></div>";
  45.     $('.replot_box').append(newDiv)
  46.     $('.replot_box').accordion("refresh");
  47.   });
  48. });
  49.  
  50. //global variable for accordion
  51. var accordion_content = "";
  52.  
  53.  
  54.  
  55. var tech_name = "";
  56. var tech_id = "";
  57. var dev_name = "";
  58. var param_name = "";
  59. var dev_id = "";
  60. var para_type = "";
  61. var sight = "";
  62. var x_Axis = "";
  63. var y_Axis = "";
  64. var test = "";
  65. var block_id = "";
  66. var temps = "";
  67. var DrawAreaArray = new Object();
  68. //Ausgewaehlte values werden hier rein gelesen:
  69. var checkedTempValue = [];
  70. checkedTempValueArray = [];
  71.  
  72.  
  73. //globale Variablen von File:
  74. DrawAreasFromFile = [];
  75. var technologie_temp = [];
  76. var device_temp = [];
  77. var curve_temp = [];
  78. var sight_temp = [];
  79. var temperatures_temp = [];
  80. var xValue_temp = [];
  81. var yValue_temp = [];
  82.    
  83.  
  84. function assert(condition, message) {
  85.     if (!condition) {
  86.         message = message || "Assertion failed";
  87.         if (typeof Error !== "undefined") {
  88.             throw new Error(message);
  89.         }
  90.         throw message; // Fallback
  91.     }
  92. }
  93.  
  94. //Size of assoziative array
  95. Object.size = function(obj) {
  96.     var size = 0, key;
  97.     for (key in obj) {
  98.         if (obj.hasOwnProperty(key)) size++;
  99.     }
  100.     return size;
  101. };
  102.  
  103. function xmlrequest(){
  104.         if (window.XMLHttpRequest) {
  105.             // code for IE7+, Firefox, Chrome, Opera, Safari
  106.             xmlhttp = new XMLHttpRequest();
  107.         }    
  108.         return xmlhttp;
  109. }
  110.  
  111. function invertCheckboxes(){
  112.     for(var i=0;i<document.filter_list.length;++i)
  113.     {
  114.         if (document.forms[0].elements[i].type == "checkbox")
  115.         {
  116.             document.forms[0].elements[i].checked = !document.forms[0].elements[i].checked;
  117.         }
  118.     }
  119. }
  120.  
  121. //DEVICE NAME AUSWAHL BEFÜLLEN
  122. function updateDeviceNameSelect(e){
  123.  
  124.     //Inhalt auslesen:
  125.     tech_id = e.options[e.selectedIndex].value;
  126.     tech_name = e.options[e.selectedIndex].text;
  127.  
  128.     //alert(tech_name + "hat ID: " + tech_id);
  129.     //Ajax teil:
  130.  
  131.     if (tech_name == "") {
  132.         document.getElementById("plot_dev_name").innerHTML = "";
  133.         return;
  134.     } else {
  135.         xmlhttp = xmlrequest();
  136.  
  137.         xmlhttp.onreadystatechange = function() {
  138.             if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  139.                 document.getElementById("plot_dev_name").innerHTML = xmlhttp.responseText;
  140.             }
  141.         };
  142.  
  143.         xmlhttp.open("GET","include/get_sql_result.php?t="+tech_id,true);
  144.         xmlhttp.send();
  145.  
  146.     }
  147. }
  148.  
  149. //PARAMETER AUSWAHL BEFÜLLEN (KIND OF CURVE)
  150. function updateParameterSelect(e){
  151.     dev_id = e.options[e.selectedIndex].value;
  152.     dev_name = e.options[e.selectedIndex].text;
  153.     //Ajax teil:  
  154.  
  155.     if (dev_id == "")
  156.     {
  157.         document.getElementById("plot_param_name").innerHTML = "";
  158.         return;
  159.     }
  160.     else
  161.     {
  162.         xmlhttp = xmlrequest();
  163.  
  164.         xmlhttp.onreadystatechange = function()
  165.         {
  166.             if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
  167.             {
  168.                 document.getElementById("plot_param_name").innerHTML = xmlhttp.responseText;
  169.             }
  170.         };
  171.         xmlhttp.open("GET","include/get_sql_result.php?d="+dev_id,true);
  172.         xmlhttp.send();
  173.     }
  174.  
  175. }
  176.  
  177. //MDM -> SIGHT AUSWAHL BEFÜLLEN (WHICH SIGHT)
  178. function updateSightSelect(e){
  179.     para_type = e.options[e.selectedIndex].value;
  180.  
  181.     //Ajax teil:  
  182.     if (para_type == "") {
  183.         document.getElementById("plot_mdm_file").innerHTML = "";
  184.         return;
  185.     } else {
  186.         xmlhttp = xmlrequest();
  187.  
  188.         xmlhttp.onreadystatechange = function() {
  189.             if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  190.                 document.getElementById("plot_mdm_file").innerHTML = xmlhttp.responseText;
  191.             }
  192.         };
  193.         xmlhttp.open("GET","include/get_sql_result.php?p="+para_type+"&d="+dev_id,true);
  194.         xmlhttp.send();
  195.     }
  196.  
  197. }
  198.  
  199. //Temperatur AUSWAHL BEFÜLLEN
  200. function updateTemparatureSelectfield(e){
  201.     sight = e.options[e.selectedIndex].value;
  202.     //Ajax teil:  
  203.  
  204.     if (sight == "")
  205.     {
  206.         document.getElementById("temperatur_block").innerHTML = "";
  207.         return;
  208.     }
  209.     else
  210.     {
  211.         xmlhttp = xmlrequest();
  212.  
  213.         xmlhttp.onreadystatechange = function()
  214.         {
  215.             if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
  216.             {
  217.                 document.getElementById("temperatur_block").innerHTML = xmlhttp.responseText;
  218.             }
  219.         };
  220.         xmlhttp.open("GET","include/get_sql_result.php?s="+sight+"&temp=1&d="+dev_id,true);
  221.         xmlhttp.send();
  222.     }
  223.  
  224. }      
  225.  
  226. //Längen/Weiten AUSWAHL BEFÜLLEN
  227. function updateWidthLengthSelectfield(){
  228.  
  229.  
  230.         xmlhttp = xmlrequest();
  231.  
  232.         xmlhttp.onreadystatechange = function()
  233.         {
  234.             if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
  235.             {
  236.                 document.getElementById("width_length_block").innerHTML = xmlhttp.responseText;
  237.             }
  238.         };
  239.         xmlhttp.open("GET","include/get_sql_result.php?s="+sight+"&temp=1&d="+dev_id+"&w=1",true);
  240.         xmlhttp.send();
  241. }
  242.  
  243. //X - Y - Achsen Auswahl befüllen:
  244. function updateXAxisYAxisSelect(from_replot = 0){
  245.  
  246.     //Temperaturen auslesen: (nur wenn nicht von replotfunktion kommend)
  247.     if(from_replot == 0){
  248.         var inputElements = getElementsByClassName(document,'messageCheckbox');
  249.         checkedTempValue = [];
  250.         for(var i=0; i < inputElements.length; ++i){
  251.               if(inputElements[i].checked){
  252.                    checkedTempValue.push(inputElements[i].value);
  253.               }
  254.             }
  255.         //alle values auf einen String schreiben um sie per Get zu uebergeben
  256.         checkedTempValue.toString();
  257.         checkedTempValue = checkedTempValue.join(',');
  258.     }
  259.  
  260.     //Ajax teil:  
  261.     if (checkedTempValue == "") {
  262.  
  263.         alert("No temperatures are chosen!!!");
  264.         return;
  265.  
  266.     } else {
  267.             xmlhttp_get_ids = xmlrequest();
  268.             xmlhttp_fill = xmlrequest();
  269.  
  270.         //Wenn erster request finished und response ready:
  271.         xmlhttp_get_ids.onreadystatechange = function() {
  272.             if (xmlhttp_get_ids.readyState == 4 && xmlhttp_get_ids.status == 200) {
  273.                 //document.getElementById("plot_area").innerHTML = xmlhttp.responseText;//vorheriger weg
  274.                 //var data = eval("(" + xmlhttp.responseText + ")"); //unsicher
  275.                 var data = JSON.parse(xmlhttp_get_ids.responseText); //hier kommt JSON Objekt zurück
  276.                 var array = [];
  277.  
  278.                 //Objekt in Array verwandeln:
  279.                 for(var x in data){
  280.                     array.push(data[x]);
  281.                 }
  282.  
  283.                 //wenn mehrere werte -> mit komma abtrennen
  284.                 block_id = array.join(',');
  285.  
  286.                 // Wenn zweiter request finished -> füllen
  287.                 xmlhttp_fill.onreadystatechange = function() {
  288.                     if (xmlhttp_fill.readyState == 4 && xmlhttp_fill.status == 200) {
  289.                         document.getElementById("plot_X_Axis").innerHTML = xmlhttp_fill.responseText;
  290.                         document.getElementById("plot_Y_Axis").innerHTML = xmlhttp_fill.responseText;
  291.                     }
  292.                 };
  293.  
  294.                 //Zweiten Request starten (X-und Y-Achsen Auswahl befüllen)
  295.                 var x = 1;
  296.                 var y = 1;
  297.                 alert("zweiter Request");
  298.                 xmlhttp_fill.open("GET","include/get_sql_result.php?x="+x+"&y="+y+"&b="+block_id,true);
  299.                 xmlhttp_fill.send();
  300.  
  301.             }
  302.         };
  303.         alert("erster Request");
  304.         //Erster Request: (Holt Block ID) Hier muss noch Länge und Weite miteingehen:
  305.        
  306.         //Temperaturen auslesen: (nur wenn nicht von replotfunktion kommend)
  307.         if(from_replot == 0){
  308.             var inputElementsLW = getElementsByClassName(document,'messageCheckboxGeo');
  309.             checkedLWValues = [];
  310.             for(var i=0; i < inputElementsLW.length; ++i){
  311.                   if(inputElementsLW[i].checked){
  312.                        checkedLWValues.push(inputElementsLW[i].value);
  313.                   }
  314.                 }
  315.             //alle values auf einen String schreiben um sie per Get zu uebergeben
  316.             checkedLWValues.toString();
  317.             checkedLWValues = checkedLWValues.join(',');
  318.                     alert(checkedLWValues);
  319.         }
  320.  
  321.        
  322.         xmlhttp_get_ids.open("POST","include/get_sql_result.php?d="+dev_id+"&temps="+checkedTempValue+"&pt="+para_type+"&s="+sight,true);
  323.         xmlhttp_get_ids.send();
  324.  
  325.     }
  326.  
  327.  
  328. }
  329.  
  330. //Muss so geschrieben werden, dass er replot usebar ist
  331. //Plotte los!
  332. function plotData(DrawArea_replot = 0, AxisParam = 0){
  333.     //Length & Width auslesen  
  334.     /*
  335.     var inputElements = getElementsByClassName(document,'messageCheckboxGeo');
  336.     checkedGeos = [];
  337.     for(var i=0; i < inputElements.length; ++i){
  338.           if(inputElements[i].checked){
  339.                checkedGeos.push(inputElements[i].value);
  340.           }
  341.         }
  342.     //alle values auf einen String schreiben um sie per Get zu uebergeben
  343.     checkedGeos.toString();
  344.     checkedGeos = checkedGeos.join(',');
  345.    
  346.     alert(checkedGeos);
  347.     */
  348.    
  349.     //gewählte x und y werte abholen (nur wenn nicht von replot Funktion kommend):
  350.     if(AxisParam == 0){
  351.         x_Axis = document.getElementById("plot_X_Axis").options[document.getElementById("plot_X_Axis").selectedIndex].value;
  352.         y_Axis = document.getElementById("plot_Y_Axis").options[document.getElementById("plot_Y_Axis").selectedIndex].value;
  353.     }
  354.  
  355.     //alert("X Achse value: "+x_Axis);
  356.     //alert("Y Achse value: "+y_Axis);
  357.  
  358.     xmlhttp = xmlrequest();
  359.  
  360.     //Wenn request finished und response ready:
  361.     xmlhttp.onreadystatechange = function() {
  362.         if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  363.  
  364.             if(DrawArea_replot == 0)
  365.             {
  366.                 var x = document.getElementById("select_drawArea").selectedIndex;
  367.                 var y = document.getElementById("select_drawArea").options;
  368.                 DrawArea_number = y[x].value;
  369.             }else
  370.             {
  371.                 DrawArea_number = DrawArea_replot;
  372.                 //Nur reingehen, wenn von FileLoad kommend:
  373.                 alert("replot : Drawarea ist: " + DrawArea_number);
  374.             }
  375.  
  376.             //define name of plot
  377.             var name = "Techn.:" + tech_name + "Dev.:" + dev_name + "Curve:" + param_name + "Sight:" + sight;
  378.  
  379.             //Ganzer Link:
  380.             alert("<img src='functions/simpleplot.php?bid="+ block_id +"&checkedtemps="+checkedTempValue+"&xaxis="+x_Axis+"&yaxis="+y_Axis+"&name="+name+"' />");
  381.             document.getElementById(DrawArea_number).innerHTML = "<img src='functions/simpleplot.php?bid="+ block_id +"&checkedtemps="+checkedTempValue+"&xaxis="+x_Axis+"&yaxis="+y_Axis+"&name="+name+"' />";
  382.            
  383.             //richtiges Datenhandling:
  384.             if(checkedTempValue.length > 1){
  385.                 checkedTempValueArray = checkedTempValue.split(",");
  386.             }
  387.             //für jeden Plot einen new plot() erstellen und der ListofPlots ausgefüllt anhängen
  388.             assert(DrawAreaArray[DrawArea_number].ListofPlots.length === 0,"listofplots ist leer");
  389.             for(i = 0; i < checkedTempValueArray.length; i++){
  390.                 DrawAreaArray[DrawArea_number].ListofPlots.push(new plot());
  391.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setDrawArea(DrawArea_number);
  392.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setTechnology(tech_name);
  393.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setDevice(dev_name);
  394.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setCurve(para_type);
  395.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setSight(sight);
  396.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setTemps(checkedTempValueArray[i]);
  397.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setxValue(x_Axis);
  398.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setyValue(y_Axis);
  399.                 DrawAreaArray[DrawArea_number].ListofPlots[i].setBlockID(block_id);
  400.             }
  401.             alert(DrawAreaArray[DrawArea_number].ListofPlots[0].Temps);
  402.         }
  403.     };
  404.     alert("Temperaturen in plotData(): "+checkedTempValueArray);
  405.     xmlhttp.open("POST","include/get_sql_result.php?d="+dev_id+"&temps="+checkedTempValueArray+"&pt="+para_type+"&s="+sight,true);
  406.     xmlhttp.send();
  407.  
  408. }
  409.  
  410. //Klassendefinition für DrawArea
  411. function DrawArea(title) {    
  412.  
  413.    //drei DIVs für eine DrawArea
  414.    this.WrapperDiv = document.createElement("div");
  415.    this.TitleDiv = document.createElement("div");
  416.    this.ContentDiv = document.createElement("div");
  417.  
  418.    this.WrapperDiv.className = "drawArea";
  419.    this.TitleDiv.className = "";
  420.    this.ContentDiv.className = "";
  421.  
  422.    //this.ListofPlots = new plot();
  423.    this.ListofPlots = [];
  424.    
  425.    //X und Y Achse:
  426.    this.xValue = "";
  427.    this.yValue = "";
  428.    
  429.    // öffentliche (public) Eigenschaften
  430.    this.WrapperDiv.id = 0;    
  431.    this.title = title;
  432.    //var newContent = document.createTextNode("new DrawArea");
  433.  
  434.    var h = document.createElement("h1"); //Erstelle H1 Html Element
  435.    var t = document.createTextNode(title);    
  436.    h.appendChild(t);  //Hänge Titel Text bei H1 ein
  437.  
  438.    var text = document.createTextNode("Choose your options in the left box. Your graph will be displayed here. ");  
  439.  
  440.    //this.WrapperDiv.appendChild(newContent); // füge den Textknoten zum neu erstellten div hinzu.
  441.    this.TitleDiv.appendChild(h); //Titel hinzufügen
  442.    this.ContentDiv.appendChild(text);
  443.  
  444.    //Title und Content bei Wrapper einhängen
  445.    this.WrapperDiv.appendChild(this.TitleDiv);
  446.    this.WrapperDiv.appendChild(this.ContentDiv);
  447.  
  448.  
  449.    // privilegierte öffentliche Methode
  450.    this.setId = function(id) {        
  451.        this.WrapperDiv.id = id;      
  452.     };    
  453.  
  454.    this.setTitle = function(title) {        
  455.        this.title = title;        
  456.     };    
  457.  
  458.  
  459. }
  460.  
  461. //Klasse um Plots einer DrawArea zu speichern
  462. function plot(){
  463.  
  464.     this.DrawArea = "";
  465.     this.Technology = "";
  466.     this.Device = "";
  467.     this.Curve = "";
  468.     this.Sight = "";
  469.     this.Temps = "";
  470.     this.xValue = "";
  471.     this.yValue = "";
  472.     this.BlockID = "";
  473.  
  474.    // privilegierte öffentliche Methode
  475.    this.setDrawArea = function(id) {        
  476.        this.DrawArea = id;      
  477.     };    
  478.  
  479.    this.setTechnology = function(technology) {        
  480.        this.Technology = technology;        
  481.     };    
  482.  
  483.     this.setDevice = function(device) {        
  484.        this.Device = device;        
  485.     };  
  486.  
  487.     this.setCurve = function(curve) {        
  488.        this.Curve = curve;        
  489.     };  
  490.  
  491.     this.setSight = function(sight) {        
  492.        this.Sight = sight;        
  493.     };  
  494.  
  495.     this.setTemps = function(temps) {        
  496.        this.Temps = temps;        
  497.     };  
  498.    
  499.     this.setxValue = function(xValue) {        
  500.        this.xValue = xValue;        
  501.     };  
  502.    
  503.     this.setyValue = function(yValue) {        
  504.        this.yValue = yValue;        
  505.     };  
  506.  
  507.     this.setBlockID = function(BlockID) {        
  508.        this.BlockID = BlockID;        
  509.     };  
  510.    
  511.    
  512. }
  513.  
  514. function add_DrawArea(){
  515.     // erstelle ein neues div Element
  516.     // und gib ihm etwas Inhalt
  517.     //currentDiv ist umschliessendes DIV der DrawAreas
  518.     var currentDiv = document.getElementById("center_this");
  519.  
  520.     //Objekte in currentDiv zählen:
  521.     var DrawArea_counter = getElementsByClassName(document,"drawArea").length;
  522.  
  523.     //object_counter erhöhen um neuer DrawArea die richtige ID zu geben
  524.     DrawArea_counter++;
  525.     alert("generate DrawArea: "+'DrawArea_'+ DrawArea_counter);
  526.     newDrawArea = new DrawArea('DrawArea_'+ DrawArea_counter);
  527.     //id festlegen um hinterher graphen in die richtige DrawArea zu bauen
  528.     newDrawArea.setId("DrawArea_"+DrawArea_counter);
  529.  
  530.     // füge das neu erstellte Element und seinen Inhalt ins DOM ein - dem bestehenden DIV hinzufügen:
  531.     currentDiv.appendChild(newDrawArea.WrapperDiv);
  532.  
  533.     //leeren Absatz einfügen
  534.     var newbr = document.createElement("br");
  535.     currentDiv.appendChild(newbr);
  536.  
  537.     //DrawArea in Array abspeichern:
  538.     DrawAreaArray["DrawArea_"+DrawArea_counter] = newDrawArea;
  539.  
  540.     //Eigene Funktion um Dropdowns zu aktualisieren
  541.     refreshPlotDropdowns();
  542.  
  543. }
  544.  
  545. //DrawArea löschen
  546. function remove_DrawArea(){  
  547.     //ausgewählten Wert holen:
  548.     var x = document.getElementById("editDrawArea").selectedIndex;
  549.     var y = document.getElementById("editDrawArea").options;
  550.  
  551.     alert("DrawAreaIndex: "+y[x].value);
  552.  
  553.     var id_element = y[x].value;
  554.     //alert(id_element);
  555.     //var element = document.getElementById(id_element);
  556.  
  557.     var element = document.getElementById(id_element);
  558.     alert("element: "+element);
  559.     //checken ob etwas ausgewählt wurde und Element löschen
  560.     if(element === null){
  561.         alert("Choose a DrawArea!");
  562.     }else{      
  563.     element.parentNode.removeChild(element);
  564.     alert("reingesprungen " + element);
  565.     }
  566.  
  567.     //Eigene Funktion um Dropdowns zu aktualisieren
  568.     refreshPlotDropdowns();
  569. }
  570.  
  571. //DrawArea Dropdowns auf Plot Seite aktualisieren
  572. function refreshPlotDropdowns(){
  573.  
  574.     //-----Dropdown aktualisieren (auch das rechte)-----
  575.     //Anzahl vorhandener DrawAreas holen:
  576.     var DrawArea_counter = getElementsByClassName(document,"drawArea").length; //Anzahl DrawAreas
  577.     //alert("Anzahl vorhandener DrawAreas: "+DrawArea_counter);
  578.  
  579.     //---------linkes Dropdown----------:
  580.     var selectElement = document.getElementById('select_drawArea');
  581.  
  582.     //Default Wert löschen:
  583.     for (var i=0; i<selectElement.length; i++)
  584.     {
  585.         if (selectElement.options[i].value === 'DrawArea_1' )
  586.            selectElement.remove(i);
  587.     }
  588.  
  589.     var option = document.createElement('option');
  590.  
  591.     //Options hinzufügen
  592.     for(var i=1; i < DrawArea_counter+1 ;i++){
  593.       var option = document.createElement('option');
  594.       option.text = 'DrawArea '+i;
  595.       option.value = 'DrawArea_'+i;
  596.       selectElement.options[i] = option;
  597.     }
  598.  
  599.     //---------rechtes Dropdown----------:
  600.     selectElement = document.getElementById('editDrawArea');
  601.  
  602.     //Default Wert löschen:
  603.     for (var i=0; i<selectElement.length; i++)
  604.     {
  605.         if (selectElement.options[i].value === 'DrawArea_1' )
  606.            selectElement.remove(i);
  607.     }
  608.  
  609.     for(var i=1; i < DrawArea_counter+1 ;i++){
  610.       var option = document.createElement('option');
  611.       option.text = 'DrawArea '+i;
  612.       option.value = 'DrawArea_'+i;
  613.       selectElement.options[i] = option;
  614.     }
  615.  
  616.  
  617. }
  618.  
  619. function fill_edit_box(){
  620.  
  621.     //Vorherige Checkboxen entfernen:
  622.     document.getElementById("replot_box").innerHTML = "";
  623.  
  624.     //ausgewählten Wert holen:
  625.     var x = document.getElementById("editDrawArea").selectedIndex;
  626.     var y = document.getElementById("editDrawArea").options;
  627.     var id_element = y[x].value;
  628.     alert("current area changed: "+ id_element +"Titel: " +DrawAreaArray[id_element].title);
  629.  
  630.     //Textbox befüllen
  631.     document.getElementById("title_text").value = DrawAreaArray[id_element].title;
  632.     var size = Object.size(DrawAreaArray);
  633.     alert("Anzahl DrawAreas: "+size);
  634.    
  635.     //Anzahl Plots in Plotlist:
  636.     amount_plots_drawArea = DrawAreaArray[id_element].ListofPlots.length;
  637.     alert(amount_plots_drawArea);
  638.    
  639.     //Schleife um für jeden Graphen eine Checkbox anzuzeigen
  640.     for(var i = 0; i < amount_plots_drawArea; i++){
  641.  
  642.         //Werte der Graphen auslesen:
  643.         var technology = DrawAreaArray[id_element].ListofPlots[i].Technology;
  644.         var device = DrawAreaArray[id_element].ListofPlots[i].Device;
  645.         var curve = DrawAreaArray[id_element].ListofPlots[i].Curve;
  646.         var sight = DrawAreaArray[id_element].ListofPlots[i].Sight;
  647.         var temps = DrawAreaArray[id_element].ListofPlots[i].Temps;
  648.         var DrawArea = DrawAreaArray[id_element].ListofPlots[i].DrawArea;
  649.  
  650.         //alert("Technology " + technology + " Device: " + device + " Curve: " + curve + " Sight: " + sight + " temps: "+ temps);
  651.        
  652.         var input = document.createElement("input");
  653.  
  654.         //Accordion Überschrift:
  655.         var accordion = document.createElement("h3");
  656.  
  657.         //Accordion Inhalt:
  658.         var div_accordion = document.createElement("div");
  659.  
  660.         //Text in Accordion Header einfügen
  661.         var label = document.createElement('label');
  662.         label.htmlFor = "id";
  663.         label.appendChild(document.createTextNode(technology+" "+device+" "+curve+" "+sight+" "+temps+" "));
  664.         accordion.appendChild(label);
  665.  
  666.         //Checkbox:
  667.         input.type = "checkbox";
  668.         input.className = "PlotCheckbox"; // set the CSS class
  669.  
  670.         //alert("value checkbox: "+technology+" "+device+" "+curve+" "+sight+" "+temps);
  671.        
  672.         input.value = (technology+" "+device+" "+curve+" "+sight+" "+temps +" "+ DrawArea);
  673.         input.name = "TEST";
  674.        
  675.         var title = (technology+" "+device+" "+curve+" "+sight+" "+temps +" "+ DrawArea);
  676.         accordion_content = "<img src='./img/edit_button.png' style='width:22px;height:22px;' title='edit this plot' >" + title;
  677.         addAccordion();
  678.        
  679.         /*
  680.         //Plot Aktiv/Nicht Aktiv:
  681.         div_accordion.appendChild(input);
  682.         var label_2 = document.createElement("label_2");
  683.         label_2.appendChild(document.createTextNode("active/not active"));
  684.         div_accordion.appendChild(label_2);
  685.  
  686.         //Zeilenumbruch:
  687.         var br = document.createElement("br");
  688.         div_accordion.appendChild(br);
  689.  
  690.         //Edit Button einfügen:
  691.         var editButton = document.createElement("img");
  692.         editButton.src = "./img/edit_button.png";
  693.         editButton.style= "width:22px;height:22px;";
  694.         editButton.title = "edit this plot";
  695.         div_accordion.appendChild(editButton);
  696.  
  697.  
  698.         //Accordion einfügen
  699.         document.getElementById("replot_box").appendChild(accordion);
  700.         document.getElementById("replot_box").appendChild(div_accordion);
  701.         */
  702.     }
  703.     alert("start accordion");
  704.     //accordion aktivieren:
  705.     //$( "#replot_box" ).accordion();
  706.    
  707.     alert("start2 accordion");
  708. }
  709.  
  710. function set_DrawArea_title(){
  711.    //Auslesen was in Textfeld steht:
  712.     var text = document.getElementById("title_text").value;
  713.  
  714.     //Welche DrawArea?
  715.     var x = document.getElementById("editDrawArea").selectedIndex;
  716.     var y = document.getElementById("editDrawArea").options;
  717.     var id_element = y[x].value;
  718.  
  719.     //Zum erneuten Auslesen zwischenspeichern:
  720.     DrawAreaArray[id_element].setTitle(text);
  721.  
  722.     //Titel über Geschwisterelement im DOM setzen
  723.     document.getElementById(id_element).previousSibling.childNodes[0].innerHTML = text ;
  724.  
  725. }
  726.  
  727. function replotfromEditBox(){
  728.     //arrays leeren damit alte Daten verschwinden:
  729.     var checkedPlots_split = [];
  730.         checkedTempValue.length = 0;
  731.  
  732.     var checkedPlots = [];
  733.     var inputElements = getElementsByClassName(document,'PlotCheckbox');
  734.     for(var i=0; i < inputElements.length; ++i){
  735.           if(inputElements[i].checked){
  736.                checkedPlots.push(inputElements[i].value);
  737.           }
  738.         }
  739.  
  740.     //Globale Variablen neu zuweisen:
  741.     for(var i = 0; i < checkedPlots.length; i++){
  742.             checkedPlots_split[i] = checkedPlots[i].split(" ");
  743.             /*
  744.             alert("Technologie: "+checkedPlots_split[i][0]);        
  745.             alert("Device: "+checkedPlots_split[i][1]);
  746.             alert("Curve: "+checkedPlots_split[i][2]);
  747.             alert("Sight: "+checkedPlots_split[i][3]);
  748.             alert("Temperatur: "+checkedPlots_split[i][4]);
  749.             */
  750.            checkedTempValue.push(checkedPlots_split[i][4]);
  751.     }
  752.     //Neuzuweisung globale Variablen (Vom ersten Graphen):
  753.     tech_name = checkedPlots_split[0][0];
  754.     dev_name = checkedPlots_split[0][1];
  755.     para_type = checkedPlots_split[0][2];
  756.     sight = checkedPlots_split[0][3] ;
  757.     var DrawArea = checkedPlots_split[0][5] ;
  758.  
  759.        
  760.     alert("replotfunktion: " +checkedPlots);
  761.     alert(checkedPlots[0]);
  762.     //Plotte mit neuen Daten los:
  763.     updateXAxisYAxisSelect(1);
  764.     plotData(DrawArea);
  765.    
  766. }
  767.  
  768. function getElementsByClassName(node, classname) {
  769.     var a = [];
  770.     var re = new RegExp('(^| )'+classname+'( |$)');
  771.     var els = node.getElementsByTagName("*");
  772.     for(var i=0,j=els.length; i<j; i++)
  773.         if(re.test(els[i].className))a.push(els[i]);
  774.     return a;
  775. }
  776. var tabs = getElementsByClassName(document.body,'tab');
  777.  
  778. //SettingsFenster (für LOAD / SAVE)
  779. function OpenSettingsWindow (Adresse) {
  780.     MeinFenster = window.open(Adresse, "Zweitfenster", "width=300,height=400,left=100,top=200");
  781.     MeinFenster.document.write("<p>ein neues Fenster!<br>(Besser wäre aber eine dialog-Box!)</p>");
  782.     MeinFenster.focus();
  783. }
  784.  
  785. //Funktioniert soweit (27.06.2016)
  786. function SaveConfigAs(){
  787.     var filename = document.getElementById("save-filename").value;
  788.     filename = filename + ".txt";
  789.     //Die gesamte bisherige Auswahl muss da rein:
  790.     var config = [];
  791.    
  792.     //Config erstellen:
  793.     //Anzahl DrawAreas:
  794.     var DrawArea_amount = Object.size(DrawAreaArray);
  795.  
  796.     //Anzahl Plots in Plotlist:
  797.     for(var j = 1; j < DrawArea_amount+1; j++){
  798.        
  799.         amount_plots_drawArea = DrawAreaArray["DrawArea_"+j].ListofPlots.length;
  800.        
  801.         //Nur wenn schon Graphen gezeichnet wurden:
  802.         if(amount_plots_drawArea > 0){
  803.             //Werte der Graphen auslesen:
  804.            // var DrawArea = DrawAreaArray["DrawArea_"+j].ListofPlots[0].DrawArea;
  805.            
  806.             var technology = DrawAreaArray["DrawArea_"+j].ListofPlots[0].Technology;
  807.             //alert(technology);
  808.             var device = DrawAreaArray["DrawArea_"+j].ListofPlots[0].Device;
  809.             //alert(device);
  810.             var curve = DrawAreaArray["DrawArea_"+j].ListofPlots[0].Curve;
  811.             //alert(curve);
  812.             var sight = DrawAreaArray["DrawArea_"+j].ListofPlots[0].Sight;
  813.             var xValue = DrawAreaArray["DrawArea_"+j].ListofPlots[0].xValue;
  814.             var yValue = DrawAreaArray["DrawArea_"+j].ListofPlots[0].yValue;
  815.             var block_id = DrawAreaArray["DrawArea_"+j].ListofPlots[0].BlockID;
  816.            
  817.             var temps = [];
  818.             //Temperaturen:
  819.         for(var i = 0; i < amount_plots_drawArea; i++){
  820.             temps.push(DrawAreaArray["DrawArea_"+j].ListofPlots[i].Temps);
  821.         }
  822.             //alert(temps);
  823.  
  824.             config.push(DrawAreaArray["DrawArea_"+j].title +":"+ technology+";"+device+";"+curve + ";" + sight + ";" + block_id + ";" + xValue + ";" + yValue + ";" +temps+"\n")
  825.  
  826.         }
  827.         else{
  828.             alert("No plots in DrawArea_"+j);
  829.         }
  830.  
  831.  
  832.     }
  833.     //alert(config);
  834.     //um letztes newline zu entfernen
  835.     //
  836.     config[config.length-1] = config[config.length-1].substring(0, config[config.length-1].length-1);
  837.     var blob = new Blob(config, {type: "text/plain;charset=utf-8"});
  838.     saveAs(blob, filename);  //FileSaver.js
  839. }
  840.  
  841. //Funktioniert soweit (27.06.2016)
  842. function LoadConfigAs(){
  843.    
  844.     //Get File
  845.     var fileInput = document.getElementById('fileInput');
  846.     var file = fileInput.files[0];
  847.    
  848.     //Init Variable for read content from textfile
  849.     var read_input
  850.     DrawAreasFromFile = [];
  851.     technologie_temp = [];
  852.     device_temp = [];
  853.     curve_temp = [];
  854.     sight_temp = [];
  855.     block_id_temp = [];
  856.     xValue_temp = [];
  857.     yValue_temp = [];
  858.    
  859.    
  860.     temperatures_temp = [];
  861.    
  862.     //output String:
  863.     var loadedConfigDesription = "";
  864.    
  865.     //Supported FileType:alert
  866.     var textType = "text/plain";
  867.    
  868.     //Get Area where information should be printed in
  869.     var loadedConfig = document.getElementById('loadedConfig');
  870.  
  871.     //Check if Filetype is ok and read content:
  872.     if (file.type.match(textType)) {
  873.         var reader = new FileReader();
  874.         //alert("Texttype in Ordnung");
  875.         reader.onload = function(e) {
  876.             read_input = reader.result;
  877.             //alert("Inhalt der Textdatei: "+read_input);
  878.            
  879.             //Zeile um Zeile splitten:
  880.             read_input = read_input.split("\n");
  881.  
  882.             for(var i = 0; i<read_input.length; i++){
  883.                 //array für temperaturen initialisieren:
  884.                 temperatures_temp[i] = [];
  885.                
  886.                 DrawAreasFromFile[i] = read_input[i].split(":")[0]; //drawArea
  887.                 technologie_temp[i] = read_input[i].split(":")[1].split(";")[0]; //technology
  888.                 //alert("techn. : "+technologie_temp[i]);
  889.                 device_temp[i] = read_input[i].split(";")[1]; //device
  890.                 curve_temp[i] = read_input[i].split(";")[2];
  891.                 sight_temp[i] = read_input[i].split(";")[3];
  892.                 block_id_temp[i] = read_input[i].split(";")[4];
  893.                 xValue_temp[i] = read_input[i].split(";")[5];
  894.                 yValue_temp[i] = read_input[i].split(";")[6];
  895.                
  896.                 //schleife um alle temperaturen abzuholen:
  897.                 for(var j = 7; j<read_input[i].split(";").length; j++){
  898.                     temperatures_temp[i].push(read_input[i].split(";")[j]);
  899.                 }
  900.                 loadedConfigDesription = loadedConfigDesription + DrawAreasFromFile[i] + ":<br>Technology: "+ technologie_temp[i] + "<br>Device: "+ device_temp[i] +"<br>Curve: " + curve_temp[i] + "<br>Sight: " + sight_temp[i] + "<br>xAxis: " + xValue_temp[i] + "<br>yAxis: " + yValue_temp[i] + "<br>Temperatures: " +  temperatures_temp[i] +"<br><br>";
  901.             }
  902.             //Button um Config nachzuplotten einfügen:
  903.             loadedConfigDesription = loadedConfigDesription + "<br><input type='button' value='Replot from this Config' onclick='ReplotConfig()'/>";
  904.             //Schreibe Inhalt der Textdatei unter Ladebutton:
  905.             loadedConfig.innerHTML = loadedConfigDesription;
  906.  
  907.         }
  908.  
  909.         reader.readAsText(file);    
  910.     } else {
  911.         //alert("File not supported! Only .txt Files supported!");
  912.     }
  913.    
  914. }
  915.  
  916. function ReplotConfig(){
  917.     if (confirm("Are you sure? everything of the current session will be lost.") == true) {
  918.        
  919.         //erstmal alle vorhandenen DrawAreas löschen:
  920.         var DrawArea_counter = getElementsByClassName(document,"drawArea").length; //wie viele DrawAreas gibt es momentan?
  921.         for(var i = 1; i < DrawArea_counter + 1; i++ ){
  922.             id_element = "DrawArea_" + i;
  923.             var element = document.getElementById(id_element);
  924.             if(element != null){    
  925.                 element.parentNode.removeChild(element);
  926.             }    
  927.         }
  928.        
  929.         //jetzt DrawAreas erzeugen, bis Anzahl gleich der Anzahl im Textfile
  930.         while(DrawArea_counter < DrawAreasFromFile.length){
  931.             add_DrawArea();
  932.             DrawArea_counter = getElementsByClassName(document,"drawArea").length; //wie viele DrawAreas gibt es momentan?
  933.         }
  934.  
  935.         //Plotte eingelesene Daten:
  936.        
  937.  
  938.         for(var i = 0; i < DrawArea_counter; i++){
  939.         //Neuzuweisung globale Variablen (Vom ersten Graphen):            
  940.             tech_name = technologie_temp[i];
  941.             dev_name = device_temp[i];
  942.             para_type = curve_temp[i];
  943.             sight = sight_temp[i] ;
  944.             x_Axis = xValue_temp[i];
  945.             y_Axis = yValue_temp[i];
  946.             block_id = block_id_temp[i];
  947.             checkedTempValue = temperatures_temp[i];
  948.             //alle values auf einen String schreiben um sie per Get zu uebergeben
  949.             checkedTempValue.toString();
  950.             checkedTempValue = checkedTempValue.join(',');
  951.            
  952.             alert("In replot funktion: temps: " + checkedTempValue);
  953.             var DrawArea = DrawAreasFromFile[i] ;
  954.             //Plotte mit neuen Daten los:
  955.             alert("Aufruf von plotData Nummer " + i + "DrawAreas to plot: "+  DrawArea_counter);
  956.             plotData(DrawArea,1);
  957.         }
  958.  
  959.     }
  960.    
  961.    
  962. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement