1
0
Fork 0
wmdeit_kaform/kaform.js

405 lines
8.8 KiB
JavaScript
Raw Normal View History

2020-02-20 13:45:47 +00:00
var currentRowId=1;
2020-02-28 15:04:43 +00:00
var banktype = "bank-eu";
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
}
return i;
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;
}
function disableCurrency()
{
if (countRows()>0){
document.getElementById("a_currency").disabled=true;
}
else {
2020-03-09 15:18:28 +00:00
document.getElementById("a_currency").disabled=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);
disableCurrency();
2020-02-20 13:45:47 +00:00
renumberTableRows();
// alert(rowId);
2020-02-20 13:45:47 +00:00
}
function countRows(){
var ctr=0;
for (i=0; i<currentRowId; i++){
var element = document.getElementById("trow"+i);
if (element)
ctr++
}
return ctr;
}
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;
}
*/
2020-03-06 16:46:15 +00:00
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}
// <input type="hidden" name="type[${currentRowId}]" value="${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}
<input type="hidden" name="date[${currentRowId}]" value="${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}
<input type="hidden" name="description[${currentRowId}]" value="${a_description}" /></td>`;
2020-02-20 13:45:47 +00:00
// add column for num
e += `<td>${a_amount}
<input type="hidden" name="amount[${currentRowId}]" value="${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>
*/
2020-03-06 12:32:24 +00:00
e += `<td>${a_currency}
<input type="hidden" name="currency[${currentRowId}]" value="${a_currency}" /></td>
</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();
disableCurrency();
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)
{
2020-02-28 15:04:43 +00:00
console.log('Tab box is ',sender.getActiveBox().nodes[0]);
banktype = sender.getActiveBox().nodes[0].attributes.id.value;
console.log(banktype);
// console.log(sender);
// 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();
function check_field(fieldid,message){
var f = document.getElementById(fieldid).value;
if (! f.trim().length ) {
document.getElementById(fieldid).focus();
showAlert(message)
return false;
}
return true;
}
2020-02-20 13:45:47 +00:00
// add on table row
2020-02-24 15:54:42 +00:00
//addTableRow();
//
//
//
2020-03-09 15:18:28 +00:00
//
function downloadDocument2(){
downloadDocument(true);
}
function downloadDocument1(){
downloadDocument(false);
}
function downloadDocument(mail)
{
2020-03-06 09:03:43 +00:00
/* if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
return;
2020-03-06 09:03:43 +00:00
*/ if (!check_field("realname", "Bitte gib deinen Realnamen an!"))
return;
if (!check_field("email", "Bitte gib deinen E-Mail-Adresse an!"))
return;
if (!check_field("projectid", "Bitte gib idie Projekt-ID an!"))
return;
if (countRows()==0){
2020-03-06 10:01:40 +00:00
document.getElementById("a_description").focus();
showAlert("Bitte f&uuml;ge mind. eine Auslage hinzu!");
return;
}
2020-02-28 15:04:43 +00:00
if (banktype == "bank-eu"){
iban = document.getElementById('iban');
if (!IBAN.isValid(iban.value)){
document.getElementById("iban").focus();
showAlert("Bitte gib eine korrekte IBAN ein!");
return;
}
2020-04-16 06:09:45 +00:00
/* if (!document.getElementById('bic').value.trim().length){
document.getElementById("bic").focus();
2020-04-16 06:09:45 +00:00
showAlert("Bitte gib einen korrekte BIC an!");
2020-02-28 15:04:43 +00:00
return;
}
2020-04-16 06:09:45 +00:00
*/
2020-02-28 15:04:43 +00:00
}
if (banktype == "bank-paypal"){
ii = document.getElementById('paypal');
if (!document.getElementById('paypal').value.trim().length){
document.getElementById("paypal").focus();
showAlert("Bitte gib einen PayPal Account an!");
return;
}
}
2020-03-06 16:46:15 +00:00
if (!document.getElementById("agree").checked){
document.getElementById("agree").focus();
showAlert("Bitte best&auml;tige, dass du alle Angaben nach bestem Wissen und Gewissen gemacht hast!");
return;
};
2020-03-09 15:18:28 +00:00
if (mail){
document.getElementById('sendmail').value="yes";
}
else{
document.getElementById('sendmail').value="no";
}
2020-02-28 15:04:43 +00:00
document.getElementById('banktype').value=banktype;
document.getElementById("theform").submit();
}
2020-02-28 15:04:43 +00:00
/*
function checkIban()
{
iban = document.getElementById('iban');
if(IBAN.isValid(iban.value))
if( document.getElementById('eu').checked ) {
if(IBAN.isValid(iban.value))
{
if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
iban.classList.add('valid');
}
else {
if(iban.classList.contains('valid')) iban.classList.remove('valid');
iban.classList.add('invalid');
}
} else {
if(iban.classList.contains('invalid')) iban.classList.remove('invalid');
if(iban.classList.contains('valid')) iban.classList.remove('valid');
}
}
*/