HOWTO-storageapi 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. HOWTO use Storage API in your content.
  2. Include the following JavaScript function in your content:
  3. --------------------javascript code--------------------
  4. function FindSTAPI(win) {
  5. var g_nFindAPITries = 0;
  6. while ((win.STAPI == null) && (win.parent != null) && (win.parent != win)) {
  7. g_nFindAPITries ++;
  8. if (g_nFindAPITries > 500) {
  9. return null;
  10. }
  11. win = win.parent;
  12. }
  13. return win.STAPI;
  14. }
  15. --------------------javascript code--------------------
  16. This function returns a facade object which has the following methods :
  17. - testCall(message) : outputs message in an alertbox, you can use it to make sure the API is reachable
  18. - getAllUsers : get a list of users info (user ids, usernames, firstnames, lastnames)
  19. Basic storage:
  20. - setValue(sv_key, sv_value): set the given value for the given key for the current user
  21. - getValue(sv_key): get the value stored for the key sv_key for the current user
  22. - getAll(): get all stored key/values pair for the current user
  23. Stack storage (you can store a stack of values instead of a single value for each key):
  24. - stack_push(sv_key, sv_value): push a new value in the stack for sv_key for the current user
  25. - stack_pop(sv_key): pop the most recently pushed value from the sv_key stack for the current user
  26. - stack_length(sv_key): get the number of stacked values for the key sv_key for the current user
  27. - stack_clear(sv_key): erase all values from the storage stack for the key sv_key for the current user
  28. - stack_getAll(sv_key): get all values from the storage stack for the key sv_key for the current user
  29. These storage values have superuser counterparts which allow platform administrators to alter values for any user :
  30. - setValue_user(sv_key, sv_value, user_id)
  31. - getValue(sv_key, user_id)
  32. - getAll(user_id)
  33. - stack_push(sv_key, sv_value, user_id)
  34. - stack_pop(sv_key, sv_value, user_id)
  35. - stack_length(sv_key, user_id)
  36. - stack_clear(sv_key, user_id)
  37. - stack_getAll(sv_key, user_id)