summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimur Sufiev <tsufiev@mirantis.com>2015-05-07 10:06:27 -0700
committerTimur Sufiev <tsufiev@mirantis.com>2015-06-03 16:06:24 +0300
commit4669e42341e84653cadf20e3e7a3fbeb1c9b33a6 (patch)
treefc6b72391411625983b8039536a66d6a7d4ebfb4
parentd9f94958c26875d62507d62dde00d6bdb7f6f5b8 (diff)
Move auto-completion machinery into a separate directive
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Timur Sufiev <tsufiev@mirantis.com> Workflow+1: Timur Sufiev <tsufiev@mirantis.com> Submitted-by: Jenkins Submitted-at: Wed, 03 Jun 2015 13:17:15 +0000 Reviewed-on: https://review.openstack.org/181082 Project: stackforge/merlin Branch: refs/heads/master
-rw-r--r--merlin/static/merlin/js/merlin.directives.js16
-rw-r--r--merlin/static/merlin/templates/fields/number.html5
-rw-r--r--merlin/static/merlin/templates/fields/string.html11
-rw-r--r--merlin/static/merlin/templates/fields/text.html5
4 files changed, 25 insertions, 12 deletions
diff --git a/merlin/static/merlin/js/merlin.directives.js b/merlin/static/merlin/js/merlin.directives.js
index 2d5546c..002e655 100644
--- a/merlin/static/merlin/js/merlin.directives.js
+++ b/merlin/static/merlin/js/merlin.directives.js
@@ -114,6 +114,18 @@
114 }) 114 })
115 .directive('typedField', ['$compile', 'merlin.templates', 115 .directive('typedField', ['$compile', 'merlin.templates',
116 function($compile, templates) { 116 function($compile, templates) {
117 function updateAutoCompletionDirective(template) {
118 template.find('input').each(function(index, elem) {
119 elem = angular.element(elem);
120 if ( elem.attr('autocompletable') ) {
121 // process 'autocompletable' attribute only once
122 elem.removeAttr('autocompletable');
123 elem.attr('typeahead-editable', true);
124 elem.attr('typeahead',
125 "option for option in value.getSuggestions() | filter:$viewValue");
126 }
127 });
128 }
117 return { 129 return {
118 restrict: 'E', 130 restrict: 'E',
119 scope: { 131 scope: {
@@ -122,6 +134,10 @@
122 }, 134 },
123 link: function(scope, element) { 135 link: function(scope, element) {
124 templates.templateReady(scope.type).then(function(template) { 136 templates.templateReady(scope.type).then(function(template) {
137 template = angular.element(template);
138 if ( scope.value.getSuggestions ) {
139 updateAutoCompletionDirective(template);
140 }
125 element.replaceWith($compile(template)(scope)); 141 element.replaceWith($compile(template)(scope));
126 }) 142 })
127 } 143 }
diff --git a/merlin/static/merlin/templates/fields/number.html b/merlin/static/merlin/templates/fields/number.html
index 7448e1e..2b53f39 100644
--- a/merlin/static/merlin/templates/fields/number.html
+++ b/merlin/static/merlin/templates/fields/number.html
@@ -1,6 +1,7 @@
1<div class="form-group"> 1<div class="form-group">
2 <pre>{$ value $}, {$ value.title() $}</pre> 2 <pre>{$ value $}, {$ value.title() $}</pre>
3 <label for="elem-{$ $id $}">{$ value.title() $}</label> 3 <label for="elem-{$ $id $}">{$ value.title() $}</label>
4 <input type="number" class="form-control" id="elem-{$ $id $}" ng-model="value.value" 4 <input type="number" class="form-control" id="elem-{$ $id $}"
5 ng-model-options="{ getterSetter: true }"> 5 ng-model="value.value" ng-model-options="{ getterSetter: true }"
6 autocompletable="true">
6</div> 7</div>
diff --git a/merlin/static/merlin/templates/fields/string.html b/merlin/static/merlin/templates/fields/string.html
index 769b1b1..e738076 100644
--- a/merlin/static/merlin/templates/fields/string.html
+++ b/merlin/static/merlin/templates/fields/string.html
@@ -1,11 +1,6 @@
1<div class="form-group"> 1<div class="form-group">
2 <label for="elem-{$ $id $}">{$ value.title() $}</label> 2 <label for="elem-{$ $id $}">{$ value.title() $}</label>
3 <input ng-if="!value.getSuggestions" 3 <input type="text" class="form-control" id="elem-{$ $id $}"
4 type="text" class="form-control" id="elem-{$ $id $}" ng-model="value.value" 4 ng-model="value.value" ng-model-options="{ getterSetter: true }"
5 ng-model-options="{ getterSetter: true }"> 5 autocompletable="true">
6 <input ng-if="value.getSuggestions"
7 type="text" class="form-control" id="elem-{$ $id $}" ng-model="value.value"
8 ng-model-options="{ getterSetter: true }"
9 typeahead="option for option in value.getSuggestions() | filter:$viewValue"
10 typeahead-editable="true">
11</div> 6</div>
diff --git a/merlin/static/merlin/templates/fields/text.html b/merlin/static/merlin/templates/fields/text.html
index 6867313..b961209 100644
--- a/merlin/static/merlin/templates/fields/text.html
+++ b/merlin/static/merlin/templates/fields/text.html
@@ -1,5 +1,6 @@
1<div class="form-group"> 1<div class="form-group">
2 <label for="elem-{$ $id $}">{$ value.title() $}</label> 2 <label for="elem-{$ $id $}">{$ value.title() $}</label>
3 <textarea class="form-control" id="elem-{$ $id $}" ng-model="value.value" 3 <textarea class="form-control" id="elem-{$ $id $}"
4 ng-model-options="{ getterSetter: true }"></textarea> 4 ng-model="value.value" ng-model-options="{ getterSetter: true }"
5 autocompletable="true"></textarea>
5</div> 6</div>