2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// coffeescript's for in loop
|
|
|
|
var __indexOf = [].indexOf || function(item) {
|
|
|
|
for (var i = 0, l = this.length; i < l; i++) {
|
|
|
|
if (i in this && this[i] === item) return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2015-08-06 05:52:59 +00:00
|
|
|
angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$rootScope',
|
|
|
|
function($http, $compile, $rootScope) {
|
2015-07-21 23:25:45 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
var getTemplateUrl = function(field) {
|
|
|
|
|
|
|
|
var type = field.fieldType;
|
|
|
|
var templateUrl = './modules/forms/views/directiveViews/field/';
|
|
|
|
var supported_fields = [
|
|
|
|
'textfield',
|
|
|
|
'email',
|
|
|
|
'textarea',
|
|
|
|
'checkbox',
|
|
|
|
'date',
|
|
|
|
'dropdown',
|
|
|
|
'hidden',
|
|
|
|
'password',
|
2015-07-27 18:11:43 +00:00
|
|
|
'radio',
|
2015-07-29 17:45:24 +00:00
|
|
|
'legal',
|
2015-07-30 00:22:53 +00:00
|
|
|
'statement',
|
|
|
|
'rating',
|
2015-07-30 01:27:46 +00:00
|
|
|
'yes_no',
|
2015-08-06 05:52:59 +00:00
|
|
|
'number',
|
2015-07-30 01:27:46 +00:00
|
|
|
'natural'
|
2015-06-29 22:51:29 +00:00
|
|
|
];
|
|
|
|
if (__indexOf.call(supported_fields, type) >= 0) {
|
|
|
|
return templateUrl += type + '.html';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var linker = function(scope, element) {
|
2015-07-21 23:25:45 +00:00
|
|
|
|
2015-08-06 05:52:59 +00:00
|
|
|
scope.setActiveField = $rootScope.setActiveField;
|
2015-07-21 23:25:45 +00:00
|
|
|
//Set format only if field is a date
|
|
|
|
if(scope.field.fieldType === 'date'){
|
|
|
|
scope.dateOptions = {
|
|
|
|
changeYear: true,
|
|
|
|
changeMonth: true,
|
2015-08-07 21:02:44 +00:00
|
|
|
altFormat: 'mm/dd/yyyy',
|
2015-07-21 23:25:45 +00:00
|
|
|
yearRange: '1900:-0',
|
|
|
|
defaultDate: 0,
|
|
|
|
};
|
|
|
|
}
|
2015-07-30 01:27:46 +00:00
|
|
|
//Set only if we have a natural lang processing field
|
|
|
|
else if(scope.field.fieldType === 'natural'){
|
2015-08-04 21:06:16 +00:00
|
|
|
scope.field.fieldMatchValue = '';
|
2015-07-30 01:27:46 +00:00
|
|
|
|
|
|
|
//Fires when field is changed
|
2015-08-04 21:06:16 +00:00
|
|
|
scope.$watch('scope.field', function(newField, oldField) {
|
|
|
|
|
2015-07-30 01:27:46 +00:00
|
|
|
});
|
|
|
|
}
|
2015-07-06 04:29:05 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
// GET template content from path
|
|
|
|
var templateUrl = getTemplateUrl(scope.field);
|
|
|
|
$http.get(templateUrl).success(function(data) {
|
|
|
|
element.html(data);
|
|
|
|
$compile(element.contents())(scope);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
template: '<div>{{field.title}}</div>',
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
2015-07-06 04:29:05 +00:00
|
|
|
field: '=',
|
|
|
|
required: '&'
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
|
|
|
link: linker
|
|
|
|
};
|
2015-08-06 05:52:59 +00:00
|
|
|
}]);
|