acha-framework
Version:
is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...
74 lines • 2.46 kB
JavaScript
(function ($, angular, underscore, window, document, undefined) {
'use strict';
angular.module('frontend.directives').directive('radio', [function () {
return {
restrict: 'E',
replace: true,
scope: {
tag: '<?',
onChange: '<?',
disabled: '=?',
visible: '=?',
cssClass: '=?',
textField: '=?',
valueField: '=?',
triggerOnInit: '=?',
items: '=?',
inline: '=?',
model: '=?'
},
templateUrl: '/templates/framework/directives/radio/template.html',
link: function (scope, element, attr) {
scope.vm = { initialized: false };
scope.vm.init = function () {
if (angular.isUndefined(scope.disabled)) {
scope.disabled = false;
}
if (angular.isUndefined(scope.inline)) {
scope.inline = false;
}
if (angular.isUndefined(scope.visible)) {
scope.visible = true;
}
if (angular.isUndefined(scope.triggerOnInit)) {
scope.triggerOnInit = false;
}
if (angular.isUndefined(scope.items)) {
scope.items = [];
}
if (angular.isUndefined(scope.cssClass)) {
scope.cssClass = '';
}
if (angular.isUndefined(scope.textField)) {
scope.textField = 'text';
}
if (angular.isUndefined(scope.valueField)) {
scope.valueField = 'value';
}
if (angular.isUndefined(scope.readonly)) {
scope.readonly = false;
}
scope.vm.bind();
};
scope.vm.onPick = function (radio) {
if (scope.disabled)
return;
scope.model = radio[scope.valueField];
};
scope.vm.bind = function () {
scope.$watch('model', function (val, old) {
if (!scope.vm.initialized) {
scope.vm.initialized = true;
if (!scope.triggerOnInit)
return;
}
if (scope.vm.initialized && angular.isFunction(scope.onChange)) {
scope.onChange(scope.model, scope.tag, scope.items);
}
});
};
scope.vm.init();
}
};
}]);
}(jQuery, angular, _, window, document));