'use strict';

angular.module('qusion.ui.multiselect', [
])
    .directive('qnMultiselect', function () {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function (scope, elem, attr) {
                //set up the plugin.
                //elem.chosen();
                var options = scope.$eval(attr.qnMultiselect);
                var source = qusion.parseSource(attr.ngOptions);

                elem.multiselect({ header: true });
                var model = attr.ngModel;
                //watch the options source and refresh the plugin.
                scope.$watch(source, function (value) {
                    elem.multiselect('refresh').multiselectfilter();
                   
                  
                });

                //scope.$watch(model, function (value) {
                //elem.multiselect('refresh').multiselectfilter();
                   
               // });
            }
        };
    });