Skip to content
Code-Schnipsel Gruppen Projekte
Commit 2caab2a2 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Delete Blocks

Übergeordneter 61e1880d
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
1 Merge Request!1Dev
<?php
/**
* This file contains package_quiqqer_blocks_ajax_getBlock
*/
/**
* delete the Block-IDs
*
* @param {String} $blockId - Block-IDs; JSON Array
*/
function package_quiqqer_blocks_ajax_block_delete($blockIds)
{
$BlockManager = new \QUI\Blocks\Manager();
$blockIds = json_decode( $blockIds, true );
foreach ( $blockIds as $blockId )
{
try
{
$BlockManager->deleteBlock( $blockId );
} catch ( QUI\Exception $Exception )
{
QUI::getMessagesHandler()->addAttention(
$Exception->getMessage()
);
}
}
}
\QUI::$Ajax->register(
'package_quiqqer_blocks_ajax_block_delete',
array('blockIds'),
'Permission::checkAdminUser'
);
...@@ -38,7 +38,9 @@ define('package/quiqqer/blocks/bin/Manager', [ ...@@ -38,7 +38,9 @@ define('package/quiqqer/blocks/bin/Manager', [
'$onCreate', '$onCreate',
'$onResize', '$onResize',
'$openCreateDialog', '$openCreateDialog',
'$onDblClick' '$openDeleteDialog',
'$onDblClick',
'$onClick'
], ],
options : { options : {
...@@ -82,10 +84,36 @@ define('package/quiqqer/blocks/bin/Manager', [ ...@@ -82,10 +84,36 @@ define('package/quiqqer/blocks/bin/Manager', [
data : result data : result
}); });
self.refreshButtons();
self.Loader.hide(); self.Loader.hide();
}); });
}, },
/**
* Refresh the buttons status
*/
refreshButtons : function()
{
var selected = this.$Grid.getSelectedData(),
AddButton = this.getButtons('block-add'),
DelButton = this.getButtons('block-delete');
if ( !selected.length )
{
AddButton.enable();
DelButton.disable();
return;
}
AddButton.enable();
DelButton.enable();
if ( selected.length > 1 ) {
AddButton.disable();
}
},
/** /**
* event : on create * event : on create
*/ */
...@@ -106,13 +134,26 @@ define('package/quiqqer/blocks/bin/Manager', [ ...@@ -106,13 +134,26 @@ define('package/quiqqer/blocks/bin/Manager', [
this.addButton( this.addButton(
new QUIButton({ new QUIButton({
text : 'Block hinzufügen', text : 'Block hinzufügen',
events : { name : 'block-add',
disabled : true,
events : {
onClick : this.$openCreateDialog onClick : this.$openCreateDialog
} }
}) })
); );
this.addButton(
new QUIButton({
text : 'Markierte Blöcke löschen',
name : 'block-delete',
disabled : true,
events : {
onClick : this.$openDeleteDialog
}
})
);
// Grid // Grid
var Container = new Element('div').inject( var Container = new Element('div').inject(
this.getContent() this.getContent()
...@@ -139,12 +180,14 @@ define('package/quiqqer/blocks/bin/Manager', [ ...@@ -139,12 +180,14 @@ define('package/quiqqer/blocks/bin/Manager', [
dataIndex : 'type', dataIndex : 'type',
dataType : 'string', dataType : 'string',
width : 200 width : 200
}] }],
multipleSelection : true
}); });
this.$Grid.addEvents({ this.$Grid.addEvents({
onRefresh : this.refresh, onRefresh : this.refresh,
onDblClick : this.$onDblClick onDblClick : this.$onDblClick,
onClick : this.$onClick
}); });
this.Loader.show(); this.Loader.show();
...@@ -200,6 +243,14 @@ define('package/quiqqer/blocks/bin/Manager', [ ...@@ -200,6 +243,14 @@ define('package/quiqqer/blocks/bin/Manager', [
); );
}, },
/**
* event : click
*/
$onClick : function()
{
this.refreshButtons();
},
/** /**
* *
*/ */
...@@ -305,6 +356,56 @@ define('package/quiqqer/blocks/bin/Manager', [ ...@@ -305,6 +356,56 @@ define('package/quiqqer/blocks/bin/Manager', [
}, },
/** /**
* Opens the delete block dialog
*/
$openDeleteDialog : function()
{
var self = this,
blockIds = this.$Grid.getSelectedData().map(function(block) {
return block.id;
});
new QUIConfirm({
maxHeight : 300,
maxWidth : 600,
autoclose : false,
events :
{
onOpen : function(Win)
{
var Content = Win.getContent(),
lists = '<ul>';
self.$Grid.getSelectedData().each(function(block) {
lists = lists +'<li>'+ block.id +' - '+ block.title +'</li>';
});
lists = lists +'</ul>';
Content.set(
'html',
'<h1>Möchten Sie folgende Block-IDs wirklich löschen</h1>' +
lists
);
},
onSubmit : function(Win)
{
Win.Loader.show();
self.deleteBlocks(blockIds, function()
{
Win.close();
self.refresh();
});
}
}
}).open();
},
/**
* Opens the edit sheet of a Block
* *
* @param {integer} blockId * @param {integer} blockId
*/ */
...@@ -411,6 +512,20 @@ define('package/quiqqer/blocks/bin/Manager', [ ...@@ -411,6 +512,20 @@ define('package/quiqqer/blocks/bin/Manager', [
}), }),
data : JSON.encode( data ) data : JSON.encode( data )
}); });
},
/**
* Delete the Block-Ids
*
* @param {array} blockIds - Block IDs which should be deleted
* @param {Function} callback
*/
deleteBlocks : function(blockIds, callback)
{
Ajax.post('package_quiqqer_blocks_ajax_block_delete', callback, {
'package' : 'quiqqer/blocks',
blockIds : JSON.encode( blockIds )
});
} }
}); });
}); });
...@@ -52,6 +52,21 @@ public function createBlockForProject(Project $Project, Block $Block) ...@@ -52,6 +52,21 @@ public function createBlockForProject(Project $Project, Block $Block)
return $lastId; return $lastId;
} }
/**
* Delete the block
*
* @param Integer $blockId - Block-ID
*/
public function deleteBlock($blockId)
{
// check if block exist
$this->getBlockById( $blockId );
QUI::getDataBase()->delete($this->_getTable(), array(
'id' => $blockId
));
}
/** /**
* Return the areas which are available in the project * Return the areas which are available in the project
* *
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren