From ceb15c426f081e89608c31d625d71759aff5e072 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Mon, 26 Feb 2018 22:37:12 +0000 Subject: [PATCH] Sender aendern und DbApi --- src/java/de/uhilger/radiozentrale/api/DbApi.java | 31 +++++++++++++++ src/java/de/uhilger/radiozentrale/api/SenderApi.java | 24 +++++------- web/app.js | 14 ++++++ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/java/de/uhilger/radiozentrale/api/DbApi.java b/src/java/de/uhilger/radiozentrale/api/DbApi.java new file mode 100644 index 0000000..1fd13e5 --- /dev/null +++ b/src/java/de/uhilger/radiozentrale/api/DbApi.java @@ -0,0 +1,31 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.uhilger.radiozentrale.api; + +import de.uhilger.baselink.GenericRecord; +import de.uhilger.baselink.PersistenceManager; +import java.util.List; + +/** + * + */ +public abstract class DbApi extends Api { + + public static final String SQL_GET_NEXT_KEY = "getNextKey"; + public static final String SQL_INCREMENT_KEY = "incrementKey"; + + protected int getNextId(PersistenceManager db, String key) { + int nextKey = -1; + List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, key); + if(list != null && list.size() > 1) { + nextKey = Integer.parseInt(list.get(1).get(0)); // erster Datensatz ist Ueberschrift + if(nextKey > -1) { + db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, key, nextKey); + } + } + return nextKey; + } +} diff --git a/src/java/de/uhilger/radiozentrale/api/SenderApi.java b/src/java/de/uhilger/radiozentrale/api/SenderApi.java index 728ffad..3b8616a 100644 --- a/src/java/de/uhilger/radiozentrale/api/SenderApi.java +++ b/src/java/de/uhilger/radiozentrale/api/SenderApi.java @@ -28,11 +28,9 @@ /** * */ -public class SenderApi extends Api { +public class SenderApi extends DbApi { public static final String SQL_GET_SENDER = "getSender"; - public static final String SQL_GET_NEXT_KEY = "getNextKey"; - public static final String SQL_INCREMENT_KEY = "incrementKey"; public static final String KEY_SENDER_ID = "sender_id"; @@ -56,19 +54,17 @@ return neuerSender; } + public Sender senderAendern(Sender sender) { + Sender geaendert = null; + Object o = getDb().update(sender, getMapper(Initialiser.MP_SENDER)); + if(o instanceof Sender) { + geaendert = (Sender) o; + } + return geaendert; + } + public List senderliste() { return getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER)); } - private int getNextId(PersistenceManager db, String key) { - int nextKey = -1; - List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, key); - if(list != null && list.size() > 1) { - nextKey = Integer.parseInt(list.get(1).get(0)); // erster Datensatz ist Ueberschrift - if(nextKey > -1) { - db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, key, nextKey); - } - } - return nextKey; - } } diff --git a/web/app.js b/web/app.js index 4670e93..e2a07e8 100644 --- a/web/app.js +++ b/web/app.js @@ -203,7 +203,11 @@ ); $('#sender-speichern').on('click', function() { $('#sender-speichern').off('click'); - app_kachel_anpassen(app_sender_dialog_lesen(senderId)); + var sender = app_sender_dialog_lesen(senderId); + + app_sender_aendern(sender); + + app_kachel_anpassen(sender); app_dialog_schliessen(); app_meldung_mit_timeout('Speichern gewaehlt', 1500); }); @@ -467,6 +471,14 @@ }, "json"); } +function app_sender_aendern(sender) { + var obj = serialisieren(sender); + var url = 'api?c=de.uhilger.radiozentrale.api.SenderApi&m=senderAendern'; + $.post( url, 'p=' + obj, function( result ) { + console.log( result ); + }, "json"); +} + /* Hilfsfunktionen */ function serialisieren(obj) { -- Gitblit v1.9.3