From d4b92a69136e46b4bcb07db1cb5f340e7cb28e97 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 10 Jan 2020 13:48:07 +0100 Subject: [PATCH] Fixed errors in VC --- pandora_console/include/javascript/pandora.js | 10 ++- .../javascript/pandora_visual_console.js | 20 ++++- .../rest-api/models/VisualConsole/Item.php | 26 +++++- .../rest-api/models/VisualConsole/View.php | 88 +++++++++---------- 4 files changed, 92 insertions(+), 52 deletions(-) diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 6d5935ac60..2151d916ff 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1920,6 +1920,10 @@ function load_modal(settings) { }; } + if (settings.beforeClose == undefined) { + settings.beforeClose = function() {}; + } + settings.target.html("Loading modal..."); settings.target .dialog({ @@ -1989,7 +1993,6 @@ function load_modal(settings) { text: settings.modal.ok, click: function() { if (AJAX_RUNNING) return; - if (settings.onsubmit != undefined) { if (settings.onsubmit.preaction != undefined) { settings.onsubmit.preaction(); @@ -2107,7 +2110,7 @@ function load_modal(settings) { } }, error: function(data) { - console.log(data); + //console.log(data); AJAX_RUNNING = 0; } }); @@ -2140,7 +2143,8 @@ function load_modal(settings) { if (id_modal_target != undefined) { $(id_modal_target).remove(); } - } + }, + beforeClose: settings.beforeClose() }); }, error: function(data) { diff --git a/pandora_console/include/javascript/pandora_visual_console.js b/pandora_console/include/javascript/pandora_visual_console.js index 4407a75bb0..f775e5e47e 100755 --- a/pandora_console/include/javascript/pandora_visual_console.js +++ b/pandora_console/include/javascript/pandora_visual_console.js @@ -1344,7 +1344,7 @@ function cleanupDOM() { $("#modalVCItemForm").empty(); } /* Defined in operations/visual_console/view.php */ -/* global $, load_modal */ +/* global $, load_modal, tinyMCE */ function createOrUpdateVisualConsoleItem( visualConsole, asyncTaskManager, @@ -1415,7 +1415,23 @@ function createOrUpdateVisualConsoleItem( }, onsubmit: { page: "include/rest-api/index", - method: "processForm" + method: "processForm", + preaction: function() { + if ( + tinyMCE != undefined && + tinyMCE.editors.length > 0 && + item.itemProps.type != 12 && + item.itemProps.type != 13 + ) { + // Content tiny. + var label = tinyMCE.activeEditor.getContent(); + $("#textarea_label").val(label); + } + } + }, + beforeClose: function() { + tinyMCE.remove("#textarea_label"); + tinyMCE.execCommand("mceRemoveControl", true, "textarea_label"); } }); diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index f7e1575ea3..e9227c9ed4 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -1899,7 +1899,6 @@ class Item extends CachedModel switch ($values['tabSelected']) { case 'label': // Label. - // TODO tinyMCE. $inputs[] = ['label' => __('Label')]; $inputs[] = [ @@ -1913,6 +1912,25 @@ class Item extends CachedModel 'return' => true, ], ]; + + // Label Position. + $fields = [ + 'down' => __('Bottom'), + 'up' => __('Top'), + 'right' => __('Right'), + 'left' => __('Left'), + ]; + + $inputs[] = [ + 'label' => __('Label position'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'name' => 'labelPosition', + 'selected' => $values['labelPosition'], + 'return' => true, + ], + ]; break; case 'general': @@ -2401,8 +2419,10 @@ class Item extends CachedModel * * @return string Html images. */ - static function imagesElementsVC(string $image, ?bool $only=false):string - { + public static function imagesElementsVC( + string $image, + ?bool $only=false + ):string { $type_image = ['']; if ($only === false) { $type_image = [ diff --git a/pandora_console/include/rest-api/models/VisualConsole/View.php b/pandora_console/include/rest-api/models/VisualConsole/View.php index 77efaaec4c..5ae8193ded 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/View.php +++ b/pandora_console/include/rest-api/models/VisualConsole/View.php @@ -92,7 +92,7 @@ class View extends \HTML 'img' => 'pencil.png', ], ]; - } else if ($type === LINE_ITEM) { + } else if ($type === LINE_ITEM || $type === BOX_ITEM) { $tabs = [ [ 'name' => __('Specific settings'), @@ -126,41 +126,43 @@ class View extends \HTML }); }, load: function( event, ui ) { - console.log(event); - console.log(ui); - tinymce.init({ - selector: "#textarea_label", - theme: "advanced", - //content_css: baseUrl + "include/styles/pandora.css", - theme_advanced_font_sizes: - "4pt=.visual_font_size_4pt, " + - "6pt=.visual_font_size_6pt, " + - "8pt=.visual_font_size_8pt, " + - "10pt=.visual_font_size_10pt, " + - "12pt=.visual_font_size_12pt, " + - "14pt=.visual_font_size_14pt, " + - "18pt=.visual_font_size_18pt, " + - "24pt=.visual_font_size_24pt, " + - "28pt=.visual_font_size_28pt, " + - "36pt=.visual_font_size_36pt, " + - "48pt=.visual_font_size_48pt, " + - "60pt=.visual_font_size_60pt, " + - "72pt=.visual_font_size_72pt, " + - "84pt=.visual_font_size_84pt, " + - "96pt=.visual_font_size_96pt, " + - "116pt=.visual_font_size_116pt, " + - "128pt=.visual_font_size_128pt, " + - "140pt=.visual_font_size_140pt, " + - "154pt=.visual_font_size_154pt, " + - "196pt=.visual_font_size_196pt", - theme_advanced_toolbar_location: "top", - theme_advanced_toolbar_align: "left", - theme_advanced_buttons1: - "bold,italic, |,justifyleft, justifycenter, justifyright, |, undo, redo, |, image, link, |, fontselect, forecolor, fontsizeselect, |,code", - theme_advanced_buttons2: "", - theme_advanced_buttons3: "", - theme_advanced_statusbar_location: "none" - }); + var active = $( "#html-tabs" ).tabs( "option", "active" ); + if (active === 0 && tinyMCE.editors.length == 0) { + // Initialice. + tinyMCE.init({ + selector: "#textarea_label", + theme: "advanced", + content_css: "'.ui_get_full_url(false, false, false, false).'include/styles/pandora.css", + theme_advanced_font_sizes: + "4pt=.visual_font_size_4pt, " + + "6pt=.visual_font_size_6pt, " + + "8pt=.visual_font_size_8pt, " + + "10pt=.visual_font_size_10pt, " + + "12pt=.visual_font_size_12pt, " + + "14pt=.visual_font_size_14pt, " + + "18pt=.visual_font_size_18pt, " + + "24pt=.visual_font_size_24pt, " + + "28pt=.visual_font_size_28pt, " + + "36pt=.visual_font_size_36pt, " + + "48pt=.visual_font_size_48pt, " + + "60pt=.visual_font_size_60pt, " + + "72pt=.visual_font_size_72pt, " + + "84pt=.visual_font_size_84pt, " + + "96pt=.visual_font_size_96pt, " + + "116pt=.visual_font_size_116pt, " + + "128pt=.visual_font_size_128pt, " + + "140pt=.visual_font_size_140pt, " + + "154pt=.visual_font_size_154pt, " + + "196pt=.visual_font_size_196pt", + theme_advanced_toolbar_location: "top", + theme_advanced_toolbar_align: "left", + theme_advanced_buttons1: + "bold,italic, |,justifyleft, justifycenter, justifyright, |, undo, redo, |, image, link, |, fontselect, forecolor, fontsizeselect, |,code", + theme_advanced_buttons2: "", + theme_advanced_buttons3: "", + theme_advanced_statusbar_location: "none" + }); + } }, active: 2 });'; @@ -255,6 +257,7 @@ class View extends \HTML // Page Label for each item. $data['label'] = \get_parameter('label'); + $data['labelPosition'] = \get_parameter('labelPosition'); // Page general for each item. $tabGeneral = (bool) \get_parameter('tabGeneral', false); @@ -353,18 +356,10 @@ class View extends \HTML $data['moduleId'] = \get_parameter('moduleId'); break; - case LABEL: - // Nothing. no specific items. - break; - case ICON: $data['imageSrc'] = \get_parameter('imageSrc'); break; - case SERVICE: - // TODO:Enterprise item. It may not exist. - break; - case GROUP_ITEM: $data['imageSrc'] = \get_parameter('imageSrc'); $data['showStatistics'] = \get_parameter_switch( @@ -423,6 +418,11 @@ class View extends \HTML // TODO:XXX. break; + case SERVICE: + // TODO:Enterprise item. It may not exist. + break; + + case LABEL: default: // Not posible. break;