rule.js
81 lines
| 2.7 KiB
| application/javascript
|
JavascriptLexer
r112 | // Copyright 2010 - 2017 RhodeCode GmbH and the AppEnlight project authors | |||
// | ||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||
// you may not use this file except in compliance with the License. | ||||
// You may obtain a copy of the License at | ||||
// | ||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||
// | ||||
// Unless required by applicable law or agreed to in writing, software | ||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
// See the License for the specific language governing permissions and | ||||
// limitations under the License. | ||||
r0 | ||||
angular.module('appenlight.directives.rule', []).directive('rule', function () { | ||||
return { | ||||
scope: {}, | ||||
bindToController:{ | ||||
parentObj: '=', | ||||
rule: '=', | ||||
ruleDefinitions: '=', | ||||
parentRule: "=", | ||||
config: "=" | ||||
}, | ||||
restrict: 'E', | ||||
r72 | templateUrl: 'directives/rule/rule.html', | |||
r0 | controller:RuleController, | |||
controllerAs:'rule_ctrlr' | ||||
}; | ||||
function RuleController(){ | ||||
var vm = this; | ||||
r147 | vm.$onInit = function () { | |||
vm.rule.dirty = false; | ||||
vm.oldField = vm.rule.field; | ||||
} | ||||
r0 | vm.add = function () { | |||
vm.rule.rules.push( | ||||
{op: "eq", field: 'http_status', value: ""} | ||||
); | ||||
vm.setDirty(); | ||||
}; | ||||
vm.setDirty = function() { | ||||
vm.rule.dirty = true; | ||||
console.log('set dirty'); | ||||
if (vm.parentObj){ | ||||
console.log('p', vm.parentObj); | ||||
console.log('set parent dirty'); | ||||
vm.parentObj.dirty = true; | ||||
} | ||||
}; | ||||
vm.fieldChange = function () { | ||||
r41 | var compound_types = ['__AND__', '__OR__', '__NOT__']; | |||
var new_is_compound = compound_types.indexOf(vm.rule.field) !== -1; | ||||
var old_was_compound = compound_types.indexOf(vm.oldField) !== -1; | ||||
r0 | ||||
if (!new_is_compound) { | ||||
vm.rule.op = vm.ruleDefinitions.fieldOps[vm.rule.field][0]; | ||||
} | ||||
if ((new_is_compound && !old_was_compound)) { | ||||
console.log('resetting config'); | ||||
delete vm.rule.value; | ||||
vm.rule.rules = []; | ||||
vm.add(); | ||||
} | ||||
else if (!new_is_compound && old_was_compound) { | ||||
console.log('resetting config'); | ||||
delete vm.rule.rules; | ||||
vm.rule.value = ''; | ||||
} | ||||
vm.oldField = vm.rule.field; | ||||
vm.setDirty(); | ||||
}; | ||||
vm.deleteRule = function (parent, rule) { | ||||
parent.rules.splice(parent.rules.indexOf(rule), 1); | ||||
vm.setDirty(); | ||||
} | ||||
} | ||||
}); | ||||