]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
added setup file move/copy/delete operations to testgui
authorMichael Wiebusch <m.wiebusch@gsi.de>
Wed, 17 Dec 2014 16:21:03 +0000 (17:21 +0100)
committerMichael Wiebusch <m.wiebusch@gsi.de>
Wed, 17 Dec 2014 16:21:03 +0000 (17:21 +0100)
layout/testgui.css
tools/editor.pl
tools/testgui.js
tools/testgui.pl

index f6817ecadb82220ea985bcac3095595c15bacf92..c99c8b8fd57fa306a5b479e7d8d653f3b721bc0e 100644 (file)
@@ -7,6 +7,10 @@
   visibility:visible;
 }
 
+.hidden_by_default {
+  display:none;
+}
+
 #theConsoleContainer {
 /*   visibility:collapse; */
   margin:5px;
index 0d46f017fdbadbea0f34cae702ac3b66aa53a446..5a483e3d72633b23904478c9a5e4dd1a91f4d994 100755 (executable)
@@ -15,6 +15,7 @@ use FindBin;
 use lib "$FindBin::Bin/..";
 use Environment;
 use File::Basename;
+use File::Copy;
 
 
 my $shared;
@@ -25,6 +26,9 @@ my $shared;
 my $dispatch = {
   table_hash => \&table_hash,
   print_file => \&print_file,
+  delete_file => \&delete_file,
+  copy_file => \&copy_file,
+  move_file => \&move_file,
   write_file => \&write_file
 };
 
@@ -126,6 +130,39 @@ sub write_file {
   print "saved!";
 }
 
