1<script type="text/javascript"> 2 function removeStep(obj) { 3 var step = obj.getAttribute('remove_step'), 4 table = jQuery('#httpStepTable'); 5 6 jQuery('#steps_' + step).remove(); 7 jQuery('#steps_' + step + '_httpstepid').remove(); 8 jQuery('#steps_' + step + '_httptestid').remove(); 9 jQuery('#steps_' + step + '_name').remove(); 10 jQuery('#steps_' + step + '_no').remove(); 11 jQuery('#steps_' + step + '_url').remove(); 12 jQuery('#steps_' + step + '_timeout').remove(); 13 jQuery('#steps_' + step + '_posts').remove(); 14 jQuery('#steps_' + step + '_variables').remove(); 15 jQuery('#steps_' + step + '_required').remove(); 16 jQuery('#steps_' + step + '_status_codes').remove(); 17 jQuery('#steps_' + step + '_headers').remove(); 18 jQuery('#steps_' + step + '_retrieve_mode').remove(); 19 jQuery('#steps_' + step + '_follow_redirects').remove(); 20 21 if (table.find('tr.sortable').length <= 1) { 22 table.sortable('disable'); 23 } 24 25 recalculateSortOrder(); 26 } 27 28 function recalculateSortOrder() { 29 var i = 0; 30 31 jQuery('#httpStepTable tr.sortable .rowNum').each(function() { 32 var step = (i == 0) ? '0' : i; 33 34 // rewrite ids to temp 35 jQuery('#remove_' + step).attr('id', 'tmp_remove_' + step); 36 jQuery('#name_' + step).attr('id', 'tmp_name_' + step); 37 jQuery('#steps_' + step).attr('id', 'tmp_steps_' + step); 38 jQuery('#steps_' + step + '_httpstepid').attr('id', 'tmp_steps_' + step + '_httpstepid'); 39 jQuery('#steps_' + step + '_httptestid').attr('id', 'tmp_steps_' + step + '_httptestid'); 40 jQuery('#steps_' + step + '_name').attr('id', 'tmp_steps_' + step + '_name'); 41 jQuery('#steps_' + step + '_no').attr('id', 'tmp_steps_' + step + '_no'); 42 jQuery('#steps_' + step + '_url').attr('id', 'tmp_steps_' + step + '_url'); 43 jQuery('#steps_' + step + '_timeout').attr('id', 'tmp_steps_' + step + '_timeout'); 44 jQuery('#steps_' + step + '_posts').attr('id', 'tmp_steps_' + step + '_posts'); 45 jQuery('#steps_' + step + '_variables').attr('id', 'tmp_steps_' + step + '_variables'); 46 jQuery('#steps_' + step + '_required').attr('id', 'tmp_steps_' + step + '_required'); 47 jQuery('#steps_' + step + '_status_codes').attr('id', 'tmp_steps_' + step + '_status_codes'); 48 jQuery('#steps_' + step + '_headers').attr('id', 'tmp_steps_' + step + '_headers'); 49 jQuery('#steps_' + step + '_follow_redirects').attr('id', 'tmp_steps_' + step + '_follow_redirects'); 50 jQuery('#steps_' + step + '_retrieve_mode').attr('id', 'tmp_steps_' + step + '_retrieve_mode'); 51 jQuery('#current_step_' + step).attr('id', 'tmp_current_step_' + step); 52 53 // set order number 54 jQuery(this) 55 .attr('new_step', i) 56 .text((i + 1) + ':'); 57 i++; 58 }); 59 60 // rewrite ids in new order 61 for (var n = 0; n < i; n++) { 62 var currStep = jQuery('#tmp_current_step_' + n), 63 newStep = currStep.attr('new_step'); 64 65 jQuery('#tmp_remove_' + n).attr('id', 'remove_' + newStep); 66 jQuery('#tmp_name_' + n).attr('id', 'name_' + newStep); 67 jQuery('#tmp_steps_' + n).attr('id', 'steps_' + newStep); 68 jQuery('#tmp_steps_' + n + '_httpstepid').attr('id', 'steps_' + newStep + '_httpstepid'); 69 jQuery('#tmp_steps_' + n + '_httptestid').attr('id', 'steps_' + newStep + '_httptestid'); 70 jQuery('#tmp_steps_' + n + '_name').attr('id', 'steps_' + newStep + '_name'); 71 jQuery('#tmp_steps_' + n + '_no').attr('id', 'steps_' + newStep + '_no'); 72 jQuery('#tmp_steps_' + n + '_url').attr('id', 'steps_' + newStep + '_url'); 73 jQuery('#tmp_steps_' + n + '_timeout').attr('id', 'steps_' + newStep + '_timeout'); 74 jQuery('#tmp_steps_' + n + '_posts').attr('id', 'steps_' + newStep + '_posts'); 75 jQuery('#tmp_steps_' + n + '_variables').attr('id', 'steps_' + newStep + '_variables'); 76 jQuery('#tmp_steps_' + n + '_required').attr('id', 'steps_' + newStep + '_required'); 77 jQuery('#tmp_steps_' + n + '_status_codes').attr('id', 'steps_' + newStep + '_status_codes'); 78 jQuery('#tmp_steps_' + n + '_headers').attr('id', 'steps_' + newStep + '_headers'); 79 jQuery('#tmp_steps_' + n + '_follow_redirects').attr('id', 'steps_' + newStep + '_follow_redirects'); 80 jQuery('#tmp_steps_' + n + '_retrieve_mode').attr('id', 'steps_' + newStep + '_retrieve_mode'); 81 82 jQuery('#remove_' + newStep).attr('remove_step', newStep); 83 jQuery('#name_' + newStep).attr('name_step', newStep); 84 jQuery('#steps_' + newStep + '_httpstepid').attr('name', 'steps[' + newStep + '][httpstepid]'); 85 jQuery('#steps_' + newStep + '_httptestid').attr('name', 'steps[' + newStep + '][httptestid]'); 86 jQuery('#steps_' + newStep + '_name').attr('name', 'steps[' + newStep + '][name]'); 87 jQuery('#steps_' + newStep + '_no') 88 .attr('name', 'steps[' + newStep + '][no]') 89 .val(parseInt(newStep) + 1); 90 jQuery('#steps_' + newStep + '_url').attr('name', 'steps[' + newStep + '][url]'); 91 jQuery('#steps_' + newStep + '_timeout').attr('name', 'steps[' + newStep + '][timeout]'); 92 jQuery('#steps_' + newStep + '_posts').attr('name', 'steps[' + newStep + '][posts]'); 93 jQuery('#steps_' + newStep + '_variables').attr('name', 'steps[' + newStep + '][variables]'); 94 jQuery('#steps_' + newStep + '_required').attr('name', 'steps[' + newStep + '][required]'); 95 jQuery('#steps_' + newStep + '_status_codes').attr('name', 'steps[' + newStep + '][status_codes]'); 96 jQuery('#steps_' + newStep + '_headers').attr('name', 'steps[' + newStep + '][headers]'); 97 jQuery('#steps_' + newStep + '_retrieve_mode').attr('name', 'steps[' + newStep + '][retrieve_mode]'); 98 jQuery('#steps_' + newStep + '_follow_redirects').attr('name', 'steps[' + newStep + '][follow_redirects]'); 99 100 // set new step order position 101 currStep.attr('id', 'current_step_' + newStep); 102 } 103 } 104 105 jQuery(function($) { 106 var stepTable = $('#httpStepTable'), 107 stepTableWidth = stepTable.width(), 108 stepTableColumns = $('#httpStepTable .header td'), 109 stepTableColumnWidths = []; 110 111 stepTableColumns.each(function() { 112 stepTableColumnWidths[stepTableColumnWidths.length] = $(this).width(); 113 }); 114 115 stepTable.sortable({ 116 disabled: (stepTable.find('tr.sortable').length < 2), 117 items: 'tbody tr.sortable', 118 axis: 'y', 119 cursor: 'move', 120 handle: 'div.<?= ZBX_STYLE_DRAG_ICON ?>', 121 tolerance: 'pointer', 122 opacity: 0.6, 123 update: recalculateSortOrder, 124 create: function () { 125 // force not to change table width 126 stepTable.width(stepTableWidth); 127 }, 128 helper: function(e, ui) { 129 ui.children().each(function(i) { 130 var td = $(this); 131 132 td.width(stepTableColumnWidths[i]); 133 }); 134 135 // when dragging element on safari, it jumps out of the table 136 if (SF) { 137 // move back draggable element to proper position 138 ui.css('left', (ui.offset().left - 2) + 'px'); 139 } 140 141 stepTableColumns.each(function(i) { 142 $(this).width(stepTableColumnWidths[i]); 143 }); 144 145 return ui; 146 }, 147 start: function(e, ui) { 148 // fix placeholder not to change height while object is being dragged 149 $(ui.placeholder).height($(ui.helper).height()); 150 } 151 }); 152 153 // http step add pop up 154 <?php if (!$this->data['templated']) : ?> 155 $('#add_step').click(function() { 156 var form = $(this).parents('form'); 157 158 // append existing step names 159 var stepNames = ''; 160 form.find('input[name^=steps]').filter('input[name*=name]').each(function(i, stepName) { 161 stepNames += '&steps_names[]=' + encodeURIComponent($(stepName).val()); 162 }); 163 164 return PopUp('popup_httpstep.php?dstfrm=httpForm' + stepNames); 165 }); 166 <?php endif ?> 167 168 // http step edit pop up 169 <?php foreach ($this->data['steps'] as $i => $step): ?> 170 $('#name_<?= $i ?>').click(function() { 171 // append existing step names 172 var stepNames = ''; 173 var form = $(this).parents('form'); 174 form.find('input[name^=steps]').filter('input[name*=name]').each(function(i, stepName) { 175 stepNames += '&steps_names[]=' + encodeURIComponent($(stepName).val()); 176 }); 177 178 return PopUp('popup_httpstep.php?dstfrm=httpForm&templated=<?= $this->data['templated'] ?>' 179 + '&list_name=steps&stepid=' + jQuery(this).attr('name_step') 180 + '<?= url_param($step['name'], false, 'name') ?>' 181 + '<?= url_param($step['url'], false, 'url') ?>' 182 + '<?= url_param($step['posts'], false, 'posts') ?>' 183 + '<?= url_param($step['variables'], false, 'variables') ?>' 184 + '<?= url_param($step['timeout'], false, 'timeout') ?>' 185 + '<?= url_param($step['required'], false, 'required') ?>' 186 + '<?= url_param($step['status_codes'], false, 'status_codes') ?>' 187 + '<?= url_param($step['name'], false, 'old_name') ?>' 188 + '<?= url_param($step['headers'], false, 'headers') ?>' 189 + '<?= url_param($step['retrieve_mode'], false, 'retrieve_mode') ?>' 190 + '<?= url_param($step['follow_redirects'], false, 'follow_redirects') ?>' 191 + stepNames); 192 }); 193 <?php endforeach ?> 194 195 $('#authentication').on('change', function() { 196 var httpFieldsDisabled = ($(this).val() == <?= HTTPTEST_AUTH_NONE ?>); 197 198 $('#http_user') 199 .attr('disabled', httpFieldsDisabled) 200 .closest('li').toggle(!httpFieldsDisabled); 201 $('#http_password') 202 .attr('disabled', httpFieldsDisabled) 203 .closest('li').toggle(!httpFieldsDisabled); 204 }); 205 206 <?php if (isset($this->data['agentVisibility']) && $this->data['agentVisibility']): ?> 207 new CViewSwitcher('agent', 'change', <?= zbx_jsvalue($this->data['agentVisibility'], true) ?>); 208 <?php endif ?> 209 210 $('#agent').trigger('change'); 211 $('#authentication').trigger('change'); 212 }); 213</script> 214