Now the alert action command fields can have a HTML wysiwyg editor

This commit is contained in:
Alejandro Gallardo Escobar 2015-02-04 16:52:20 +01:00
parent 031cb3a3a0
commit a3783f70e1
4 changed files with 106 additions and 49 deletions

View File

@ -65,8 +65,12 @@ if (is_ajax ()) {
$fields_rows = array(); $fields_rows = array();
for ($i = 1; $i <= 10; $i++) { for ($i = 1; $i <= 10; $i++) {
if (!empty($fields_descriptions[$i - 1])) {
$fdesc = $fields_descriptions[$i - 1] . $field_description = $fields_descriptions[$i - 1];
$field_value = $fields_values[$i - 1];
if (!empty($field_description)) {
$fdesc = $field_description .
' <br><span style="font-size:xx-small; font-weight:normal;">' . sprintf(__('Field %s'), $i) . '</span>'; ' <br><span style="font-size:xx-small; font-weight:normal;">' . sprintf(__('Field %s'), $i) . '</span>';
} }
else { else {
@ -79,22 +83,53 @@ if (is_ajax ()) {
} }
} }
if (!empty($fields_values[$i-1])) { if (!empty($field_value)) {
$fields_value_select = array(); $field_value = io_safe_output($field_value);
$fv = $fields_values[$i-1]; // HTML type
$fv = explode(';', $fv); if (preg_match ("/^_html_editor_$/i", $field_value)) {
if (empty($fv)) { $editor_type_chkbx = "<div style=\"padding: 4px 0px;\"><b><small>";
$fv = array(); $editor_type_chkbx .= __('Basic') . "&nbsp;&nbsp;";
$editor_type_chkbx .= html_print_radio_button_extended ('editor_type_value_'.$i, 0, '', false, false, "removeTinyMCE('textarea_field".$i."_value')", '', true);
$editor_type_chkbx .= "&nbsp;&nbsp;&nbsp;&nbsp;";
$editor_type_chkbx .= __('Advanced') . "&nbsp;&nbsp;";
$editor_type_chkbx .= html_print_radio_button_extended ('editor_type_value_'.$i, 0, '', true, false, "addTinyMCE('textarea_field".$i."_value')", '', true);
$editor_type_chkbx .= "</small></b></div>";
$ffield = $editor_type_chkbx;
$ffield .= html_print_textarea ('field'.$i.'_value', 1, 1, '', 'class="fields"', true);
$editor_type_chkbx = "<div style=\"padding: 4px 0px;\"><b><small>";
$editor_type_chkbx .= __('Basic') . "&nbsp;&nbsp;";
$editor_type_chkbx .= html_print_radio_button_extended ('editor_type_recovery_value_'.$i, 0, '', false, false, "removeTinyMCE('textarea_field".$i."_recovery_value')", '', true);
$editor_type_chkbx .= "&nbsp;&nbsp;&nbsp;&nbsp;";
$editor_type_chkbx .= __('Advanced') . "&nbsp;&nbsp;";
$editor_type_chkbx .= html_print_radio_button_extended ('editor_type_recovery_value_'.$i, 0, '', true, false, "addTinyMCE('textarea_field".$i."_recovery_value')", '', true);
$editor_type_chkbx .= "</small></b></div>";
$rfield = $editor_type_chkbx;
$rfield .= html_print_textarea ('field'.$i.'_recovery_value', 1, 1, '', 'class="fields_recovery"', true);
} }
// Select type
foreach ($fv as $fv_option) { else {
$fv_option = explode(',', $fv_option); $fields_value_select = array();
$fields_value_select[$fv_option[0]] = $fv_option[1]; $fv = explode(';', $field_value);
if (!empty($fv)) {
foreach ($fv as $fv_option) {
$fv_option = explode(',', $fv_option);
if (empty($fv_option))
continue;
if (!isset($fv_option[1]))
$fv_option[1] = $fv_option[0];
$fields_value_select[$fv_option[0]] = $fv_option[1];
}
}
$ffield = html_print_select($fields_value_select, 'field'.$i.'_value', '', '', '', 0, true, false, false);
$rfield = html_print_select($fields_value_select, 'field'.$i.'_recovery_value', '', '', '', 0, true, false, false);
} }
$ffield = html_print_select($fields_value_select, 'field'.$i.'_value', '', '', '', 0, true, false, false);
$rfield = html_print_select($fields_value_select, 'field'.$i.'_recovery_value', '', '', '', 0, true, false, false);
} }
else { else {
$ffield = html_print_textarea ('field'.$i.'_value', 1, 1, '', 'style="min-height:40px" class="fields"', true); $ffield = html_print_textarea ('field'.$i.'_value', 1, 1, '', 'style="min-height:40px" class="fields"', true);

View File

@ -199,6 +199,7 @@ echo '</form>';
enterprise_hook('close_meta_frame'); enterprise_hook('close_meta_frame');
ui_require_javascript_file ('pandora_alerts'); ui_require_javascript_file ('pandora_alerts');
ui_require_javascript_file('tiny_mce', 'include/javascript/tiny_mce/');
?> ?>
<script type="text/javascript"> <script type="text/javascript">
@ -238,48 +239,66 @@ $(document).ready (function () {
render_command_preview (original_command); render_command_preview (original_command);
command_description = js_html_entity_decode (data["description"]); command_description = js_html_entity_decode (data["description"]);
render_command_description(command_description); render_command_description(command_description);
for (i = 1; i <= 10; i++) { for (i = 1; i <= 10; i++) {
var old_value = ''; var old_value = '';
var old_recovery_value = ''; var old_recovery_value = '';
var field_row = data["fields_rows"][i]; var field_row = data["fields_rows"][i];
var $table_macros_field = $('#table_macros-field' + i);
// If the row is empty, hide it
if (field_row == '') {
$table_macros_field.hide();
continue;
}
// Only keep the value if is provided from hidden (first time) // Only keep the value if is provided from hidden (first time)
if (($("[name=field" + i + "_value]").attr('id')) if (($("[name=field" + i + "_value]").attr('id'))
== ("hidden-field" + i + "_value")) { == ("hidden-field" + i + "_value")) {
old_value = $("[name=field" + i + "_value]").val(); old_value = $("[name=field" + i + "_value]").val();
} }
if (($("[name=field" + i + "_recovery_value]").attr('id')) if (($("[name=field" + i + "_recovery_value]").attr('id'))
== ("hidden-field" + i + "_recovery_value")) { == ("hidden-field" + i + "_recovery_value")) {
old_recovery_value = $("[name=field" + i + "_recovery_value]").val(); old_recovery_value = $("[name=field" + i + "_recovery_value]").val();
} }
// Replace the old column with the new
$table_macros_field.replaceWith(field_row);
$("[name=field" + i + "_value]").val(old_value);
$("[name=field" + i + "_recovery_value]").val(old_recovery_value);
// If the row is empty, hide de row // Add help hint only in first field
if (field_row == '') { if (i == 1) {
$('#table_macros-field' + i).hide(); var td_content = $table_macros_field.find('td').eq(0);
}
else { $(td_content)
$('#table_macros-field' + i).replaceWith(field_row); .html(
$("[name=field" + i + "_value]").val(old_value); $(td_content).html() + $('#help_alert_macros_hint').html());
$("[name=field" + i + "_recovery_value]").val(old_recovery_value);
// Add help hint only in first field
if (i == 1) {
var td_content = $('#table_macros-field' + i)
.find('td').eq(0);
$(td_content)
.html(
$(td_content).html() + $('#help_alert_macros_hint').html());
}
$('#table_macros-field' + i).show();
} }
$table_macros_field.show();
} }
tinyMCE.init({
selector: 'textarea.tiny-mce-editor',
theme : "advanced",
plugins : "preview, print, table, searchreplace, nonbreaking, xhtmlxtras, noneditable",
theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsize,select",
theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,image,|,cleanup,code,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_resizing : true,
theme_advanced_statusbar_location : "bottom",
force_p_newlines : false,
forced_root_block : '',
inline_styles : true,
valid_children : "+body[style]",
element_format : "html"
});
render_command_preview(original_command); render_command_preview(original_command);
render_command_recovery_preview(original_command); render_command_recovery_preview(original_command);
@ -292,10 +311,7 @@ $(document).ready (function () {
}, },
"json" "json"
); );
}); }).change();
// Charge the fields of the command
$("#id_command").trigger('change');
}); });
</script> </script>

