diff --git a/extensions/mistral/static/mistral/js/controllers.js b/extensions/mistral/static/mistral/js/controllers.js
index 7a32a4c..ac2e9ac 100644
--- a/extensions/mistral/static/mistral/js/controllers.js
+++ b/extensions/mistral/static/mistral/js/controllers.js
@@ -3,9 +3,36 @@
*/
(function() {
+
+ function isObject(obj) {
+ return Object.prototype.toString.call(obj) === '[object Object]'
+ }
+
+ function isArray(obj) {
+ return Object.prototype.toString.call(obj) === '[object Array]'
+ }
+
angular.module('hz')
.controller('workbookCtrl', function($scope) {
+ $scope.defaults = {
+ 'actions': {
+ name: 'Action1',
+ base: 'nova.create_server',
+ baseInput: {
+ flavorId: {
+ title: 'Flavor Id',
+ type: 'string'
+ },
+ imageId: {
+ title: 'Image Id',
+ type: 'string'
+ }
+ },
+ input: [],
+ output: []
+ }
+ };
$scope.data = {
actions: [{
id: 'action1',
@@ -81,14 +108,65 @@
$scope.isAtomic = function(type) {
return ['string'].indexOf(type) > -1;
+ };
+
+ $scope.remove = function(parent, item) {
+ if ( angular.isString(parent) ) {
+ parent = $scope.data[parent];
+ }
+ var index = parent.indexOf(item);
+ parent.splice(index, 1);
+ return parent.length;
+ };
+
+ $scope.removeKey = function(parent, key) {
+ if ( angular.isString(parent) ) {
+ parent = $scope.data[parent];
+ }
+ if ( !angular.isObject(parent) ) {
+ return;
+ }
+ delete parent[key];
+ return $scope.getKeys(parent).length;
+ };
+
+ $scope.addAutoKey = function(parent) {
+ if ( angular.isString(parent) ) {
+ parent = $scope.data[parent];
+ }
+ if ( !angular.isObject(parent) ) {
+ return;
+ }
+ var maxNumber = $scope.getKeys(parent).map(function(key) {
+ var match = /[Kk]ey(\d+)/.exec(key);
+ if ( match ) {
+ return +match[1];
+ } else {
+ return null;
+ }
+ }).filter(function(value) {
+ return value;
+ }).reduce(function(prevValue, curValue) {
+ return prevValue > curValue ? prevValue : curValue;
+ }, 0),
+ newKey = 'key' + (maxNumber+1);
+ parent[newKey] = '';
+ };
+
+ $scope.add = function(parent, value) {
+ var defaultValue, key;
+ if ( angular.isString(parent) ) {
+ key = parent;
+ defaultValue = angular.copy($scope.defaults[key]);
+ parent = $scope.data[key];
+ defaultValue.id = key + parent.length;
+ }
+ parent.push(value || defaultValue);
}
})
.controller('actionCtrl', function($scope) {
- $scope.fixedFields = [['name', 'base']];
- $scope.fields = ['baseInput', 'input', 'output'];
-
var actionBase = null,
baseTypes = {
'nova.create_server': {
@@ -120,14 +198,14 @@
})
.controller('dictionaryCtrl', function($scope) {
- if ( !$scope.item.value ) {
- $scope.item.value = {'Key1': ''};
+ if ( !isObject($scope.subItem.value) ) {
+ $scope.subItem.value = {'Key1': ''};
}
})
.controller('listCtrl', function($scope) {
- if ( !$scope.item.value ) {
- $scope.item.value = [''];
+ if ( !isArray($scope.subItem.value) ) {
+ $scope.subItem.value = [''];
}
})
diff --git a/extensions/mistral/static/mistral/js/directives.js b/extensions/mistral/static/mistral/js/directives.js
index 7dd70bd..d0e1dc0 100644
--- a/extensions/mistral/static/mistral/js/directives.js
+++ b/extensions/mistral/static/mistral/js/directives.js
@@ -67,15 +67,10 @@
transclude: true,
scope: {
title: '@',
- removable: '@'
+ removable: '&'
},
- compile: function(element, attrs) {
- defaultSetter(attrs, 'removable', false);
- return {
- post: function(scope, element, attrs) {
- disableClickDefaultBehaviour(element);
- }
- }
+ link: function(scope, element, attrs) {
+ disableClickDefaultBehaviour(element);
}
}
})
@@ -87,16 +82,16 @@
transclude: true,
scope: {
title: '@',
- additive: '@',
- removable: '@'
+ onAdd: '&',
+ onRemove: '&'
},
- compile: function(element, attrs) {
- defaultSetter(attrs, 'removable', false);
- defaultSetter(attrs, 'additive', false);
- return {
- post: function(scope, element) {
- disableClickDefaultBehaviour(element);
- }
+ link: function(scope, element, attrs) {
+ disableClickDefaultBehaviour(element);
+ if ( attrs.onAdd ) {
+ scope.additive = true;
+ }
+ if ( attrs.onRemove ) {
+ scope.removable = true;
}
}
}
diff --git a/extensions/mistral/templates/mistral/create.html b/extensions/mistral/templates/mistral/create.html
index 2c82a90..df7ffb8 100644
--- a/extensions/mistral/templates/mistral/create.html
+++ b/extensions/mistral/templates/mistral/create.html
@@ -36,7 +36,7 @@