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 $scope.buildField = function (field, parentElement) {
19 if (field.fieldType === 'LIST_MULTI_SELECT') {
20 /*x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br>'+
21 '<div class="select2-container ebz-listbox form-field" style="height:100px;" tabindex="0" >'+
22 '<label ng-repeat="item in ngModel.'+field.fieldId+'" style="display:block;">'+
23 '<input type="checkbox" style="margin-top: 10px;" ng-model="item.defaultValue" ng-change="triggerFormFields('+field.triggerOtherFormFields+')" att-checkbox title="{{item.title}}"/> {{item.title}}<br/>'+
28 '<div class="listbox-container">'+
29 '<h3 id="source_listbox-2---multiselectable">'+field.fieldDisplayName+'</h3>'+
30 '<div class="listbox-list" tabindex="-1">'+
31 '<b2b-list-box listbox-data= "ngModel.'+field.fieldId+'" aria-multiselectable="true">'+
32 '<div tabindex="-1" data-index="{{$index}}" b2b-accessibility-click="13,32" ng-repeat="number in ngModel.'+field.fieldId+'" role="option" class="b2b-list-box-item" ng-class="{'+
33 "'b2b-list-box-item--selected'"+
34 ': number.selected}" ng-bind-html="number.title | unsafe"></div>'+
38 } else if (field.fieldType === 'LIST_BOX') {
41 '<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label>'+
42 '<select id="dropdown1" name="dropdown1" aria-describedby="dropdown1" b2b-dropdown placeholder-text="Select" ng-model="ngModel.'+field.fieldId+'" ng-change="triggerFormFields('+field.triggerOtherFormFields+')">'+
43 ' <option b2b-dropdown-list option-repeat="d in formFieldLuValues.'+ field.fieldId +'" value="{{d.value}}">{{d.title}}</option>'+
47 x = angular.element(temp);
48 //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>');
49 } else if((field.fieldType === 'text' || field.fieldType === 'TEXT') && field.validationType === 'DATE'){
50 x = angular.element('<label><i>'+field.fieldDisplayName+'<span ng-show="ngShowFieldId"> [ '+field.fieldId+' ] </span>:</i></label><br> <div class="datepicker-container" > <input id="'+field.fieldId+'" type="text" ng-model="ngModel.'+field.fieldId+'" tabindex="0" ng-change="triggerFormFields('+field.triggerOtherFormFields+')" b2b-datepicker></div>');
51 } else if((field.fieldType === 'text' || field.fieldType === 'TEXT') && field.validationType === 'TIMESTAMP_MIN'){
52 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>');
53 } else if(field.fieldType === 'text' || field.fieldType === 'TEXT'){
54 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+')" />');
55 } else if(field.fieldType === 'CHECK_BOX'){
56 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>');
58 parentElement.append(x);
63 $scope.buildForm = function() {
64 // create elements <table> and a <tbody>
65 var tbl = angular.element("<table></table>");
66 var tblBody = angular.element("<tbody></tbody>");
67 var row = angular.element("<tr></tr>");
69 var ngFormFieldsLength = $scope.ngFormFields.length;
71 for (var j = 0; j < ngFormFieldsLength; j++) {
72 var cell = angular.element("<td style='padding: 5px;'></td>");
73 $scope.buildField($scope.ngFormFields[j],cell);
76 if((j!=0 && (j+1)%$scope.ngNumFormCols==0) || j==(ngFormFieldsLength-1)){
78 row = angular.element("<tr></tr>");
82 angular.element($scope.element).html('');
83 $scope.element.append(tbl);
87 $scope.formFieldLuValues = {};
88 $scope.getEBZFormat = function() {
89 if($scope.ngFormFields && $scope.ngFormFields.length>0){
90 $scope.ngFormFields.forEach(function(formField) {
91 if(formField.fieldType === 'LIST_MULTI_SELECT') {
92 $scope.ngModel[formField.fieldId]= [];
93 if(formField.formFieldValues && formField.formFieldValues.length>0){
94 formField.formFieldValues.forEach(function(entry,i) {
95 $scope.ngModel[formField.fieldId].push({ index: i, value: entry.id, title: entry.name, defaultValue: entry.defaultValue});
98 } else if(formField.fieldType==='LIST_BOX') {
99 $scope.formFieldLuValues[formField.fieldId]= [];
100 if(formField.formFieldValues && formField.formFieldValues.length>0){
101 formField.formFieldValues.forEach(function(entry,i) {
102 $scope.formFieldLuValues[formField.fieldId].push({ index: i, value: entry.id, title: entry.name});
103 if(entry.defaultValue){
104 //$scope.ngModel[formField.fieldId]={ index: i, value: entry.id, title: entry.name};
108 } else if(formField.fieldType === 'text' || formField.fieldType === 'TEXT' ||
109 formField.validationType === 'DATE' || formField.validationType === 'TIMESTAMP_MIN') {
110 if(formField.formFieldValues && formField.formFieldValues.length>0){
111 $scope.ngModel[formField.fieldId]=formField.formFieldValues[0].id;
118 $scope.$watch("ngFormFields",function(newValue,oldValue) {
119 if($scope.ngFormFields){
120 $scope.getEBZFormat();
125 $scope.triggerFormFields = function(triggerFlag) {
127 $scope.element.html('Loading...');
128 $scope.ngTriggerMethod();