Speichern von globalen Variablen im Plugin

27.06.2024 18:25
#1 Speichern von globalen Variablen im Plugin
TW
Mitglied

Hi ihr

Ich arbeite mich langsam in die Plugins ein, doch scheitere gerade grandios beim Speichern von globalen Variablen. In der Dokumentation konnte ich schon entnehmen, dass ich wahrscheinlich den callback brauche, da ich was im "Einstellungen - Profil editieren" speichern möchte, was dann im "Mitglieder Profil" angezeigt werden soll.

Das zugehörige Textfeld hab ich mir dazu schon auch einfach von den bestehenden aus dem Template 'geklaut', das funktioniert einwandfrei. Allerdings verschwindet der eingegebene Text immer, nachdem ich auf speichern gedrückt habe.

Das wäre mein aktueller Code von "Einstellungen - Profil editieren"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
<br><hr>
<table width="99%"><tr><td><b class="grey">Quote</b></td>
<td width="75%"><input type="text" style="width: 99%;" class="inputbox" id="theglobal">
</td></tr>
<br>
</table>
 

 
<script>
function saveGlobal(){
var newval = $("#theglobal").val();
xobor.plugin("gifandquote").setGlob("profil_quote_text_globvar",newval,callback);
}

</script>
 



Das im "Mitglieder Profil"

1
2
3
4
5
6
 
<br><img src="XXX" style="max-width: 300px; max-height: 150px; object-fit:cover; padding: 5px;">
<br><div style="padding: 5px;"><b>Quote: </b>{{plugin_gifandquote_global_profil_quote_text_globvar}}
 

</div>
 
 



Ich weiß das das Speichern in der Dokumentation erklärt ist und wahrscheinlich zu den Basics gehört. Doch ich hab jegliche Möglichkeit, die ich in der Doku gefunden habe, versucht und auch so schon außerhalb nach Java Code geguckt. Doch nichts hat geholfen, weswegen ich mal vorsichtig nachfragen wollte, ob mir jemand weiterhelfen kann und mir erklärt, wo mein Fehler liegt bzw auf was ich achten muss etc

Liebe Grüße,

Grace


 Antworten

 Beitrag melden
27.06.2024 20:19
avatar  Mike48
#2 RE: Speichern von globalen Variablen im Plugin
avatar
Mitglied

1. Das <br> in der Tabelle nach unterhalb der Tabelle verlegt.

2. callback gibt es wahrscheinlich nicht als Variable.
Als callback habe ich eine Funktion eingefügt mit einer Variable res die in der Funktion abgefragt werden kann.
res ist true wenn das speichern funktioniert und false bei Fehler.

3. Mit dem Ereignis change wird bei einer Änderung beim Input die Funktion saveGlobal() aufgerufen um die Eingabe zu speichern.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
<br>
<hr>
<table width="99%">
<tr>
<td><b class="grey">Quote</b></td>
<td width="75%"><input type="text" style="width: 99%;" class="inputbox" id="theglobal"></td>
</tr>
</table>
<br>
 
<script>
function saveGlobal(){
var newval = $("#theglobal").val();
xobor.plugin("gifandquote").setGlob("profil_quote_text_globvar",newval,function(res) {
console.log("Globale Var profil_quote_text_globvar speichern: "+res);
});
}
 
$("#theglobal").on('change', function() {
saveGlobal();
});
</script>
 


www.friends-of-xobor.de (621181 - V4 Template)
www.seniorenclub-sel-koeln.de (578865 - V6 Template)

 Antworten

 Beitrag melden
28.06.2024 14:21
#3 RE: Speichern von globalen Variablen im Plugin
TW
Mitglied

Hi @Mike48

erst einmal vielen Dank für deine Hilfe. Das hat hervorragend funktioniert und ich konnte es so umsetzen wie geplant

Allerdings habe ich festgestellt, dass ich statt einer 'Globalen Variable' eine 'Data Variable' brauche, da die Informationen je Profil abgespeichert werden müssen. Per Globale Variable wurde so schließlich immer die Version verwendet, die als letztes von einem Mitgleid abgespeichert wurde, womit man überall das gleiche in den Profilen hat. Was nicht Sinn der Sache ist.

