diff options
author | 2017-04-22 13:25:07 +0200 | |
---|---|---|
committer | 2017-04-22 13:25:07 +0200 | |
commit | d182202fc6001983541504ed323d68479086317e (patch) | |
tree | 11d4c10cdd3e995f519c3e0e324968fdaf175114 /moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js | |
parent | 83c1c966baf73329fab8ddcfad19ad7fe0c41c2a (diff) |
add moonv4
Change-Id: I247af788d0b0fb961fbc85416486b241eb1d807c
Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js')
-rw-r--r-- | moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js b/moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js new file mode 100644 index 00000000..d1c34c79 --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js @@ -0,0 +1,108 @@ +/** + * @author arnaud marhin<arnaud.marhin@orange.com> + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PDPAddController', PDPAddController); + + PDPAddController.$inject = ['$scope', '$translate', 'alertService', 'formService', 'pdpService', 'policyService', 'utilService']; + + function PDPAddController($scope, $translate, alertService, formService, pdpService, policyService, utilService) { + + var add = this; + + /* + * + */ + + add.form = {}; + + add.pdp = {}; + + add.policies = []; + + add.selectedPolicy = null; + + add.loading = false; + add.loadingPolicies = true; + + add.create = createPDP; + + resolvePolicies(); + + /* + * + */ + + /** + * This function return an array of all policies/template ids + */ + function resolvePolicies() { + + policyService.findAllWithCallback(function(policies){ + + add.policies = policies; + add.loadingPolicies = false; + }); + + } + + function createPDP(pdp) { + + if(formService.isInvalid(add.form)) { + + formService.checkFieldsValidity(add.form); + + } else { + + add.loading = true; + + pdpService.data.pdp.create({}, { + + name: add.pdp.name, + description: add.pdp.description, + security_pipeline: [add.selectedPolicy.id], + keystone_project_id: null + + }, createSuccess, createError); + + } + + function createSuccess(data) { + + $translate('moon.pdp.add.success', { pdpName: pdp.name }) + .then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + var createdPdp = utilService.transformOne(data, 'pdps'); + + add.loading = false; + + $scope.$emit('event:pdpCreatedSuccess', createdPdp); + + } + + function createError(reason) { + + $translate('moon.pdp.add.error', { pdpName: pdp.name }) + .then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + add.loading = false; + + $scope.$emit('event:pdpCreatedError'); + + } + + } + + } + +})(); |