UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

67 lines 2.24 kB
(function ($, angular, underscore, window, document, undefined) { 'use strict'; angular.module('frontend.directives').directive('numbox', [function () { return { restrict: 'E', replace: true, scope: { tag: '<?', disabled: '=?', visible: '=?', cssClass: '=?', required: '=?', triggerOnInit: '=?', readonly: '=?', model: '=?' }, templateUrl: '/templates/framework/directives/numbox/template.html', link: function (scope, element, attr) { scope.vm = {}; scope.vm.init = function () { if (angular.isUndefined(scope.disabled)) { scope.disabled = false; } if (angular.isUndefined(scope.visible)) { scope.visible = true; } if (angular.isUndefined(scope.required)) { scope.required = true; } if (angular.isUndefined(scope.cssClass)) { scope.cssClass = ''; } if (scope.required && angular.isUndefined(scope.model)) { scope.model = 0; } if (angular.isUndefined(scope.readonly)) { scope.readonly = false; } scope.vm.bind(); }; scope.vm.increase = function () { if (scope.disabled || scope.readonly) return; scope.model = parseInt(scope.model || 0) + 1; }; scope.vm.decrease = function () { if (scope.disabled || scope.readonly) return; scope.model = parseInt(scope.model || 0) - 1; }; 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.vm.init(); } }; }]); }(jQuery, angular, _, window, document));