[icinga-checkins] icinga.org: icinga-web/mhein/extlayout: * Simple Preference editor added

git at icinga.org git at icinga.org
Tue May 11 19:18:10 CEST 2010


Module: icinga-web
Branch: mhein/extlayout
Commit: e2de3f85264e862f68bff4ac35d2eda07ff0955a
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=e2de3f85264e862f68bff4ac35d2eda07ff0955a

Author: jmosshammer <jannis.mosshammer at netways.de>
Date:   Thu Apr 29 09:45:45 2010 +0200

* Simple Preference editor added

---

 app/config/routing.xml                             |    1 +
 .../actions/User/PreferencesAction.class.php       |   12 +++++-
 .../AppKit/templates/User/PreferencesSuccess.php   |   48 +++++++++++++++-----
 app/modules/AppKit/validate/User/Preferences.xml   |    4 +-
 lib/appkit/AppKit.class.php                        |   25 ++++++-----
 5 files changed, 66 insertions(+), 24 deletions(-)

diff --git a/app/config/routing.xml b/app/config/routing.xml
index 302ab0a..13d1247 100644
--- a/app/config/routing.xml
+++ b/app/config/routing.xml
@@ -72,6 +72,7 @@
 			<route name="my" pattern="^/my" module="AppKit">
 			  <route pattern="^$" action="User.Index"/>
 			  <route name=".preferences" pattern="^/preferences">
+				  <route name=".remove" pattern="^/({remove:remove})$" action="User.Preferences"/>
 				 <route pattern="^$" action="User.Preferences"/>
 			  </route>
 			</route>
diff --git a/app/modules/AppKit/actions/User/PreferencesAction.class.php b/app/modules/AppKit/actions/User/PreferencesAction.class.php
index f0b0186..feba995 100755
--- a/app/modules/AppKit/actions/User/PreferencesAction.class.php
+++ b/app/modules/AppKit/actions/User/PreferencesAction.class.php
@@ -19,6 +19,14 @@ class AppKit_User_PreferencesAction extends ICINGAAppKitBaseAction
 		return 'Success';
 	}
 	
+	public function isSecure() {
+		return true;	
+	}
+	
+	public function getCredentials() {
+		return array('icinga.user');
+	}
+	
 	public function executeRead(AgaviRequestDataHolder $rd) {
 		return "Success";
 	}
@@ -33,8 +41,10 @@ class AppKit_User_PreferencesAction extends ICINGAAppKitBaseAction
 		if($key) {
 			$val = $rd->getParameter("upref_val");
 			$isLong = $rd->getParameter("isLong",false);
-			if($val) {
+			if($val && !$rd->getParameter("remove",false)) {
 				$this->setPreference($user,$key,$val,$isLong);
+			} else if($rd->getParameter("remove")) {
+				$user->getNsmUser()->delPref($key);
 			}
 		} else if($batch) {
 			foreach($batch as $preference) {
diff --git a/app/modules/AppKit/templates/User/PreferencesSuccess.php b/app/modules/AppKit/templates/User/PreferencesSuccess.php
index fa84570..a007d2a 100755
--- a/app/modules/AppKit/templates/User/PreferencesSuccess.php
+++ b/app/modules/AppKit/templates/User/PreferencesSuccess.php
@@ -60,12 +60,9 @@ Ext.onReady(function() {
 			},{
 				title: _('Advanced'),
 				type:'fieldset',
-				collapsible:true,
-				striperows: true,
-				disableSelection:false,
-				clicksToEdit: 2,
+				collapsible:true,	
 				collapsed:true,
-				selModel: new Ext.grid.RowSelectionModel({singleSelect: true}),
+				autoHeight: true,		
 				borders:true,
 				width:500,
 				tools: [{
@@ -77,16 +74,45 @@ Ext.onReady(function() {
 					scope: this
 				}],
 				items: new Ext.grid.PropertyGrid({
-						autoHeight: true,
-						width:500,
-						source: <? echo json_encode($user->getPreferences()) ?>,
-						id: 'pedit_preferences',
-						listeners: {
-							beforeedit: function(event)  {
+					clicksToEdit: 2,
+
+					autoHeight: true,					
+					selModel: new Ext.grid.RowSelectionModel({singleSelect: true}),
+					striperows:true,
+					width:500,
+					source: <? echo json_encode($user->getPreferences()) ?>,
+					id: 'pedit_preferences',
+					listeners: {
+						beforeedit: function(event)  {
 							if(event.value == 'BLOB') {
 								AppKit.Ext.infoField("This item is read only!",2);
 								return false;
 							}
+						},
+						rowcontextmenu: function(grid,rowIndex,e) {
+							e.preventDefault();
+							var record = grid.getStore().getAt(rowIndex);
+							new Ext.menu.Menu({
+								items: [{
+									text: _('Remove this preference'),
+									iconCls: 'silk-cancel',
+									handler: function() {
+										var mask = new Ext.LoadMask(Ext.getBody(), {msg: _("Saving")});
+										mask.show();
+										var params = record.data;
+										params["upref_key"] = params["name"];
+										params["remove"] = true;
+										record.store.remove(record);
+										Ext.Ajax.request({
+											url: '<? echo $ro->gen("my.preferences") ?>',
+											params: params,
+											callback: function() {
+												mask.hide();
+											}
+										});
+									}
+								}]
+							}).showAt(e.getXY());
 						}
 					}
 				}),
diff --git a/app/modules/AppKit/validate/User/Preferences.xml b/app/modules/AppKit/validate/User/Preferences.xml
index 592a19a..38abfbd 100755
--- a/app/modules/AppKit/validate/User/Preferences.xml
+++ b/app/modules/AppKit/validate/User/Preferences.xml
@@ -16,7 +16,9 @@
 			<validator name="isLong" class="string" depends="upref_key">
 				<argument>isLong</argument>
 			</validator>
-			
+			<validator name="remove" class="string">
+				<argument>remove</argument>
+			</validator>			
 			<validator name="params" class="string" required="false">
 				<arguments base="params[][]" />
 			</validator>
diff --git a/lib/appkit/AppKit.class.php b/lib/appkit/AppKit.class.php
index 9b520de..d1cd804 100644
--- a/lib/appkit/AppKit.class.php
+++ b/lib/appkit/AppKit.class.php
@@ -39,7 +39,6 @@ class AppKit {
 	 * @author Marius Hein
 	 */
 	public static function bootstrap() {
-		file_put_contents("/var/www/time.log","Bootstrap\n",FILE_APPEND);
 		
 		// Our directory we live on!
 		self::$class_dir = dirname(__FILE__);
@@ -67,7 +66,7 @@ class AppKit {
 		self::initEventHandling();
 	
 		// Init the event handler system
-		self::setLanguageDomain($user);
+		self::setLanguageDomain();
 			
 		// Say hello to our components
 		AppKitEventDispatcher::getInstance()->triggerSimpleEvent('appkit.bootstrap', 'AppKit bootstrap finished');
@@ -295,17 +294,21 @@ class AppKit {
 	 * 
 	 */
 	private static function setLanguageDomain() {
-		$context = AgaviContext::getInstance(AgaviConfig::get('core.default_context'));
-		$user = $context->getUser()->getNsmUser();
-		if(!$user)
-			return true;
-		$translationMgr = $context->getTranslationManager();		
-		$locale = $user->getPrefVal("de.icinga.appkit.locale",$translationMgr->getDefaultLocaleIdentifier());
 		try {
-			$translationMgr->setLocale($locale);
+			$context = AgaviContext::getInstance(AgaviConfig::get('core.default_context'));
+			$appKitUser = $context->getUser()->getNsmUser();
+			if(!$user)
+				return true;
+			$translationMgr = $context->getTranslationManager();		
+			$locale = $user->getPrefVal("de.icinga.appkit.locale",$translationMgr->getDefaultLocaleIdentifier());
+			try {
+				$translationMgr->setLocale($locale);
+			} catch(Exception $e) {
+				$context->getLoggerManager()->logError("Invalid locale %s for user %s - switching to default",$locale,$user->get("user_name"));
+				$translationMgr->setLocale($translationMgr->getDefaultLocaleIdentifier());
+			}
 		} catch(Exception $e) {
-			$context->getLoggerManager()->logError("Invalid locale %s for user %s - switching to default",$locale,$user->get("user_name"));
-			$translationMgr->setLocale($translationMgr->getDefaultLocaleIdentifier());
+			return true;
 		}
 	}
 }





More information about the icinga-checkins mailing list