Skip to content

Commit be8e427

Browse files
committed
List view UI: Implement sub-select in widget
To support sub-select dropdown across all list views (PF,LB,NAT), refactor 'subselect' option in listView widget, instead of just the multiEdit.
1 parent a48bf09 commit be8e427

2 files changed

Lines changed: 52 additions & 52 deletions

File tree

‎ui/scripts/ui/widgets/listView.js‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,10 @@
844844
var rows = [];
845845
var reorder = options.reorder;
846846
var detailView = options.detailView;
847-
var uiCustom = $tbody.closest('.list-view').data('view-args').uiCustom;
847+
var $listView = $tbody.closest('.list-view');
848+
var listViewArgs = $listView.data('view-args');
849+
var uiCustom = listViewArgs.uiCustom;
850+
var subselect = uiCustom ? listViewArgs.listView.subselect : null;
848851

849852
if (!data || ($.isArray(data) && !data.length)) {
850853
if (!$tbody.find('tr').size()) {
@@ -1041,6 +1044,54 @@
10411044
$listView.trigger('cloudStack.listView.addRow', { $tr: $tr });
10421045
}
10431046

1047+
// Add sub-select
1048+
if (subselect) {
1049+
var $td = $tr.find('td.first');
1050+
var $select = $('<div></div>').addClass('subselect').append(
1051+
$('<select>')
1052+
).hide();
1053+
var $selectionArea = $tr.find('td:last').find('input');
1054+
1055+
$td.append($select);
1056+
1057+
// Show and populate selection
1058+
$selectionArea.change(function() {
1059+
if ($(this).is(':checked')) {
1060+
// Populate data
1061+
subselect({
1062+
context: $.extend(true, {}, options.context, {
1063+
instances: [$tr.data('json-obj')]
1064+
}),
1065+
response: {
1066+
success: function(args) {
1067+
var data = args.data;
1068+
1069+
if (data.length) {
1070+
$(data).map(function(index, item) {
1071+
var $option = $('<option>');
1072+
1073+
$option.attr('value', item.id);
1074+
$option.append(item.description);
1075+
$option.appendTo($select.find('select'));
1076+
});
1077+
$select.show();
1078+
} else {
1079+
$select.hide();
1080+
}
1081+
}
1082+
}
1083+
});
1084+
1085+
if ($(this).is('input[type=radio]')) {
1086+
$(this).closest('tr').siblings().find('input[type=radio]').change();
1087+
}
1088+
} else {
1089+
$select.find('option').remove();
1090+
$select.hide();
1091+
}
1092+
});
1093+
}
1094+
10441095
// Add quick view
10451096
if (detailView &&
10461097
!$.isFunction(detailView) &&

‎ui/scripts/ui/widgets/multiEdit.js‎

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -468,57 +468,6 @@
468468
// Change action label
469469
$listView.find('th.actions').html(_l('Select'));
470470

471-
// Add sub-select
472-
if (instances.listView.subselect) {
473-
$listView.bind('cloudStack.listView.addRow', function(event, data) {
474-
var $tr = data.$tr;
475-
var $td = $tr.find('td.first');
476-
var $select = $('<div></div>').addClass('subselect').append(
477-
$('<select>')
478-
).hide();
479-
var $selectionArea = $tr.find('td:last').find('input');
480-
481-
$td.append($select);
482-
483-
// Show and populate selection
484-
$selectionArea.change(function() {
485-
if ($(this).is(':checked')) {
486-
// Populate data
487-
instances.listView.subselect({
488-
context: $.extend(true, {}, context, {
489-
instances: [$tr.data('json-obj')]
490-
}),
491-
response: {
492-
success: function(args) {
493-
var data = args.data;
494-
495-
if (data.length) {
496-
$(data).map(function(index, item) {
497-
var $option = $('<option>');
498-
499-
$option.attr('value', item.id);
500-
$option.append(item.description);
501-
$option.appendTo($select.find('select'));
502-
});
503-
$select.show();
504-
} else {
505-
$select.hide();
506-
}
507-
}
508-
}
509-
});
510-
511-
if ($(this).is('input[type=radio]')) {
512-
$(this).closest('tr').siblings().find('input[type=radio]').change();
513-
}
514-
} else {
515-
$select.find('option').remove();
516-
$select.hide();
517-
}
518-
});
519-
});
520-
}
521-
522471
var $dataList = $listView.addClass('multi-edit-add-list').dialog({
523472
dialogClass: 'multi-edit-add-list panel',
524473
width: 825,

0 commit comments

Comments
 (0)