Durch die 'Data Variablen' bin ich erneut auf ein Problem gestoßen. Gleiches Thema, andere Variablen.
Aus den Guide, deinen vorherigen Code und teilweise aus alten Beiträgen von dir konnte ich mir diesen Code zusammenbasteln:

"Einstellungen - Profil editieren":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
<br>
<hr>
<table width="99%">
<tr>
<td><b class="grey">Quote</b></td>
<td width="75%">{{profile_quote_noedit==true.start}} {{profile_quote==true.start}} {{profile_quote_datavar}} {{profile_quote==true.else}}{[userprofile_locked_and_empty]}{{profile_quote==true.end}}
{{profile_quote_noedit==true.else}}<input type="text" style="width: 99%;" class="inputbox" id="theglobal" name="profile_quote" value="{{profile_quote_datavar}}"></td>{{profile_quote_noedit==true.end}}
</tr>
</table>
<br>
 
<script>
function saveGlobal(){
var newval = $("#theglobal").val();

xobor.plugin("gifandquote").setDataVar('profile_quote_datavar', 3, {{userid}}, newval, function(res) {console.log("Globale Var profile_quote_datavar speichern: "+res);}, {{userid}} );
}

$("#theglobal").on('change', function() {
saveGlobal();
});
</script>
 



Für das Mitgliederprofil habe ich aktuell nur das:

1
2
3
4
5
6
 
<br><img src="{{plugin_gifandquote_global_profile_gif_globvar}}" style="max-width: 300px; max-height: 150px; object-fit:cover; padding: 5px;">
<br><div style="padding: 5px;">{{profile_quote_datavar==true.start}}<b>Quote: </b>"{{profile_quote_datavar}}"{{profile_quote_datavar==true.else}} {{profile_quote_datavar==true.end}}
 
xobor.plugin("gifandquote").getDataVar('profile_quote_datavar', 3, {{userid}}, function(res) {profile_quote_datavar=res;}, {userid}} );
 
</div>
 



Meine Problematik ist aktuell folgende:
- ich weiß nicht, wie ich die 'Data Variable' lesen soll
- da ich sie nicht ausspielen kann, kann ich aktuell leider auch noch nicht überprüfen, ob die Speicherfunktion funktioniert

Wäre super wenn du mir da noch einmal helfen könntest. Ich denke mit diesem Wissen bin ich dann auf einem guten Weg auch andere Ideen umzusetzen, da damit ja ein Grundbaustein gelegt ist mit dem man gut arbeiten kann

Viele Grüße,

Grace


 Antworten

 Beitrag melden
28.06.2024 16:54
avatar  Mike48
#4 RE: Speichern von globalen Variablen im Plugin
avatar
Mitglied

Bei dataVar gibt es kein TPL-Code zum lesen und speichern. Das geht nur mit JS.
Also {{profile_quote_datavar}} gibt es nicht, es sei denn du legst sie extra an.

1
2
3
 
// variable profile_quote_datavar anlegen
{{profile_quote_datavar==start}}Mike48{{profile_quote_datavar==end}}
// sie den den Wert [b]Mike48[/b]
 


Das lezte {{userid}} ist nur nötig bei userseparated Variablen.
Da du die Var im User-Profil anlegst ist sie ja schon User userseparated.
Beim starten des Plugin wird die dataVar im sessionstorage abgelegt.
Da kannst du in den Entwickler-Tools nachschauen was darin gespeichert ist.
Den Code habe ich nicht getestet. Probier mal.

<br>
<hr>
<table width="99%">
<tr>
<td><b class="grey">Quote</b></td>
<td width="75%">{[userprofile_locked_and_empty]} <input type="text" style="width: 99%;" class="inputbox" id="theglobal" name="profile_quote" value=""></td>
</tr>
</table>
<br>

