2012-07-19 Sergio Martin <sergio.martin@artica.es>

* godmode/modules/manage_network_components_form.php
	godmode/modules/manage_network_components_form_plugin.php: Add 
	first version of dynamic macros in network components of type
	plug-in



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6792 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-07-19 16:44:15 +00:00
parent 68c30b0ce2
commit c5b7b285b4
3 changed files with 117 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2012-07-19 Sergio Martin <sergio.martin@artica.es>
* godmode/modules/manage_network_components_form.php
godmode/modules/manage_network_components_form_plugin.php: Add
first version of dynamic macros in network components of type
plug-in
2012-07-19 Sergio Martin <sergio.martin@artica.es>
* pandoradb.sql

View File

@ -478,4 +478,97 @@ $(document).ready (function () {
type_change ();
<?php endif; ?>
//-->
// Functions to add and remove dynamic fields for macros
function delete_macro() {
var next_row = parseInt($('#next_row').html());
$('#next_row').html(next_row-2);
var next_number = parseInt($('#next_macro').html());
$('#next_macro').html(next_number-1);
var nrow1 = next_row - 2;
var nrow2 = next_row - 1;
var $row1 = $('#network_component-plugin_'+nrow1).remove();
var $row2 = $('#network_component-plugin_'+nrow2).remove();
}
function new_macro() {
var next_row = parseInt($('#next_row').html());
$('#next_row').html(next_row+2);
var nrow1 = next_row - 2;
var nrow2 = next_row - 1;
var nrow3 = next_row;
var nrow4 = next_row + 1;
var next_number = parseInt($('#next_macro').html());
$('#next_macro').html(next_number+1);
var current_number = next_number - 1;
// Clone two last rows
var $row1 = $('#network_component-plugin_'+nrow1).clone(true);
var $row2 = $('#network_component-plugin_'+nrow2).clone(true);
// Change the tr ID
$row1.attr('id','network_component-plugin_'+(nrow3));
$row2.attr('id','network_component-plugin_'+(nrow4));
// Change the td ID
$row1.find('td').attr('id', changeTdId);
$row2.find('td').attr('id', changeTdId);
// Insert after last field
$row2.insertAfter('#network_component-plugin_'+nrow2);
$row1.insertAfter('#network_component-plugin_'+nrow2);
// Change labels
for(i=0;i<=3;i++) {
var label1 = $("#network_component-plugin_"+nrow3+"-"+i).html();
var exp_reg = new RegExp('field'+current_number, 'g');
label1 = label1.replace(exp_reg,'field'+next_number);
$("#network_component-plugin_"+nrow3+"-"+i).html(label1);
}
for(i=0;i<=1;i++) {
var label2 = $("#network_component-plugin_"+nrow4+"-"+i).html();
var exp_reg = new RegExp('field'+current_number, 'g');
label2 = label2.replace(exp_reg,'field'+next_number);
$("#network_component-plugin_"+nrow4+"-"+i).html(label2);
}
// Empty the text inputs
$('#text-field'+next_number+'_desc').val('');
$('#text-field'+next_number+'_help').val('');
$('#text-field'+next_number+'_value').val('');
function changeTdId() {
switch(this.id) {
case 'network_component-plugin_'+(nrow1)+'-0':
return 'network_component-plugin_'+(nrow3)+'-0';
break;
case 'network_component-plugin_'+(nrow1)+'-1':
return 'network_component-plugin_'+(nrow3)+'-1';
break;
case 'network_component-plugin_'+(nrow1)+'-2':
return 'network_component-plugin_'+(nrow3)+'-2';
break;
case 'network_component-plugin_'+(nrow1)+'-3':
return 'network_component-plugin_'+(nrow3)+'-3';
break;
case 'network_component-plugin_'+(nrow2)+'-0':
return 'network_component-plugin_'+(nrow4)+'-0';
break;
case 'network_component-plugin_'+(nrow2)+'-1':
return 'network_component-plugin_'+(nrow4)+'-1';
break;
case 'network_component-plugin_'+(nrow2)+'-2':
return 'network_component-plugin_'+(nrow4)+'-2';
break;
case 'network_component-plugin_'+(nrow2)+'-3':
return 'network_component-plugin_'+(nrow4)+'-3';
break;
}
}
}
</script>

View File

@ -63,7 +63,11 @@ push_table_row ($data, 'plugin_4');
$macros = json_decode($macros,true);
// The next row number is plugin_5
$next_name_number = 5;
for($i=1;$i<=6;$i++) {
$i = 1;
while(1) {
if(!isset($macros[$i]) || $macros[$i]['desc'] == '') {
break;
}
$macro_desc_name = 'field'.$i.'_desc';
$macro_desc_value = '';
$macro_help_name = 'field'.$i.'_help';
@ -97,7 +101,7 @@ for($i=1;$i<=6;$i++) {
push_table_row ($data, 'plugin_'.$next_name_number);
$next_name_number++;
$table->colspan['plugin_'.$next_name_number][1] = 3;
$table->colspan['plugin_'.$next_name_number][1] = 2;
$data = array ();
$data[0] = sprintf(__('Macro %s help'),$macro_name);
@ -106,7 +110,18 @@ for($i=1;$i<=6;$i++) {
push_table_row ($data, 'plugin_'.$next_name_number);
$next_name_number++;
$i++;
}
$table->colspan['plugin_n'][2] = 2;
$data = array ();
$data[0] = '';
$data[1] = __('Add macro').' <a href="javascript:new_macro()">'.html_print_image('images/add.png',true).'</a>';
$data[1] .= '<div id="next_macro" style="display:none">'.$i.'</div>';
$data[1] .= '<div id="next_row" style="display:none">'.$next_name_number.'</div>';
$data[2] = __('Delete macro').' <a href="javascript:delete_macro()">'.html_print_image('images/cancel.png',true).'</a>';
push_table_row ($data, 'plugin_n');
?>