From: hickert Date: Tue, 17 Apr 2007 06:37:58 +0000 (+0000) Subject: Added warning if content was modified but not saved yet. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4227a759c3e9de07d2f56a3584482b1e57f92dd1;p=gosa.git Added warning if content was modified but not saved yet. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@6059 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc index 83a10850b..a8230776f 100644 --- a/plugins/addons/gotomasses/class_gotomasses.inc +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -14,7 +14,13 @@ class gotomasses extends plugin var $file_to_read = "Undefined"; #Set in constructor /* Parsed csv content */ - var $contents = array(); + var $contents = array(); + + /* Used to detect changes made on the csv content. + * Buttons will be disabled and js warnings will be + * shown if the content wasn't saved or discarded + */ + var $contents_backup = array(); function gotomasses($config, $dn= NULL) @@ -82,12 +88,38 @@ class gotomasses extends plugin /* Call parent execute */ plugin::execute(); $smarty= get_smarty(); + $smarty->assign("contents_modified",$this->contents_modified()); $smarty->assign("ogs", $this->get_object_groups()); $smarty->assign("contents", $this->contents); $smarty->assign("launchimage","images/launch.png"); return ($smarty->fetch (get_template_path('contents.tpl', TRUE))); } + + /* Check if something is modified */ + function contents_modified($display = FALSE) + { + $a = $this->contents; + $b = $this->contents_backup; + if(count($a) != count($b)){ + if($display){ + print_a(array_diff_assoc($a,$b)); + } + return(TRUE); + }else{ + foreach($a as $a_key => $a_val){ + if(count(array_diff($a_val, $b[$a_key]))){ + + if($display){ + print_a(array_diff($a_val, $b[$a_key])); + } + return(TRUE); + } + } + } + return(FALSE); + } + function load_csv_data($data = NULL) { @@ -131,6 +163,7 @@ class gotomasses extends plugin } } } + $this->contents_backup = $this->contents; } @@ -186,6 +219,11 @@ class gotomasses extends plugin /* Write back all changes */ if(isset($_POST['save_gotomass_changes'])){ $this->save_csv_data(); + + /* Call load again, so we will see if everything is fine. + * And load_csv_data causes the contents_backup to be updated + */ + $this->load_csv_data(); } /* Reload data from csv file ? */ diff --git a/plugins/addons/gotomasses/contents.tpl b/plugins/addons/gotomasses/contents.tpl index 59bfa56a0..f2d108f58 100644 --- a/plugins/addons/gotomasses/contents.tpl +++ b/plugins/addons/gotomasses/contents.tpl @@ -82,8 +82,25 @@

 

+{if $contents_modified} +{else} + + +{/if}

+ + +{if !$contents_modified} + +{/if} + + + + + + + diff --git a/plugins/addons/gotomasses/main.inc b/plugins/addons/gotomasses/main.inc index 89dea8fb8..07877f190 100644 --- a/plugins/addons/gotomasses/main.inc +++ b/plugins/addons/gotomasses/main.inc @@ -30,7 +30,9 @@ if (!$remove_lock){ /* Execute formular */ $display= $gotomasses->save_object(); $display= $gotomasses->execute (); - $display.= "\n"; + +/* Ignore plugin changes is handled by the gotomasses class itself */ +# $display.= "\n"; /* Page header*/ $display= print_header(get_template_path('images/system.png'), _("Mass machine deployment")).$display;