<script>
var plugin_gifandquote = new function() { // begin - kapselung
var self = this;
self.tmp_profile_quote_datavar = "";

function saveGlobal() {
var newval = $("#theglobal").val();
xobor.plugin("gifandquote").setDataVar('profile_quote_datavar', 3, {{userid}}, newval, function(res) {
console.log("Globale Var profile_quote_datavar speichern: "+res);
});
} // end - self.saveGlobal()

self.run = function() {
xobor.plugin("gifandquote").getDataVar('profile_quote_datavar', 3, {{userid}}, function(res){
if(res) {
self.tmp_profile_quote_datavar = res;
$('#theglobal').val(self.tmp_profile_quote_datavar);

xobor.plugin("gifandquote").sessionstorage.set('profile_quote_datavar', profile_quote_datavar);
}
}};
}; // end - run

$("#theglobal").on('change', function() {
saveGlobal();
});

} // end - kapselung

plugin_gifandquote.run(); // start - plugin

</script>

1
 

 


www.friends-of-xobor.de (621181 - V4 Template)
www.seniorenclub-sel-koeln.de (578865 - V6 Template)

 Antworten

 Beitrag melden
28.06.2024 17:28 (zuletzt bearbeitet: 28.06.2024 17:29)
avatar  Olaf
#5 RE: Speichern von globalen Variablen im Plugin
Ol
Mitglied

Zitat von Mike48 im Beitrag #4

1
2
3
 
// variable profile_quote_datavar anlegen
{{profile_quote_datavar==start}}Mike48{{profile_quote_datavar==end}}
// sie den den Wert [b]Mike48[/b]
 





Ich meine,eine Variable wird so angelegt:

1
2
3
 
// variable profile_quote_datavar anlegen
{{profile_quote_datavar.start}}Mike48{{profile_quote_datavar.end}}
// sie den den Wert [b]Mike48[/b]
 



Ansonsten wäre es eine Abfrage.

Gruß
Olaf

__________________________

http://138600.homepagemodules.de/

 Antworten

 Beitrag melden
28.06.2024 17:29
avatar  Mike48
#6 RE: Speichern von globalen Variablen im Plugin
avatar
Mitglied

Stimmt. Fehler von mir.


www.friends-of-xobor.de (621181 - V4 Template)
www.seniorenclub-sel-koeln.de (578865 - V6 Template)

 Antworten

 Beitrag melden
28.06.2024 17:36
#7 RE: Speichern von globalen Variablen im Plugin
TW
Mitglied

Hi Mike,

als allererstes, ich habe es gerade erst gesehen: Alles Gute zum Geburtstag! Lass dich schön feiern zu deinem Ehrentag!

Danke für deine Hilfe und auch dir Olaf. Ich werde mich gleich mal ans Plugin setzen und es ausprobieren. Allerdings schon jetzt direkt eine Frage, da es sich mir leider noch nicht erschließt.

Wenn ich keine TPL-Codes nutzen kann, wie kann ich die Data Variable abrufen, sodass im Profil angezeigt wird, was man im Edit Mode vom Profil gespeichert hat?
Oder geht es mit folgenden Code dann:

1
 
{{profile_quote_datavar.start}}<input type="text" style="width: 99%;" class="inputbox" id="theglobal" name="profile_quote" value="">{{profile_quote_datavar.end}}
 



Sodass dann das, was ins Textfeld geschrieben wird, in der neu angelegten Data Variable gespeichert wird, die man schlussendlich im Mitglieder Profil ebenso aufrufen kann.

Viele Grüße,

Grace


 Antworten

 Beitrag melden
28.06.2024 17:40 (zuletzt bearbeitet: 28.06.2024 17:58)
avatar  Mike48
#8 RE: Speichern von globalen Variablen im Plugin
avatar
Mitglied

Zitat von TWD_Grace im Beitrag #7
Wenn ich keine TPL-Codes nutzen kann, wie kann ich die Data Variable abrufen, sodass im Profil angezeigt wird, was man im Edit Mode vom Profil gespeichert hat?

1
2
3
4
5
 
      xobor.plugin("gifandquote").getDataVar('profile_quote_datavar', 3, {{user_id}}, function(res){
if(res) {
$('#theglobal').val(res);
}
}};
 



