From 8cba8a37aa7d536ec33d508b12fdbdebb8dd3ec8 Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Wed, 17 Dec 2014 17:21:03 +0100 Subject: [PATCH] added setup file move/copy/delete operations to testgui --- layout/testgui.css | 4 ++ tools/editor.pl | 37 +++++++++++++++ tools/testgui.js | 112 +++++++++++++++++++++++++++++++++++++++++++-- tools/testgui.pl | 24 ++++++++-- 4 files changed, 169 insertions(+), 8 deletions(-) diff --git a/layout/testgui.css b/layout/testgui.css index f6817ec..c99c8b8 100644 --- a/layout/testgui.css +++ b/layout/testgui.css @@ -7,6 +7,10 @@ visibility:visible; } +.hidden_by_default { + display:none; +} + #theConsoleContainer { /* visibility:collapse; */ margin:5px; diff --git a/tools/editor.pl b/tools/editor.pl index 0d46f01..5a483e3 100755 --- a/tools/editor.pl +++ b/tools/editor.pl @@ -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 => \©_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 { diff --git a/tools/testgui.js b/tools/testgui.js index b7a495e..ebf56bf 100644 --- a/tools/testgui.js +++ b/tools/testgui.js @@ -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(" ... "); +} diff --git a/tools/testgui.pl b/tools/testgui.pl index a9829b0..deaa28b 100755 --- a/tools/testgui.pl +++ b/tools/testgui.pl @@ -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 ""; + + print ""; + print ""; + print ""; + print ""; + + print ""; + + print "
"; + print "
"; print "chose setup: "; print ""; $setup_selector->print_html(); @@ -163,7 +164,21 @@ sub init_html{ print "edit setup file"; print ""; print "edit system file"; - print "
"; + print "
"; + print "copy/move setup file"; + print "
new filename:"; + print ""; + print ""; + print "
"; print_setupStructure(); @@ -186,6 +201,7 @@ sub init_html{ print "