added my-label-select
[angular-drzb] / app / js / directives.js
index cac0c3c..ac273fe 100644 (file)
@@ -28,7 +28,56 @@ angular.module('myApp.directives', []).
                        element.replaceWith(html);
                }
     };
-  })
+  }).
+
+directive('myLabelInput', function() {
+    return {
+               restrict: 'C',
+               compile: function(element, attrs) {
+                       var my_class = attrs['class'] || '';
+                       my_class = my_class.replace(/ *my-input */,'');
+                       var my_type  = attrs['type']  || 'text';
+                       var m = attrs.ngModel;
+                       var html =
+'  <div class="control-group">'+
+'    <label class="control-label" for="'+m+'">'+attrs.label+'</label>'+
+'    <div class="controls">'+
+'      <input type="'+my_type+'" id="'+m+'" ng-model="'+m+'"';
+                       ;
+                       if ( attrs.placeholder ) html += ' placeholder="' + attrs.placeholder + '"';
+                       if ( attrs.ngRequired ) html += ' ng-required="' + attrs.ngRequired + '"';
+                       html += '>'+
+'    </div>'+
+'  </div>';
+
+                       element.replaceWith(html);
+               }
+    };
+})
+
+.directive('myLabelSelect', function() {
+    return {
+               restrict: 'C',
+               compile: function(element, attrs) {
+                       var my_class = attrs['class'] || '';
+                       my_class = my_class.replace(/ *my-input */,'');
+                       var m = attrs.ngModel;
+                       var html =
+'  <div class="control-group">'+
+'    <label class="control-label" for="'+m+'">'+attrs.label+'</label>'+
+'    <div class="controls">'+
+'      <select id="'+m+'" ng-model="'+m+'"';
+                       ;
+                       if ( attrs.ngOptions  ) html += ' ng-options="' + attrs.ngOptions + '"';
+                       html += '></select>'+
+'    </div>'+
+'  </div>';
+
+                       element.replaceWith(html);
+               }
+    };
+})
+
 .directive('bsTypeahead', ['$parse', function($parse) {
        'use strict';