harbor/static/resources/js/components/log/advanced-search.directive.js

150 lines
3.3 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
angular
.module('harbor.log')
.directive('advancedSearch', advancedSearch);
AdvancedSearchController.$inject = ['$scope', 'ListLogService'];
function AdvancedSearchController($scope, ListLogService) {
var vm = this;
2016-04-28 19:36:39 +02:00
vm.checkOperation = checkOperation;
vm.close = close;
vm.opAll = true;
2016-07-04 13:09:19 +02:00
vm.doSearch = doSearch;
$scope.$watch('vm.op', function(current) {
if(current && vm.op[0] === 'all') {
vm.opCreate = true;
vm.opPull = true;
vm.opPush = true;
vm.opDelete = true;
vm.opOthers = true;
}
}, true);
$scope.$watch('vm.fromDate', function(current) {
if(current) {
vm.fromDate = current;
}
});
$scope.$watch('vm.toDate', function(current) {
if(current) {
vm.toDate = current;
}
});
2016-07-04 13:09:19 +02:00
vm.opCreate = true;
vm.opPull = true;
vm.opPush = true;
vm.opDelete = true;
vm.opOthers = true;
2016-07-04 13:09:19 +02:00
vm.others = '';
2016-04-28 19:36:39 +02:00
vm.op = [];
vm.op.push('all');
function checkOperation(e) {
2016-05-23 12:29:17 +02:00
if(e.checked === 'all') {
vm.opCreate = vm.opAll;
vm.opPull = vm.opAll;
vm.opPush = vm.opAll;
vm.opDelete = vm.opAll;
vm.opOthers = vm.opAll;
}else {
vm.opAll = false;
}
vm.op = [];
if(vm.opCreate) {
vm.op.push('create');
}
if(vm.opPull) {
2016-07-04 13:09:19 +02:00
vm.op.push('pull');
}
if(vm.opPush) {
2016-07-04 13:09:19 +02:00
vm.op.push('push');
}
if(vm.opDelete) {
2016-07-04 13:09:19 +02:00
vm.op.push('delete');
}
if(vm.opOthers && $.trim(vm.others) !== '') {
vm.op.push($.trim(vm.others));
}
2016-04-28 19:36:39 +02:00
}
vm.pickUp = pickUp;
function pickUp(e) {
switch(e.key){
case 'fromDate':
vm.fromDate = e.value;
break;
case 'toDate':
vm.toDate = e.value;
break;
}
2016-04-28 19:36:39 +02:00
$scope.$apply();
}
2016-04-28 19:36:39 +02:00
function close() {
vm.op = [];
vm.op.push('all');
vm.fromDate = '';
vm.toDate = '';
vm.others = '';
vm.isOpen = false;
}
2016-07-04 13:09:19 +02:00
function doSearch (e){
if(vm.opOthers && $.trim(vm.others) !== '') {
e.op.push(vm.others);
}
vm.search(e);
}
}
function advancedSearch() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/resources/js/components/log/advanced-search.directive.html',
'scope': {
2016-04-27 12:29:55 +02:00
'isOpen': '=',
'op': '=',
2016-07-04 13:09:19 +02:00
'opOthers': '=',
2016-04-27 12:29:55 +02:00
'others': '=',
2016-04-28 19:36:39 +02:00
'fromDate': '=',
'toDate': '=',
2016-04-27 12:29:55 +02:00
'search': '&'
},
2016-04-28 19:36:39 +02:00
'link': link,
'controller': AdvancedSearchController,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
2016-04-28 19:36:39 +02:00
function link(scope, element, attrs, ctrl) {
element.find('.datetimepicker').datetimepicker({
locale: 'en-US',
ignoreReadonly: true,
format: 'L',
showClear: true
});
element.find('#fromDatePicker').on('blur', function(){
ctrl.pickUp({'key': 'fromDate', 'value': $(this).val()});
});
element.find('#toDatePicker').on('blur', function(){
ctrl.pickUp({'key': 'toDate', 'value': $(this).val()});
});
}
}
})();