diff --git a/ajax/block/delete.php b/ajax/block/delete.php new file mode 100644 index 0000000000000000000000000000000000000000..2c9844e9601039e5f6f8ea7ab2225f132bf998ae --- /dev/null +++ b/ajax/block/delete.php @@ -0,0 +1,36 @@ +<?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' +); diff --git a/bin/Manager.js b/bin/Manager.js index ed0c891e8456f54c1ccb4ac9c1e94d5e27993ea7..99be56e7b696139991dc56a55bd7ed8aba702f80 100644 --- a/bin/Manager.js +++ b/bin/Manager.js @@ -38,7 +38,9 @@ define('package/quiqqer/blocks/bin/Manager', [ '$onCreate', '$onResize', '$openCreateDialog', - '$onDblClick' + '$openDeleteDialog', + '$onDblClick', + '$onClick' ], options : { @@ -82,10 +84,36 @@ define('package/quiqqer/blocks/bin/Manager', [ data : result }); + self.refreshButtons(); + 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 */ @@ -106,13 +134,26 @@ define('package/quiqqer/blocks/bin/Manager', [ this.addButton( new QUIButton({ - text : 'Block hinzufügen', - events : { + text : 'Block hinzufügen', + name : 'block-add', + disabled : true, + events : { onClick : this.$openCreateDialog } }) ); + this.addButton( + new QUIButton({ + text : 'Markierte Blöcke löschen', + name : 'block-delete', + disabled : true, + events : { + onClick : this.$openDeleteDialog + } + }) + ); + // Grid var Container = new Element('div').inject( this.getContent() @@ -139,12 +180,14 @@ define('package/quiqqer/blocks/bin/Manager', [ dataIndex : 'type', dataType : 'string', width : 200 - }] + }], + multipleSelection : true }); this.$Grid.addEvents({ onRefresh : this.refresh, - onDblClick : this.$onDblClick + onDblClick : this.$onDblClick, + onClick : this.$onClick }); this.Loader.show(); @@ -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', [ }, /** + * 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 */ @@ -411,6 +512,20 @@ define('package/quiqqer/blocks/bin/Manager', [ }), 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 ) + }); } }); }); diff --git a/lib/QUI/Blocks/Manager.php b/lib/QUI/Blocks/Manager.php index 7a8502b4cf79401a82ccd4df999cfe18e728ee00..b6b587d9c6cff07a32b289024f11397faaa3886b 100644 --- a/lib/QUI/Blocks/Manager.php +++ b/lib/QUI/Blocks/Manager.php @@ -52,6 +52,21 @@ public function createBlockForProject(Project $Project, Block $Block) 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 *