[icinga-checkins] icinga.org: icinga-web/master: * CronkListing: Deleting cronks

git at icinga.org git at icinga.org
Mon Jan 3 16:30:53 CET 2011


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Mon Jan  3 15:19:34 2011 +0100

* CronkListing: Deleting cronks

---

 .../Cronks/actions/Provider/CronksAction.class.php |    8 ++++
 app/modules/Cronks/lib/js/CronkListingPanel.js     |   38 ++++++++++++++++++--
 .../models/Provider/CronksDataModel.class.php      |   28 ++++++++++++++
 .../views/Provider/CronksSuccessView.class.php     |    5 ++-
 4 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/app/modules/Cronks/actions/Provider/CronksAction.class.php b/app/modules/Cronks/actions/Provider/CronksAction.class.php
index 965ea08..0cfa81f 100755
--- a/app/modules/Cronks/actions/Provider/CronksAction.class.php
+++ b/app/modules/Cronks/actions/Provider/CronksAction.class.php
@@ -53,6 +53,14 @@ class Cronks_Provider_CronksAction extends CronksBaseAction {
 			$cronk_record->save();
 			
 		}
+		elseif($rd->getParameter('xaction') == 'delete') {
+			try {
+				$this->cronks->deleteCronkRecord($rd->getParameter('cid'), $rd->getParameter('name'));
+			}
+			catch (Exception $e) {
+				$this->appendAttribute('errors', $e->getMessage());
+			}
+		}
 		else {
 			$cronks = $this->cronks->getCronks();
 		
diff --git a/app/modules/Cronks/lib/js/CronkListingPanel.js b/app/modules/Cronks/lib/js/CronkListingPanel.js
index a49ac05..281dbcd 100644
--- a/app/modules/Cronks/lib/js/CronkListingPanel.js
+++ b/app/modules/Cronks/lib/js/CronkListingPanel.js
@@ -348,6 +348,10 @@ Ext.extend(Cronk.util.CronkListingPanel, Ext.Panel, {
 					}
 				},
 				
+				getListing : function() {
+					return this.listing
+				},
+				
 				id: idPrefix,
 				
 				items: [{
@@ -370,7 +374,35 @@ Ext.extend(Cronk.util.CronkListingPanel, Ext.Panel, {
 					text: _('Delete'),
 					iconCls: 'icinga-icon-bin',
 					handler: function(b, e) {
-						
+						var item = ctxMenu.getItemData();
+						Ext.Msg.confirm(_('elete cronk'), String.format(_('Are you sure to delete {0}'), item['name']), function(btn) {
+							if (btn == 'yes') {
+								Ext.Ajax.request({
+									url: AppKit.c.path + '/cronks/provider/cronks',
+									params: {
+										xaction: 'delete',
+										cid: item.cronkid,
+										name: item.name,
+										categories: item.categories,
+										description: item.description,
+										image: item.image,
+										module: item.module,
+										action: item.action
+									},
+									success: function(response, options) {
+										AppKit.notifyMessage(_('Cronk deleted'), String.format(_('We have deleted your cronk "{0}"'), item['name']));
+										
+										ctxMenu.getListing().reloadAll();
+									},
+									failure: function(response, options) {
+										var o = Ext.decode(response.responseText);
+										if (Ext.isObject(o) && Ext.isDefined(o.errors)) {
+											AppKit.notifyMessage(_('Error'), String.format(_('Some error: {0}'), o.errors[0]));
+										}
+									}
+								});
+							}
+						});
 					}
 				}],
 				
@@ -384,8 +416,6 @@ Ext.extend(Cronk.util.CronkListingPanel, Ext.Panel, {
 							this.items.get(idPrefix + '-button-edit').setDisabled(false);
 							this.items.get(idPrefix + '-button-delete').setDisabled(false);
 						}
-						
-						this.items.get(idPrefix + '-button-delete').setDisabled(true);
 					}
 				}
 			});
@@ -403,6 +433,8 @@ Ext.extend(Cronk.util.CronkListingPanel, Ext.Panel, {
 		
 		ctxMenu.setItemData(view, index, node);
 		
+		ctxMenu.listing = this;
+		
 		ctxMenu.showAt(e.getXY());
 	},
 	
diff --git a/app/modules/Cronks/models/Provider/CronksDataModel.class.php b/app/modules/Cronks/models/Provider/CronksDataModel.class.php
index b58e8c3..b44a683 100755
--- a/app/modules/Cronks/models/Provider/CronksDataModel.class.php
+++ b/app/modules/Cronks/models/Provider/CronksDataModel.class.php
@@ -472,6 +472,34 @@ class Cronks_Provider_CronksDataModel extends CronksBaseModel {
 		return $record;
 	}
 	
+	public function deleteCronkRecord($cronkid, $cronkname, $own=true) {
+		$q = Doctrine_Query::create()
+		->select('c.*')
+		->from('Cronk c')
+		->where('c.cronk_uid=? and c.cronk_name=?', array($cronkid, $cronkname));
+		
+		if ($own==true) {
+			$q->andWhere('c.cronk_user_id=?', array($this->user->user_id));
+		}
+		
+		$cronk = $q->execute()->getFirst();
+		
+		if ($cronk instanceof Cronk && $cronk->cronk_id > 0) {
+			Doctrine_Manager::getInstance()->getCurrentConnection()->beginTransaction();
+			
+			$cronk->CronkPrincipalCronk->delete();
+			$cronk->CronkCategoryCronk->delete();
+			$cronk->delete();
+			
+			Doctrine_Manager::getInstance()->getCurrentConnection()->commit();
+			
+			return true;
+		}
+		else {
+			throw new AppKitModelException('Cronk not found: '. $cronkid);
+		}
+	}
+	
 	public function combinedData() {
 		$cat_out = array ();
 		
diff --git a/app/modules/Cronks/views/Provider/CronksSuccessView.class.php b/app/modules/Cronks/views/Provider/CronksSuccessView.class.php
index 8f3af5e..4dace78 100755
--- a/app/modules/Cronks/views/Provider/CronksSuccessView.class.php
+++ b/app/modules/Cronks/views/Provider/CronksSuccessView.class.php
@@ -3,11 +3,14 @@
 class Cronks_Provider_CronksSuccessView extends CronksBaseView {
 	public function executeHtml(AgaviRequestDataHolder $rd) {
 		$this->setupHtml($rd);
-
 		$this->setAttribute('_title', 'Provider.Cronks');
 	}
 
 	public function executeJson(AgaviRequestDataHolder $rd) {
+		if ($this->hasAttribute('errors')) {
+			$this->getContainer()->getResponse()->setHttpStatusCode(500);
+			return json_encode(array('errors' => $this->getAttribute('errors')));
+		}
 		
 		if ($rd->getParameter('xaction') == 'write') {
 			$return = array (





More information about the icinga-checkins mailing list