View File

@ -14,3 +14,6 @@ value1,tag1;value2,tag2;value3,tag3
Example: Example:
<br><br> <br><br>
1,Number one;2,Number two;3,Number three;4,Number four 1,Number one;2,Number two;3,Number three;4,Number four
<br><br>
Also is possible to configure the field as a HTML editor by introducing the value <i>_html_editor_</i>.

View File

@ -5,12 +5,15 @@
?> ?>
<h1>Valores de los campos</h1> <h1>Valores de los campos</h1>
Para limitar los valores posibles de un campo, se puede definir una lista de valor/etiqueta. Si esta lista es definida, el campo sera un combo de seleccion. Para limitar los valores posibles de un campo, se puede definir una lista de valor/etiqueta. Si esta lista es definida, el campo será un combo de selección.
<br><br> <br><br>
El formato sera el siguiente: El formato será el siguiente:
<br><br> <br><br>
valor1,etiqueta1;valor2,etiqueta2;valor3,etiqueta3 valor1,etiqueta1;valor2,etiqueta2;valor3,etiqueta3
<br><br> <br><br>
Ejemplo: Ejemplo:
<br><br> <br><br>
1,Numero uno;2,Numero dos;3,Numero tres;4,Numero cuatro 1,Número uno;2,Número dos;3,Número tres;4,Número cuatro
<br><br><br>
También es posible indicar que el campo debe ser un editor de HTML, para lo cual hay que introducir el valor <i>_html_editor_</i>.