Wenn du Pimplugin eien dataVar einfügst wird dir nur JS angeboten, kein TPL.

Mir ist noch aufgefallen das die Variable für die User-id eventuell falsch sein könnte.
{{user_id}} ist für die eigene id mit der man eingeloggt ist.
{{userid}} ist für die fremde, also die User-id von dem User wo man gerade auf dem Profil ist.
Ich weiß nicht was du bezweckst.


www.friends-of-xobor.de (621181 - V4 Template)
www.seniorenclub-sel-koeln.de (578865 - V6 Template)

 Antworten

 Beitrag melden
28.06.2024 18:03
#9 RE: Speichern von globalen Variablen im Plugin
TW
Mitglied

Ich hab den Code einmal in "Einstellungen - Profil editieren" eingefügt und den von deiner letzten Nachricht in "Mitglieder Profil".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
<br>
<hr>
<table width="99%">
<tr>
<td><b class="grey">Quote</b></td>
<td width="75%"><input type="text" style="width: 99%;" class="inputbox" id="theglobal" name="profile_quote" value=""></td>
</tr>
</table>
<br>
 
<script>
var plugin_gifandquote = new function() { // begin - kapselung
var self = this;
self.tmp_profile_quote_datavar = "";
 
function saveGlobal() {
var newval = $("#theglobal").val();
xobor.plugin("gifandquote").setDataVar('profile_quote_datavar', 3, {{userid}}, newval, function(res) {
console.log("Globale Var profile_quote_datavar speichern: "+res);
});
} // end - self.saveGlobal()
 
self.run = function() {
xobor.plugin("gifandquote").getDataVar('profile_quote_datavar', 3, {{userid}}, function(res){
if(res) {
self.tmp_profile_quote_datavar = res;
$('#theglobal').val(self.tmp_profile_quote_datavar);
 
xobor.plugin("gifandquote").sessionstorage.set('profile_quote_datavar', profile_quote_datavar);
}
}};
}; // end - run
 
$("#theglobal").on('change', function() {
saveGlobal();
});
 
} // end - kapselung
 
plugin_gifandquote.run(); // start - plugin
 
</script>
 
 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
<br><img src="{{plugin_gifandquote_global_profile_gif_globvar}}" style="max-width: 300px; max-height: 150px; object-fit:cover; padding: 5px;">
<br><div style="padding: 5px;">{{profile_quote_datavar==true.start}}<b>Quote: </b> xobor.plugin("gifandquote").getDataVar('profile_quote_datavar', 3, {{userid}}, function(res){
if(res) {
$('#theglobal').val(res);
}
}};
 

 
</div>
 

<script>
var plugin_gifandquote = new function() { // begin - kapselung
var self = this;
self.tmp_profile_quote_datavar = "";
 
function saveGlobal() {
var newval = $("#theglobal").val();
xobor.plugin("gifandquote").setDataVar('profile_quote_datavar', 3, {{userid}}, newval, function(res) {
console.log("Globale Var profile_quote_datavar speichern: "+res);
});
} // end - self.saveGlobal()
 
self.run = function() {
xobor.plugin("gifandquote").getDataVar('profile_quote_datavar', 3, {{userid}}, function(res){
if(res) {
self.tmp_profile_quote_datavar = res;
$('#theglobal').val(self.tmp_profile_quote_datavar);
 
xobor.plugin("gifandquote").sessionstorage.set('profile_quote_datavar', profile_quote_datavar);
}
}};
}; // end - run
 
$("#theglobal").on('change', function() {
saveGlobal();
});
 
} // end - kapselung
 
plugin_gifandquote.run(); // start - plugin
 
</script>
 



Wenn ich das Profil bearbeite und was in das Textfeld eigebe und speichere, dann wir mir leider nichts angezeigt - außer der Code von deiner letzten Nachricht als Text. Woran kann das liegen?


 Antworten

 Beitrag melden
Bereits Mitglied?
Jetzt anmelden!
Mitglied werden?
Jetzt registrieren!