WIP: At this point, PEN form is operative and functional
This commit is contained in:
parent
86cbecc9a0
commit
2b21266a38
|
@ -45,11 +45,6 @@ try {
|
|||
<script>
|
||||
|
||||
function SendPENsAjax(action, id, number, manufacturer, description){
|
||||
console.log(action);
|
||||
console.log(id);
|
||||
console.log(number);
|
||||
console.log(manufacturer);
|
||||
console.log(description);
|
||||
$.ajax({
|
||||
async: true,
|
||||
type: "POST",
|
||||
|
@ -63,44 +58,39 @@ try {
|
|||
pen_description: description,
|
||||
},
|
||||
success: function(d) {
|
||||
console.log(d);
|
||||
console.log(action);
|
||||
if (action == 'add' || action == 'delete') {
|
||||
$('#main_table_area').html(d);
|
||||
} else {
|
||||
$('#message_show_area').html(d);
|
||||
}
|
||||
},
|
||||
error: function(d) {
|
||||
alert('Something goes wrong! -> '+String(data));
|
||||
alert('Failed trying update database! -> '+String(data)); // True, must change the message
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function deletePEN(e){
|
||||
var action = 'delete';
|
||||
var pen_id = e.target.value;
|
||||
SendPENsAjax(action, '2', pen_id, '', '');
|
||||
}
|
||||
|
||||
function addNewPEN(){
|
||||
var action = 'add';
|
||||
var pen_id = '2';
|
||||
var pen_id = '2'; // Temporary solution
|
||||
var success = true;
|
||||
var pen_number = $('#text-pen_number');
|
||||
var pen_number_val = pen_number.val();
|
||||
var pen_manufacturer = $('#text-pen_manufacturer');
|
||||
var pen_manufacturer_val = pen_manufacturer.val();
|
||||
var pen_description = $('#text-pen_description');
|
||||
var pen_description_val = pen_description.val();
|
||||
|
||||
// Test if the data is correct.
|
||||
if (pen_number_val == '' || isNaN(pen_number_val)) {
|
||||
success = false;
|
||||
pen_number.css('border','1px solid red');
|
||||
} else if (pen_manufacturer_val == '') {
|
||||
}
|
||||
if (pen_manufacturer_val == '') {
|
||||
success = false;
|
||||
pen_manufacturer.css('border','1px solid red');
|
||||
} else if (pen_description_val == '') {
|
||||
}
|
||||
if (pen_description_val == '') {
|
||||
pen_description.css('border','1px solid red');
|
||||
} else {
|
||||
}
|
||||
// Number and Manuacturer are enought for save data.
|
||||
if (success) {
|
||||
SendPENsAjax(action, pen_id, pen_number_val, pen_manufacturer_val, pen_description_val);
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +98,8 @@ try {
|
|||
function modifyPENLine(e){
|
||||
var action = 'update';
|
||||
var pen_id = e.target.value;
|
||||
|
||||
var changed = false;
|
||||
// Enable the label for be editable.
|
||||
$("span[id$='_"+pen_id+"']").each(function(){
|
||||
let thisElement = $(this);
|
||||
if (thisElement.attr('contenteditable') === 'false') {
|
||||
|
@ -123,15 +113,21 @@ try {
|
|||
$('#'+e.target.id).attr('src','images/edit.png')
|
||||
}
|
||||
});
|
||||
|
||||
// If select the red pill.
|
||||
if (changed === true) {
|
||||
|
||||
let pen_number = $('#pen_number_'+pen_id).html();
|
||||
let pen_manufacturer = $('#pen_manufacturer_'+pen_id).html();
|
||||
let pen_description = $('#pen_description_'+pen_id).html();
|
||||
|
||||
// Modify the data. // Temporary solution
|
||||
SendPENsAjax(action, '2', pen_number, pen_manufacturer, pen_description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function deletePEN(e){
|
||||
var action = 'delete';
|
||||
var pen_id = e.target.value;
|
||||
//Is not necessary pass more data.
|
||||
SendPENsAjax(action, '2', pen_id, '', '');
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -53,9 +53,9 @@ $pen_id_np = get_parameter('pen_id');
|
|||
$pen_number = get_parameter('pen_number');
|
||||
$pen_manufacturer = get_parameter('pen_manufacturer');
|
||||
$pen_description = get_parameter('pen_description');
|
||||
|
||||
// Set the variables needed here.
|
||||
$configPEN = new ConfigPEN();
|
||||
$message = '';
|
||||
$output = '';
|
||||
// Let's do something.
|
||||
// First, get the current data.
|
||||
|
@ -74,12 +74,12 @@ switch ($action) {
|
|||
]
|
||||
);
|
||||
if ($work === false) {
|
||||
$output = ui_print_error_message(__('Error inserting new PEN'));
|
||||
$message = ui_print_error_message(__('Error inserting new PEN'), '', true);
|
||||
} else {
|
||||
$output = $configPEN->createMainTable();
|
||||
$message = ui_print_success_message(__('PEN added in DB'), '', true);
|
||||
}
|
||||
} else {
|
||||
$output = ui_print_error_message(sprintf(__('The PEN %s exists already'), $pen_number));
|
||||
$message = ui_print_error_message(sprintf(__('The PEN %s exists already'), $pen_number));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -100,12 +100,12 @@ switch ($action) {
|
|||
);
|
||||
|
||||
if ($work === false) {
|
||||
$output = ui_print_error_message(__('Error updating data'));
|
||||
$message = ui_print_error_message(__('Error updating data'));
|
||||
} else {
|
||||
$output = ui_print_success_message(__('PEN updated in DB'));
|
||||
$message = ui_print_success_message(__('PEN updated in DB'));
|
||||
}
|
||||
} else {
|
||||
$output = ui_print_error_message(__('No changes applied'));
|
||||
$message = ui_print_error_message(__('No changes applied'));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -116,9 +116,10 @@ switch ($action) {
|
|||
'tpen',
|
||||
['pen' => $pen_number]
|
||||
);
|
||||
$output = $configPEN->createMainTable();
|
||||
|
||||
$message = ui_print_success_message(__('PEN deleted in DB'), '', true);
|
||||
} else {
|
||||
$output = ui_print_error_message(__('Something goes wrong. Please, retry'));
|
||||
$message = ui_print_error_message(__('Something goes wrong. Please, retry'), '', true);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -127,5 +128,20 @@ switch ($action) {
|
|||
break;
|
||||
}
|
||||
|
||||
// Make the data for return
|
||||
$output = html_print_div(
|
||||
[
|
||||
'id' => 'ajax_message_show',
|
||||
'content' => $message,
|
||||
]
|
||||
);
|
||||
|
||||
$output .= html_print_div(
|
||||
[
|
||||
'id' => 'ajax_main_table',
|
||||
'content' => $configPEN->createMainTable(),
|
||||
]
|
||||
);
|
||||
// Return data.
|
||||
return $output;
|
||||
echo $output;
|
||||
// return $output;
|
||||
|
|
|
@ -159,7 +159,7 @@ class ConfigPEN extends HTML
|
|||
]
|
||||
);
|
||||
|
||||
ui_pagination($countPENs, false, $this->offset);
|
||||
$output = ui_pagination($countPENs, false, $this->offset, 0, true);
|
||||
// Create the table with Module Block list.
|
||||
$table = new StdClasS();
|
||||
$table->class = 'databox data';
|
||||
|
@ -206,7 +206,7 @@ class ConfigPEN extends HTML
|
|||
true,
|
||||
[
|
||||
'title' => 'Edit',
|
||||
'onclick' => 'javascript:modifyPENLine(event)',
|
||||
'onclick' => 'modifyPENLine(event)',
|
||||
]
|
||||
);
|
||||
$data[4] .= html_print_input_image(
|
||||
|
@ -217,7 +217,7 @@ class ConfigPEN extends HTML
|
|||
true,
|
||||
[
|
||||
'title' => 'Delete PEN',
|
||||
'onclick' => 'if (confirm(\''.__('Are you sure?').'\')) deletePEN(event);',
|
||||
'onclick' => 'if (confirm(\''.sprintf(__('Are you sure to remove the PEN: %s?'), $row['pen']).'\')) deletePEN(event);',
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -239,14 +239,16 @@ class ConfigPEN extends HTML
|
|||
true,
|
||||
[
|
||||
'title' => 'Add new PEN',
|
||||
'onclick' => 'javascript:addNewPEN()',
|
||||
'onclick' => 'addNewPEN()',
|
||||
]
|
||||
);
|
||||
|
||||
// Add last line.
|
||||
array_push($table->data, $data);
|
||||
// Return the entire table.
|
||||
return html_print_table($table, true);
|
||||
$output .= html_print_table($table, true);
|
||||
// $output = 'mis huevos morenos';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue