1
0
Fork 0
wmdeit_kaform/kaform.js

246 lines
5.2 KiB
JavaScript
Raw Normal View History

2020-02-20 13:45:47 +00:00
var currentRowId=1;
2020-02-20 13:45:47 +00:00
2020-02-20 13:45:47 +00:00
function renumberTableRows(){
var row_no=1;
var table = document.getElementById("tabbody");
for (var i = 0, row; row = table.rows[i]; i++) {
// row.cells[0].innerHTML=row_no++;
2020-02-20 13:45:47 +00:00
}
}
function isFloat(val) {
var floatRegex = /^-?\d+(?:[.,]\d*?)?$/;
if (!floatRegex.test(val))
return false;
val = parseFloat(val);
if (isNaN(val))
return false;
return true;
}
2020-02-20 13:45:47 +00:00
function deleteTableRow(rowId){
2020-02-20 13:45:47 +00:00
var target = document.getElementById("upload-target"+rowId);
// this.message = app.message;
var children = target.children;
2020-02-20 13:45:47 +00:00
// delete all uploaded elements
/* for (var i = 0; i < children.length; i++) {
2020-02-20 13:45:47 +00:00
var tmp = children[i].getAttribute("data-id");
alert ("DEL");
alert (tmp);
2020-02-20 13:45:47 +00:00
$K.ajax.post({
url: 'delete.php',
data: 'id='+tmp,
before: function(xhr) {},
success: function(response) {},
error: function(response) {}
});
}
*/
2020-02-20 13:45:47 +00:00
// delete the row from table
var element = document.getElementById("trow"+rowId);
2020-02-20 13:45:47 +00:00
element.parentNode.removeChild(element);
renumberTableRows();
// alert(rowId);
}
function showAlert(text) {
$K.app.message.show( { message: `${text}`, position: 'centered', type: 'is-error' });
return;
}
function reset2()
{
document.getElementById("a_type").value="";
document.getElementById("a_description").value="";
document.getElementById("a_amount").value="";
setUploadField();
}
2020-02-20 13:45:47 +00:00
function addTableRow(){
var $node = $K.dom('#tabbody');
// create a new table row with id
var element = document.createElement('tr');
element.setAttribute("id", "trow"+currentRowId);
2020-02-20 13:45:47 +00:00
var a_type = document.getElementById("a_type").value;
if (!a_type.trim().length ) {
document.getElementById("a_type").focus();
showAlert("Bitte gib eine Auslagenart an!");
return;
}
var a_date = document.getElementById("a_date").value;
if (!a_date.trim().length){
document.getElementById("a_date").focus();
showAlert("Bitte gib ein g&uuml;ltiges Datum an!");
return;
}
var a_description = document.getElementById("a_description").value;
if (!a_description.trim().length){
document.getElementById("a_description").focus();
showAlert("Bitte gib eine Beschreibung ein!");
return;
}
var a_amount = document.getElementById("a_amount").value;
if (!isFloat(a_amount)){
document.getElementById("a_amount").focus();
showAlert("Bitte gib einen g&uuml;ltigen Betrag ein!");
return;
}
var a_currency = document.getElementById("a_currency").value;
if (!a_currency.trim().length){
document.getElementById("a_currency").focus();
showAlert("Bitte gib eine W&auml;hrung an!");
return;
}
var target = document.getElementById("upload-target"+currentRowId);
var children = target.children;
if (!children.length){
showAlert("Bitte lade mindestens einen Beleg hoch!");
return;
}
/* a_type = "Hello";*/
2020-02-20 13:45:47 +00:00
var e="";
// add column for position no
e += `<td>${a_type}</td>`;
2020-02-20 13:45:47 +00:00
// add coluemn for a_type (Auslagenart)
// e += `<td><textarea name="desc[${nextRowId}]" rows="2"></textarea> </td>`;
e += `<td>${a_date}</td>`;
2020-02-20 13:45:47 +00:00
// add column for date
// e += `<td><input name="date[${nextRowId}]" type="date"/></td>`;
e += `<td>${a_description}</td>`;
2020-02-20 13:45:47 +00:00
// add column for num
e += `<td>${a_amount}</td>`;
2020-02-20 13:45:47 +00:00
// add column for file upload
/* e+= `
2020-02-20 13:45:47 +00:00
<td data-kube="">
<div class="form-item">
<div class="upload"
data-kube="upload"
data-type="file" data-multiple="true"
data-target="#upload-target${nextRowId}"
data-url="upload.php?row=${nextRowId}" data-url-remove="delete.php"
data-progress="true">
</div>
<div id="upload-target${nextRowId}" class="upload-target"></div>
</div>
</td>
*/
e += `<td>${a_currency}</td>`;
// `;
2020-02-20 13:45:47 +00:00
// add delete bnutton
e +=
`<td><span
onclick="deleteTableRow(${currentRowId})"
2020-02-20 13:45:47 +00:00
class="close is-large">
</span></td>`;
$node.append(element);
element.innerHTML=(e);
// renumberTableRows();
currentRowId++;
reset2();
2020-02-20 13:45:47 +00:00
}
function setUploadField()
{
var e = $K.dom('#uploadfield');
var uf =`<div class="upload"
data-kube="upload"
data-type="file" data-multiple="true"
data-target="#upload-target${currentRowId}"
data-url="upload.php?row=${currentRowId}" data-url-remove="delete.php"
data-progress="true">Beleg hochladen
</div>
<div id="upload-target${currentRowId}" class="upload-target small"></div>
</div>
`;
document.getElementById("uploadfield").innerHTML=uf;
}
2020-02-20 13:45:47 +00:00
2020-02-24 15:54:42 +00:00
$K.add('module', 'kaform', {
init: function(app, context)
{
this.app = app;
this.message = app.message;
2020-02-24 15:54:42 +00:00
},
// catch event
onmessage: {
tabs: {
opened: function(sender)
{
console.log('Tab box is ',sender.getActiveBox());
this.message.show({ message: 'My message' });
}
2020-02-24 15:54:42 +00:00
}
},
2020-02-20 13:45:47 +00:00
2020-02-24 15:54:42 +00:00
});
$K.init({
observer: true
2020-02-20 13:45:47 +00:00
});
// startup is here
// on startup clear session on server
$K.ajax.get({
url: 'clear.php',
data: '', // or key=value object
before: function(xhr) {},
success: function(response) {},
error: function(response) {}
});
setUploadField();
2020-02-20 13:45:47 +00:00
// add on table row
2020-02-24 15:54:42 +00:00
//addTableRow();