diff --git a/pandora_console/include/class/ExternalTools.class.php b/pandora_console/include/class/ExternalTools.class.php index e34317d945..27a2e7e1a1 100644 --- a/pandora_console/include/class/ExternalTools.class.php +++ b/pandora_console/include/class/ExternalTools.class.php @@ -159,6 +159,7 @@ class ExternalTools extends HTML // Make the table for show the form. $table = new stdClass(); $table->width = '100%'; + $table->id = 'commandsTable'; $table->data = []; @@ -191,7 +192,11 @@ class ExternalTools extends HTML 'content' => html_print_image( 'images/add.png', true, - [ 'title' => __('Add new custom command') ] + [ + 'title' => __('Add new custom command'), + 'onclick' => 'manageCommandLines(event)', + 'id' => 'img_add_button_custom_command', + ] ), ], true @@ -200,45 +205,29 @@ class ExternalTools extends HTML $table->data[6][0] = __('Command'); $table->data[6][1] = __('Parameters'); - $i = 0; - $iRow = 6; - foreach ($this->pathCustomComm as $command) { - $i++; - $iRow++; + $i = 1; + $iRow = 7; - // Fill the fields. - $customCommand = ($command['custom_command'] ?? ''); - $customParams = ($command['custom_params'] ?? ''); - // Attach the fields. + if (empty($this->pathCustomComm) === true) { $table->rowid[$iRow] = 'custom_row_'.$i; - $table->data[$iRow][0] = html_print_input_text( - 'command_custom_'.$i, - $customCommand, - '', - 40, - 255, - true - ); - $table->data[$iRow][1] = html_print_input_text( - 'params_custom_'.$i, - $customParams, - '', - 40, - 255, - true - ); - $table->data[$iRow][2] = html_print_div( - [ - 'id' => 'delete_custom_'.$i, - 'class' => '', - 'content' => html_print_image( - 'images/delete.png', - true, - ['title' => __('Delete this custom command')] - ), - ], - true - ); + + $table->data[$iRow][0] = $this->customCommandPair('command', $i); + $table->data[$iRow][1] = $this->customCommandPair('params', $i); + $table->data[$iRow][2] = $this->customCommandPair('delete', $i); + } else { + foreach ($this->pathCustomComm as $command) { + $i++; + $iRow++; + + // Fill the fields. + $customCommand = ($command['custom_command'] ?? ''); + $customParams = ($command['custom_params'] ?? ''); + // Attach the fields. + $table->rowid[$iRow] = 'custom_row_'.$i; + $table->data[$iRow][0] = $this->customCommandPair('command', $i, $customCommand); + $table->data[$iRow][1] = $this->customCommandPair('params', $i, $customParams); + $table->data[$iRow][2] = $this->customCommandPair('delete', $i); + } } $form = '
'; @@ -263,6 +252,60 @@ class ExternalTools extends HTML } + /** + * Prints the custom command fields. + * + * @param string $type Type of field. + * @param integer $index Control index. + * @param string $value Value of this field. + * + * @return string + */ + private function customCommandPair($type, $index=0, $value='') + { + $output = ''; + + switch ($type) { + case 'command': + case 'params': + $output = html_print_input_text( + $type.'_custom_'.$index, + $value, + '', + 40, + 255, + true + ); + break; + + case 'delete': + $output = html_print_div( + [ + 'id' => 'delete_button_custom_'.$index, + 'class' => '', + 'content' => html_print_image( + 'images/delete.png', + true, + [ + 'title' => __('Delete this custom command'), + 'onclick' => 'manageCommandLines(event)', + 'id' => 'img_delete_button_custom_'.$index, + ] + ), + ], + true + ); + break; + + default: + // Do none. + break; + } + + return $output; + } + + /** * Print the form for use the external tools. * @@ -690,52 +733,69 @@ class ExternalTools extends HTML