diff --git a/ironic_ui/static/dashboard/admin/ironic/base-port/base-port.controller.js b/ironic_ui/static/dashboard/admin/ironic/base-port/base-port.controller.js new file mode 100644 index 00000000..2c728c5f --- /dev/null +++ b/ironic_ui/static/dashboard/admin/ironic/base-port/base-port.controller.js @@ -0,0 +1,68 @@ +/* + * Copyright 2016 Cray Inc. + * + * 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() { + 'use strict'; + + /** + * Controller used to support operations on an Ironic port + */ + angular + .module('horizon.dashboard.admin.ironic') + .controller('BasePortController', BasePortController); + + BasePortController.$inject = [ + '$uibModalInstance', + 'ctrl' + ]; + + function BasePortController($uibModalInstance, + ctrl) { + ctrl.port = { + address: null, + extra: {} + }; + + /** + * Cancel the modal + * + * @return {void} + */ + ctrl.cancel = function() { + $uibModalInstance.dismiss('cancel'); + }; + + /** + * Delete a port metadata property + * + * @param {string} propertyName - Name of the property + * @return {void} + */ + ctrl.deleteExtra = function(propertyName) { + delete ctrl.port.extra[propertyName]; + }; + + /** + * Check whether the specified port metadata property already exists + * + * @param {string} propertyName - Name of the metadata property + * @return {boolean} True if the property already exists, + * otherwise false + */ + ctrl.checkExtraUnique = function(propertyName) { + return !(propertyName in ctrl.port.extra); + }; + } +})(); diff --git a/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.html b/ironic_ui/static/dashboard/admin/ironic/base-port/base-port.html similarity index 94% rename from ironic_ui/static/dashboard/admin/ironic/create-port/create-port.html rename to ironic_ui/static/dashboard/admin/ironic/base-port/base-port.html index 1da80a2c..626f7d90 100644 --- a/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.html +++ b/ironic_ui/static/dashboard/admin/ironic/base-port/base-port.html @@ -6,7 +6,7 @@ aria-label="Close"> - + diff --git a/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.controller.js b/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.controller.js index 07606ab1..42dff16a 100644 --- a/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.controller.js +++ b/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.controller.js @@ -25,36 +25,27 @@ CreatePortController.$inject = [ '$rootScope', + '$controller', '$uibModalInstance', 'horizon.app.core.openstack-service-api.ironic', 'horizon.dashboard.admin.ironic.events', - '$log', 'node' ]; function CreatePortController($rootScope, + $controller, $uibModalInstance, ironic, ironicEvents, - $log, node) { var ctrl = this; - // Paramater object that defines the port to be created - ctrl.port = { - node_uuid: node.id, - address: null, - extra: {} - }; + $controller('BasePortController', + {ctrl: ctrl, + $uibModalInstance: $uibModalInstance}); - /** - * Cancel the port creation process - * - * @return {void} - */ - ctrl.cancel = function() { - $uibModalInstance.dismiss('cancel'); - }; + ctrl.modalTitle = gettext("Create Port"); + ctrl.submitButtonTitle = ctrl.modalTtile; /** * Create the defined port @@ -62,6 +53,7 @@ * @return {void} */ ctrl.createPort = function() { + ctrl.port.node_uuid = node.id; ironic.createPort(ctrl.port).then( function() { $uibModalInstance.close(); @@ -71,25 +63,8 @@ }); }; - /** - * Delete a port metadata property - * - * @param {string} propertyName - Name of the property - * @return {void} - */ - ctrl.deleteExtra = function(propertyName) { - delete ctrl.port.extra[propertyName]; - }; - - /** - * Check whether the specified port metadata property already exists - * - * @param {string} propertyName - Name of the metadata property - * @return {boolean} True if the property already exists, - * otherwise false - */ - ctrl.checkExtraUnique = function(propertyName) { - return !(propertyName in ctrl.port.extra); + ctrl.submit = function() { + ctrl.createPort(); }; } })(); diff --git a/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.service.js b/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.service.js index 01dfa282..d23f5c8f 100644 --- a/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.service.js +++ b/ironic_ui/static/dashboard/admin/ironic/create-port/create-port.service.js @@ -41,7 +41,7 @@ return node; } }, - templateUrl: basePath + '/create-port/create-port.html' + templateUrl: basePath + '/base-port/base-port.html' }; return $uibModal.open(options); }