acha-framework
Version:
is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...
88 lines • 2.84 kB
JavaScript
(function ($, angular, underscore, window, document, undefined) {
'use strict';
angular.module('frontend.directives').directive('multiSelect', [
'$document',
function ($document) {
return {
restrict: 'E',
replace: true,
scope: {
tag: '<?',
disabled: '=?',
visible: '=?',
cssClass: '=?',
textField: '=?',
valueField: '=?',
placeHolderTranslate: '=?',
placeHolder: '=?',
items: '=?',
model: '=?'
},
templateUrl: '/templates/framework/directives/multi-select/template.html',
link: function (scope, element, attr) {
scope.vm = { plate: false };
scope.vm.init = function () {
if (angular.isUndefined(scope.disabled)) {
scope.disabled = false;
}
if (angular.isUndefined(scope.visible)) {
scope.visible = true;
}
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.model)) {
scope.model = [];
}
if (angular.isUndefined(scope.items)) {
scope.items = [];
}
if (angular.isUndefined(scope.readonly)) {
scope.readonly = false;
}
scope.vm.bind();
};
scope.vm.closeElseWhere = function (e) {
scope.$apply(function () {
scope.vm.plate = false;
});
};
scope.vm.prevent = function ($event) {
$event.stopPropagation();
$event.preventDefault();
};
scope.vm.onAdd = function ($event, item) {
if (scope.disabled)
return;
scope.model.add(item);
};
scope.vm.onDelete = function ($event, item) {
$event.preventDefault();
$event.stopPropagation();
if (scope.disabled)
return;
scope.model.del(item);
};
scope.vm.togglePlate = function () {
if (scope.disabled || scope.readonly)
return;
scope.vm.plate = !scope.vm.plate;
};
scope.vm.bind = function () {
scope.$on('$destroy', function () {
$document.off('click', scope.vm.closeElseWhere);
});
$document.on('click', scope.vm.closeElseWhere);
};
scope.vm.init();
}
};
}
]);
}(jQuery, angular, _, window, document));