[Kimchi-devel] [PATCH] [Kimchi] Fix issue #1019: Hide storage volume actions menu for iSCSI/SCSI pools
Lucio Correia
luciojhc at linux.vnet.ibm.com
Wed Sep 28 17:07:02 UTC 2016
Reviewed-By: Lucio Correia <luciojhc at linux.vnet.ibm.com>
On 28-09-2016 11:34, Aline Manera wrote:
> Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> ---
> ui/js/src/kimchi.storage_main.js | 57 +++++++++++++++++++++++++++-------------
> ui/pages/tabs/storage.html.tmpl | 4 +--
> 2 files changed, 41 insertions(+), 20 deletions(-)
>
> diff --git a/ui/js/src/kimchi.storage_main.js b/ui/js/src/kimchi.storage_main.js
> index 0d7a6d7..3208bd2 100644
> --- a/ui/js/src/kimchi.storage_main.js
> +++ b/ui/js/src/kimchi.storage_main.js
> @@ -234,24 +234,37 @@ kimchi.storageBindClick = function() {
> var checkbox = $(this);
> var volumeBlock = $(this).closest('.wok-datagrid-row');
> var volumesBlock = $(this).closest('.volumeslist');
> + var poolType = volumesBlock.data('type')
> + var selectedVolumes = $('[name="selected-volume[]"]:checked',volumesBlock)
> var disabled = [];
> - if($('[name="selected-volume[]"]:checked',volumesBlock).length > 1) {
> - disabled = ['volume-clone','volume-wipe','volume-delete'];
> - $('.volume-resize',volumesBlock).parent().addClass('disabled');
> - for (i = 0; i < disabled.length; i++) {
> - $('.'+disabled[i],volumesBlock).parent().removeClass('disabled');
> - }
> - }else if($('[name="selected-volume[]"]:checked',volumesBlock).length === 1){
> - disabled = ['volume-resize','volume-clone','volume-wipe','volume-delete'];
> - for (i = 0; i < disabled.length; i++) {
> - $('.'+disabled[i],volumesBlock).parent().removeClass('disabled');
> - }
> - }else {
> + var enabled = [];
> +
> + // No volume selected
> + if (selectedVolumes.length === 0) {
> disabled = ['volume-resize','volume-clone','volume-wipe','volume-delete'];
> - for (i = 0; i < disabled.length; i++) {
> - $('.'+disabled[i],volumesBlock).parent().addClass('disabled');
> + enabled = [];
> + // One or more volumes selected
> + } else {
> + // Read-write pools
> + if (poolType !== 'scsi' && poolType !== 'iscsi') {
> + if (selectedVolumes.length > 1) {
> + disabled = ['volume-resize'];
> + enabled = ['volume-clone','volume-wipe','volume-delete'];
> + } else {
> + disabled = [];
> + enabled = ['volume-resize','volume-clone','volume-wipe', 'volume-delete'];
> + }
> }
> }
> +
> + for (i = 0; i < disabled.length; i++) {
> + $('.'+disabled[i],volumesBlock).parent().addClass('disabled');
> + }
> +
> + for (i = 0; i < enabled.length; i++) {
> + $('.'+enabled[i],volumesBlock).parent().removeClass('disabled');
> + }
> +
> if(checkbox.is(":checked")){
> volumeBlock.addClass('selected');
> }else {
> @@ -293,19 +306,27 @@ kimchi.storageBindClick = function() {
> }
> });
>
> - $('.pool-add-volume').each(function(index) {
> + $('.volume-add').each(function(index) {
> var canAddVolume =
> $(this).data('stat') === 'active' &&
> $(this).data('type') !== 'iscsi' &&
> $(this).data('type') !== 'scsi';
> if(canAddVolume) {
> - $(this).parent().show();
> + $(this).parent().removeClass('disabled');
> }
> else {
> - $(this).parent().hide();
> + $(this).parent().addClass('disabled');
> }
> });
>
> + $('.volumeslist').each(function(index) {
> + var rwpool = $(this).data('type') !== 'iscsi' &&
> + $(this).data('type') !== 'scsi'
> +
> + if (!rwpool)
> + $('.pool-action', $(this)).addClass('hidden');
> + });
> +
> if(wok.tabMode['storage'] === 'admin') {
> $('.pool-delete').on('click', function(event) {
> event.preventDefault();
> @@ -382,7 +403,7 @@ kimchi.storageBindClick = function() {
> }
> });
>
> - $('.pool-add-volume').on('click', function(event) {
> + $('.volume-add').on('click', function(event) {
> event.preventDefault();
> var poolName = $(this).data('name');
> kimchi.selectedSP = poolName;
> diff --git a/ui/pages/tabs/storage.html.tmpl b/ui/pages/tabs/storage.html.tmpl
> index 92d9b75..65d6d19 100644
> --- a/ui/pages/tabs/storage.html.tmpl
> +++ b/ui/pages/tabs/storage.html.tmpl
> @@ -125,13 +125,13 @@
> </span>
> </span>
> <div class="volumes">
> - <div id="volume-{name}" class="volumeslist" data-name="{name}">
> + <div id="volume-{name}" class="volumeslist" data-name="{name}" data-type="{type}">
> <div class="row">
> <div class="pull-left">
> <div class="dropdown menu-flat pool-action">
> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false" aria-haspopup="true"><span class="edit-alt"></span>$_("Actions")<span class="caret"></span></button>
> <ul class="dropdown-menu actionsheet">
> - <li><a href="#" class="pool-add-volume" data-stat="{state}" data-name="{name}" data-type="{type}"><i class="fa fa-plus-circle"></i> $_("Add Volume")</a></li>
> + <li class="disabled"><a href="#" class="volume-add" data-stat="{state}" data-name="{name}" data-type="{type}"><i class="fa fa-plus-circle"></i> $_("Add Volume")</a></li>
> <li class="disabled"><a href="#" class="volume-resize" data-name="{name}"><i class="fa fa-external-link-square"></i> $_("Resize")</a></li>
> <li class="disabled"><a href="#" class="volume-clone" data-name="{name}"><i class="fa fa-copy"></i> $_("Clone")</a></li>
> <li class="disabled"><a href="#" class="volume-wipe" data-name="{name}"><i class="fa fa-eraser"></i> $_("Wipe")</a></li>
>
--
Lucio Correia
Software Engineer
IBM LTC Brazil
More information about the Kimchi-devel
mailing list