2015-06-29 15:51:29 -07: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
angular.module('forms').directive('fieldDirective', function($http, $compile) {
|
2015-07-21 16:25:45 -07:00
|
|
|
|
2015-06-29 15:51:29 -07: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',
|
|
|
|
'radio'
|
|
|
|
];
|
|
|
|
if (__indexOf.call(supported_fields, type) >= 0) {
|
|
|
|
return templateUrl += type + '.html';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var linker = function(scope, element) {
|
2015-07-05 21:29:05 -07:00
|
|
|
scope.field.required = scope.required;
|
2015-07-21 16:25:45 -07:00
|
|
|
|
|
|
|
//Set format only if field is a date
|
|
|
|
if(scope.field.fieldType === 'date'){
|
|
|
|
scope.dateOptions = {
|
|
|
|
changeYear: true,
|
|
|
|
changeMonth: true,
|
|
|
|
altFormat: "mm/dd/yyyy",
|
|
|
|
yearRange: '1900:-0',
|
|
|
|
defaultDate: 0,
|
|
|
|
};
|
|
|
|
}
|
2015-07-05 21:29:05 -07:00
|
|
|
|
2015-06-29 15:51:29 -07: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-05 21:29:05 -07:00
|
|
|
field: '=',
|
|
|
|
required: '&'
|
2015-06-29 15:51:29 -07:00
|
|
|
},
|
|
|
|
link: linker
|
|
|
|
};
|
|
|
|
});
|