+sub delete_file {
+  my $file = $q->param('file');
+  if ( -e $file ) {
+    unlink($file) or die "error while deleting file";
+    print "file was deleted";
+  } else {
+    print "selected file not found";
+  }
+}
+
+sub move_file {
+  my $file = $q->param('file');
+  my $newFile = $q->param('newFile');
+  
+  if( -e $newFile ) {
+    print "file already exists!";
+  } else {
+    move($file,$newFile) or die "move failed!";
+    print "file moved!";
+  }
+}
+
+sub copy_file {
+  my $file = $q->param('file');
+  my $newFile = $q->param('newFile');
+  
+  if( -e $newFile ) {
+    print "file already exists!";
+  } else {
+    copy($file,$newFile) or die "copy failed!";
+    print "file copied!";
+  }
+}
 
 sub passHashToJs {
 
index b7a495ed4cc89d8406f35d4383fb1bb89af1165d..ebf56bf4c7f5dcb68d963159210dc29909638de0 100644 (file)
@@ -49,6 +49,86 @@ function startupOnly(){
   
 }
 
+function delete_file(){
+      $.ajax({
+        url:       "editor.pl",
+        cache:     false,
+        async:     false,
+        dataType:  "text",
+        data:      {
+          sub        : "delete_file",
+          file       : setupFile
+        },
+        success:   function(result) {
+          $("#report").html(result);
+        }
+     }); 
+}
+
+function get_newFilename() {
+  var fileName = $("#input_newFilename").val();
+  var patt = /\.xml/i;
+  if(patt.test(fileName)){
+    return fileName;
+  } else {
+    return fileName+".xml";
+  }
+}
+
+function copy_file(){
+      $.ajax({
+        url:       "editor.pl",
+        cache:     false,
+        async:     false,
+        dataType:  "text",
+        data:      {
+          sub        : "copy_file",
+          file       : setupFile,
+          newFile    : setupDir+get_newFilename()
+        },
+        success:   function(result) {
+          $("#report").html(result);
+          set_clear_timer();
+        }
+     }); 
+}
+
+function move_file(){
+      $.ajax({
+        url:       "editor.pl",
+        cache:     false,
+        async:     false,
+        dataType:  "text",
+        data:      {
+          sub        : "move_file",
+          file       : setupFile,
+          newFile    : setupDir+get_newFilename()
+        },
+        success:   function(result) {
+          $("#report").html(result);
+          set_clear_timer();
+        }
+     }); 
+}
+
+function delete_file(){
+      $.ajax({
+        url:       "editor.pl",
+        cache:     false,
+        async:     false,
+        dataType:  "text",
+        data:      {
+          sub        : "delete_file",
+          file       : setupFile
+        },
+        success:   function(result) {
+          $("#report").html(result);
+          set_clear_timer();
+        }
+     }); 
+}
+
+var timer;
 
 $(document).ready(function(){
 
@@ -61,21 +141,45 @@ $(document).ready(function(){
   $("#setupeditorlink").attr("href","editor.pl?file="+encodeURIComponent(setupFile));
   $("#systemeditorlink").attr("href","editor.pl?file="+encodeURIComponent(systemFile));
   
-  $("#advancedOptionsContainer").hide();
-  $("#theConsoleContainer").hide();
+  $("#setupcopylink").click(function(){
+    $("#setup_options_container").fadeToggle();
+  });
+  
+  $("#button_copy").click(function(){
+    copy_file();
+  });
+  $("#button_move").click(function(){
+    move_file();
+  });
+  $("#button_delete").click(function(){
+    delete_file();
+  });
     
   $("#advoptbtn").click(function(){
 //     toggleVis("advancedOptionsContainer");
     $("#advancedOptionsContainer").fadeToggle();
     var $target = $('html,body'); 
-    $target.animate({scrollTop: $target.height()}, 1000);
+//     $target.animate({scrollTop: $target.height()}, 1000);
   });
   $("#debugbtn").click(function(){
 //     toggleVis("theConsoleContainer");
     $("#theConsoleContainer").fadeToggle();
     var $target = $('html,body'); 
-    $target.animate({scrollTop: $target.height()}, 1000);
+//     $target.animate({scrollTop: $target.height()}, 1000);
   });
   
   
+  timer = $.timer(function() {
+    clear_report();
+    timer.stop();
+  });
+  
 });
+
+function set_clear_timer(){
+     timer.set({time:3000,autostart: true});
+}
+
+function clear_report (){
+   $("#report").html(" ... ");
+}
index a9829b00c0fd085c318c2b23f45480dcda86da14..deaa28b132c48e5bc5c68206d639057597c377e6 100755 (executable)
@@ -141,6 +141,7 @@ sub init_html{
   { -type => 'text/javascript', -src => './testgui.js'},
   { -type => 'text/javascript', -src => './hideAndShow.js'},
   { -type => 'text/javascript', -src => './getdata.js'},
+  { -type => 'text/javascript', -src => '../scripts/jquery.timer.js'},
   { -type => 'text/javascript', -src => './xmlOperations.js'}
   ]
   );
@@ -155,7 +156,7 @@ sub init_html{
   $setup_selector->add_item(value=>'...');
   $setup_selector->add_items_from_dir(dir=>$setupDir,ext=>"xml");
   
-  print "<table><tr><td>";
+  print "<table><tr><td align='right'>";
   print "chose setup: ";
   print "</td><td>";
   $setup_selector->print_html();
@@ -163,7 +164,21 @@ sub init_html{
   print "<a href='#' id='setupeditorlink' >edit setup file</a>";
   print "</td><td>";
   print "<a href='#' id='systemeditorlink' >edit system file</a>";
-  print "</td></tr></table>";
+  print "</td><td>";
+  print "<a href='#' id='setupcopylink' >copy/move setup file</a>";
+  print "</td></tr>";
+  
+  print "<tr id='setup_options_container' class='hidden_by_default'>";
+  print "<td align='right'>new filename:</td>";
+  print "<td colspan=2><input type='text' id='input_newFilename'>";
+  print "<input type='button' id='button_copy' value='copy'>";
+  print "<input type='button' id='button_move' value='move'>";
+  print "<input type='button' id='button_delete' value='delete'></td>";
+  print "<td colspan=5 id='report'></td>";
+  
+  print "</tr>";
+  
+  print "</table>";
   
   print_setupStructure();
 
@@ -186,6 +201,7 @@ sub init_html{
   print "<script language='javascript'>\n";
   print q%var setupFile = '%.$setupFile.q%';%."\n";
   print q%var systemFile = '%.SYSTEMDIR."/".$systemName.".xml".q%';%."\n";
+  print q%var setupDir = '%.SETUPDIR.q%';%."\n";
   print "var previewAreaIdHash = new Object();\n";
   for my $sensorId (keys %previewAreaIdHash){
     print "previewAreaIdHash[\"$sensorId\"]=\"".$previewAreaIdHash{$sensorId}."\";\n";
@@ -201,7 +217,7 @@ sub init_html{
 
   print "</p>";
   
-  print "<div id='advancedOptionsContainer' class='stylishBox'>";
+  print "<div id='advancedOptionsContainer' class='stylishBox hidden_by_default'>";
   print "<div class='header'>advanced options</div>";
   print "<div id='advancedOptions'>";
   
@@ -216,7 +232,7 @@ sub init_html{
   print "</div>";
   
   
-  print "<div id='theConsoleContainer' class='stylishBox'>";
+  print "<div id='theConsoleContainer' class='stylishBox hidden_by_default'>";
   print "<div class='header'>debug output</div>";
   print "<div id='theConsole'>[the \"console\"]</div>";
   print "</div>";