From add6df5ef79fa8a81893a716d3cf0ae6e54c1a02 Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Mon, 29 Dec 2014 10:07:10 -0800 Subject: [PATCH] Replace collapsible groups boilerplate html with angular directive Change-Id: Id47d0ea3dfc466187a14b7da423004f24795826d --- .../angular-templates/collapsible-group.html | 15 + .../mistral/static/mistral/js/directives.js | 45 +- .../mistral/static/mistral/js/services.js | 11 + .../mistral/templates/mistral/create.html | 631 +++++++----------- 4 files changed, 296 insertions(+), 406 deletions(-) create mode 100644 extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html diff --git a/extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html b/extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html new file mode 100644 index 0000000..dcab3e3 --- /dev/null +++ b/extensions/mistral/static/mistral/js/angular-templates/collapsible-group.html @@ -0,0 +1,15 @@ +
+
+ +
+ +
+
+ +
+
+
+
+
\ No newline at end of file diff --git a/extensions/mistral/static/mistral/js/directives.js b/extensions/mistral/static/mistral/js/directives.js index e7be3e8..dea1a50 100644 --- a/extensions/mistral/static/mistral/js/directives.js +++ b/extensions/mistral/static/mistral/js/directives.js @@ -3,6 +3,14 @@ */ (function() { + function disableClickDefaultBehaviour(element) { + angular.element(element).find('a[data-toggle="collapse"]') + .on('click', function(e) { + e.preventDefault(); + return true; + }); + } + angular.module('hz') .directive('editable', function() { @@ -59,17 +67,46 @@ } }) - .directive('collapsiblePanel', function($parse, idGenerator) { + .directive('collapsiblePanel', function($parse, idGenerator, defaultSetter) { return { restrict: 'E', templateUrl: '/static/mistral/js/angular-templates/collapsible-panel.html', transclude: true, scope: { panelTitle: '@', - removable: '=' + removable: '@' }, - link: function(scope) { - scope.panelId = idGenerator(); + compile: function(element, attrs) { + defaultSetter(attrs, 'removable', false); + return { + post: function(scope, element) { + scope.panelId = idGenerator(); + disableClickDefaultBehaviour(element); + } + } + } + } + }) + + .directive('collapsibleGroup', function($parse, idGenerator, defaultSetter) { + return { + restrict: 'E', + templateUrl: '/static/mistral/js/angular-templates/collapsible-group.html', + transclude: true, + scope: { + groupTitle: '@', + additive: '@', + removable: '@' + }, + compile: function(element, attrs) { + defaultSetter(attrs, 'removable', false); + defaultSetter(attrs, 'additive', false); + return { + post: function(scope) { + scope.groupId = idGenerator(); + disableClickDefaultBehaviour(element); + } + } } } }) diff --git a/extensions/mistral/static/mistral/js/services.js b/extensions/mistral/static/mistral/js/services.js index e5143ea..2e982b1 100644 --- a/extensions/mistral/static/mistral/js/services.js +++ b/extensions/mistral/static/mistral/js/services.js @@ -11,4 +11,15 @@ return 'elem-id-'+id; }; }) + + .factory('defaultSetter', function($parse) { + return function(attrs, attrName, defaultValue) { + if ( attrs[attrName] === undefined ) { + attrs[attrName] = defaultValue; + } else { + attrs[attrName] = $parse(attrs[attrName])(); + } + } + }); + })(); \ No newline at end of file diff --git a/extensions/mistral/templates/mistral/create.html b/extensions/mistral/templates/mistral/create.html index 3741419..6b2bd1c 100644 --- a/extensions/mistral/templates/mistral/create.html +++ b/extensions/mistral/templates/mistral/create.html @@ -103,157 +103,131 @@
-
-
- Base Input
-
-
- - -
-
- - -
+ +
+ +
-
+
+ + +
+
-
+
- -
- -
-
-
-
-
-
-
- - -
+
+
+
+ +
-
+ -
+ +
-
-
- Output
+
+
+ + +
-
- +
+
+ + +
-
- + +
- - + + -
- - -
-
-
- -
-
-
-
- - -
-
-
-
- -
- - -
+ +
+ +
-
-
-
-
- -
- - -
-
-
-
- -
-
- -
-
-
-
- - -
-
-
- -
+
+
+
+
+ +
-
-
-
-
- - -
-
-
- -
+
+
-
+ +
+
+
+
+ + +
+
+
+ +
+ + +
+
+
+
+
+
+
+ + +
+
+
+ +
+
+
+
@@ -278,320 +252,173 @@
-
+
- -
- -
-
-
-
-
-
-
- - -
+
+
+
+ +
-
+ -
+ +
-
-
- Output
+
+
+ + +
-
- +
+
+ + +
-
- + + + + + + + + + + + + + + + +
- - +
+
+
+
+ +
-
+
+
+
- - + +
-
-
-
- -
-
-
- -
- -
-
-
- - -
-
-
-
- -
- -
-
-
- -
-
-
-
- -
- -
-
-
- -
-
-
-
-
-
- -
- -
-
-
-
-
- -
- -
-
-
+ +
-
+
- - -
-
-
-
- - -
-
-
-
-
-
- - -
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- - -
-
-
-
-
-
-
-
-
- -
- -
-
-
-
-
-
-
- -
- - -
-
-
-
-
-
-
-
-
- -
- -
-
-
- -
-
-
-
- -
- -
-
-
- -
-
-
-
- -
- -
-
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
-
- - -
-
-
-
-
-
- - -
-
-
-
-
-
- - -
-
-
-
- - -
-
-
-
-
-
- - -
+ +
+ +
-
-
-
+ + +
+
+
+
+ +
+ + +
+
+
+
+
+
+ + + + + + + + + + +
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ +