2 .directive('formBuilder', ['$q', '$parse', '$http', '$templateCache', '$compile', '$document', '$timeout', function ($q, $parse, $http, $templateCache, $compile, $document, $timeout) {
4 restrict: 'E', // supports using directive as element only
12 link: function ($scope, element, attrs) {
13 $scope.element=element;
14 $scope.datetimeformat = "MM/dd/yyyy hh:mm a";
15 console.log("$scope");
17 $scope.buildField = function (field, parentElement) {
20 if (field.fieldType === 'LIST_MULTI_SELECT') {
21 x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br>'+
22 '<div class="select2-container ebz-listbox form-field" style="height:100px;" tabindex="0" >'+
23 '<label ng-repeat="item in ngModel.'+field.fieldId+'" style="display:block;">'+
24 '<input type="checkbox" style="margin-top: 10px;" ng-model="item.defaultValue" ng-change="triggerFormFields('+field.triggerOtherFormFields+')" att-checkbox title="{{item.title}}"/> {{item.title}}<br/>'+
27 } else if (field.fieldType === 'LIST_BOX') {
28 x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br> <div class="form-field" att-select="formFieldLuValues.'+field.fieldId+'" ng-model="ngModel.'+field.fieldId+'" ng-change="triggerFormFields('+field.triggerOtherFormFields+')"></div>');
29 } else if((field.fieldType === 'text' || field.fieldType === 'TEXT') && field.validationType === 'DATE'){
30 x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br> <input id="'+field.fieldId+'" type="text" ng-model="ngModel.'+field.fieldId+'" tabindex="0" ng-change="triggerFormFields('+field.triggerOtherFormFields+')" att-datepicker>');
31 } else if((field.fieldType === 'text' || field.fieldType === 'TEXT') && field.validationType === 'TIMESTAMP_MIN'){
32 x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br> <input id="'+field.fieldId+'" type="text" date-format="datetimeformat" ng-model="ngModel.'+field.fieldId+'" tabindex="0" ng-change="triggerFormFields('+field.triggerOtherFormFields+')" att-date-time-picker>');
33 } else if(field.fieldType === 'text' || field.fieldType === 'TEXT'){
34 x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br> <input type="text" class="form-field" ng-model="ngModel.'+field.fieldId+'" maxlength="'+field.length+'" ng-blur="triggerFormFields('+field.triggerOtherFormFields+')" />');
35 } else if(field.fieldType === 'CHECK_BOX'){
36 x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br> <input type="checkbox" ng-model="ngModel.'+field.fieldId+'" tabindex="0" ng-change="triggerFormFields('+field.triggerOtherFormFields+')" att-checkbox>');
39 parentElement.append(x);
42 $scope.buildForm = function() {
43 // create elements <table> and a <tbody>
44 var tbl = angular.element("<table></table>");
45 var tblBody = angular.element("<tbody></tbody>");
46 var row = angular.element("<tr></tr>");
48 var ngFormFieldsLength = $scope.ngFormFields.length;
50 for (var j = 0; j < ngFormFieldsLength; j++) {
51 var cell = angular.element("<td style='padding: 5px;'></td>");
52 $scope.buildField($scope.ngFormFields[j],cell);
55 if((j!=0 && (j+1)%$scope.ngNumFormCols==0) || j==(ngFormFieldsLength-1)){
57 row = angular.element("<tr></tr>");
61 angular.element($scope.element).html('');
62 $scope.element.append(tbl);
66 $scope.formFieldLuValues = {};
67 $scope.getEBZFormat = function() {
68 if($scope.ngFormFields && $scope.ngFormFields.length>0){
69 $scope.ngFormFields.forEach(function(formField) {
70 if(formField.fieldType === 'LIST_MULTI_SELECT') {
71 $scope.ngModel[formField.fieldId]= [];
72 if(formField.formFieldValues && formField.formFieldValues.length>0){
73 formField.formFieldValues.forEach(function(entry,i) {
74 $scope.ngModel[formField.fieldId].push({ index: i, value: entry.id, title: entry.name, defaultValue: entry.defaultValue});
77 } else if(formField.fieldType==='LIST_BOX') {
78 $scope.formFieldLuValues[formField.fieldId]= [];
79 if(formField.formFieldValues && formField.formFieldValues.length>0){
80 formField.formFieldValues.forEach(function(entry,i) {
81 $scope.formFieldLuValues[formField.fieldId].push({ index: i, value: entry.id, title: entry.name});
82 if(entry.defaultValue){
83 $scope.ngModel[formField.fieldId]={ index: i, value: entry.id, title: entry.name};
87 } else if(formField.fieldType === 'text' || formField.fieldType === 'TEXT' ||
88 formField.validationType === 'DATE' || formField.validationType === 'TIMESTAMP_MIN') {
89 if(formField.formFieldValues && formField.formFieldValues.length>0){
90 $scope.ngModel[formField.fieldId]=formField.formFieldValues[0].id;
97 $scope.$watch("ngFormFields",function(newValue,oldValue) {
98 if($scope.ngFormFields){
99 $scope.getEBZFormat();
104 $scope.triggerFormFields = function(triggerFlag) {
106 $scope.element.html('Loading...');
107 $scope.ngTriggerMethod();