From 7021718ab206883c2ac507a7c47d937834b13dce Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Wed, 22 Jul 2015 21:03:15 +0300 Subject: [PATCH] Rewrite directive to render editable labels Common part of , and is moved to a separate directive. Implements blueprint: composable-templates Change-Id: If5f8da39aad0f4f3195e9af18e384de9f3ed2d75 --- .../mistral/templates/mistral/create.html | 2 +- merlin/static/merlin/js/merlin.directives.js | 29 ++++++++++++------- .../merlin/templates/collapsible-group.html | 4 +-- .../merlin/templates/collapsible-panel.html | 4 +-- .../merlin/templates/fields/dictionary.html | 11 ++----- .../merlin/templates/fields/frozendict.html | 7 ++--- merlin/static/merlin/templates/labeled.html | 4 ++- merlin/static/merlin/templates/title.html | 3 ++ 8 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 merlin/static/merlin/templates/title.html diff --git a/extensions/mistral/templates/mistral/create.html b/extensions/mistral/templates/mistral/create.html index 4ee0011..931f969 100644 --- a/extensions/mistral/templates/mistral/create.html +++ b/extensions/mistral/templates/mistral/create.html @@ -73,7 +73,7 @@
- +
diff --git a/merlin/static/merlin/js/merlin.directives.js b/merlin/static/merlin/js/merlin.directives.js index ace9c56..fa0e69d 100644 --- a/merlin/static/merlin/js/merlin.directives.js +++ b/merlin/static/merlin/js/merlin.directives.js @@ -41,6 +41,7 @@ * */ .directive('typedField', typedField) + .directive('editableTitle', editableTitle) .directive('labeled', labeled); function labeled() { @@ -49,12 +50,27 @@ templateUrl: '/static/merlin/templates/labeled.html', transclude: true, scope: { - label: '@', + label: '=', for: '@' } }; } + function editableTitle() { + return { + restrict: 'E', + templateUrl: '/static/merlin/templates/title.html', + scope: { + ngModel: '=' + }, + link: function(scope) { + if (angular.isFunction(scope.ngModel)) { + scope.editable = true; + } + } + }; + } + function editable() { return { restrict: 'E', @@ -136,12 +152,7 @@ panel: '=content' }, link: function(scope) { - if (angular.isDefined(scope.panel)) { - scope.isCollapsed = false; - if (angular.isFunction(scope.panel.title)) { - scope.editable = true; - } - } + scope.isCollapsed = false; } }; } @@ -152,16 +163,12 @@ templateUrl: '/static/merlin/templates/collapsible-group.html', transclude: true, scope: { - group: '=content', title: '=', onAdd: '&', onRemove: '&' }, link: function(scope, element, attrs) { scope.isCollapsed = false; - if (angular.isFunction(scope.title)) { - scope.editable = true; - } if ( attrs.onAdd && attrs.additive !== 'false' ) { scope.additive = true; } diff --git a/merlin/static/merlin/templates/collapsible-group.html b/merlin/static/merlin/templates/collapsible-group.html index b549d9b..a29f3c4 100644 --- a/merlin/static/merlin/templates/collapsible-group.html +++ b/merlin/static/merlin/templates/collapsible-group.html @@ -3,9 +3,7 @@
- - {$ ::title $} +
diff --git a/merlin/static/merlin/templates/collapsible-panel.html b/merlin/static/merlin/templates/collapsible-panel.html index e321d6f..b38798e 100644 --- a/merlin/static/merlin/templates/collapsible-panel.html +++ b/merlin/static/merlin/templates/collapsible-panel.html @@ -3,9 +3,7 @@

- - {$ ::panel.title $} +

diff --git a/merlin/static/merlin/templates/fields/dictionary.html b/merlin/static/merlin/templates/fields/dictionary.html index 33017ac..858d4dc 100644 --- a/merlin/static/merlin/templates/fields/dictionary.html +++ b/merlin/static/merlin/templates/fields/dictionary.html @@ -1,10 +1,7 @@
-
- +
@@ -13,11 +10,9 @@
-
+
- diff --git a/merlin/static/merlin/templates/fields/frozendict.html b/merlin/static/merlin/templates/fields/frozendict.html index 97b4c0f..f4c5264 100644 --- a/merlin/static/merlin/templates/fields/frozendict.html +++ b/merlin/static/merlin/templates/fields/frozendict.html @@ -2,20 +2,19 @@
- +
-
+ label="key" for="{$ field.uid() $}">
diff --git a/merlin/static/merlin/templates/labeled.html b/merlin/static/merlin/templates/labeled.html index f011b06..1920581 100644 --- a/merlin/static/merlin/templates/labeled.html +++ b/merlin/static/merlin/templates/labeled.html @@ -1,4 +1,6 @@
- +
diff --git a/merlin/static/merlin/templates/title.html b/merlin/static/merlin/templates/title.html new file mode 100644 index 0000000..b5740aa --- /dev/null +++ b/merlin/static/merlin/templates/title.html @@ -0,0 +1,3 @@ + +{$ ::ngModel $}