2
user_decided_length: false,
6
getConsoleLog: function(via_user_submit) {
7
var form_element = $("#tail_length"),
10
if (!via_user_submit) {
11
via_user_submit = false;
14
if(this.user_decided_length) {
15
data = $(form_element).serialize();
21
url: $(form_element).attr('action'),
24
success: function(response_body) {
25
$('pre.logs').text(response_body);
27
error: function(response) {
29
horizon.clearErrorMessages();
30
horizon.alert('error', gettext('There was a problem communicating with the server, please try again.'));
37
* Gets the html select element associated with a given
38
* rule id for rule_id.
40
get_rule_element: function(rule_id) {
41
return $('li > label[for^="id_rule_' + rule_id + '"]');
45
* Initializes an associative array of lists of the current
48
init_rule_list: function() {
49
horizon.firewalls.rules_selected = [];
50
horizon.firewalls.rules_available = [];
51
$(this.get_rule_element("")).each(function(){
53
var $input = $this.children("input");
55
name:$this.text().replace(/^\s+/,""),
57
value:$input.attr("value")
59
if($input.is(':checked')) {
60
horizon.firewalls.rules_selected.push(rule_property);
62
horizon.firewalls.rules_available.push(rule_property);
68
* Generates the HTML structure for a rule that will be displayed
69
* as a list item in the rule list.
71
generate_rule_element: function(name, id, value) {
73
$li.attr('name', value).html(name + '<em class="rule_id">(' + value + ')</em><a href="#" class="btn btn-primary"></a>');
78
* Generates the HTML structure for the Rule List.
80
generate_rulelist_html: function() {
82
var updateForm = function() {
83
var lists = $("#ruleListId div.input li").attr('data-index',100);
84
var active_rules = $("#selected_rule > li").map(function(){
85
return $(this).attr("name");
87
$("#ruleListId div.input input:checkbox").removeAttr('checked');
88
active_rules.each(function(index, value){
89
$("#ruleListId div.input input:checkbox[value=" + value + "]")
90
.attr('checked','checked')
91
.parents("li").attr('data-index',index);
93
$("#ruleListId div.input ul").html(
94
lists.sort(function(a,b){
95
if( $(a).data("index") < $(b).data("index")) return -1;
96
if( $(a).data("index") > $(b).data("index")) return 1;
101
$("#ruleListSortContainer").show();
102
$("#ruleListIdContainer").hide();
103
self.init_rule_list();
104
// Make sure we don't duplicate the rules in the list
105
$("#available_rule").empty();
106
$.each(self.rules_available, function(index, value){
107
$("#available_rule").append(self.generate_rule_element(value.name, value.id, value.value));
109
// Make sure we don't duplicate the rules in the list
110
$("#selected_rule").empty();
111
$.each(self.rules_selected, function(index, value){
112
$("#selected_rule").append(self.generate_rule_element(value.name, value.id, value.value));
114
$(".rulelist > li > a.btn").click(function(e){
118
if($this.parents("ul#available_rule").length > 0) {
119
$this.parent().appendTo($("#selected_rule"));
120
} else if ($this.parents("ul#selected_rule").length > 0) {
121
$this.parent().appendTo($("#available_rule"));
125
if ($("#ruleListId > div.control-group.error").length > 0) {
126
var errortext = $("#ruleListId > div.control-group.error").find("span.help-inline").text();
127
$("#selected_rule_h4").before($('<div class="dynamic-error">').html(errortext));
129
$(".rulelist").sortable({
130
connectWith: "ul.rulelist",
131
placeholder: "ui-state-highlight",
133
start:function(e,info){
134
$("#selected_rule").addClass("dragging");
136
stop:function(e,info){
137
$("#selected_rule").removeClass("dragging");
140
}).disableSelection();
143
workflow_init: function(modal) {
144
// Initialise the drag and drop rule list
145
horizon.firewalls.generate_rulelist_html();
149
horizon.addInitFunction(function () {
150
$(document).on('submit', '#tail_length', function (evt) {
151
horizon.firewalls.user_decided_length = true;
152
horizon.firewalls.getConsoleLog(true);
153
evt.preventDefault();