diff --git a/gbpui/_1550_gbp_project_add_panel_group.py b/gbpui/_1550_gbp_project_add_panel_group.py index d57de7b..25d20e1 100644 --- a/gbpui/_1550_gbp_project_add_panel_group.py +++ b/gbpui/_1550_gbp_project_add_panel_group.py @@ -14,3 +14,6 @@ ADD_INSTALLED_APPS = ['gbpui', ] PANEL_GROUP = 'GroupPolicyPanels' PANEL_GROUP_NAME = 'Policy' PANEL_GROUP_DASHBOARD = 'project' + +AUTO_DISCOVER_STATIC_FILES = True +ADD_ANGULAR_MODULES = ['gbpui', ] diff --git a/gbpui/fields.py b/gbpui/fields.py index 8046a7e..4ec3f2b 100644 --- a/gbpui/fields.py +++ b/gbpui/fields.py @@ -16,6 +16,11 @@ from django.forms import TextInput from django.forms import widgets from django.utils.safestring import mark_safe +from django.forms.utils import flatatt +from django.utils.html import format_html + +from django.utils.translation import ugettext_lazy as _ + class DynamicMultiSelectWidget(widgets.SelectMultiple): @@ -84,3 +89,78 @@ class DropdownEditWidget(TextInput): data_list += '"); + option.attr("value", optionObject.id); + option.append(optionObject.name); + $elem.append(option); + }); + + // This change listener watches for changes to the raw + // HTML select element; since the select should be hidden, + // the only possible change is the creation of a new + // option using the horizon add button. + $elem.change(function () { + // Find the last option in the select, since the + // addition is done by Horizon appending the a new + // option element + var option = $(this).find("option").last(); + + // Create a valid option object and make it available + // at the end of the available list + var val = { + 'id': option.attr('value'), + 'name': option.text() + }; + $scope.tableData.available.push(val); + + // Deallocate all the objects using the built in + // transfer table controller deallocation method + var toDeallocate = $scope.tableData.allocated.slice(); + $.each(toDeallocate, function (index, object) { + $scope.trCtrl.deallocate(object); + }); + // Notify the scope of the deallocations + $scope.$apply(); + + // Allocate the new option; this mimicks te behaviour + // of the normal Horizon based adding + $scope.trCtrl.allocate(val); + + // Notify the scope of the allocation changes + $scope.$apply(); + }); + + // The directive watches for a changes in the allocated + // list to dynamically set values for the hidden element. + $scope.$watchCollection( + function (scope) { + return $scope.tableData.allocated; + }, + function (newValue, oldValue) { + var values = $.map( + newValue, function (value, index) { + return value.id; + }); + $elem.val(values); + } + ); + + // Sets initial values as allocated when appropriate + $.each($scope.initial, function (index, initialObject) { + $scope.trCtrl.allocate(initialObject); + }); + + + } + } + }); +})(); diff --git a/gbpui/static/dashboard/gbpui/transfer-table-bridge/d-table.directive.js b/gbpui/static/dashboard/gbpui/transfer-table-bridge/d-table.directive.js new file mode 100644 index 0000000..de48adc --- /dev/null +++ b/gbpui/static/dashboard/gbpui/transfer-table-bridge/d-table.directive.js @@ -0,0 +1,91 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +(function () { + angular + .module('gbpui.transfer-table-bridge') + .directive('dTable', ['gbpui.basePath', function(basePath){ + return { + restrict: 'E', + scope: true, + templateUrl: basePath + + "transfer-table-bridge/transfer-table-bridge.html", + transclude: true, + link: function($scope, $elem, $attrs, $ctrl, $transclude) { + + var initial = []; + var available = []; + + var transcluded = $transclude(); + + transcluded.each(function(index, element) { + if(element.localName=="option") { + var val = { + 'id': $(element).attr('value'), + 'name': $(element).text() + }; + available.push(val); + + if($(element).prop('selected')) { + initial.push(val); + } + } + }); + $scope.initial = initial; + + var allocated = []; + + $scope.tableData = { + available: available, + allocated: allocated, + displayedAvailable: [], + displayedAllocated: [], + minItems: -1 + }; + + var maxAllocation = "maxItems" in $attrs + ? Number($attrs["maxItems"]) + : -1; + $scope.tableLimits = { + maxAllocation: maxAllocation + }; + + $scope.tableHelpText = { + allocHelpText: $attrs['allocatedHelpText'], + availHelpText: $attrs['availableHelpText'], + noAllocText: $attrs['noAllocatedText'], + noAvailText: $attrs['noAvailableText'] + }; + + $scope.facets = [{ + label: gettext("Name"), + name: "name", + singleton: true + }]; + + if("addItemLink" in $attrs) { + $scope.addItemLink = $attrs["addItemLink"]; + } + + if("allocatedFilter" in $attrs) { + $scope.allocatedFilter = true; + } + + $scope.id = $attrs["id"]; + $scope.name = $attrs["name"]; + + } + } + }]) + +})(); \ No newline at end of file diff --git a/gbpui/static/dashboard/gbpui/transfer-table-bridge/transfer-table-bridge.html b/gbpui/static/dashboard/gbpui/transfer-table-bridge/transfer-table-bridge.html new file mode 100644 index 0000000..f98369d --- /dev/null +++ b/gbpui/static/dashboard/gbpui/transfer-table-bridge/transfer-table-bridge.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + +
+ +
Name
+
+ {$ ::tableHelpText.noAllocText $} +
+
+ {$ row.name $} + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Name
+
+ {$ ::tableHelpText.noAvailText $} +
+
{$ row.name $} + + + + + + +
+ +
+ +
+
+ +
diff --git a/gbpui/static/dashboard/gbpui/transfer-table-bridge/transfer-table.module.js b/gbpui/static/dashboard/gbpui/transfer-table-bridge/transfer-table.module.js new file mode 100644 index 0000000..b56c38e --- /dev/null +++ b/gbpui/static/dashboard/gbpui/transfer-table-bridge/transfer-table.module.js @@ -0,0 +1,17 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +(function () { + angular + .module('gbpui.transfer-table-bridge', ['horizon.app.core.workflow']); +})(); \ No newline at end of file